@xmtp/browser-sdk 6.4.1 → 7.0.0-dev.57a7203
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 +17 -0
- package/dist/index.d.ts +257 -57
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/package.json +16 -7
- package/src/Client.ts +250 -5
- package/src/Conversation.ts +53 -40
- package/src/WorkerClient.ts +64 -2
- package/src/WorkerConversation.ts +29 -33
- package/src/index.ts +6 -0
- package/src/types/actions/client.ts +81 -1
- package/src/types/actions/conversation.ts +23 -12
- package/src/types/options.ts +19 -0
- package/src/utils/WorkerBridge.ts +1 -1
- package/src/utils/createClient.ts +11 -4
- package/src/utils/signer.ts +37 -1
- package/src/workers/client.ts +68 -22
|
@@ -8,12 +8,14 @@ import type {
|
|
|
8
8
|
GroupMember,
|
|
9
9
|
Intent,
|
|
10
10
|
ListMessagesOptions,
|
|
11
|
+
Message,
|
|
11
12
|
MessageDisappearingSettings,
|
|
12
13
|
MultiRemoteAttachment,
|
|
13
14
|
Reaction,
|
|
14
15
|
RemoteAttachment,
|
|
15
16
|
Reply,
|
|
16
17
|
SendMessageOpts,
|
|
18
|
+
SendOpts,
|
|
17
19
|
TransactionReference,
|
|
18
20
|
WalletSendCalls,
|
|
19
21
|
} from "@xmtp/wasm-bindings";
|
|
@@ -50,6 +52,15 @@ export type ConversationAction =
|
|
|
50
52
|
id: string;
|
|
51
53
|
};
|
|
52
54
|
}
|
|
55
|
+
| {
|
|
56
|
+
action: "conversation.processStreamedMessage";
|
|
57
|
+
id: string;
|
|
58
|
+
result: Message[];
|
|
59
|
+
data: {
|
|
60
|
+
id: string;
|
|
61
|
+
envelopeBytes: Uint8Array;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
53
64
|
| {
|
|
54
65
|
action: "conversation.messages";
|
|
55
66
|
id: string;
|
|
@@ -189,7 +200,7 @@ export type ConversationAction =
|
|
|
189
200
|
data: {
|
|
190
201
|
id: string;
|
|
191
202
|
text: string;
|
|
192
|
-
|
|
203
|
+
opts?: SendOpts;
|
|
193
204
|
};
|
|
194
205
|
}
|
|
195
206
|
| {
|
|
@@ -199,7 +210,7 @@ export type ConversationAction =
|
|
|
199
210
|
data: {
|
|
200
211
|
id: string;
|
|
201
212
|
markdown: string;
|
|
202
|
-
|
|
213
|
+
opts?: SendOpts;
|
|
203
214
|
};
|
|
204
215
|
}
|
|
205
216
|
| {
|
|
@@ -209,7 +220,7 @@ export type ConversationAction =
|
|
|
209
220
|
data: {
|
|
210
221
|
id: string;
|
|
211
222
|
reaction: Reaction;
|
|
212
|
-
|
|
223
|
+
opts?: SendOpts;
|
|
213
224
|
};
|
|
214
225
|
}
|
|
215
226
|
| {
|
|
@@ -218,7 +229,7 @@ export type ConversationAction =
|
|
|
218
229
|
result: string;
|
|
219
230
|
data: {
|
|
220
231
|
id: string;
|
|
221
|
-
|
|
232
|
+
opts?: SendOpts;
|
|
222
233
|
};
|
|
223
234
|
}
|
|
224
235
|
| {
|
|
@@ -228,7 +239,7 @@ export type ConversationAction =
|
|
|
228
239
|
data: {
|
|
229
240
|
id: string;
|
|
230
241
|
reply: Reply;
|
|
231
|
-
|
|
242
|
+
opts?: SendOpts;
|
|
232
243
|
};
|
|
233
244
|
}
|
|
234
245
|
| {
|
|
@@ -238,7 +249,7 @@ export type ConversationAction =
|
|
|
238
249
|
data: {
|
|
239
250
|
id: string;
|
|
240
251
|
transactionReference: TransactionReference;
|
|
241
|
-
|
|
252
|
+
opts?: SendOpts;
|
|
242
253
|
};
|
|
243
254
|
}
|
|
244
255
|
| {
|
|
@@ -248,7 +259,7 @@ export type ConversationAction =
|
|
|
248
259
|
data: {
|
|
249
260
|
id: string;
|
|
250
261
|
walletSendCalls: WalletSendCalls;
|
|
251
|
-
|
|
262
|
+
opts?: SendOpts;
|
|
252
263
|
};
|
|
253
264
|
}
|
|
254
265
|
| {
|
|
@@ -258,7 +269,7 @@ export type ConversationAction =
|
|
|
258
269
|
data: {
|
|
259
270
|
id: string;
|
|
260
271
|
actions: Actions;
|
|
261
|
-
|
|
272
|
+
opts?: SendOpts;
|
|
262
273
|
};
|
|
263
274
|
}
|
|
264
275
|
| {
|
|
@@ -268,7 +279,7 @@ export type ConversationAction =
|
|
|
268
279
|
data: {
|
|
269
280
|
id: string;
|
|
270
281
|
intent: Intent;
|
|
271
|
-
|
|
282
|
+
opts?: SendOpts;
|
|
272
283
|
};
|
|
273
284
|
}
|
|
274
285
|
| {
|
|
@@ -278,7 +289,7 @@ export type ConversationAction =
|
|
|
278
289
|
data: {
|
|
279
290
|
id: string;
|
|
280
291
|
attachment: Attachment;
|
|
281
|
-
|
|
292
|
+
opts?: SendOpts;
|
|
282
293
|
};
|
|
283
294
|
}
|
|
284
295
|
| {
|
|
@@ -288,7 +299,7 @@ export type ConversationAction =
|
|
|
288
299
|
data: {
|
|
289
300
|
id: string;
|
|
290
301
|
multiRemoteAttachment: MultiRemoteAttachment;
|
|
291
|
-
|
|
302
|
+
opts?: SendOpts;
|
|
292
303
|
};
|
|
293
304
|
}
|
|
294
305
|
| {
|
|
@@ -298,6 +309,6 @@ export type ConversationAction =
|
|
|
298
309
|
data: {
|
|
299
310
|
id: string;
|
|
300
311
|
remoteAttachment: RemoteAttachment;
|
|
301
|
-
|
|
312
|
+
opts?: SendOpts;
|
|
302
313
|
};
|
|
303
314
|
};
|
package/src/types/options.ts
CHANGED
|
@@ -17,9 +17,13 @@ import type {
|
|
|
17
17
|
RemoteAttachment,
|
|
18
18
|
TransactionReference,
|
|
19
19
|
WalletSendCalls,
|
|
20
|
+
WasmVisibilityConfirmationOptions,
|
|
21
|
+
WorkerConfigOptions,
|
|
20
22
|
} from "@xmtp/wasm-bindings";
|
|
21
23
|
import type { DecodedMessage } from "@/DecodedMessage";
|
|
22
24
|
|
|
25
|
+
export type VisibilityConfirmationOptions = WasmVisibilityConfirmationOptions;
|
|
26
|
+
|
|
23
27
|
export type XmtpEnv =
|
|
24
28
|
| "local"
|
|
25
29
|
| "dev"
|
|
@@ -115,10 +119,25 @@ export type OtherOptions = {
|
|
|
115
119
|
* Logging level
|
|
116
120
|
*/
|
|
117
121
|
loggingLevel?: LogLevel;
|
|
122
|
+
/**
|
|
123
|
+
* Tuning for the background worker scheduler (intervals, jitter, per-worker
|
|
124
|
+
* overrides, and disabled workers). All fields are optional; omitting this
|
|
125
|
+
* object preserves the default worker behavior.
|
|
126
|
+
*
|
|
127
|
+
* Intervals are specified in nanoseconds.
|
|
128
|
+
*/
|
|
129
|
+
workerConfig?: WorkerConfigOptions;
|
|
118
130
|
/**
|
|
119
131
|
* Disable automatic registration when creating a client
|
|
120
132
|
*/
|
|
121
133
|
disableAutoRegister?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Options for waiting until client registration is visible on the network.
|
|
136
|
+
*
|
|
137
|
+
* When set, `registerIdentity` will wait for the specified quorum of nodes
|
|
138
|
+
* to confirm the registration before resolving.
|
|
139
|
+
*/
|
|
140
|
+
waitForRegistrationVisible?: VisibilityConfirmationOptions;
|
|
122
141
|
};
|
|
123
142
|
|
|
124
143
|
export type ClientOptions = (NetworkOptions | { backend: Backend }) &
|
|
@@ -6,9 +6,15 @@ import {
|
|
|
6
6
|
type Backend,
|
|
7
7
|
type Identifier,
|
|
8
8
|
} from "@xmtp/wasm-bindings";
|
|
9
|
-
import type { ClientOptions
|
|
9
|
+
import type { ClientOptions } from "@/types/options";
|
|
10
10
|
import { createBackend, envToString } from "@/utils/createBackend";
|
|
11
11
|
|
|
12
|
+
type CreateClientOptions = ClientOptions extends infer T
|
|
13
|
+
? T extends ClientOptions
|
|
14
|
+
? Omit<T, "codecs">
|
|
15
|
+
: never
|
|
16
|
+
: never;
|
|
17
|
+
|
|
12
18
|
const networkOptionKeys = [
|
|
13
19
|
"env",
|
|
14
20
|
"apiUrl",
|
|
@@ -21,7 +27,7 @@ const hasBackend = (options: object): options is { backend: Backend } => {
|
|
|
21
27
|
};
|
|
22
28
|
|
|
23
29
|
const resolveBackend = async (
|
|
24
|
-
options?:
|
|
30
|
+
options?: CreateClientOptions,
|
|
25
31
|
): Promise<Backend> => {
|
|
26
32
|
if (!options) {
|
|
27
33
|
return createBackend();
|
|
@@ -43,12 +49,12 @@ const resolveBackend = async (
|
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
// No backend provided — build one from NetworkOptions
|
|
46
|
-
return createBackend(options
|
|
52
|
+
return createBackend(options);
|
|
47
53
|
};
|
|
48
54
|
|
|
49
55
|
export const createClient = async (
|
|
50
56
|
identifier: Identifier,
|
|
51
|
-
options?:
|
|
57
|
+
options?: CreateClientOptions,
|
|
52
58
|
) => {
|
|
53
59
|
const backend = await resolveBackend(options);
|
|
54
60
|
|
|
@@ -80,6 +86,7 @@ export const createClient = async (
|
|
|
80
86
|
dbPath,
|
|
81
87
|
options?.dbEncryptionKey,
|
|
82
88
|
deviceSyncMode,
|
|
89
|
+
options?.workerConfig,
|
|
83
90
|
isLogging
|
|
84
91
|
? {
|
|
85
92
|
structured: options.structuredLogging ?? false,
|
package/src/utils/signer.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { IdentifierKind, type Identifier } from "@xmtp/wasm-bindings";
|
|
2
|
+
import { toBytes } from "viem";
|
|
3
|
+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
2
4
|
|
|
3
5
|
type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
|
|
4
6
|
type GetIdentifier = () => Promise<Identifier> | Identifier;
|
|
@@ -36,6 +38,40 @@ export type SafeSigner =
|
|
|
36
38
|
blockNumber?: bigint;
|
|
37
39
|
};
|
|
38
40
|
|
|
41
|
+
export const createEOASigner = (key = generatePrivateKey()): Signer => {
|
|
42
|
+
const account = privateKeyToAccount(key);
|
|
43
|
+
return {
|
|
44
|
+
type: "EOA",
|
|
45
|
+
getIdentifier: () => ({
|
|
46
|
+
identifier: account.address.toLowerCase(),
|
|
47
|
+
identifierKind: IdentifierKind.Ethereum,
|
|
48
|
+
}),
|
|
49
|
+
signMessage: async (message: string) => {
|
|
50
|
+
const signature = await account.signMessage({ message });
|
|
51
|
+
return toBytes(signature);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const createSCWSigner = (
|
|
57
|
+
address: `0x${string}`,
|
|
58
|
+
signMessage: (message: string) => Promise<string> | string,
|
|
59
|
+
chainId: bigint,
|
|
60
|
+
): Signer => {
|
|
61
|
+
return {
|
|
62
|
+
type: "SCW",
|
|
63
|
+
getIdentifier: () => ({
|
|
64
|
+
identifier: address.toLowerCase(),
|
|
65
|
+
identifierKind: IdentifierKind.Ethereum,
|
|
66
|
+
}),
|
|
67
|
+
signMessage: async (message: string) => {
|
|
68
|
+
const signature = await signMessage(message);
|
|
69
|
+
return toBytes(signature);
|
|
70
|
+
},
|
|
71
|
+
getChainId: () => chainId,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
39
75
|
export const toSafeSigner = async (
|
|
40
76
|
signer: Signer,
|
|
41
77
|
signature: Uint8Array,
|
package/src/workers/client.ts
CHANGED
|
@@ -235,7 +235,11 @@ self.onmessage = async (
|
|
|
235
235
|
if (!signatureRequest) {
|
|
236
236
|
throw new Error("Signature request not found");
|
|
237
237
|
}
|
|
238
|
-
await client.registerIdentity(
|
|
238
|
+
await client.registerIdentity(
|
|
239
|
+
data.signer,
|
|
240
|
+
signatureRequest,
|
|
241
|
+
data.waitForRegistrationVisible,
|
|
242
|
+
);
|
|
239
243
|
signatureRequests.delete(data.signatureRequestId);
|
|
240
244
|
postMessage({ id, action, result: undefined });
|
|
241
245
|
break;
|
|
@@ -300,6 +304,16 @@ self.onmessage = async (
|
|
|
300
304
|
postMessage({ id, action, result });
|
|
301
305
|
break;
|
|
302
306
|
}
|
|
307
|
+
case "client.fetchLatestInboxUpdatesCount": {
|
|
308
|
+
const result = await client.fetchLatestInboxUpdatesCount(data.inboxIds);
|
|
309
|
+
postMessage({ id, action, result });
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "client.fetchOwnInboxUpdatesCount": {
|
|
313
|
+
const result = await client.fetchOwnInboxUpdatesCount();
|
|
314
|
+
postMessage({ id, action, result });
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
303
317
|
case "client.getInboxIdByIdentifier": {
|
|
304
318
|
const result = await client.getInboxIdByIdentifier(data.identifier);
|
|
305
319
|
postMessage({ id, action, result });
|
|
@@ -343,6 +357,41 @@ self.onmessage = async (
|
|
|
343
357
|
postMessage({ id, action, result: undefined });
|
|
344
358
|
break;
|
|
345
359
|
}
|
|
360
|
+
case "client.sendSyncArchive": {
|
|
361
|
+
await client.sendSyncArchive(data.options, data.serverUrl, data.pin);
|
|
362
|
+
postMessage({ id, action, result: undefined });
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
case "client.processSyncArchive": {
|
|
366
|
+
await client.processSyncArchive(data.archivePin);
|
|
367
|
+
postMessage({ id, action, result: undefined });
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case "client.listAvailableArchives": {
|
|
371
|
+
const result = client.listAvailableArchives(data.daysCutoff);
|
|
372
|
+
postMessage({ id, action, result });
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
case "client.createArchive": {
|
|
376
|
+
const result = await client.createArchive(data.opts, data.key);
|
|
377
|
+
postMessage({ id, action, result });
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "client.importArchive": {
|
|
381
|
+
await client.importArchive(data.data, data.key);
|
|
382
|
+
postMessage({ id, action, result: undefined });
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case "client.archiveMetadata": {
|
|
386
|
+
const result = await client.archiveMetadata(data.data, data.key);
|
|
387
|
+
postMessage({ id, action, result });
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
case "client.syncAllDeviceSyncGroups": {
|
|
391
|
+
const result = await client.syncAllDeviceSyncGroups();
|
|
392
|
+
postMessage({ id, action, result });
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
346
395
|
/**
|
|
347
396
|
* Debug information actions
|
|
348
397
|
*/
|
|
@@ -778,6 +827,12 @@ self.onmessage = async (
|
|
|
778
827
|
postMessage({ id, action, result: undefined });
|
|
779
828
|
break;
|
|
780
829
|
}
|
|
830
|
+
case "conversation.processStreamedMessage": {
|
|
831
|
+
const group = getGroup(data.id);
|
|
832
|
+
const result = await group.processStreamedMessage(data.envelopeBytes);
|
|
833
|
+
postMessage({ id, action, result });
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
781
836
|
case "conversation.messages": {
|
|
782
837
|
const group = getGroup(data.id);
|
|
783
838
|
const messages = await group.messages(data.options);
|
|
@@ -1002,37 +1057,31 @@ self.onmessage = async (
|
|
|
1002
1057
|
}
|
|
1003
1058
|
case "conversation.sendText": {
|
|
1004
1059
|
const group = getGroup(data.id);
|
|
1005
|
-
const result = await group.sendText(data.text, data.
|
|
1060
|
+
const result = await group.sendText(data.text, data.opts);
|
|
1006
1061
|
postMessage({ id, action, result });
|
|
1007
1062
|
break;
|
|
1008
1063
|
}
|
|
1009
1064
|
case "conversation.sendMarkdown": {
|
|
1010
1065
|
const group = getGroup(data.id);
|
|
1011
|
-
const result = await group.sendMarkdown(
|
|
1012
|
-
data.markdown,
|
|
1013
|
-
data.isOptimistic,
|
|
1014
|
-
);
|
|
1066
|
+
const result = await group.sendMarkdown(data.markdown, data.opts);
|
|
1015
1067
|
postMessage({ id, action, result });
|
|
1016
1068
|
break;
|
|
1017
1069
|
}
|
|
1018
1070
|
case "conversation.sendReaction": {
|
|
1019
1071
|
const group = getGroup(data.id);
|
|
1020
|
-
const result = await group.sendReaction(
|
|
1021
|
-
data.reaction,
|
|
1022
|
-
data.isOptimistic,
|
|
1023
|
-
);
|
|
1072
|
+
const result = await group.sendReaction(data.reaction, data.opts);
|
|
1024
1073
|
postMessage({ id, action, result });
|
|
1025
1074
|
break;
|
|
1026
1075
|
}
|
|
1027
1076
|
case "conversation.sendReadReceipt": {
|
|
1028
1077
|
const group = getGroup(data.id);
|
|
1029
|
-
const result = await group.sendReadReceipt(data.
|
|
1078
|
+
const result = await group.sendReadReceipt(data.opts);
|
|
1030
1079
|
postMessage({ id, action, result });
|
|
1031
1080
|
break;
|
|
1032
1081
|
}
|
|
1033
1082
|
case "conversation.sendReply": {
|
|
1034
1083
|
const group = getGroup(data.id);
|
|
1035
|
-
const result = await group.sendReply(data.reply, data.
|
|
1084
|
+
const result = await group.sendReply(data.reply, data.opts);
|
|
1036
1085
|
postMessage({ id, action, result });
|
|
1037
1086
|
break;
|
|
1038
1087
|
}
|
|
@@ -1040,7 +1089,7 @@ self.onmessage = async (
|
|
|
1040
1089
|
const group = getGroup(data.id);
|
|
1041
1090
|
const result = await group.sendTransactionReference(
|
|
1042
1091
|
data.transactionReference,
|
|
1043
|
-
data.
|
|
1092
|
+
data.opts,
|
|
1044
1093
|
);
|
|
1045
1094
|
postMessage({ id, action, result });
|
|
1046
1095
|
break;
|
|
@@ -1049,29 +1098,26 @@ self.onmessage = async (
|
|
|
1049
1098
|
const group = getGroup(data.id);
|
|
1050
1099
|
const result = await group.sendWalletSendCalls(
|
|
1051
1100
|
data.walletSendCalls,
|
|
1052
|
-
data.
|
|
1101
|
+
data.opts,
|
|
1053
1102
|
);
|
|
1054
1103
|
postMessage({ id, action, result });
|
|
1055
1104
|
break;
|
|
1056
1105
|
}
|
|
1057
1106
|
case "conversation.sendActions": {
|
|
1058
1107
|
const group = getGroup(data.id);
|
|
1059
|
-
const result = await group.sendActions(data.actions, data.
|
|
1108
|
+
const result = await group.sendActions(data.actions, data.opts);
|
|
1060
1109
|
postMessage({ id, action, result });
|
|
1061
1110
|
break;
|
|
1062
1111
|
}
|
|
1063
1112
|
case "conversation.sendIntent": {
|
|
1064
1113
|
const group = getGroup(data.id);
|
|
1065
|
-
const result = await group.sendIntent(data.intent, data.
|
|
1114
|
+
const result = await group.sendIntent(data.intent, data.opts);
|
|
1066
1115
|
postMessage({ id, action, result });
|
|
1067
1116
|
break;
|
|
1068
1117
|
}
|
|
1069
1118
|
case "conversation.sendAttachment": {
|
|
1070
1119
|
const group = getGroup(data.id);
|
|
1071
|
-
const result = await group.sendAttachment(
|
|
1072
|
-
data.attachment,
|
|
1073
|
-
data.isOptimistic,
|
|
1074
|
-
);
|
|
1120
|
+
const result = await group.sendAttachment(data.attachment, data.opts);
|
|
1075
1121
|
postMessage({ id, action, result });
|
|
1076
1122
|
break;
|
|
1077
1123
|
}
|
|
@@ -1079,7 +1125,7 @@ self.onmessage = async (
|
|
|
1079
1125
|
const group = getGroup(data.id);
|
|
1080
1126
|
const result = await group.sendMultiRemoteAttachment(
|
|
1081
1127
|
data.multiRemoteAttachment,
|
|
1082
|
-
data.
|
|
1128
|
+
data.opts,
|
|
1083
1129
|
);
|
|
1084
1130
|
postMessage({ id, action, result });
|
|
1085
1131
|
break;
|
|
@@ -1088,7 +1134,7 @@ self.onmessage = async (
|
|
|
1088
1134
|
const group = getGroup(data.id);
|
|
1089
1135
|
const result = await group.sendRemoteAttachment(
|
|
1090
1136
|
data.remoteAttachment,
|
|
1091
|
-
data.
|
|
1137
|
+
data.opts,
|
|
1092
1138
|
);
|
|
1093
1139
|
postMessage({ id, action, result });
|
|
1094
1140
|
break;
|