@hybrd/xmtp 1.3.2 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +16 -3
- 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
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
XmtpServiceMessage,
|
|
23
23
|
XmtpServiceResponse
|
|
24
24
|
} from "./types"
|
|
25
|
+
import { logger } from "./lib/logger"
|
|
25
26
|
|
|
26
27
|
export class XmtpServiceClient {
|
|
27
28
|
private config: XmtpServiceClientConfig
|
|
@@ -35,6 +36,9 @@ export class XmtpServiceClient {
|
|
|
35
36
|
body?: Record<string, unknown>,
|
|
36
37
|
method: "GET" | "POST" = "POST"
|
|
37
38
|
): Promise<XmtpServiceResponse<T>> {
|
|
39
|
+
const startTime = performance.now()
|
|
40
|
+
logger.debug(`🌐 [HTTP] Starting ${method} request to ${endpoint}`)
|
|
41
|
+
|
|
38
42
|
try {
|
|
39
43
|
const baseUrl = this.config.serviceUrl.replace(/\/+$/, "")
|
|
40
44
|
|
|
@@ -60,7 +64,14 @@ export class XmtpServiceClient {
|
|
|
60
64
|
fetchOptions.body = JSON.stringify(body)
|
|
61
65
|
}
|
|
62
66
|
|
|
67
|
+
const sanitizedUrl = `${baseUrl}${endpoint}?token=***`
|
|
68
|
+
logger.debug(`🌐 [HTTP] Making fetch request to ${sanitizedUrl}`)
|
|
69
|
+
const fetchStartTime = performance.now()
|
|
70
|
+
|
|
63
71
|
const response = await fetch(url, fetchOptions)
|
|
72
|
+
|
|
73
|
+
const fetchEndTime = performance.now()
|
|
74
|
+
logger.debug(`🌐 [HTTP] Fetch completed in ${(fetchEndTime - fetchStartTime).toFixed(2)}ms, status: ${response.status}`)
|
|
64
75
|
|
|
65
76
|
if (!response.ok) {
|
|
66
77
|
let errorMessage = `HTTP ${response.status}`
|
|
@@ -75,16 +86,28 @@ export class XmtpServiceClient {
|
|
|
75
86
|
} catch {
|
|
76
87
|
// If we can't read the response at all, use the status
|
|
77
88
|
}
|
|
89
|
+
|
|
90
|
+
const endTime = performance.now()
|
|
91
|
+
logger.debug(`🌐 [HTTP] Request failed in ${(endTime - startTime).toFixed(2)}ms: ${errorMessage}`)
|
|
78
92
|
throw new Error(errorMessage)
|
|
79
93
|
}
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
const jsonStartTime = performance.now()
|
|
96
|
+
const result = {
|
|
82
97
|
success: true,
|
|
83
98
|
data: (await response.json()) as T
|
|
84
99
|
}
|
|
100
|
+
const jsonEndTime = performance.now()
|
|
101
|
+
logger.debug(`🌐 [HTTP] JSON parsing completed in ${(jsonEndTime - jsonStartTime).toFixed(2)}ms`)
|
|
102
|
+
|
|
103
|
+
const endTime = performance.now()
|
|
104
|
+
logger.debug(`🌐 [HTTP] Total request completed in ${(endTime - startTime).toFixed(2)}ms`)
|
|
105
|
+
|
|
106
|
+
return result
|
|
85
107
|
} catch (error) {
|
|
86
|
-
|
|
87
|
-
|
|
108
|
+
const endTime = performance.now()
|
|
109
|
+
logger.error(
|
|
110
|
+
`❌ [XmtpServiceClient] Request to ${endpoint} failed in ${(endTime - startTime).toFixed(2)}ms:`,
|
|
88
111
|
error
|
|
89
112
|
)
|
|
90
113
|
return {
|
package/src/types.ts
CHANGED
|
@@ -1,157 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { TransactionReference } from "@xmtp/content-type-transaction-reference"
|
|
11
|
-
import { WalletSendCallsParams } from "@xmtp/content-type-wallet-send-calls"
|
|
12
|
-
import { Client, Conversation, DecodedMessage } from "@xmtp/node-sdk"
|
|
13
|
-
import type { Resolver } from "./resolver/resolver"
|
|
14
|
-
|
|
15
|
-
export type HonoVariables = {
|
|
16
|
-
xmtpClient: XmtpClient
|
|
17
|
-
resolver?: Resolver
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ===================================================================
|
|
21
|
-
// XMTP Core Client Types
|
|
22
|
-
// ===================================================================
|
|
23
|
-
|
|
24
|
-
type Codec =
|
|
25
|
-
| GroupUpdated
|
|
26
|
-
| Reaction
|
|
27
|
-
| Reply
|
|
28
|
-
| TransactionReference
|
|
29
|
-
| WalletSendCallsParams
|
|
30
|
-
|
|
31
|
-
export type XmtpClient = Client<string | Codec>
|
|
32
|
-
export type XmtpConversation = Conversation<string | Codec>
|
|
33
|
-
export type XmtpMessage = DecodedMessage<string | Codec>
|
|
34
|
-
export type XmtpSender = {
|
|
35
|
-
address: string
|
|
36
|
-
inboxId: string
|
|
37
|
-
name: string
|
|
38
|
-
basename?: string
|
|
39
|
-
}
|
|
40
|
-
export type XmtpSubjects = Record<string, `0x${string}`>
|
|
41
|
-
|
|
42
|
-
export interface MessageEvent {
|
|
43
|
-
conversation: XmtpConversation
|
|
44
|
-
message: XmtpMessage
|
|
45
|
-
rootMessage: XmtpMessage
|
|
46
|
-
parentMessage?: XmtpMessage // The directly referenced message if this is a reply
|
|
47
|
-
sender: XmtpSender
|
|
48
|
-
subjects: XmtpSubjects
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ===================================================================
|
|
52
|
-
// XMTP Service Client Types
|
|
53
|
-
// ===================================================================
|
|
54
|
-
|
|
55
|
-
export interface XmtpServiceClientConfig {
|
|
56
|
-
serviceUrl: string
|
|
57
|
-
serviceToken: string
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface TransactionCall {
|
|
61
|
-
to: string
|
|
62
|
-
data: string
|
|
63
|
-
gas?: string
|
|
64
|
-
value?: string
|
|
65
|
-
metadata?: Record<string, unknown>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface TransactionRequest {
|
|
69
|
-
fromAddress: string
|
|
70
|
-
chainId: string
|
|
71
|
-
calls: TransactionCall[]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface XmtpServiceResponse<T = unknown> {
|
|
75
|
-
success: boolean
|
|
76
|
-
data?: T
|
|
77
|
-
error?: string
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface XmtpServiceMessage {
|
|
81
|
-
id: string
|
|
82
|
-
conversationId: string
|
|
83
|
-
content: string | Record<string, unknown>
|
|
84
|
-
senderInboxId: string
|
|
85
|
-
sentAt: string
|
|
86
|
-
contentType?: {
|
|
87
|
-
typeId: string
|
|
88
|
-
authorityId?: string
|
|
89
|
-
versionMajor?: number
|
|
90
|
-
versionMinor?: number
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface XmtpRootMessageResponse {
|
|
95
|
-
id: string
|
|
96
|
-
conversationId: string
|
|
97
|
-
content: string | Record<string, unknown>
|
|
98
|
-
senderInboxId: string
|
|
99
|
-
sentAt: string
|
|
100
|
-
contentType?: {
|
|
101
|
-
typeId: string
|
|
102
|
-
authorityId?: string
|
|
103
|
-
versionMajor?: number
|
|
104
|
-
versionMinor?: number
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Function parameter types
|
|
109
|
-
export interface SendMessageParams {
|
|
110
|
-
content: string
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface SendReplyParams {
|
|
114
|
-
content: string
|
|
115
|
-
messageId: string
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export interface SendReactionParams {
|
|
119
|
-
messageId: string
|
|
120
|
-
emoji: string
|
|
121
|
-
action: "added" | "removed"
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface SendTransactionParams extends TransactionRequest {}
|
|
125
|
-
|
|
126
|
-
export interface GetMessageParams {
|
|
127
|
-
messageId: string
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface GetRootMessageParams {
|
|
131
|
-
messageId: string
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Response types
|
|
135
|
-
export interface SendMessageResponse {
|
|
136
|
-
success: boolean
|
|
137
|
-
action: "send"
|
|
138
|
-
conversationId: string
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface SendReplyResponse {
|
|
142
|
-
success: boolean
|
|
143
|
-
action: "reply"
|
|
144
|
-
conversationId: string
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface SendReactionResponse {
|
|
148
|
-
success: boolean
|
|
149
|
-
action: "react"
|
|
150
|
-
conversationId: string
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface SendTransactionResponse {
|
|
154
|
-
success: boolean
|
|
155
|
-
action: "transaction"
|
|
156
|
-
conversationId: string
|
|
157
|
-
}
|
|
1
|
+
// Re-export types from @hybrd/types for backward compatibility
|
|
2
|
+
export type {
|
|
3
|
+
HonoVariables,
|
|
4
|
+
XmtpClient,
|
|
5
|
+
XmtpConversation,
|
|
6
|
+
XmtpMessage,
|
|
7
|
+
XmtpSender,
|
|
8
|
+
XmtpSubjects
|
|
9
|
+
} from "@hybrd/types"
|
package/src/types.ts.old
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview XMTP Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for both the XMTP core client and service client library.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { GroupUpdated } from "@xmtp/content-type-group-updated"
|
|
8
|
+
import { Reaction } from "@xmtp/content-type-reaction"
|
|
9
|
+
import { Reply } from "@xmtp/content-type-reply"
|
|
10
|
+
import { TransactionReference } from "@xmtp/content-type-transaction-reference"
|
|
11
|
+
import { WalletSendCallsParams } from "@xmtp/content-type-wallet-send-calls"
|
|
12
|
+
import { Client, Conversation, DecodedMessage } from "@xmtp/node-sdk"
|
|
13
|
+
import type { Resolver } from "./resolver/resolver"
|
|
14
|
+
|
|
15
|
+
export type HonoVariables = {
|
|
16
|
+
xmtpClient: XmtpClient
|
|
17
|
+
resolver?: Resolver
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ===================================================================
|
|
21
|
+
// XMTP Core Client Types
|
|
22
|
+
// ===================================================================
|
|
23
|
+
|
|
24
|
+
type Codec =
|
|
25
|
+
| GroupUpdated
|
|
26
|
+
| Reaction
|
|
27
|
+
| Reply
|
|
28
|
+
| TransactionReference
|
|
29
|
+
| WalletSendCallsParams
|
|
30
|
+
|
|
31
|
+
export type XmtpClient = Client<string | Codec>
|
|
32
|
+
export type XmtpConversation = Conversation<string | Codec>
|
|
33
|
+
export type XmtpMessage = DecodedMessage<string | Codec>
|
|
34
|
+
export type XmtpSender = {
|
|
35
|
+
address: string
|
|
36
|
+
inboxId: string
|
|
37
|
+
name: string
|
|
38
|
+
basename?: string
|
|
39
|
+
}
|
|
40
|
+
export type XmtpSubjects = Record<string, `0x${string}`>
|
|
41
|
+
|
|
42
|
+
export interface MessageEvent {
|
|
43
|
+
conversation: XmtpConversation
|
|
44
|
+
message: XmtpMessage
|
|
45
|
+
rootMessage: XmtpMessage
|
|
46
|
+
parentMessage?: XmtpMessage // The directly referenced message if this is a reply
|
|
47
|
+
sender: XmtpSender
|
|
48
|
+
subjects: XmtpSubjects
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ===================================================================
|
|
52
|
+
// XMTP Service Client Types
|
|
53
|
+
// ===================================================================
|
|
54
|
+
|
|
55
|
+
export interface XmtpServiceClientConfig {
|
|
56
|
+
serviceUrl: string
|
|
57
|
+
serviceToken: string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface TransactionCall {
|
|
61
|
+
to: string
|
|
62
|
+
data: string
|
|
63
|
+
gas?: string
|
|
64
|
+
value?: string
|
|
65
|
+
metadata?: Record<string, unknown>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface TransactionRequest {
|
|
69
|
+
fromAddress: string
|
|
70
|
+
chainId: string
|
|
71
|
+
calls: TransactionCall[]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface XmtpServiceResponse<T = unknown> {
|
|
75
|
+
success: boolean
|
|
76
|
+
data?: T
|
|
77
|
+
error?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface XmtpServiceMessage {
|
|
81
|
+
id: string
|
|
82
|
+
conversationId: string
|
|
83
|
+
content: string | Record<string, unknown>
|
|
84
|
+
senderInboxId: string
|
|
85
|
+
sentAt: string
|
|
86
|
+
contentType?: {
|
|
87
|
+
typeId: string
|
|
88
|
+
authorityId?: string
|
|
89
|
+
versionMajor?: number
|
|
90
|
+
versionMinor?: number
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface XmtpRootMessageResponse {
|
|
95
|
+
id: string
|
|
96
|
+
conversationId: string
|
|
97
|
+
content: string | Record<string, unknown>
|
|
98
|
+
senderInboxId: string
|
|
99
|
+
sentAt: string
|
|
100
|
+
contentType?: {
|
|
101
|
+
typeId: string
|
|
102
|
+
authorityId?: string
|
|
103
|
+
versionMajor?: number
|
|
104
|
+
versionMinor?: number
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Function parameter types
|
|
109
|
+
export interface SendMessageParams {
|
|
110
|
+
content: string
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SendReplyParams {
|
|
114
|
+
content: string
|
|
115
|
+
messageId: string
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface SendReactionParams {
|
|
119
|
+
messageId: string
|
|
120
|
+
emoji: string
|
|
121
|
+
action: "added" | "removed"
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface SendTransactionParams extends TransactionRequest {}
|
|
125
|
+
|
|
126
|
+
export interface GetMessageParams {
|
|
127
|
+
messageId: string
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface GetRootMessageParams {
|
|
131
|
+
messageId: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Response types
|
|
135
|
+
export interface SendMessageResponse {
|
|
136
|
+
success: boolean
|
|
137
|
+
action: "send"
|
|
138
|
+
conversationId: string
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface SendReplyResponse {
|
|
142
|
+
success: boolean
|
|
143
|
+
action: "reply"
|
|
144
|
+
conversationId: string
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface SendReactionResponse {
|
|
148
|
+
success: boolean
|
|
149
|
+
action: "react"
|
|
150
|
+
conversationId: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface SendTransactionResponse {
|
|
154
|
+
success: boolean
|
|
155
|
+
action: "transaction"
|
|
156
|
+
conversationId: string
|
|
157
|
+
}
|