@xmtp/browser-sdk 6.5.0 → 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.
@@ -1,4 +1,6 @@
1
- import type { Identifier } from "@xmtp/wasm-bindings";
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,
@@ -91,6 +91,7 @@ self.onmessage = async (
91
91
  action,
92
92
  result: {
93
93
  appVersion: maybeClient.appVersion,
94
+ env: maybeClient.env,
94
95
  inboxId: maybeClient.inboxId,
95
96
  installationId: maybeClient.installationId,
96
97
  installationIdBytes: maybeClient.installationIdBytes,
@@ -234,7 +235,11 @@ self.onmessage = async (
234
235
  if (!signatureRequest) {
235
236
  throw new Error("Signature request not found");
236
237
  }
237
- await client.registerIdentity(data.signer, signatureRequest);
238
+ await client.registerIdentity(
239
+ data.signer,
240
+ signatureRequest,
241
+ data.waitForRegistrationVisible,
242
+ );
238
243
  signatureRequests.delete(data.signatureRequestId);
239
244
  postMessage({ id, action, result: undefined });
240
245
  break;
@@ -299,6 +304,16 @@ self.onmessage = async (
299
304
  postMessage({ id, action, result });
300
305
  break;
301
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
+ }
302
317
  case "client.getInboxIdByIdentifier": {
303
318
  const result = await client.getInboxIdByIdentifier(data.identifier);
304
319
  postMessage({ id, action, result });
@@ -338,10 +353,45 @@ self.onmessage = async (
338
353
  break;
339
354
  }
340
355
  case "client.sendSyncRequest": {
341
- await client.sendSyncRequest();
356
+ await client.sendSyncRequest(data.options, data.serverUrl);
357
+ postMessage({ id, action, result: undefined });
358
+ break;
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);
342
367
  postMessage({ id, action, result: undefined });
343
368
  break;
344
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
+ }
345
395
  /**
346
396
  * Debug information actions
347
397
  */
@@ -1007,37 +1057,31 @@ self.onmessage = async (
1007
1057
  }
1008
1058
  case "conversation.sendText": {
1009
1059
  const group = getGroup(data.id);
1010
- const result = await group.sendText(data.text, data.isOptimistic);
1060
+ const result = await group.sendText(data.text, data.opts);
1011
1061
  postMessage({ id, action, result });
1012
1062
  break;
1013
1063
  }
1014
1064
  case "conversation.sendMarkdown": {
1015
1065
  const group = getGroup(data.id);
1016
- const result = await group.sendMarkdown(
1017
- data.markdown,
1018
- data.isOptimistic,
1019
- );
1066
+ const result = await group.sendMarkdown(data.markdown, data.opts);
1020
1067
  postMessage({ id, action, result });
1021
1068
  break;
1022
1069
  }
1023
1070
  case "conversation.sendReaction": {
1024
1071
  const group = getGroup(data.id);
1025
- const result = await group.sendReaction(
1026
- data.reaction,
1027
- data.isOptimistic,
1028
- );
1072
+ const result = await group.sendReaction(data.reaction, data.opts);
1029
1073
  postMessage({ id, action, result });
1030
1074
  break;
1031
1075
  }
1032
1076
  case "conversation.sendReadReceipt": {
1033
1077
  const group = getGroup(data.id);
1034
- const result = await group.sendReadReceipt(data.isOptimistic);
1078
+ const result = await group.sendReadReceipt(data.opts);
1035
1079
  postMessage({ id, action, result });
1036
1080
  break;
1037
1081
  }
1038
1082
  case "conversation.sendReply": {
1039
1083
  const group = getGroup(data.id);
1040
- const result = await group.sendReply(data.reply, data.isOptimistic);
1084
+ const result = await group.sendReply(data.reply, data.opts);
1041
1085
  postMessage({ id, action, result });
1042
1086
  break;
1043
1087
  }
@@ -1045,7 +1089,7 @@ self.onmessage = async (
1045
1089
  const group = getGroup(data.id);
1046
1090
  const result = await group.sendTransactionReference(
1047
1091
  data.transactionReference,
1048
- data.isOptimistic,
1092
+ data.opts,
1049
1093
  );
1050
1094
  postMessage({ id, action, result });
1051
1095
  break;
@@ -1054,29 +1098,26 @@ self.onmessage = async (
1054
1098
  const group = getGroup(data.id);
1055
1099
  const result = await group.sendWalletSendCalls(
1056
1100
  data.walletSendCalls,
1057
- data.isOptimistic,
1101
+ data.opts,
1058
1102
  );
1059
1103
  postMessage({ id, action, result });
1060
1104
  break;
1061
1105
  }
1062
1106
  case "conversation.sendActions": {
1063
1107
  const group = getGroup(data.id);
1064
- const result = await group.sendActions(data.actions, data.isOptimistic);
1108
+ const result = await group.sendActions(data.actions, data.opts);
1065
1109
  postMessage({ id, action, result });
1066
1110
  break;
1067
1111
  }
1068
1112
  case "conversation.sendIntent": {
1069
1113
  const group = getGroup(data.id);
1070
- const result = await group.sendIntent(data.intent, data.isOptimistic);
1114
+ const result = await group.sendIntent(data.intent, data.opts);
1071
1115
  postMessage({ id, action, result });
1072
1116
  break;
1073
1117
  }
1074
1118
  case "conversation.sendAttachment": {
1075
1119
  const group = getGroup(data.id);
1076
- const result = await group.sendAttachment(
1077
- data.attachment,
1078
- data.isOptimistic,
1079
- );
1120
+ const result = await group.sendAttachment(data.attachment, data.opts);
1080
1121
  postMessage({ id, action, result });
1081
1122
  break;
1082
1123
  }
@@ -1084,7 +1125,7 @@ self.onmessage = async (
1084
1125
  const group = getGroup(data.id);
1085
1126
  const result = await group.sendMultiRemoteAttachment(
1086
1127
  data.multiRemoteAttachment,
1087
- data.isOptimistic,
1128
+ data.opts,
1088
1129
  );
1089
1130
  postMessage({ id, action, result });
1090
1131
  break;
@@ -1093,7 +1134,7 @@ self.onmessage = async (
1093
1134
  const group = getGroup(data.id);
1094
1135
  const result = await group.sendRemoteAttachment(
1095
1136
  data.remoteAttachment,
1096
- data.isOptimistic,
1137
+ data.opts,
1097
1138
  );
1098
1139
  postMessage({ id, action, result });
1099
1140
  break;