@xmtp/browser-sdk 6.4.1 → 7.0.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 +17 -0
- package/dist/index.d.ts +139 -6
- 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 +10 -2
- package/src/Client.ts +145 -5
- package/src/Conversation.ts +13 -0
- package/src/WorkerClient.ts +41 -0
- package/src/WorkerConversation.ts +4 -0
- package/src/index.ts +2 -0
- package/src/types/actions/client.ts +62 -0
- package/src/types/actions/conversation.ts +10 -0
- package/src/utils/signer.ts +37 -1
- package/src/workers/client.ts +41 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ArchiveMetadata,
|
|
2
3
|
ArchiveOptions,
|
|
4
|
+
AvailableArchiveInfo,
|
|
5
|
+
GroupSyncSummary,
|
|
3
6
|
Identifier,
|
|
4
7
|
KeyPackageStatus,
|
|
5
8
|
} from "@xmtp/wasm-bindings";
|
|
@@ -225,4 +228,63 @@ export type ClientAction =
|
|
|
225
228
|
options: ArchiveOptions;
|
|
226
229
|
serverUrl: string;
|
|
227
230
|
};
|
|
231
|
+
}
|
|
232
|
+
| {
|
|
233
|
+
action: "client.sendSyncArchive";
|
|
234
|
+
id: string;
|
|
235
|
+
result: undefined;
|
|
236
|
+
data: {
|
|
237
|
+
options: ArchiveOptions;
|
|
238
|
+
serverUrl: string;
|
|
239
|
+
pin: string;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
| {
|
|
243
|
+
action: "client.processSyncArchive";
|
|
244
|
+
id: string;
|
|
245
|
+
result: undefined;
|
|
246
|
+
data: {
|
|
247
|
+
archivePin?: string | null;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
| {
|
|
251
|
+
action: "client.listAvailableArchives";
|
|
252
|
+
id: string;
|
|
253
|
+
result: AvailableArchiveInfo[];
|
|
254
|
+
data: {
|
|
255
|
+
daysCutoff: number;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
| {
|
|
259
|
+
action: "client.createArchive";
|
|
260
|
+
id: string;
|
|
261
|
+
result: Uint8Array;
|
|
262
|
+
data: {
|
|
263
|
+
opts: ArchiveOptions;
|
|
264
|
+
key: Uint8Array;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
| {
|
|
268
|
+
action: "client.importArchive";
|
|
269
|
+
id: string;
|
|
270
|
+
result: undefined;
|
|
271
|
+
data: {
|
|
272
|
+
data: Uint8Array;
|
|
273
|
+
key: Uint8Array;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
| {
|
|
277
|
+
action: "client.archiveMetadata";
|
|
278
|
+
id: string;
|
|
279
|
+
result: ArchiveMetadata;
|
|
280
|
+
data: {
|
|
281
|
+
data: Uint8Array;
|
|
282
|
+
key: Uint8Array;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
| {
|
|
286
|
+
action: "client.syncAllDeviceSyncGroups";
|
|
287
|
+
id: string;
|
|
288
|
+
result: GroupSyncSummary;
|
|
289
|
+
data: undefined;
|
|
228
290
|
};
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
GroupMember,
|
|
9
9
|
Intent,
|
|
10
10
|
ListMessagesOptions,
|
|
11
|
+
Message,
|
|
11
12
|
MessageDisappearingSettings,
|
|
12
13
|
MultiRemoteAttachment,
|
|
13
14
|
Reaction,
|
|
@@ -50,6 +51,15 @@ export type ConversationAction =
|
|
|
50
51
|
id: string;
|
|
51
52
|
};
|
|
52
53
|
}
|
|
54
|
+
| {
|
|
55
|
+
action: "conversation.processStreamedMessage";
|
|
56
|
+
id: string;
|
|
57
|
+
result: Message[];
|
|
58
|
+
data: {
|
|
59
|
+
id: string;
|
|
60
|
+
envelopeBytes: Uint8Array;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
53
63
|
| {
|
|
54
64
|
action: "conversation.messages";
|
|
55
65
|
id: string;
|
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
|
@@ -343,6 +343,41 @@ self.onmessage = async (
|
|
|
343
343
|
postMessage({ id, action, result: undefined });
|
|
344
344
|
break;
|
|
345
345
|
}
|
|
346
|
+
case "client.sendSyncArchive": {
|
|
347
|
+
await client.sendSyncArchive(data.options, data.serverUrl, data.pin);
|
|
348
|
+
postMessage({ id, action, result: undefined });
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case "client.processSyncArchive": {
|
|
352
|
+
await client.processSyncArchive(data.archivePin);
|
|
353
|
+
postMessage({ id, action, result: undefined });
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case "client.listAvailableArchives": {
|
|
357
|
+
const result = client.listAvailableArchives(data.daysCutoff);
|
|
358
|
+
postMessage({ id, action, result });
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
case "client.createArchive": {
|
|
362
|
+
const result = await client.createArchive(data.opts, data.key);
|
|
363
|
+
postMessage({ id, action, result });
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
case "client.importArchive": {
|
|
367
|
+
await client.importArchive(data.data, data.key);
|
|
368
|
+
postMessage({ id, action, result: undefined });
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case "client.archiveMetadata": {
|
|
372
|
+
const result = await client.archiveMetadata(data.data, data.key);
|
|
373
|
+
postMessage({ id, action, result });
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case "client.syncAllDeviceSyncGroups": {
|
|
377
|
+
const result = await client.syncAllDeviceSyncGroups();
|
|
378
|
+
postMessage({ id, action, result });
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
346
381
|
/**
|
|
347
382
|
* Debug information actions
|
|
348
383
|
*/
|
|
@@ -778,6 +813,12 @@ self.onmessage = async (
|
|
|
778
813
|
postMessage({ id, action, result: undefined });
|
|
779
814
|
break;
|
|
780
815
|
}
|
|
816
|
+
case "conversation.processStreamedMessage": {
|
|
817
|
+
const group = getGroup(data.id);
|
|
818
|
+
const result = await group.processStreamedMessage(data.envelopeBytes);
|
|
819
|
+
postMessage({ id, action, result });
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
781
822
|
case "conversation.messages": {
|
|
782
823
|
const group = getGroup(data.id);
|
|
783
824
|
const messages = await group.messages(data.options);
|