@xmtp/browser-sdk 0.0.22 → 1.0.0-rc1

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.
@@ -2,6 +2,7 @@ import type {
2
2
  ConsentEntityType,
3
3
  ConsentState,
4
4
  ConversationType,
5
+ Identifier,
5
6
  MetadataField,
6
7
  PermissionPolicy,
7
8
  PermissionUpdateType,
@@ -56,7 +57,7 @@ export type ClientEvents =
56
57
  installationIdBytes: Uint8Array;
57
58
  };
58
59
  data: {
59
- address: string;
60
+ identifier: Identifier;
60
61
  encryptionKey: Uint8Array;
61
62
  options?: ClientOptions;
62
63
  };
@@ -72,7 +73,7 @@ export type ClientEvents =
72
73
  id: string;
73
74
  result: string | undefined;
74
75
  data: {
75
- newAccountAddress: string;
76
+ newIdentifier: Identifier;
76
77
  };
77
78
  }
78
79
  | {
@@ -80,7 +81,7 @@ export type ClientEvents =
80
81
  id: string;
81
82
  result: string | undefined;
82
83
  data: {
83
- accountAddress: string;
84
+ identifier: Identifier;
84
85
  };
85
86
  }
86
87
  | {
@@ -98,7 +99,7 @@ export type ClientEvents =
98
99
  };
99
100
  }
100
101
  | {
101
- action: "addSignature";
102
+ action: "addEcdsaSignature";
102
103
  id: string;
103
104
  result: undefined;
104
105
  data: {
@@ -140,7 +141,7 @@ export type ClientEvents =
140
141
  id: string;
141
142
  result: Map<string, boolean>;
142
143
  data: {
143
- accountAddresses: string[];
144
+ identifiers: Identifier[];
144
145
  };
145
146
  }
146
147
  | {
@@ -177,11 +178,11 @@ export type ClientEvents =
177
178
  };
178
179
  }
179
180
  | {
180
- action: "findInboxIdByAddress";
181
+ action: "findInboxIdByIdentifier";
181
182
  id: string;
182
183
  result: string | undefined;
183
184
  data: {
184
- address: string;
185
+ identifier: Identifier;
185
186
  };
186
187
  }
187
188
  | {
@@ -263,16 +264,16 @@ export type ClientEvents =
263
264
  };
264
265
  }
265
266
  | {
266
- action: "newGroup";
267
+ action: "newGroupWithIdentifiers";
267
268
  id: string;
268
269
  result: SafeConversation;
269
270
  data: {
270
- accountAddresses: string[];
271
+ identifiers: Identifier[];
271
272
  options?: SafeCreateGroupOptions;
272
273
  };
273
274
  }
274
275
  | {
275
- action: "newGroupByInboxIds";
276
+ action: "newGroupWithInboxIds";
276
277
  id: string;
277
278
  result: SafeConversation;
278
279
  data: {
@@ -281,16 +282,16 @@ export type ClientEvents =
281
282
  };
282
283
  }
283
284
  | {
284
- action: "newDm";
285
+ action: "newDmWithIdentifier";
285
286
  id: string;
286
287
  result: SafeConversation;
287
288
  data: {
288
- accountAddress: string;
289
+ identifier: Identifier;
289
290
  options?: SafeCreateDmOptions;
290
291
  };
291
292
  }
292
293
  | {
293
- action: "newDmByInboxId";
294
+ action: "newDmWithInboxId";
294
295
  id: string;
295
296
  result: SafeConversation;
296
297
  data: {
@@ -446,7 +447,7 @@ export type ClientEvents =
446
447
  result: undefined;
447
448
  data: {
448
449
  id: string;
449
- accountAddresses: string[];
450
+ identifiers: Identifier[];
450
451
  };
451
452
  }
452
453
  | {
@@ -455,7 +456,7 @@ export type ClientEvents =
455
456
  result: undefined;
456
457
  data: {
457
458
  id: string;
458
- accountAddresses: string[];
459
+ identifiers: Identifier[];
459
460
  };
460
461
  }
461
462
  | {
@@ -623,6 +624,14 @@ export type ClientEvents =
623
624
  groupId: string;
624
625
  streamId: string;
625
626
  };
627
+ }
628
+ | {
629
+ action: "getGroupPausedForVersion";
630
+ id: string;
631
+ result: string | undefined;
632
+ data: {
633
+ id: string;
634
+ };
626
635
  };
627
636
 
628
637
  export type ClientEventsActions = ClientEvents["action"];
@@ -1,3 +1,4 @@
1
+ import type { Identifier } from "@xmtp/wasm-bindings";
1
2
  import type {
2
3
  EventsClientMessageData,
3
4
  EventsClientPostMessageData,
@@ -15,16 +16,16 @@ export type UtilsEvents =
15
16
  id: string;
16
17
  result: string;
17
18
  data: {
18
- address: string;
19
+ identifier: Identifier;
19
20
  enableLogging: boolean;
20
21
  };
21
22
  }
22
23
  | {
23
- action: "getInboxIdForAddress";
24
+ action: "getInboxIdForIdentifier";
24
25
  id: string;
25
26
  result: string | undefined;
26
27
  data: {
27
- address: string;
28
+ identifier: Identifier;
28
29
  env?: XmtpEnv;
29
30
  enableLogging: boolean;
30
31
  };
@@ -20,6 +20,7 @@ import {
20
20
  type DeliveryStatus,
21
21
  type GroupMessageKind,
22
22
  type HmacKey,
23
+ type Identifier,
23
24
  type InboxState,
24
25
  type Installation,
25
26
  type Message,
@@ -394,17 +395,17 @@ export const toSafeInstallation = (
394
395
  });
395
396
 
396
397
  export type SafeInboxState = {
397
- accountAddresses: string[];
398
+ accountIdentifiers: Identifier[];
398
399
  inboxId: string;
399
400
  installations: SafeInstallation[];
400
- recoveryAddress: string;
401
+ recoveryIdentifier: Identifier;
401
402
  };
402
403
 
403
404
  export const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({
404
- accountAddresses: inboxState.accountAddresses,
405
+ accountIdentifiers: inboxState.accountIdentifiers,
405
406
  inboxId: inboxState.inboxId,
406
407
  installations: inboxState.installations.map(toSafeInstallation),
407
- recoveryAddress: inboxState.recoveryAddress,
408
+ recoveryIdentifier: inboxState.recoveryIdentifier,
408
409
  });
409
410
 
410
411
  export type SafeConsent = {
@@ -423,7 +424,7 @@ export const fromSafeConsent = (consent: SafeConsent): Consent =>
423
424
  new Consent(consent.entityType, consent.state, consent.entity);
424
425
 
425
426
  export type SafeGroupMember = {
426
- accountAddresses: string[];
427
+ accountIdentifiers: Identifier[];
427
428
  consentState: ConsentState;
428
429
  inboxId: string;
429
430
  installationIds: string[];
@@ -431,7 +432,7 @@ export type SafeGroupMember = {
431
432
  };
432
433
 
433
434
  export const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({
434
- accountAddresses: member.accountAddresses,
435
+ accountIdentifiers: member.accountIdentifiers,
435
436
  consentState: member.consentState,
436
437
  inboxId: member.inboxId,
437
438
  installationIds: member.installationIds,
@@ -441,7 +442,7 @@ export const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({
441
442
  export const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>
442
443
  new GroupMember(
443
444
  member.inboxId,
444
- member.accountAddresses,
445
+ member.accountIdentifiers,
445
446
  member.installationIds,
446
447
  member.permissionLevel,
447
448
  member.consentState,
@@ -1,28 +1,24 @@
1
- import init, {
1
+ import {
2
2
  createClient as createWasmClient,
3
3
  generateInboxId,
4
- getInboxIdForAddress,
4
+ getInboxIdForIdentifier,
5
5
  LogOptions,
6
+ type Identifier,
6
7
  } from "@xmtp/wasm-bindings";
7
8
  import { ApiUrls, HistorySyncUrls } from "@/constants";
8
9
  import type { ClientOptions } from "@/types";
9
10
 
10
11
  export const createClient = async (
11
- accountAddress: string,
12
+ identifier: Identifier,
12
13
  encryptionKey: Uint8Array,
13
14
  options?: Omit<ClientOptions, "codecs">,
14
15
  ) => {
15
- // initialize WASM module
16
- await init();
17
-
18
16
  const host = options?.apiUrl || ApiUrls[options?.env || "dev"];
19
- const dbPath =
20
- options?.dbPath || `xmtp-${options?.env || "dev"}-${accountAddress}.db3`;
21
-
22
17
  const inboxId =
23
- (await getInboxIdForAddress(host, accountAddress)) ||
24
- generateInboxId(accountAddress);
25
-
18
+ (await getInboxIdForIdentifier(host, identifier)) ||
19
+ generateInboxId(identifier);
20
+ const dbPath =
21
+ options?.dbPath || `xmtp-${options?.env || "dev"}-${inboxId}.db3`;
26
22
  const isLogging =
27
23
  options &&
28
24
  (options.loggingLevel !== undefined ||
@@ -35,7 +31,7 @@ export const createClient = async (
35
31
  return createWasmClient(
36
32
  host,
37
33
  inboxId,
38
- accountAddress,
34
+ identifier,
39
35
  dbPath,
40
36
  encryptionKey,
41
37
  historySyncUrl,
@@ -1,18 +1,23 @@
1
+ import type { Identifier } from "@xmtp/wasm-bindings";
2
+
1
3
  export type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
2
- export type GetAddress = () => Promise<string> | string;
4
+ export type GetIdentifier = () => Promise<Identifier> | Identifier;
3
5
  export type GetChainId = () => bigint;
4
6
  export type GetBlockNumber = () => bigint;
5
7
 
6
8
  export type Signer =
7
9
  | {
8
- walletType: "EOA";
9
- getAddress: GetAddress;
10
+ type: "EOA";
11
+ getIdentifier: GetIdentifier;
10
12
  signMessage: SignMessage;
11
13
  }
12
14
  | {
13
- walletType: "SCW";
14
- getAddress: GetAddress;
15
+ type: "SCW";
16
+ getIdentifier: GetIdentifier;
15
17
  signMessage: SignMessage;
16
18
  getBlockNumber?: GetBlockNumber;
17
19
  getChainId: GetChainId;
18
20
  };
21
+
22
+ export type EOASigner = Extract<Signer, { type: "EOA" }>;
23
+ export type SCWSigner = Extract<Signer, { type: "SCW" }>;
@@ -1,9 +1,9 @@
1
- import type {
2
- Consent,
3
- Conversation,
4
- Message,
5
- StreamCloser,
6
- UserPreference,
1
+ import init, {
2
+ type Consent,
3
+ type Conversation,
4
+ type Message,
5
+ type StreamCloser,
6
+ type UserPreference,
7
7
  } from "@xmtp/wasm-bindings";
8
8
  import type {
9
9
  ClientEventsActions,
@@ -73,11 +73,14 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
73
73
  console.log("client worker received event data", event.data);
74
74
  }
75
75
 
76
+ // initialize WASM module
77
+ await init();
78
+
76
79
  try {
77
80
  // init is a special action that initializes the client
78
81
  if (action === "init" && !maybeClient) {
79
82
  maybeClient = await WorkerClient.create(
80
- data.address,
83
+ data.identifier,
81
84
  data.encryptionKey,
82
85
  data.options,
83
86
  );
@@ -138,16 +141,12 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
138
141
  break;
139
142
  }
140
143
  case "addAccountSignatureText": {
141
- const result = await client.addAccountSignatureText(
142
- data.newAccountAddress,
143
- );
144
+ const result = await client.addAccountSignatureText(data.newIdentifier);
144
145
  postMessage({ id, action, result });
145
146
  break;
146
147
  }
147
148
  case "removeAccountSignatureText": {
148
- const result = await client.removeAccountSignatureText(
149
- data.accountAddress,
150
- );
149
+ const result = await client.removeAccountSignatureText(data.identifier);
151
150
  postMessage({ id, action, result });
152
151
  break;
153
152
  }
@@ -163,8 +162,8 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
163
162
  postMessage({ id, action, result });
164
163
  break;
165
164
  }
166
- case "addSignature":
167
- await client.addSignature(data.type, data.bytes);
165
+ case "addEcdsaSignature":
166
+ await client.addEcdsaSignature(data.type, data.bytes);
168
167
  postMessage({ id, action, result: undefined });
169
168
  break;
170
169
  case "addScwSignature":
@@ -190,7 +189,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
190
189
  break;
191
190
  }
192
191
  case "canMessage": {
193
- const result = await client.canMessage(data.accountAddresses);
192
+ const result = await client.canMessage(data.identifiers);
194
193
  postMessage({ id, action, result });
195
194
  break;
196
195
  }
@@ -219,8 +218,8 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
219
218
  postMessage({ id, action, result });
220
219
  break;
221
220
  }
222
- case "findInboxIdByAddress": {
223
- const result = await client.findInboxIdByAddress(data.address);
221
+ case "findInboxIdByIdentifier": {
222
+ const result = await client.findInboxIdByIdentifier(data.identifier);
224
223
  postMessage({ id, action, result });
225
224
  break;
226
225
  }
@@ -388,17 +387,17 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
388
387
  postMessage({ id, action, result });
389
388
  break;
390
389
  }
391
- case "newGroup": {
392
- const conversation = await client.conversations.newGroup(
393
- data.accountAddresses,
390
+ case "newGroupWithIdentifiers": {
391
+ const conversation = await client.conversations.newGroupWithIdentifiers(
392
+ data.identifiers,
394
393
  data.options,
395
394
  );
396
395
  const result = await toSafeConversation(conversation);
397
396
  postMessage({ id, action, result });
398
397
  break;
399
398
  }
400
- case "newGroupByInboxIds": {
401
- const conversation = await client.conversations.newGroupByInboxIds(
399
+ case "newGroupWithInboxIds": {
400
+ const conversation = await client.conversations.newGroup(
402
401
  data.inboxIds,
403
402
  data.options,
404
403
  );
@@ -406,17 +405,17 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
406
405
  postMessage({ id, action, result });
407
406
  break;
408
407
  }
409
- case "newDm": {
410
- const conversation = await client.conversations.newDm(
411
- data.accountAddress,
408
+ case "newDmWithIdentifier": {
409
+ const conversation = await client.conversations.newDmWithIdentifier(
410
+ data.identifier,
412
411
  data.options,
413
412
  );
414
413
  const result = await toSafeConversation(conversation);
415
414
  postMessage({ id, action, result });
416
415
  break;
417
416
  }
418
- case "newDmByInboxId": {
419
- const conversation = await client.conversations.newDmByInboxId(
417
+ case "newDmWithInboxId": {
418
+ const conversation = await client.conversations.newDm(
420
419
  data.inboxId,
421
420
  data.options,
422
421
  );
@@ -588,25 +587,25 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
588
587
  }
589
588
  case "addGroupMembers": {
590
589
  const group = getGroup(data.id);
591
- await group.addMembers(data.accountAddresses);
590
+ await group.addMembersByIdentifiers(data.identifiers);
592
591
  postMessage({ id, action, result: undefined });
593
592
  break;
594
593
  }
595
594
  case "removeGroupMembers": {
596
595
  const group = getGroup(data.id);
597
- await group.removeMembers(data.accountAddresses);
596
+ await group.removeMembersByIdentifiers(data.identifiers);
598
597
  postMessage({ id, action, result: undefined });
599
598
  break;
600
599
  }
601
600
  case "addGroupMembersByInboxId": {
602
601
  const group = getGroup(data.id);
603
- await group.addMembersByInboxId(data.inboxIds);
602
+ await group.addMembers(data.inboxIds);
604
603
  postMessage({ id, action, result: undefined });
605
604
  break;
606
605
  }
607
606
  case "removeGroupMembersByInboxId": {
608
607
  const group = getGroup(data.id);
609
- await group.removeMembersByInboxId(data.inboxIds);
608
+ await group.removeMembers(data.inboxIds);
610
609
  postMessage({ id, action, result: undefined });
611
610
  break;
612
611
  }
@@ -697,6 +696,12 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
697
696
  postMessage({ id, action, result: undefined });
698
697
  break;
699
698
  }
699
+ case "getGroupPausedForVersion": {
700
+ const group = getGroup(data.id);
701
+ const result = group.pausedForVersion();
702
+ postMessage({ id, action, result });
703
+ break;
704
+ }
700
705
  }
701
706
  } catch (e) {
702
707
  postMessageError({
@@ -1,6 +1,7 @@
1
1
  import init, {
2
- generateInboxId as generate_inbox_id,
3
- getInboxIdForAddress as get_inbox_id_for_address,
2
+ generateInboxId,
3
+ getInboxIdForIdentifier as get_inbox_id_for_identifier,
4
+ type Identifier,
4
5
  } from "@xmtp/wasm-bindings";
5
6
  import { ApiUrls } from "@/constants";
6
7
  import type {
@@ -27,15 +28,12 @@ const postMessageError = (data: UtilsEventsErrorData) => {
27
28
  self.postMessage(data);
28
29
  };
29
30
 
30
- export const generateInboxId = async (address: string) => {
31
- await init();
32
- return generate_inbox_id(address);
33
- };
34
-
35
- export const getInboxIdForAddress = async (address: string, env?: XmtpEnv) => {
36
- await init();
31
+ const getInboxIdForIdentifier = async (
32
+ identifier: Identifier,
33
+ env?: XmtpEnv,
34
+ ) => {
37
35
  const host = env ? ApiUrls[env] : ApiUrls.dev;
38
- return get_inbox_id_for_address(host, address);
36
+ return get_inbox_id_for_identifier(host, identifier);
39
37
  };
40
38
 
41
39
  self.onmessage = async (event: MessageEvent<UtilsEventsClientMessageData>) => {
@@ -44,20 +42,23 @@ self.onmessage = async (event: MessageEvent<UtilsEventsClientMessageData>) => {
44
42
  console.log("utils worker received event data", event.data);
45
43
  }
46
44
 
45
+ // initialize WASM module
46
+ await init();
47
+
47
48
  try {
48
49
  switch (action) {
49
50
  case "generateInboxId":
50
51
  postMessage({
51
52
  id,
52
53
  action,
53
- result: await generateInboxId(data.address),
54
+ result: generateInboxId(data.identifier),
54
55
  });
55
56
  break;
56
- case "getInboxIdForAddress":
57
+ case "getInboxIdForIdentifier":
57
58
  postMessage({
58
59
  id,
59
60
  action,
60
- result: await getInboxIdForAddress(data.address, data.env),
61
+ result: await getInboxIdForIdentifier(data.identifier, data.env),
61
62
  });
62
63
  break;
63
64
  // no default