@xmtp/browser-sdk 0.0.23 → 1.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.
@@ -4,6 +4,7 @@ import {
4
4
  type Conversation,
5
5
  type EncodedContent,
6
6
  type GroupMember,
7
+ type Identifier,
7
8
  type Message,
8
9
  type MetadataField,
9
10
  type PermissionPolicy,
@@ -121,19 +122,19 @@ export class WorkerConversation {
121
122
  return this.#group.sync();
122
123
  }
123
124
 
124
- async addMembers(accountAddresses: string[]) {
125
- return this.#group.addMembers(accountAddresses);
125
+ async addMembersByIdentifiers(identifiers: Identifier[]) {
126
+ return this.#group.addMembers(identifiers);
126
127
  }
127
128
 
128
- async addMembersByInboxId(inboxIds: string[]) {
129
+ async addMembers(inboxIds: string[]) {
129
130
  return this.#group.addMembersByInboxId(inboxIds);
130
131
  }
131
132
 
132
- async removeMembers(accountAddresses: string[]) {
133
- return this.#group.removeMembers(accountAddresses);
133
+ async removeMembersByIdentifiers(identifiers: Identifier[]) {
134
+ return this.#group.removeMembers(identifiers);
134
135
  }
135
136
 
136
- async removeMembersByInboxId(inboxIds: string[]) {
137
+ async removeMembers(inboxIds: string[]) {
137
138
  return this.#group.removeMembersByInboxId(inboxIds);
138
139
  }
139
140
 
@@ -209,4 +210,8 @@ export class WorkerConversation {
209
210
  };
210
211
  return this.#group.stream({ on_message, on_error });
211
212
  }
213
+
214
+ pausedForVersion() {
215
+ return this.#group.pausedForVersion();
216
+ }
212
217
  }
@@ -1,12 +1,11 @@
1
1
  import {
2
2
  ConversationType,
3
- type Consent,
4
3
  type ConsentState,
5
4
  type Conversation,
6
5
  type ConversationListItem,
7
6
  type Conversations,
7
+ type Identifier,
8
8
  type Message,
9
- type UserPreference,
10
9
  } from "@xmtp/wasm-bindings";
11
10
  import type { StreamCallback } from "@/AsyncStream";
12
11
  import {
@@ -96,18 +95,18 @@ export class WorkerConversations {
96
95
  );
97
96
  }
98
97
 
99
- async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {
98
+ async newGroupWithIdentifiers(
99
+ identifiers: Identifier[],
100
+ options?: SafeCreateGroupOptions,
101
+ ) {
100
102
  const group = await this.#conversations.createGroup(
101
- accountAddresses,
103
+ identifiers,
102
104
  options ? fromSafeCreateGroupOptions(options) : undefined,
103
105
  );
104
106
  return new WorkerConversation(this.#client, group);
105
107
  }
106
108
 
107
- async newGroupByInboxIds(
108
- inboxIds: string[],
109
- options?: SafeCreateGroupOptions,
110
- ) {
109
+ async newGroup(inboxIds: string[], options?: SafeCreateGroupOptions) {
111
110
  const group = await this.#conversations.createGroupByInboxIds(
112
111
  inboxIds,
113
112
  options ? fromSafeCreateGroupOptions(options) : undefined,
@@ -115,15 +114,18 @@ export class WorkerConversations {
115
114
  return new WorkerConversation(this.#client, group);
116
115
  }
117
116
 
118
- async newDm(accountAddress: string, options?: SafeCreateDmOptions) {
117
+ async newDmWithIdentifier(
118
+ identifier: Identifier,
119
+ options?: SafeCreateDmOptions,
120
+ ) {
119
121
  const group = await this.#conversations.createDm(
120
- accountAddress,
122
+ identifier,
121
123
  options ? fromSafeCreateDmOptions(options) : undefined,
122
124
  );
123
125
  return new WorkerConversation(this.#client, group);
124
126
  }
125
127
 
126
- async newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions) {
128
+ async newDm(inboxId: string, options?: SafeCreateDmOptions) {
127
129
  const group = await this.#conversations.createDmByInboxId(
128
130
  inboxId,
129
131
  options ? fromSafeCreateDmOptions(options) : undefined,
@@ -174,27 +176,4 @@ export class WorkerConversations {
174
176
  conversationType,
175
177
  );
176
178
  }
177
-
178
- streamConsent(callback?: StreamCallback<Consent[]>) {
179
- const on_consent_update = (consent: Consent[]) => {
180
- void callback?.(null, consent);
181
- };
182
- const on_error = (error: Error | null) => {
183
- void callback?.(error, undefined);
184
- };
185
- return this.#conversations.streamConsent({ on_consent_update, on_error });
186
- }
187
-
188
- streamPreferences(callback?: StreamCallback<UserPreference[]>) {
189
- const on_user_preference_update = (preferences: UserPreference[]) => {
190
- void callback?.(null, preferences);
191
- };
192
- const on_error = (error: Error | null) => {
193
- void callback?.(error, undefined);
194
- };
195
- return this.#conversations.streamPreferences({
196
- on_user_preference_update,
197
- on_error,
198
- });
199
- }
200
179
  }
@@ -0,0 +1,58 @@
1
+ import {
2
+ type Client,
3
+ type Consent,
4
+ type ConsentEntityType,
5
+ type Conversations,
6
+ type UserPreference,
7
+ } from "@xmtp/wasm-bindings";
8
+ import type { StreamCallback } from "@/AsyncStream";
9
+ import { fromSafeConsent, type SafeConsent } from "@/utils/conversions";
10
+
11
+ export class WorkerPreferences {
12
+ #client: Client;
13
+ #conversations: Conversations;
14
+
15
+ constructor(client: Client, conversations: Conversations) {
16
+ this.#client = client;
17
+ this.#conversations = conversations;
18
+ }
19
+
20
+ async inboxState(refreshFromNetwork: boolean) {
21
+ return this.#client.inboxState(refreshFromNetwork);
22
+ }
23
+
24
+ async getLatestInboxState(inboxId: string) {
25
+ return this.#client.getLatestInboxState(inboxId);
26
+ }
27
+
28
+ async setConsentStates(records: SafeConsent[]) {
29
+ return this.#client.setConsentStates(records.map(fromSafeConsent));
30
+ }
31
+
32
+ async getConsentState(entityType: ConsentEntityType, entity: string) {
33
+ return this.#client.getConsentState(entityType, entity);
34
+ }
35
+
36
+ streamConsent(callback?: StreamCallback<Consent[]>) {
37
+ const on_consent_update = (consent: Consent[]) => {
38
+ void callback?.(null, consent);
39
+ };
40
+ const on_error = (error: Error | null) => {
41
+ void callback?.(error, undefined);
42
+ };
43
+ return this.#conversations.streamConsent({ on_consent_update, on_error });
44
+ }
45
+
46
+ streamPreferences(callback?: StreamCallback<UserPreference[]>) {
47
+ const on_user_preference_update = (preferences: UserPreference[]) => {
48
+ void callback?.(null, preferences);
49
+ };
50
+ const on_error = (error: Error | null) => {
51
+ void callback?.(error, undefined);
52
+ };
53
+ return this.#conversations.streamPreferences({
54
+ on_user_preference_update,
55
+ on_error,
56
+ });
57
+ }
58
+ }
package/src/index.ts CHANGED
@@ -9,7 +9,11 @@ export { Utils } from "./Utils";
9
9
  export { ApiUrls, HistorySyncUrls } from "./constants";
10
10
  export type * from "./types";
11
11
  export * from "./utils/conversions";
12
- export type { UserPreference } from "@xmtp/wasm-bindings";
12
+ export type {
13
+ Identifier,
14
+ IdentifierKind,
15
+ UserPreference,
16
+ } from "@xmtp/wasm-bindings";
13
17
  export {
14
18
  Consent,
15
19
  ConsentEntityType,
@@ -37,6 +41,7 @@ export {
37
41
  Message,
38
42
  MessageDisappearingSettings,
39
43
  MetadataField,
44
+ Opfs,
40
45
  PermissionLevel,
41
46
  PermissionPolicy,
42
47
  PermissionPolicySet,
@@ -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" }>;