@xmtp/browser-sdk 6.4.1 → 7.0.0-dev.b5cdc06
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 +206 -8
- 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 +13 -0
- package/src/WorkerClient.ts +64 -2
- package/src/WorkerConversation.ts +4 -0
- package/src/index.ts +5 -0
- package/src/types/actions/client.ts +81 -1
- package/src/types/actions/conversation.ts +10 -0
- 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 +56 -1
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);
|