@xmtp/agent-sdk 1.2.4 → 1.2.5-rc1
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/debug.d.ts +141 -1
- package/dist/debug.js +85 -2
- package/dist/debug.js.map +1 -1
- package/dist/index.d.ts +176 -4
- package/dist/index.js +703 -5
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +81 -1
- package/dist/middleware.js +59 -2
- package/dist/middleware.js.map +1 -1
- package/dist/user.d.ts +16 -1
- package/dist/user.js +111 -2
- package/dist/user.js.map +1 -1
- package/dist/util.d.ts +46 -1
- package/dist/util.js +74 -2
- package/dist/util.js.map +1 -1
- package/package.json +14 -21
- package/dist/bin/generateKeys.d.ts +0 -2
- package/dist/bin/generateKeys.js +0 -44
- package/dist/bin/generateKeys.js.map +0 -1
- package/dist/core/Agent.d.ts +0 -84
- package/dist/core/Agent.js +0 -394
- package/dist/core/Agent.js.map +0 -1
- package/dist/core/AgentError.d.ts +0 -7
- package/dist/core/AgentError.js +0 -13
- package/dist/core/AgentError.js.map +0 -1
- package/dist/core/ClientContext.d.ts +0 -9
- package/dist/core/ClientContext.js +0 -13
- package/dist/core/ClientContext.js.map +0 -1
- package/dist/core/ConversationContext.d.ts +0 -19
- package/dist/core/ConversationContext.js +0 -43
- package/dist/core/ConversationContext.js.map +0 -1
- package/dist/core/MessageContext.d.ts +0 -33
- package/dist/core/MessageContext.js +0 -75
- package/dist/core/MessageContext.js.map +0 -1
- package/dist/core/filter.d.ts +0 -84
- package/dist/core/filter.js +0 -88
- package/dist/core/filter.js.map +0 -1
- package/dist/core/index.d.ts +0 -6
- package/dist/core/index.js +0 -7
- package/dist/core/index.js.map +0 -1
- package/dist/debug/index.d.ts +0 -1
- package/dist/debug/index.js +0 -2
- package/dist/debug/index.js.map +0 -1
- package/dist/debug/log.d.ts +0 -18
- package/dist/debug/log.js +0 -80
- package/dist/debug/log.js.map +0 -1
- package/dist/middleware/CommandRouter.d.ts +0 -14
- package/dist/middleware/CommandRouter.js +0 -57
- package/dist/middleware/CommandRouter.js.map +0 -1
- package/dist/middleware/index.d.ts +0 -1
- package/dist/middleware/index.js +0 -2
- package/dist/middleware/index.js.map +0 -1
- package/dist/user/NameResolver.d.ts +0 -1
- package/dist/user/NameResolver.js +0 -45
- package/dist/user/NameResolver.js.map +0 -1
- package/dist/user/User.d.ts +0 -10
- package/dist/user/User.js +0 -35
- package/dist/user/User.js.map +0 -1
- package/dist/user/index.d.ts +0 -2
- package/dist/user/index.js +0 -3
- package/dist/user/index.js.map +0 -1
- package/dist/util/AttachmentUtil.d.ts +0 -41
- package/dist/util/AttachmentUtil.js +0 -67
- package/dist/util/AttachmentUtil.js.map +0 -1
- package/dist/util/LimitedMap.d.ts +0 -6
- package/dist/util/LimitedMap.js +0 -20
- package/dist/util/LimitedMap.js.map +0 -1
- package/dist/util/TestUtil.d.ts +0 -35
- package/dist/util/TestUtil.js +0 -83
- package/dist/util/TestUtil.js.map +0 -1
- package/dist/util/index.d.ts +0 -1
- package/dist/util/index.js +0 -2
- package/dist/util/index.js.map +0 -1
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type MarkdownCodec } from "@xmtp/content-type-markdown";
|
|
2
|
-
import type { ContentCodec } from "@xmtp/content-type-primitives";
|
|
3
|
-
import { type Reaction, type ReactionCodec } from "@xmtp/content-type-reaction";
|
|
4
|
-
import type { ReadReceiptCodec } from "@xmtp/content-type-read-receipt";
|
|
5
|
-
import type { RemoteAttachmentCodec } from "@xmtp/content-type-remote-attachment";
|
|
6
|
-
import { type ReplyCodec } from "@xmtp/content-type-reply";
|
|
7
|
-
import { type TextCodec } from "@xmtp/content-type-text";
|
|
8
|
-
import type { TransactionReferenceCodec } from "@xmtp/content-type-transaction-reference";
|
|
9
|
-
import type { WalletSendCallsCodec } from "@xmtp/content-type-wallet-send-calls";
|
|
10
|
-
import { type DecodedMessageWithContent } from "../core/filter.js";
|
|
11
|
-
import type { AgentBaseContext } from "./Agent.js";
|
|
12
|
-
import { ConversationContext } from "./ConversationContext.js";
|
|
13
|
-
export type MessageContextParams<ContentTypes = unknown> = Omit<AgentBaseContext<ContentTypes>, "message"> & {
|
|
14
|
-
message: DecodedMessageWithContent<ContentTypes>;
|
|
15
|
-
};
|
|
16
|
-
export declare class MessageContext<ContentTypes = unknown> extends ConversationContext<ContentTypes> {
|
|
17
|
-
#private;
|
|
18
|
-
constructor({ message, conversation, client, }: MessageContextParams<ContentTypes>);
|
|
19
|
-
usesCodec<T extends ContentCodec>(codecClass: new () => T): this is MessageContext<ReturnType<T["decode"]>>;
|
|
20
|
-
isMarkdown(): this is MessageContext<ReturnType<MarkdownCodec["decode"]>>;
|
|
21
|
-
isText(): this is MessageContext<ReturnType<TextCodec["decode"]>>;
|
|
22
|
-
isReply(): this is MessageContext<ReturnType<ReplyCodec["decode"]>>;
|
|
23
|
-
isReaction(): this is MessageContext<ReturnType<ReactionCodec["decode"]>>;
|
|
24
|
-
isReadReceipt(): this is MessageContext<ReturnType<ReadReceiptCodec["decode"]>>;
|
|
25
|
-
isRemoteAttachment(): this is MessageContext<ReturnType<RemoteAttachmentCodec["decode"]>>;
|
|
26
|
-
isTransactionReference(): this is MessageContext<ReturnType<TransactionReferenceCodec["decode"]>>;
|
|
27
|
-
isWalletSendCalls(): this is MessageContext<ReturnType<WalletSendCallsCodec["decode"]>>;
|
|
28
|
-
sendReaction(content: string, schema?: Reaction["schema"]): Promise<void>;
|
|
29
|
-
sendMarkdownReply(markdown: string): Promise<void>;
|
|
30
|
-
sendTextReply(text: string): Promise<void>;
|
|
31
|
-
getSenderAddress(): Promise<string | undefined>;
|
|
32
|
-
get message(): DecodedMessageWithContent<ContentTypes>;
|
|
33
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ContentTypeMarkdown, } from "@xmtp/content-type-markdown";
|
|
2
|
-
import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
3
|
-
import { ContentTypeReply, } from "@xmtp/content-type-reply";
|
|
4
|
-
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
5
|
-
import { filter } from "../core/filter.js";
|
|
6
|
-
import { ConversationContext } from "./ConversationContext.js";
|
|
7
|
-
export class MessageContext extends ConversationContext {
|
|
8
|
-
#message;
|
|
9
|
-
constructor({ message, conversation, client, }) {
|
|
10
|
-
super({ conversation, client });
|
|
11
|
-
this.#message = message;
|
|
12
|
-
}
|
|
13
|
-
usesCodec(codecClass) {
|
|
14
|
-
return filter.usesCodec(this.#message, codecClass);
|
|
15
|
-
}
|
|
16
|
-
isMarkdown() {
|
|
17
|
-
return filter.isMarkdown(this.#message);
|
|
18
|
-
}
|
|
19
|
-
isText() {
|
|
20
|
-
return filter.isText(this.#message);
|
|
21
|
-
}
|
|
22
|
-
isReply() {
|
|
23
|
-
return filter.isReply(this.#message);
|
|
24
|
-
}
|
|
25
|
-
isReaction() {
|
|
26
|
-
return filter.isReaction(this.#message);
|
|
27
|
-
}
|
|
28
|
-
isReadReceipt() {
|
|
29
|
-
return filter.isReadReceipt(this.#message);
|
|
30
|
-
}
|
|
31
|
-
isRemoteAttachment() {
|
|
32
|
-
return filter.isRemoteAttachment(this.#message);
|
|
33
|
-
}
|
|
34
|
-
isTransactionReference() {
|
|
35
|
-
return filter.isTransactionReference(this.#message);
|
|
36
|
-
}
|
|
37
|
-
isWalletSendCalls() {
|
|
38
|
-
return filter.isWalletSendCalls(this.#message);
|
|
39
|
-
}
|
|
40
|
-
async sendReaction(content, schema = "unicode") {
|
|
41
|
-
const reaction = {
|
|
42
|
-
action: "added",
|
|
43
|
-
reference: this.#message.id,
|
|
44
|
-
referenceInboxId: this.#message.senderInboxId,
|
|
45
|
-
schema,
|
|
46
|
-
content,
|
|
47
|
-
};
|
|
48
|
-
await this.conversation.send(reaction, ContentTypeReaction);
|
|
49
|
-
}
|
|
50
|
-
async #sendReply(text, contentType = ContentTypeText) {
|
|
51
|
-
const reply = {
|
|
52
|
-
reference: this.#message.id,
|
|
53
|
-
referenceInboxId: this.#message.senderInboxId,
|
|
54
|
-
contentType,
|
|
55
|
-
content: text,
|
|
56
|
-
};
|
|
57
|
-
await this.conversation.send(reply, ContentTypeReply);
|
|
58
|
-
}
|
|
59
|
-
async sendMarkdownReply(markdown) {
|
|
60
|
-
await this.#sendReply(markdown, ContentTypeMarkdown);
|
|
61
|
-
}
|
|
62
|
-
async sendTextReply(text) {
|
|
63
|
-
await this.#sendReply(text, ContentTypeText);
|
|
64
|
-
}
|
|
65
|
-
async getSenderAddress() {
|
|
66
|
-
const inboxState = await this.client.preferences.inboxStateFromInboxIds([
|
|
67
|
-
this.#message.senderInboxId,
|
|
68
|
-
]);
|
|
69
|
-
return inboxState[0]?.identifiers[0]?.identifier;
|
|
70
|
-
}
|
|
71
|
-
get message() {
|
|
72
|
-
return this.#message;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=MessageContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageContext.js","sourceRoot":"","sources":["../../src/core/MessageContext.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,mBAAmB,GAGpB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,gBAAgB,GAGjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAkB,MAAM,yBAAyB,CAAC;AAG1E,OAAO,EAAE,MAAM,EAAkC,MAAM,kBAAkB,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAS/D,MAAM,OAAO,cAEX,SAAQ,mBAAiC;IACzC,QAAQ,CAA0C;IAElD,YAAY,EACV,OAAO,EACP,YAAY,EACZ,MAAM,GAC6B;QACnC,KAAK,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,C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,WAAW,GAAG,eAAe;QAC1D,MAAM,KAAK,GAAU;YACnB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3B,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;YAC7C,WAAW;YACX,OAAO,EAAE,IAAI;SACd,CAAC;QACF,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,QAAgB;QACtC,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAAY;QAC9B,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,sBAAsB,CAAC;YACtE,IAAI,CAAC,QAAQ,CAAC,aAAa;SAC5B,CAAC,CAAC;QACH,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;IACnD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
|
package/dist/core/filter.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { type GroupUpdatedCodec } from "@xmtp/content-type-group-updated";
|
|
2
|
-
import { type MarkdownCodec } from "@xmtp/content-type-markdown";
|
|
3
|
-
import type { ContentCodec } from "@xmtp/content-type-primitives";
|
|
4
|
-
import { type ReactionCodec } from "@xmtp/content-type-reaction";
|
|
5
|
-
import { type ReadReceiptCodec } from "@xmtp/content-type-read-receipt";
|
|
6
|
-
import { type RemoteAttachmentCodec } from "@xmtp/content-type-remote-attachment";
|
|
7
|
-
import { type ReplyCodec } from "@xmtp/content-type-reply";
|
|
8
|
-
import { type TextCodec } from "@xmtp/content-type-text";
|
|
9
|
-
import { type TransactionReferenceCodec } from "@xmtp/content-type-transaction-reference";
|
|
10
|
-
import { type WalletSendCallsCodec } from "@xmtp/content-type-wallet-send-calls";
|
|
11
|
-
import { Dm, Group, type Client, type Conversation, type DecodedMessage } from "@xmtp/node-sdk";
|
|
12
|
-
export type DecodedMessageWithContent<ContentTypes = unknown> = DecodedMessage<ContentTypes> & {
|
|
13
|
-
content: ContentTypes;
|
|
14
|
-
};
|
|
15
|
-
export declare const filter: {
|
|
16
|
-
fromSelf: <ContentTypes>(message: DecodedMessage<ContentTypes>, client: Client<ContentTypes>) => boolean;
|
|
17
|
-
hasContent: <ContentTypes>(message: DecodedMessage<ContentTypes>) => message is DecodedMessageWithContent<ContentTypes>;
|
|
18
|
-
isDM: (conversation: Conversation) => conversation is Dm;
|
|
19
|
-
isGroup: (conversation: Conversation) => conversation is Group;
|
|
20
|
-
isGroupAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
21
|
-
isGroupSuperAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
22
|
-
isGroupUpdate: (message: DecodedMessage) => message is DecodedMessage & {
|
|
23
|
-
content: ReturnType<GroupUpdatedCodec["decode"]>;
|
|
24
|
-
};
|
|
25
|
-
isMarkdown: (message: DecodedMessage) => message is DecodedMessageWithContent<ReturnType<MarkdownCodec["decode"]>>;
|
|
26
|
-
isReaction: (message: DecodedMessage) => message is DecodedMessage & {
|
|
27
|
-
content: ReturnType<ReactionCodec["decode"]>;
|
|
28
|
-
};
|
|
29
|
-
isReadReceipt: (message: DecodedMessage) => message is DecodedMessage & {
|
|
30
|
-
content: ReturnType<ReadReceiptCodec["decode"]>;
|
|
31
|
-
};
|
|
32
|
-
isRemoteAttachment: (message: DecodedMessage) => message is DecodedMessage & {
|
|
33
|
-
content: ReturnType<RemoteAttachmentCodec["decode"]>;
|
|
34
|
-
};
|
|
35
|
-
isReply: (message: DecodedMessage) => message is DecodedMessage & {
|
|
36
|
-
content: ReturnType<ReplyCodec["decode"]>;
|
|
37
|
-
};
|
|
38
|
-
isText: (message: DecodedMessage) => message is DecodedMessageWithContent<ReturnType<TextCodec["decode"]>>;
|
|
39
|
-
isTextReply: (message: DecodedMessage) => boolean;
|
|
40
|
-
isTransactionReference: (message: DecodedMessage) => message is DecodedMessage & {
|
|
41
|
-
content: ReturnType<TransactionReferenceCodec["decode"]>;
|
|
42
|
-
};
|
|
43
|
-
isWalletSendCalls: (message: DecodedMessage) => message is DecodedMessage & {
|
|
44
|
-
content: ReturnType<WalletSendCallsCodec["decode"]>;
|
|
45
|
-
};
|
|
46
|
-
usesCodec: <T extends ContentCodec>(message: DecodedMessage, codecClass: new () => T) => message is DecodedMessage & {
|
|
47
|
-
content: ReturnType<T["decode"]>;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export declare const f: {
|
|
51
|
-
fromSelf: <ContentTypes>(message: DecodedMessage<ContentTypes>, client: Client<ContentTypes>) => boolean;
|
|
52
|
-
hasContent: <ContentTypes>(message: DecodedMessage<ContentTypes>) => message is DecodedMessageWithContent<ContentTypes>;
|
|
53
|
-
isDM: (conversation: Conversation) => conversation is Dm;
|
|
54
|
-
isGroup: (conversation: Conversation) => conversation is Group;
|
|
55
|
-
isGroupAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
56
|
-
isGroupSuperAdmin: (conversation: Conversation, message: DecodedMessage) => boolean;
|
|
57
|
-
isGroupUpdate: (message: DecodedMessage) => message is DecodedMessage & {
|
|
58
|
-
content: ReturnType<GroupUpdatedCodec["decode"]>;
|
|
59
|
-
};
|
|
60
|
-
isMarkdown: (message: DecodedMessage) => message is DecodedMessageWithContent<ReturnType<MarkdownCodec["decode"]>>;
|
|
61
|
-
isReaction: (message: DecodedMessage) => message is DecodedMessage & {
|
|
62
|
-
content: ReturnType<ReactionCodec["decode"]>;
|
|
63
|
-
};
|
|
64
|
-
isReadReceipt: (message: DecodedMessage) => message is DecodedMessage & {
|
|
65
|
-
content: ReturnType<ReadReceiptCodec["decode"]>;
|
|
66
|
-
};
|
|
67
|
-
isRemoteAttachment: (message: DecodedMessage) => message is DecodedMessage & {
|
|
68
|
-
content: ReturnType<RemoteAttachmentCodec["decode"]>;
|
|
69
|
-
};
|
|
70
|
-
isReply: (message: DecodedMessage) => message is DecodedMessage & {
|
|
71
|
-
content: ReturnType<ReplyCodec["decode"]>;
|
|
72
|
-
};
|
|
73
|
-
isText: (message: DecodedMessage) => message is DecodedMessageWithContent<ReturnType<TextCodec["decode"]>>;
|
|
74
|
-
isTextReply: (message: DecodedMessage) => boolean;
|
|
75
|
-
isTransactionReference: (message: DecodedMessage) => message is DecodedMessage & {
|
|
76
|
-
content: ReturnType<TransactionReferenceCodec["decode"]>;
|
|
77
|
-
};
|
|
78
|
-
isWalletSendCalls: (message: DecodedMessage) => message is DecodedMessage & {
|
|
79
|
-
content: ReturnType<WalletSendCallsCodec["decode"]>;
|
|
80
|
-
};
|
|
81
|
-
usesCodec: <T extends ContentCodec>(message: DecodedMessage, codecClass: new () => T) => message is DecodedMessage & {
|
|
82
|
-
content: ReturnType<T["decode"]>;
|
|
83
|
-
};
|
|
84
|
-
};
|
package/dist/core/filter.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { ContentTypeGroupUpdated, } from "@xmtp/content-type-group-updated";
|
|
2
|
-
import { ContentTypeMarkdown, } from "@xmtp/content-type-markdown";
|
|
3
|
-
import { ContentTypeReaction, } from "@xmtp/content-type-reaction";
|
|
4
|
-
import { ContentTypeReadReceipt, } from "@xmtp/content-type-read-receipt";
|
|
5
|
-
import { ContentTypeRemoteAttachment, } from "@xmtp/content-type-remote-attachment";
|
|
6
|
-
import { ContentTypeReply } from "@xmtp/content-type-reply";
|
|
7
|
-
import { ContentTypeText } from "@xmtp/content-type-text";
|
|
8
|
-
import { ContentTypeTransactionReference, } from "@xmtp/content-type-transaction-reference";
|
|
9
|
-
import { ContentTypeWalletSendCalls, } from "@xmtp/content-type-wallet-send-calls";
|
|
10
|
-
import { Dm, Group, } from "@xmtp/node-sdk";
|
|
11
|
-
const fromSelf = (message, client) => {
|
|
12
|
-
return message.senderInboxId === client.inboxId;
|
|
13
|
-
};
|
|
14
|
-
const hasContent = (message) => {
|
|
15
|
-
return message.content !== undefined && message.content !== null;
|
|
16
|
-
};
|
|
17
|
-
const isDM = (conversation) => {
|
|
18
|
-
return conversation instanceof Dm;
|
|
19
|
-
};
|
|
20
|
-
const isGroup = (conversation) => {
|
|
21
|
-
return conversation instanceof Group;
|
|
22
|
-
};
|
|
23
|
-
const isGroupAdmin = (conversation, message) => {
|
|
24
|
-
if (isGroup(conversation)) {
|
|
25
|
-
return conversation.isAdmin(message.senderInboxId);
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
};
|
|
29
|
-
const isGroupSuperAdmin = (conversation, message) => {
|
|
30
|
-
if (isGroup(conversation)) {
|
|
31
|
-
return conversation.isSuperAdmin(message.senderInboxId);
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
};
|
|
35
|
-
const isGroupUpdate = (message) => {
|
|
36
|
-
return !!message.contentType?.sameAs(ContentTypeGroupUpdated);
|
|
37
|
-
};
|
|
38
|
-
const isReaction = (message) => {
|
|
39
|
-
return !!message.contentType?.sameAs(ContentTypeReaction);
|
|
40
|
-
};
|
|
41
|
-
const isReply = (message) => {
|
|
42
|
-
return !!message.contentType?.sameAs(ContentTypeReply);
|
|
43
|
-
};
|
|
44
|
-
const isRemoteAttachment = (message) => {
|
|
45
|
-
return !!message.contentType?.sameAs(ContentTypeRemoteAttachment);
|
|
46
|
-
};
|
|
47
|
-
const isMarkdown = (message) => {
|
|
48
|
-
return !!message.contentType?.sameAs(ContentTypeMarkdown);
|
|
49
|
-
};
|
|
50
|
-
const isReadReceipt = (message) => {
|
|
51
|
-
return !!message.contentType?.sameAs(ContentTypeReadReceipt);
|
|
52
|
-
};
|
|
53
|
-
const isText = (message) => {
|
|
54
|
-
return !!message.contentType?.sameAs(ContentTypeText);
|
|
55
|
-
};
|
|
56
|
-
const isTextReply = (message) => {
|
|
57
|
-
return isReply(message) && typeof message.content.content === "string";
|
|
58
|
-
};
|
|
59
|
-
const isTransactionReference = (message) => {
|
|
60
|
-
return !!message.contentType?.sameAs(ContentTypeTransactionReference);
|
|
61
|
-
};
|
|
62
|
-
const isWalletSendCalls = (message) => {
|
|
63
|
-
return !!message.contentType?.sameAs(ContentTypeWalletSendCalls);
|
|
64
|
-
};
|
|
65
|
-
const usesCodec = (message, codecClass) => {
|
|
66
|
-
return message.contentType?.sameAs(new codecClass().contentType) ?? false;
|
|
67
|
-
};
|
|
68
|
-
export const filter = {
|
|
69
|
-
fromSelf,
|
|
70
|
-
hasContent,
|
|
71
|
-
isDM,
|
|
72
|
-
isGroup,
|
|
73
|
-
isGroupAdmin,
|
|
74
|
-
isGroupSuperAdmin,
|
|
75
|
-
isGroupUpdate,
|
|
76
|
-
isMarkdown,
|
|
77
|
-
isReaction,
|
|
78
|
-
isReadReceipt,
|
|
79
|
-
isRemoteAttachment,
|
|
80
|
-
isReply,
|
|
81
|
-
isText,
|
|
82
|
-
isTextReply,
|
|
83
|
-
isTransactionReference,
|
|
84
|
-
isWalletSendCalls,
|
|
85
|
-
usesCodec,
|
|
86
|
-
};
|
|
87
|
-
export const f = filter;
|
|
88
|
-
//# sourceMappingURL=filter.js.map
|
package/dist/core/filter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/core/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAExB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,GAEpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,mBAAmB,GAEpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,GAEvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAC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AC;AACzE,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAC7B,OAAuB,EAGvB,EAAE;IACF,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,+BAA+B,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CACxB,OAAuB,EAGvB,EAAE;IACF,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,OAAuB,EACvB,UAAuB,EAGvB,EAAE;IACF,OAAO,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC;AAC5E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,OAAO;IACP,YAAY;IACZ,iBAAiB;IACjB,aAAa;IACb,UAAU;IACV,UAAU;IACV,aAAa;IACb,kBAAkB;IAClB,OAAO;IACP,MAAM;IACN,WAAW;IACX,sBAAsB;IACtB,iBAAiB;IACjB,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC"}
|
package/dist/core/index.d.ts
DELETED
package/dist/core/index.js
DELETED
package/dist/core/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
package/dist/debug/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./log.js";
|
package/dist/debug/index.js
DELETED
package/dist/debug/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/debug/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/dist/debug/log.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Client } from "@xmtp/node-sdk";
|
|
2
|
-
import type { Agent } from "../core/Agent.js";
|
|
3
|
-
export declare const logDetails: <ContentTypes>(agent: Agent<ContentTypes>) => Promise<void>;
|
|
4
|
-
/**
|
|
5
|
-
* Returns a URL to test your agent on https://xmtp.chat/ (for development purposes only).
|
|
6
|
-
*
|
|
7
|
-
* @param client - Your XMTP client
|
|
8
|
-
* @returns The URL to test your agent with
|
|
9
|
-
*/
|
|
10
|
-
export declare const getTestUrl: <ContentTypes>(client: Client<ContentTypes>) => string;
|
|
11
|
-
type InstallationInfo = {
|
|
12
|
-
totalInstallations: number;
|
|
13
|
-
installationId: string;
|
|
14
|
-
mostRecentInstallationId: null | string;
|
|
15
|
-
isMostRecent: boolean;
|
|
16
|
-
};
|
|
17
|
-
export declare const getInstallationInfo: <ContentTypes>(client: Client<ContentTypes>) => Promise<InstallationInfo>;
|
|
18
|
-
export {};
|
package/dist/debug/log.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Client } from "@xmtp/node-sdk";
|
|
2
|
-
export const logDetails = async (agent) => {
|
|
3
|
-
const xmtp = `\x1b[38;2;252;76;52m
|
|
4
|
-
██╗ ██╗███╗ ███╗████████╗██████╗
|
|
5
|
-
╚██╗██╔╝████╗ ████║╚══██╔══╝██╔══██╗
|
|
6
|
-
╚███╔╝ ██╔████╔██║ ██║ ██████╔╝
|
|
7
|
-
██╔██╗ ██║╚██╔╝██║ ██║ ██╔═══╝
|
|
8
|
-
██╔╝ ██╗██║ ╚═╝ ██║ ██║ ██║
|
|
9
|
-
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
10
|
-
\x1b[0m`;
|
|
11
|
-
const client = agent.client;
|
|
12
|
-
const clientsByAddress = client.accountIdentifier?.identifier;
|
|
13
|
-
const inboxId = client.inboxId;
|
|
14
|
-
const installationId = client.installationId;
|
|
15
|
-
const env = client.options?.env ?? "dev";
|
|
16
|
-
const urls = [`http://xmtp.chat/${env}/dm/${clientsByAddress}`];
|
|
17
|
-
const conversations = await client.conversations.list();
|
|
18
|
-
const inboxState = await client.preferences.inboxState();
|
|
19
|
-
const keyPackageStatuses = await client.getKeyPackageStatusesForInstallationIds([installationId]);
|
|
20
|
-
let createdDate = new Date();
|
|
21
|
-
let expiryDate = new Date();
|
|
22
|
-
// Extract key package status for the specific installation
|
|
23
|
-
const keyPackageStatus = keyPackageStatuses[installationId] ?? {};
|
|
24
|
-
if (keyPackageStatus.lifetime) {
|
|
25
|
-
createdDate = new Date(Number(keyPackageStatus.lifetime.notBefore) * 1000);
|
|
26
|
-
expiryDate = new Date(Number(keyPackageStatus.lifetime.notAfter) * 1000);
|
|
27
|
-
}
|
|
28
|
-
console.log(`
|
|
29
|
-
${xmtp}
|
|
30
|
-
|
|
31
|
-
✓ XMTP Client:
|
|
32
|
-
• InboxId: ${inboxId}
|
|
33
|
-
• LibXMTP Version: ${agent.libxmtpVersion}
|
|
34
|
-
• Address: ${clientsByAddress}
|
|
35
|
-
• Conversations: ${conversations.length}
|
|
36
|
-
• Installations: ${inboxState.installations.length}
|
|
37
|
-
• InstallationId: ${installationId}
|
|
38
|
-
• Key Package created: ${createdDate.toLocaleString()}
|
|
39
|
-
• Key Package valid until: ${expiryDate.toLocaleString()}
|
|
40
|
-
• Networks: ${env}
|
|
41
|
-
${urls.map((url) => `• URL: ${url}`).join("\n")}`);
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Returns a URL to test your agent on https://xmtp.chat/ (for development purposes only).
|
|
45
|
-
*
|
|
46
|
-
* @param client - Your XMTP client
|
|
47
|
-
* @returns The URL to test your agent with
|
|
48
|
-
*/
|
|
49
|
-
export const getTestUrl = (client) => {
|
|
50
|
-
const address = client.accountIdentifier?.identifier;
|
|
51
|
-
const env = client.options?.env ?? "dev";
|
|
52
|
-
return `http://xmtp.chat/${env}/dm/${address}`;
|
|
53
|
-
};
|
|
54
|
-
export const getInstallationInfo = async (client) => {
|
|
55
|
-
const myInboxId = client.inboxId;
|
|
56
|
-
const myInstallationId = client.installationId;
|
|
57
|
-
const inboxStates = await Client.inboxStateFromInboxIds([myInboxId], client.options?.env);
|
|
58
|
-
const installations = inboxStates.find((state) => state.inboxId === myInboxId)?.installations ||
|
|
59
|
-
[];
|
|
60
|
-
const sortedInstallations = [...installations].sort((a, b) => {
|
|
61
|
-
const aTime = a.clientTimestampNs ?? 0n;
|
|
62
|
-
const bTime = b.clientTimestampNs ?? 0n;
|
|
63
|
-
return bTime > aTime ? 1 : bTime < aTime ? -1 : 0;
|
|
64
|
-
});
|
|
65
|
-
const mostRecentInstallation = sortedInstallations[0];
|
|
66
|
-
const myInstallationIdHex = Buffer.from(client.installationIdBytes).toString("hex");
|
|
67
|
-
const info = {
|
|
68
|
-
totalInstallations: installations.length,
|
|
69
|
-
installationId: myInstallationId,
|
|
70
|
-
mostRecentInstallationId: null,
|
|
71
|
-
isMostRecent: false,
|
|
72
|
-
};
|
|
73
|
-
if (mostRecentInstallation) {
|
|
74
|
-
const mostRecentIdHex = Buffer.from(mostRecentInstallation.bytes).toString("hex");
|
|
75
|
-
info.mostRecentInstallationId = mostRecentIdHex;
|
|
76
|
-
info.isMostRecent = myInstallationIdHex === mostRecentIdHex;
|
|
77
|
-
}
|
|
78
|
-
return info;
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=log.js.map
|
package/dist/debug/log.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/debug/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,MAAM,CAAC,MA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AG,CAAC,CAAC,iBAAiB,IAAI,EAAE,CAAC;QACxC,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAEtD,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAC1E,KAAK,CACN,CAAC;IAEF,MAAM,IAAI,GAAqB;QAC7B,kBAAkB,EAAE,aAAa,CAAC,MAAM;QACxC,cAAc,EAAE,gBAAgB;QAChC,wBAAwB,EAAE,IAAI;QAC9B,YAAY,EAAE,KAAK;KACpB,CAAC;IAEF,IAAI,sBAAsB,EAAE,CAAC;QAC3B,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,QAAQ,CACxE,KAAK,CACN,CAAC;QACF,IAAI,CAAC,wBAAwB,GAAG,eAAe,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,mBAAmB,KAAK,eAAe,CAAC;IAC9D,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { TextCodec } from "@xmtp/content-type-text";
|
|
2
|
-
import { type AgentMessageHandler, type AgentMiddleware } from "../core/Agent.js";
|
|
3
|
-
import type { MessageContext } from "../core/MessageContext.js";
|
|
4
|
-
/** Content type supported by the "CommandRouter" */
|
|
5
|
-
type SupportedType = ReturnType<TextCodec["decode"]>;
|
|
6
|
-
export declare class CommandRouter {
|
|
7
|
-
#private;
|
|
8
|
-
get commandList(): string[];
|
|
9
|
-
command(command: string, handler: AgentMessageHandler<SupportedType>): this;
|
|
10
|
-
default(handler: AgentMessageHandler<SupportedType>): this;
|
|
11
|
-
handle(ctx: MessageContext<SupportedType>): Promise<boolean>;
|
|
12
|
-
middleware(): AgentMiddleware;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export class CommandRouter {
|
|
2
|
-
#commandMap = new Map();
|
|
3
|
-
#defaultHandler = null;
|
|
4
|
-
get commandList() {
|
|
5
|
-
return Array.from(this.#commandMap.keys());
|
|
6
|
-
}
|
|
7
|
-
command(command, handler) {
|
|
8
|
-
if (!command.startsWith("/")) {
|
|
9
|
-
throw new Error('Command must start with "/"');
|
|
10
|
-
}
|
|
11
|
-
this.#commandMap.set(command.toLowerCase(), handler);
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
default(handler) {
|
|
15
|
-
this.#defaultHandler = handler;
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
async handle(ctx) {
|
|
19
|
-
const messageText = ctx.message.content;
|
|
20
|
-
const parts = messageText.split(" ");
|
|
21
|
-
const command = parts[0]?.toLowerCase();
|
|
22
|
-
if (!command) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
// Check if this is a command message
|
|
26
|
-
if (command.startsWith("/")) {
|
|
27
|
-
const handler = this.#commandMap.get(command);
|
|
28
|
-
if (handler) {
|
|
29
|
-
// Create a new context with modified content (everything after the command)
|
|
30
|
-
const argsText = parts.slice(1).join(" ");
|
|
31
|
-
ctx.message.content = argsText;
|
|
32
|
-
await handler(ctx);
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// If no command matched and there's a default handler, use it
|
|
37
|
-
if (this.#defaultHandler) {
|
|
38
|
-
await this.#defaultHandler(ctx);
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
middleware() {
|
|
44
|
-
return async (ctx, next) => {
|
|
45
|
-
if (ctx.isText()) {
|
|
46
|
-
const handled = await this.handle(ctx);
|
|
47
|
-
if (!handled) {
|
|
48
|
-
await next();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
await next();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=CommandRouter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommandRouter.js","sourceRoot":"","sources":["../../src/middleware/CommandRouter.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,aAAa;IACxB,WAAW,GAAG,IAAI,GAAG,EAA8C,CAAC;IACpE,eAAe,GAA8C,IAAI,CAAC;IAElE,IAAI,WAAW;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,CAAC,OAAe,EAAE,OAA2C;QAClE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,OAA2C;QACjD,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAkC;QAC7C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;QACxC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;QAExC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACf,CAAC;QAED,qCAAqC;QACrC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,OAAO,EAAE,CAAC;gBACZ,4EAA4E;gBAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC1C,GAAG,CAAC,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;gBAC/B,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,8DAA8D;QAC9D,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,UAAU;QACR,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;gBACjB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvC,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,MAAM,IAAI,EAAE,CAAC;gBACf,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./CommandRouter.js";
|
package/dist/middleware/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createNameResolver: (apiKey?: string) => (name: string) => Promise<string | null>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { escape } from "node:querystring";
|
|
2
|
-
import { isAddress } from "viem";
|
|
3
|
-
import { AgentError } from "../core/AgentError.js";
|
|
4
|
-
import { LimitedMap } from "../util/LimitedMap.js";
|
|
5
|
-
const cache = new LimitedMap(1000);
|
|
6
|
-
const fetchFromWeb3Bio = async (name, apiKey) => {
|
|
7
|
-
const endpoint = `https://api.web3.bio/ns/${escape(name)}`;
|
|
8
|
-
const headers = {
|
|
9
|
-
"Content-Type": "application/json",
|
|
10
|
-
};
|
|
11
|
-
if (apiKey) {
|
|
12
|
-
headers["X-API-KEY"] = `Bearer ${apiKey}`;
|
|
13
|
-
}
|
|
14
|
-
const response = await fetch(endpoint, {
|
|
15
|
-
method: "GET",
|
|
16
|
-
headers,
|
|
17
|
-
});
|
|
18
|
-
if (!response.ok) {
|
|
19
|
-
throw new AgentError(2000, `Could not resolve address for name "${name}": ${response.statusText} (${response.status})`);
|
|
20
|
-
}
|
|
21
|
-
return response.json();
|
|
22
|
-
};
|
|
23
|
-
const resolveName = async (name, apiKey) => {
|
|
24
|
-
if (isAddress(name)) {
|
|
25
|
-
return name;
|
|
26
|
-
}
|
|
27
|
-
const cachedAddress = cache.get(name);
|
|
28
|
-
if (cachedAddress !== undefined) {
|
|
29
|
-
return cachedAddress;
|
|
30
|
-
}
|
|
31
|
-
const response = await fetchFromWeb3Bio(name, apiKey);
|
|
32
|
-
if (response.length === 0) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
const address = response[0]?.address;
|
|
36
|
-
if (!address) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
cache.set(name, address);
|
|
40
|
-
return address;
|
|
41
|
-
};
|
|
42
|
-
export const createNameResolver = (apiKey) => {
|
|
43
|
-
return (name) => resolveName(name, apiKey);
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=NameResolver.js.map
|
|
@@ -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AAC;IAEtC,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;IACrC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzB,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAe,EAAE,EAAE;IACpD,OAAO,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC,CAAC"}
|
package/dist/user/User.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type HexString, type Identifier, type Signer } from "@xmtp/node-sdk";
|
|
2
|
-
import { type Chain, type Hex, type PrivateKeyAccount, type WalletClient } from "viem";
|
|
3
|
-
export type User = {
|
|
4
|
-
key: Hex;
|
|
5
|
-
account: PrivateKeyAccount;
|
|
6
|
-
wallet: WalletClient;
|
|
7
|
-
};
|
|
8
|
-
export declare const createUser: (key?: HexString, chain?: Chain) => User;
|
|
9
|
-
export declare const createIdentifier: (user: User) => Identifier;
|
|
10
|
-
export declare const createSigner: (user: User) => Signer;
|
package/dist/user/User.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createWalletClient, http, toBytes, } from "viem";
|
|
2
|
-
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
3
|
-
import { sepolia } from "viem/chains";
|
|
4
|
-
export const createUser = (key, chain = sepolia) => {
|
|
5
|
-
const accountKey = key ?? generatePrivateKey();
|
|
6
|
-
const account = privateKeyToAccount(accountKey);
|
|
7
|
-
return {
|
|
8
|
-
key: accountKey,
|
|
9
|
-
account,
|
|
10
|
-
wallet: createWalletClient({
|
|
11
|
-
account,
|
|
12
|
-
chain,
|
|
13
|
-
transport: http(),
|
|
14
|
-
}),
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export const createIdentifier = (user) => ({
|
|
18
|
-
identifier: user.account.address.toLowerCase(),
|
|
19
|
-
identifierKind: 0 /* IdentifierKind.Ethereum */,
|
|
20
|
-
});
|
|
21
|
-
export const createSigner = (user) => {
|
|
22
|
-
const identifier = createIdentifier(user);
|
|
23
|
-
return {
|
|
24
|
-
type: "EOA",
|
|
25
|
-
getIdentifier: () => identifier,
|
|
26
|
-
signMessage: async (message) => {
|
|
27
|
-
const signature = await user.wallet.signMessage({
|
|
28
|
-
account: user.account,
|
|
29
|
-
message,
|
|
30
|
-
});
|
|
31
|
-
return toBytes(signature);
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=User.js.map
|
package/dist/user/User.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"User.js","sourceRoot":"","sources":["../../src/user/User.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAClB,IAAI,EACJ,OAAO,GAKR,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQtC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAe,EAAE,QAAe,OAAO,EAAQ,EAAE;IAC1E,MAAM,UAAU,GAAG,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO;QAC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