@xmtp/browser-sdk 0.0.1 → 0.0.3

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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
2
- import { WasmSignatureRequestType, WasmConsentState, WasmConsentEntityType, WasmConversations, WasmClient, WasmGroup, WasmGroupMember, WasmEncodedContent, WasmContentTypeId, WasmDeliveryStatus, WasmGroupMessageKind, WasmMessage, WasmListMessagesOptions, WasmListConversationsOptions, WasmGroupPermissionsOptions, WasmCreateGroupOptions, WasmPermissionPolicy, WasmInstallation, WasmInboxState, WasmConsent, WasmPermissionLevel } from '@xmtp/wasm-bindings';
3
- export * from '@xmtp/wasm-bindings';
4
- import { ContentCodec, ContentTypeId, EncodedContent } from '@xmtp/content-type-primitives';
2
+ import { SignatureRequestType, ConsentState, ConsentEntityType, Conversations as Conversations$1, Client as Client$1, Conversation as Conversation$1, EncodedContent, ContentTypeId, DeliveryStatus, GroupMessageKind, Message, SortDirection, ListMessagesOptions, GroupMembershipState, ConversationType, ListConversationsOptions, GroupPermissionsOptions, CreateGroupOptions, PermissionPolicy, Installation, InboxState, Consent, PermissionLevel, GroupMember } from '@xmtp/wasm-bindings';
3
+ export { Consent, ConsentEntityType, ConsentState, ContentTypeId, ConversationType, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, Message, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection } from '@xmtp/wasm-bindings';
4
+ import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
5
5
 
6
6
  declare const ApiUrls: {
7
7
  readonly local: "http://localhost:5555";
@@ -24,15 +24,6 @@ type NetworkOptions = {
24
24
  */
25
25
  apiUrl?: string;
26
26
  };
27
- /**
28
- * Encryption options
29
- */
30
- type EncryptionOptions = {
31
- /**
32
- * Encryption key to use for the local DB
33
- */
34
- encryptionKey?: Uint8Array;
35
- };
36
27
  /**
37
28
  * Storage options
38
29
  */
@@ -50,11 +41,19 @@ type ContentOptions = {
50
41
  };
51
42
  type OtherOptions = {
52
43
  /**
53
- * Enable logging of events between the client and worker
44
+ * Enable structured JSON logging
45
+ */
46
+ structuredLogging?: boolean;
47
+ /**
48
+ * Enable performance metrics
49
+ */
50
+ performanceLogging?: boolean;
51
+ /**
52
+ * Logging level
54
53
  */
55
- enableLogging?: boolean;
54
+ loggingLevel?: "off" | "error" | "warn" | "info" | "debug" | "trace";
56
55
  };
57
- type ClientOptions = NetworkOptions & EncryptionOptions & StorageOptions & ContentOptions & OtherOptions;
56
+ type ClientOptions = NetworkOptions & StorageOptions & ContentOptions & OtherOptions;
58
57
 
59
58
  type ClientEvents =
60
59
  /**
@@ -69,6 +68,7 @@ type ClientEvents =
69
68
  };
70
69
  data: {
71
70
  address: string;
71
+ encryptionKey: Uint8Array;
72
72
  options?: ClientOptions;
73
73
  };
74
74
  } | {
@@ -100,11 +100,21 @@ type ClientEvents =
100
100
  id: string;
101
101
  result: undefined;
102
102
  data: {
103
- type: WasmSignatureRequestType;
103
+ type: SignatureRequestType;
104
104
  bytes: Uint8Array;
105
105
  };
106
106
  } | {
107
- action: "applySignaturesRequests";
107
+ action: "addScwSignature";
108
+ id: string;
109
+ result: undefined;
110
+ data: {
111
+ type: SignatureRequestType;
112
+ bytes: Uint8Array;
113
+ chainId: bigint;
114
+ blockNumber?: bigint;
115
+ };
116
+ } | {
117
+ action: "applySignatures";
108
118
  id: string;
109
119
  result: undefined;
110
120
  data: undefined;
@@ -149,9 +159,9 @@ type ClientEvents =
149
159
  } | {
150
160
  action: "getConsentState";
151
161
  id: string;
152
- result: WasmConsentState;
162
+ result: ConsentState;
153
163
  data: {
154
- entityType: WasmConsentEntityType;
164
+ entityType: ConsentEntityType;
155
165
  entity: string;
156
166
  };
157
167
  } | {
@@ -179,6 +189,13 @@ type ClientEvents =
179
189
  data: {
180
190
  id: string;
181
191
  };
192
+ } | {
193
+ action: "getDmByInboxId";
194
+ id: string;
195
+ result: SafeConversation | undefined;
196
+ data: {
197
+ inboxId: string;
198
+ };
182
199
  } | {
183
200
  action: "getConversations";
184
201
  id: string;
@@ -186,6 +203,20 @@ type ClientEvents =
186
203
  data: {
187
204
  options?: SafeListConversationsOptions;
188
205
  };
206
+ } | {
207
+ action: "getGroups";
208
+ id: string;
209
+ result: SafeConversation[];
210
+ data: {
211
+ options?: Omit<SafeListConversationsOptions, "conversation_type">;
212
+ };
213
+ } | {
214
+ action: "getDms";
215
+ id: string;
216
+ result: SafeConversation[];
217
+ data: {
218
+ options?: Omit<SafeListConversationsOptions, "conversation_type">;
219
+ };
189
220
  } | {
190
221
  action: "newGroup";
191
222
  id: string;
@@ -194,6 +225,13 @@ type ClientEvents =
194
225
  accountAddresses: string[];
195
226
  options?: SafeCreateGroupOptions;
196
227
  };
228
+ } | {
229
+ action: "newDm";
230
+ id: string;
231
+ result: SafeConversation;
232
+ data: {
233
+ accountAddress: string;
234
+ };
197
235
  } | {
198
236
  action: "syncConversations";
199
237
  id: string;
@@ -377,7 +415,7 @@ type ClientEvents =
377
415
  } | {
378
416
  action: "getGroupConsentState";
379
417
  id: string;
380
- result: WasmConsentState;
418
+ result: ConsentState;
381
419
  data: {
382
420
  id: string;
383
421
  };
@@ -387,7 +425,14 @@ type ClientEvents =
387
425
  result: undefined;
388
426
  data: {
389
427
  id: string;
390
- state: WasmConsentState;
428
+ state: ConsentState;
429
+ };
430
+ } | {
431
+ action: "getDmPeerInboxId";
432
+ id: string;
433
+ result: string;
434
+ data: {
435
+ id: string;
391
436
  };
392
437
  };
393
438
  type ClientEventsActions = ClientEvents["action"];
@@ -462,18 +507,22 @@ type EventsErrorData<Events extends GenericEvent> = {
462
507
 
463
508
  declare class WorkerConversations {
464
509
  #private;
465
- constructor(client: WorkerClient, conversations: WasmConversations);
510
+ constructor(client: WorkerClient, conversations: Conversations$1);
466
511
  sync(): Promise<void>;
467
512
  getConversationById(id: string): WorkerConversation | undefined;
468
513
  getMessageById(id: string): SafeMessage | undefined;
514
+ getDmByInboxId(inboxId: string): WorkerConversation | undefined;
469
515
  list(options?: SafeListConversationsOptions): Promise<WorkerConversation[]>;
516
+ listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<WorkerConversation[]>;
517
+ listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<WorkerConversation[]>;
470
518
  newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
519
+ newDm(accountAddress: string): Promise<WorkerConversation>;
471
520
  }
472
521
 
473
522
  declare class WorkerClient {
474
523
  #private;
475
- constructor(client: WasmClient);
476
- static create(accountAddress: string, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
524
+ constructor(client: Client$1);
525
+ static create(accountAddress: string, encryptionKey: Uint8Array, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
477
526
  get accountAddress(): string;
478
527
  get inboxId(): string;
479
528
  get installationId(): string;
@@ -482,21 +531,22 @@ declare class WorkerClient {
482
531
  getAddWalletSignatureText(accountAddress: string): Promise<string | undefined>;
483
532
  getRevokeWalletSignatureText(accountAddress: string): Promise<string | undefined>;
484
533
  getRevokeInstallationsSignatureText(): Promise<string | undefined>;
485
- addSignature(type: WasmSignatureRequestType, bytes: Uint8Array): Promise<void>;
486
- applySignaturesRequests(): Promise<void>;
534
+ addSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<void>;
535
+ addScwSignature(type: SignatureRequestType, bytes: Uint8Array, chainId: bigint, blockNumber?: bigint): Promise<void>;
536
+ applySignatures(): Promise<void>;
487
537
  canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
488
538
  registerIdentity(): Promise<void>;
489
539
  findInboxIdByAddress(address: string): Promise<string | undefined>;
490
- inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.WasmInboxState>;
491
- getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.WasmInboxState>;
540
+ inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
541
+ getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
492
542
  setConsentStates(records: SafeConsent[]): Promise<void>;
493
- getConsentState(entityType: WasmConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.WasmConsentState>;
543
+ getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
494
544
  get conversations(): WorkerConversations;
495
545
  }
496
546
 
497
547
  declare class WorkerConversation {
498
548
  #private;
499
- constructor(client: WorkerClient, group: WasmGroup);
549
+ constructor(client: WorkerClient, group: Conversation$1);
500
550
  get id(): string;
501
551
  get name(): string;
502
552
  updateName(name: string): Promise<void>;
@@ -513,12 +563,12 @@ declare class WorkerConversation {
513
563
  creatorInboxId: string;
514
564
  conversationType: string;
515
565
  };
516
- members(): Promise<WasmGroupMember[]>;
566
+ members(): Promise<SafeGroupMember[]>;
517
567
  get admins(): string[];
518
568
  get superAdmins(): string[];
519
569
  get permissions(): {
520
- policyType: _xmtp_wasm_bindings.WasmGroupPermissionsOptions;
521
- policySet: _xmtp_wasm_bindings.WasmPermissionPolicySet;
570
+ policyType: _xmtp_wasm_bindings.GroupPermissionsOptions;
571
+ policySet: _xmtp_wasm_bindings.PermissionPolicySet;
522
572
  };
523
573
  isAdmin(inboxId: string): boolean;
524
574
  isSuperAdmin(inboxId: string): boolean;
@@ -532,25 +582,26 @@ declare class WorkerConversation {
532
582
  addSuperAdmin(inboxId: string): Promise<void>;
533
583
  removeSuperAdmin(inboxId: string): Promise<void>;
534
584
  publishMessages(): Promise<void>;
535
- sendOptimistic(encodedContent: WasmEncodedContent): string;
536
- send(encodedContent: WasmEncodedContent): Promise<string>;
537
- messages(options?: SafeListMessagesOptions): _xmtp_wasm_bindings.WasmMessage[];
538
- get consentState(): WasmConsentState;
539
- updateConsentState(state: WasmConsentState): void;
585
+ sendOptimistic(encodedContent: EncodedContent): string;
586
+ send(encodedContent: EncodedContent): Promise<string>;
587
+ messages(options?: SafeListMessagesOptions): _xmtp_wasm_bindings.Message[];
588
+ get consentState(): ConsentState;
589
+ updateConsentState(state: ConsentState): void;
590
+ dmPeerInboxId(): string;
540
591
  }
541
592
 
542
- declare const toContentTypeId: (contentTypeId: WasmContentTypeId) => ContentTypeId;
543
- declare const fromContentTypeId: (contentTypeId: ContentTypeId) => WasmContentTypeId;
593
+ declare const toContentTypeId: (contentTypeId: ContentTypeId) => ContentTypeId$1;
594
+ declare const fromContentTypeId: (contentTypeId: ContentTypeId$1) => ContentTypeId;
544
595
  type SafeContentTypeId = {
545
596
  authorityId: string;
546
597
  typeId: string;
547
598
  versionMajor: number;
548
599
  versionMinor: number;
549
600
  };
550
- declare const toSafeContentTypeId: (contentTypeId: ContentTypeId) => SafeContentTypeId;
551
- declare const fromSafeContentTypeId: (contentTypeId: SafeContentTypeId) => ContentTypeId;
552
- declare const toEncodedContent: (content: WasmEncodedContent) => EncodedContent;
553
- declare const fromEncodedContent: (content: EncodedContent) => WasmEncodedContent;
601
+ declare const toSafeContentTypeId: (contentTypeId: ContentTypeId$1) => SafeContentTypeId;
602
+ declare const fromSafeContentTypeId: (contentTypeId: SafeContentTypeId) => ContentTypeId$1;
603
+ declare const toEncodedContent: (content: EncodedContent) => EncodedContent$1;
604
+ declare const fromEncodedContent: (content: EncodedContent$1) => EncodedContent;
554
605
  type SafeEncodedContent = {
555
606
  type: SafeContentTypeId;
556
607
  parameters: Record<string, string>;
@@ -558,42 +609,45 @@ type SafeEncodedContent = {
558
609
  compression?: number;
559
610
  content: Uint8Array;
560
611
  };
561
- declare const toSafeEncodedContent: (content: EncodedContent) => SafeEncodedContent;
562
- declare const fromSafeEncodedContent: (content: SafeEncodedContent) => EncodedContent;
612
+ declare const toSafeEncodedContent: (content: EncodedContent$1) => SafeEncodedContent;
613
+ declare const fromSafeEncodedContent: (content: SafeEncodedContent) => EncodedContent$1;
563
614
  type SafeMessage = {
564
615
  content: SafeEncodedContent;
565
616
  convoId: string;
566
- deliveryStatus: WasmDeliveryStatus;
617
+ deliveryStatus: DeliveryStatus;
567
618
  id: string;
568
- kind: WasmGroupMessageKind;
619
+ kind: GroupMessageKind;
569
620
  senderInboxId: string;
570
621
  sentAtNs: bigint;
571
622
  };
572
- declare const toSafeMessage: (message: WasmMessage) => SafeMessage;
623
+ declare const toSafeMessage: (message: Message) => SafeMessage;
573
624
  type SafeListMessagesOptions = {
574
- delivery_status?: WasmDeliveryStatus;
625
+ deliveryStatus?: DeliveryStatus;
626
+ direction?: SortDirection;
575
627
  limit?: bigint;
576
- sent_after_ns?: bigint;
577
- sent_before_ns?: bigint;
628
+ sentAfterNs?: bigint;
629
+ sentBeforeNs?: bigint;
578
630
  };
579
- declare const toSafeListMessagesOptions: (options: WasmListMessagesOptions) => SafeListMessagesOptions;
580
- declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => WasmListMessagesOptions;
631
+ declare const toSafeListMessagesOptions: (options: ListMessagesOptions) => SafeListMessagesOptions;
632
+ declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => ListMessagesOptions;
581
633
  type SafeListConversationsOptions = {
582
- created_after_ns?: bigint;
583
- created_before_ns?: bigint;
634
+ allowedStates?: GroupMembershipState[];
635
+ conversationType?: ConversationType;
636
+ createdAfterNs?: bigint;
637
+ createdBeforeNs?: bigint;
584
638
  limit?: bigint;
585
639
  };
586
- declare const toSafeListConversationsOptions: (options: WasmListConversationsOptions) => SafeListConversationsOptions;
587
- declare const fromSafeListConversationsOptions: (options: SafeListConversationsOptions) => WasmListConversationsOptions;
640
+ declare const toSafeListConversationsOptions: (options: ListConversationsOptions) => SafeListConversationsOptions;
641
+ declare const fromSafeListConversationsOptions: (options: SafeListConversationsOptions) => ListConversationsOptions;
588
642
  type SafeCreateGroupOptions = {
589
- permissions?: WasmGroupPermissionsOptions;
643
+ permissions?: GroupPermissionsOptions;
590
644
  name?: string;
591
645
  imageUrlSquare?: string;
592
646
  description?: string;
593
647
  pinnedFrameUrl?: string;
594
648
  };
595
- declare const toSafeCreateGroupOptions: (options: WasmCreateGroupOptions) => SafeCreateGroupOptions;
596
- declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) => WasmCreateGroupOptions;
649
+ declare const toSafeCreateGroupOptions: (options: CreateGroupOptions) => SafeCreateGroupOptions;
650
+ declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) => CreateGroupOptions;
597
651
  type SafeConversation = {
598
652
  id: string;
599
653
  name: string;
@@ -601,16 +655,16 @@ type SafeConversation = {
601
655
  description: string;
602
656
  pinnedFrameUrl: string;
603
657
  permissions: {
604
- policyType: WasmGroupPermissionsOptions;
658
+ policyType: GroupPermissionsOptions;
605
659
  policySet: {
606
- addAdminPolicy: WasmPermissionPolicy;
607
- addMemberPolicy: WasmPermissionPolicy;
608
- removeAdminPolicy: WasmPermissionPolicy;
609
- removeMemberPolicy: WasmPermissionPolicy;
610
- updateGroupDescriptionPolicy: WasmPermissionPolicy;
611
- updateGroupImageUrlSquarePolicy: WasmPermissionPolicy;
612
- updateGroupNamePolicy: WasmPermissionPolicy;
613
- updateGroupPinnedFrameUrlPolicy: WasmPermissionPolicy;
660
+ addAdminPolicy: PermissionPolicy;
661
+ addMemberPolicy: PermissionPolicy;
662
+ removeAdminPolicy: PermissionPolicy;
663
+ removeMemberPolicy: PermissionPolicy;
664
+ updateGroupDescriptionPolicy: PermissionPolicy;
665
+ updateGroupImageUrlSquarePolicy: PermissionPolicy;
666
+ updateGroupNamePolicy: PermissionPolicy;
667
+ updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
614
668
  };
615
669
  };
616
670
  isActive: boolean;
@@ -628,30 +682,30 @@ type SafeInstallation = {
628
682
  id: string;
629
683
  clientTimestampNs?: bigint;
630
684
  };
631
- declare const toSafeInstallation: (installation: WasmInstallation) => SafeInstallation;
685
+ declare const toSafeInstallation: (installation: Installation) => SafeInstallation;
632
686
  type SafeInboxState = {
633
687
  accountAddresses: string[];
634
688
  inboxId: string;
635
689
  installations: SafeInstallation[];
636
690
  recoveryAddress: string;
637
691
  };
638
- declare const toSafeInboxState: (inboxState: WasmInboxState) => SafeInboxState;
692
+ declare const toSafeInboxState: (inboxState: InboxState) => SafeInboxState;
639
693
  type SafeConsent = {
640
694
  entity: string;
641
- entityType: WasmConsentEntityType;
642
- state: WasmConsentState;
695
+ entityType: ConsentEntityType;
696
+ state: ConsentState;
643
697
  };
644
- declare const toSafeConsent: (consent: WasmConsent) => SafeConsent;
645
- declare const fromSafeConsent: (consent: SafeConsent) => WasmConsent;
698
+ declare const toSafeConsent: (consent: Consent) => SafeConsent;
699
+ declare const fromSafeConsent: (consent: SafeConsent) => Consent;
646
700
  type SafeGroupMember = {
647
701
  accountAddresses: string[];
648
- consentState: WasmConsentState;
702
+ consentState: ConsentState;
649
703
  inboxId: string;
650
704
  installationIds: string[];
651
- permissionLevel: WasmPermissionLevel;
705
+ permissionLevel: PermissionLevel;
652
706
  };
653
- declare const toSafeGroupMember: (member: WasmGroupMember) => SafeGroupMember;
654
- declare const fromSafeGroupMember: (member: SafeGroupMember) => WasmGroupMember;
707
+ declare const toSafeGroupMember: (member: GroupMember) => SafeGroupMember;
708
+ declare const fromSafeGroupMember: (member: SafeGroupMember) => GroupMember;
655
709
 
656
710
  declare class ClientWorkerClass {
657
711
  #private;
@@ -666,7 +720,7 @@ type MessageDeliveryStatus = "unpublished" | "published" | "failed";
666
720
  declare class DecodedMessage {
667
721
  #private;
668
722
  content: any;
669
- contentType: ContentTypeId;
723
+ contentType: ContentTypeId$1;
670
724
  conversationId: string;
671
725
  deliveryStatus: MessageDeliveryStatus;
672
726
  fallback?: string;
@@ -703,16 +757,16 @@ declare class Conversation {
703
757
  admins(): Promise<string[]>;
704
758
  superAdmins(): Promise<string[]>;
705
759
  get permissions(): {
706
- policyType: _xmtp_wasm_bindings.WasmGroupPermissionsOptions;
760
+ policyType: _xmtp_wasm_bindings.GroupPermissionsOptions;
707
761
  policySet: {
708
- addAdminPolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
709
- addMemberPolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
710
- removeAdminPolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
711
- removeMemberPolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
712
- updateGroupDescriptionPolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
713
- updateGroupImageUrlSquarePolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
714
- updateGroupNamePolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
715
- updateGroupPinnedFrameUrlPolicy: _xmtp_wasm_bindings.WasmPermissionPolicy;
762
+ addAdminPolicy: _xmtp_wasm_bindings.PermissionPolicy;
763
+ addMemberPolicy: _xmtp_wasm_bindings.PermissionPolicy;
764
+ removeAdminPolicy: _xmtp_wasm_bindings.PermissionPolicy;
765
+ removeMemberPolicy: _xmtp_wasm_bindings.PermissionPolicy;
766
+ updateGroupDescriptionPolicy: _xmtp_wasm_bindings.PermissionPolicy;
767
+ updateGroupImageUrlSquarePolicy: _xmtp_wasm_bindings.PermissionPolicy;
768
+ updateGroupNamePolicy: _xmtp_wasm_bindings.PermissionPolicy;
769
+ updateGroupPinnedFrameUrlPolicy: _xmtp_wasm_bindings.PermissionPolicy;
716
770
  };
717
771
  } | undefined;
718
772
  isAdmin(inboxId: string): Promise<boolean>;
@@ -727,11 +781,12 @@ declare class Conversation {
727
781
  addSuperAdmin(inboxId: string): Promise<undefined>;
728
782
  removeSuperAdmin(inboxId: string): Promise<undefined>;
729
783
  publishMessages(): Promise<undefined>;
730
- sendOptimistic(content: any, contentType?: ContentTypeId): Promise<string>;
731
- send(content: any, contentType?: ContentTypeId): Promise<string>;
784
+ sendOptimistic(content: any, contentType?: ContentTypeId$1): Promise<string>;
785
+ send(content: any, contentType?: ContentTypeId$1): Promise<string>;
732
786
  messages(options?: SafeListMessagesOptions): Promise<DecodedMessage[]>;
733
- consentState(): Promise<WasmConsentState>;
734
- updateConsentState(state: WasmConsentState): Promise<undefined>;
787
+ consentState(): Promise<ConsentState>;
788
+ updateConsentState(state: ConsentState): Promise<undefined>;
789
+ dmPeerInboxId(): Promise<string>;
735
790
  }
736
791
 
737
792
  declare class Conversations {
@@ -740,37 +795,43 @@ declare class Conversations {
740
795
  sync(): Promise<undefined>;
741
796
  getConversationById(id: string): Promise<SafeConversation | undefined>;
742
797
  getMessageById(id: string): Promise<SafeMessage | undefined>;
798
+ getDmByInboxId(inboxId: string): Promise<SafeConversation | undefined>;
743
799
  list(options?: SafeListConversationsOptions): Promise<Conversation[]>;
800
+ listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<SafeConversation[]>;
801
+ listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<SafeConversation[]>;
744
802
  newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
803
+ newDm(accountAddress: string): Promise<Conversation>;
745
804
  }
746
805
 
747
806
  declare class Client extends ClientWorkerClass {
748
807
  #private;
749
808
  address: string;
750
809
  options?: ClientOptions;
751
- constructor(address: string, options?: ClientOptions);
810
+ constructor(address: string, encryptionKey: Uint8Array, options?: ClientOptions);
752
811
  init(): Promise<void>;
753
- static create(address: string, options?: ClientOptions): Promise<Client>;
812
+ static create(address: string, encryptionKey: Uint8Array, options?: ClientOptions): Promise<Client>;
754
813
  get isReady(): boolean;
755
814
  get inboxId(): string | undefined;
756
815
  get installationId(): string | undefined;
757
816
  getCreateInboxSignatureText(): Promise<string | undefined>;
758
817
  getAddWalletSignatureText(accountAddress: string): Promise<string | undefined>;
759
818
  getRevokeWalletSignatureText(accountAddress: string): Promise<string | undefined>;
760
- addSignature(type: WasmSignatureRequestType, bytes: Uint8Array): Promise<undefined>;
761
- applySignaturesRequests(): Promise<undefined>;
819
+ getRevokeInstallationsSignatureText(): Promise<string | undefined>;
820
+ addSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<undefined>;
821
+ addScwSignature(type: SignatureRequestType, bytes: Uint8Array, chainId: bigint, blockNumber?: bigint): Promise<undefined>;
822
+ applySignatures(): Promise<undefined>;
762
823
  registerIdentity(): Promise<undefined>;
763
824
  isRegistered(): Promise<boolean>;
764
825
  canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
765
826
  findInboxIdByAddress(address: string): Promise<string | undefined>;
766
- inboxState(refreshFromNetwork: boolean): Promise<SafeInboxState>;
827
+ inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
767
828
  getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
768
829
  setConsentStates(records: SafeConsent[]): Promise<undefined>;
769
- getConsentState(entityType: WasmConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.WasmConsentState>;
830
+ getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
770
831
  get conversations(): Conversations;
771
- codecFor(contentType: ContentTypeId): ContentCodec | undefined;
772
- encodeContent(content: any, contentType: ContentTypeId): SafeEncodedContent;
773
- decodeContent(message: SafeMessage, contentType: ContentTypeId): any;
832
+ codecFor(contentType: ContentTypeId$1): ContentCodec | undefined;
833
+ encodeContent(content: any, contentType: ContentTypeId$1): SafeEncodedContent;
834
+ decodeContent(message: SafeMessage, contentType: ContentTypeId$1): any;
774
835
  }
775
836
 
776
837
  declare class UtilsWorkerClass {
@@ -788,4 +849,4 @@ declare class Utils extends UtilsWorkerClass {
788
849
  getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
789
850
  }
790
851
 
791
- export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EncryptionOptions, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SendMessageData, type StorageOptions, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage };
852
+ export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SendMessageData, type StorageOptions, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{WasmContentTypeId as i,WasmEncodedContent as r,WasmListMessagesOptions as o,WasmListConversationsOptions as a,WasmCreateGroupOptions as d,WasmConsent as c,WasmGroupMember as p,WasmGroupMessageKind as l,WasmDeliveryStatus as m}from"@xmtp/wasm-bindings";import{v4 as h}from"uuid";import{ContentTypeId as u}from"@xmtp/content-type-primitives";const g=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class y{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",g),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",g),this.#e.terminate()}}const b=e=>new u({authorityId:e.authority_id,typeId:e.type_id,versionMajor:e.version_major,versionMinor:e.version_minor}),v=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),I=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new u({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),_=e=>({type:b(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),w=e=>new r(v(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),x=e=>({type:I(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),A=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),S=e=>({content:x(_(e.content)),convoId:e.convo_id,deliveryStatus:e.delivery_status,id:e.id,kind:e.kind,senderInboxId:e.sender_inbox_id,sentAtNs:e.sent_at_ns}),f=e=>({delivery_status:e.delivery_status,limit:e.limit,sent_after_ns:e.sent_after_ns,sent_before_ns:e.sent_before_ns}),k=e=>new o(e.sent_before_ns,e.sent_after_ns,e.limit,e.delivery_status),U=e=>({created_after_ns:e.created_after_ns,created_before_ns:e.created_before_ns,limit:e.limit}),G=e=>new a(e.created_after_ns,e.created_before_ns,e.limit),L=e=>({permissions:e.permissions,name:e.group_name,imageUrlSquare:e.group_image_url_square,description:e.group_description,pinnedFrameUrl:e.group_pinned_frame_url}),C=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl),F=e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,pinnedFrameUrl:e.pinnedFrameUrl,permissions:{policyType:e.permissions.policyType,policySet:{addAdminPolicy:e.permissions.policySet.add_admin_policy,addMemberPolicy:e.permissions.policySet.add_member_policy,removeAdminPolicy:e.permissions.policySet.remove_admin_policy,removeMemberPolicy:e.permissions.policySet.remove_member_policy,updateGroupDescriptionPolicy:e.permissions.policySet.update_group_description_policy,updateGroupImageUrlSquarePolicy:e.permissions.policySet.update_group_image_url_square_policy,updateGroupNamePolicy:e.permissions.policySet.update_group_name_policy,updateGroupPinnedFrameUrlPolicy:e.permissions.policySet.update_group_pinned_frame_url_policy}},isActive:e.isActive,addedByInboxId:e.addedByInboxId,metadata:e.metadata,admins:e.admins,superAdmins:e.superAdmins,createdAtNs:e.createdAtNs}),N=e=>({id:e.id,clientTimestampNs:e.client_timestamp_ns}),B=e=>({accountAddresses:e.account_addresses,inboxId:e.inbox_id,installations:e.installations.map(N),recoveryAddress:e.recovery_address}),E=e=>({entity:e.entity,entityType:e.entity_type,state:e.state}),T=e=>new c(e.entityType,e.state,e.entity),j=e=>({accountAddresses:e.account_addresses,consentState:e.consent_state,inboxId:e.inbox_id,installationIds:e.installation_ids,permissionLevel:e.permission_level}),P=e=>new p(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState);class R{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,t.kind){case l.Application:this.kind="application";break;case l.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case m.Unpublished:this.deliveryStatus="unpublished";break;case m.Published:this.deliveryStatus="published";break;case m.Failed:this.deliveryStatus="failed"}this.contentType=M(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class q{#n;#i;#r;#o;#a;#d;#c;#p;#l;#m;#h;constructor(e,t,s){this.#n=e,this.#i=t,this.#u(s)}#u(e){this.#r=e?.name??"",this.#o=e?.imageUrl??"",this.#a=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#p=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#m=e?.permissions??void 0,this.#h=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#o}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#o=e}get description(){return this.#a}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#a=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#p}get createdAtNs(){return this.#h}get createdAt(){return this.#h?(e=this.#h,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#l}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}async admins(){return this.#n.sendMessage("getGroupAdmins",{id:this.#i})}async superAdmins(){return this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i})}get permissions(){return this.#m}async isAdmin(e){return(await this.admins()).includes(e)}async isSuperAdmin(e){return(await this.superAdmins()).includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#u(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new R(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}}class W{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async getConversationById(e){return this.#n.sendMessage("getConversationById",{id:e})}async getMessageById(e){return this.#n.sendMessage("getMessageById",{id:e})}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new q(this.#n,e.id,e)))}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new q(this.#n,s.id,s)}}class D extends y{address;options;#g=!1;#y;#b;#v;#I;constructor(t,s){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),s?.enableLogging??!1),this.address=t,this.options=s,this.#v=new W(this);const i=[new e,new n,...s?.codecs??[]];this.#I=new Map(i.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{address:this.address,options:this.options});this.#y=e.inboxId,this.#b=e.installationId,this.#g=!0}static async create(e,t){const s=new D(e,t);return await s.init(),s}get isReady(){return this.#g}get inboxId(){return this.#y}get installationId(){return this.#b}async getCreateInboxSignatureText(){return this.sendMessage("getCreateInboxSignatureText",void 0)}async getAddWalletSignatureText(e){return this.sendMessage("getAddWalletSignatureText",{accountAddress:e})}async getRevokeWalletSignatureText(e){return this.sendMessage("getRevokeWalletSignatureText",{accountAddress:e})}async addSignature(e,t){return this.sendMessage("addSignature",{type:e,bytes:t})}async applySignaturesRequests(){return this.sendMessage("applySignaturesRequests",void 0)}async registerIdentity(){return this.sendMessage("registerIdentity",void 0)}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#v}codecFor(e){return this.#I.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),x(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==l.MembershipChange)throw new Error("Error decoding group membership change");const i=A(e.content);return n.decode(i,this)}}const $=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class O{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",$),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",$),this.#e.terminate()}}class z extends O{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const H={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};export{H as ApiUrls,D as Client,q as Conversation,W as Conversations,R as DecodedMessage,z as Utils,v as fromContentTypeId,w as fromEncodedContent,T as fromSafeConsent,M as fromSafeContentTypeId,C as fromSafeCreateGroupOptions,A as fromSafeEncodedContent,P as fromSafeGroupMember,G as fromSafeListConversationsOptions,k as fromSafeListMessagesOptions,b as toContentTypeId,_ as toEncodedContent,E as toSafeConsent,I as toSafeContentTypeId,F as toSafeConversation,L as toSafeCreateGroupOptions,x as toSafeEncodedContent,j as toSafeGroupMember,B as toSafeInboxState,N as toSafeInstallation,U as toSafeListConversationsOptions,f as toSafeListMessagesOptions,S as toSafeMessage};
1
+ import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as o,ListConversationsOptions as a,CreateGroupOptions as d,Consent as c,GroupMember as p,GroupMessageKind as l,DeliveryStatus as m}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as u}from"uuid";import{ContentTypeId as g}from"@xmtp/content-type-primitives";const h=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class y{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",h),this.#t=t}sendMessage(e,t){const s=u();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",h),this.#e.terminate()}}const I=e=>new g({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),b=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),v=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new g({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),w=e=>({type:I(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),S=e=>new r(b(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),x=e=>({type:v(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),A=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),f=e=>({content:x(w(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),k=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),G=e=>new o(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),N=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),U=e=>new a(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),C=e=>({permissions:e.permissions,name:e.groupName,imageUrlSquare:e.groupImageUrlSquare,description:e.groupDescription,pinnedFrameUrl:e.groupPinnedFrameUrl}),P=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl),L=e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,pinnedFrameUrl:e.pinnedFrameUrl,permissions:{policyType:e.permissions.policyType,policySet:{addAdminPolicy:e.permissions.policySet.addAdminPolicy,addMemberPolicy:e.permissions.policySet.addMemberPolicy,removeAdminPolicy:e.permissions.policySet.removeAdminPolicy,removeMemberPolicy:e.permissions.policySet.removeMemberPolicy,updateGroupDescriptionPolicy:e.permissions.policySet.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.permissions.policySet.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.permissions.policySet.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:e.permissions.policySet.updateGroupPinnedFrameUrlPolicy}},isActive:e.isActive,addedByInboxId:e.addedByInboxId,metadata:e.metadata,admins:e.admins,superAdmins:e.superAdmins,createdAtNs:e.createdAtNs}),T=e=>({id:e.id,clientTimestampNs:e.clientTimestampNs}),B=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(T),recoveryAddress:e.recoveryAddress}),F=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),E=e=>new c(e.entityType,e.state,e.entity),D=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),j=e=>new p(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState);class R{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,t.kind){case l.Application:this.kind="application";break;case l.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case m.Unpublished:this.deliveryStatus="unpublished";break;case m.Published:this.deliveryStatus="published";break;case m.Failed:this.deliveryStatus="failed"}this.contentType=M(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class q{#n;#i;#r;#o;#a;#d;#c;#p;#l;#m;#u;constructor(e,t,s){this.#n=e,this.#i=t,this.#g(s)}#g(e){this.#r=e?.name??"",this.#o=e?.imageUrl??"",this.#a=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#p=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#m=e?.permissions??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#o}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#o=e}get description(){return this.#a}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#a=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#p}get createdAtNs(){return this.#u}get createdAt(){return this.#u?(e=this.#u,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#l}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}async admins(){return this.#n.sendMessage("getGroupAdmins",{id:this.#i})}async superAdmins(){return this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i})}get permissions(){return this.#m}async isAdmin(e){return(await this.admins()).includes(e)}async isSuperAdmin(e){return(await this.superAdmins()).includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#g(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new R(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}async dmPeerInboxId(){return this.#n.sendMessage("getDmPeerInboxId",{id:this.#i})}}class O{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async getConversationById(e){return this.#n.sendMessage("getConversationById",{id:e})}async getMessageById(e){return this.#n.sendMessage("getMessageById",{id:e})}async getDmByInboxId(e){return this.#n.sendMessage("getDmByInboxId",{inboxId:e})}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new q(this.#n,e.id,e)))}async listGroups(e){return this.#n.sendMessage("getGroups",{options:e})}async listDms(e){return this.#n.sendMessage("getDms",{options:e})}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new q(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new q(this.#n,t.id,t)}}class W extends y{address;options;#h=!1;#y;#I;#b;#v;#M;constructor(t,s,i){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==i?.loggingLevel&&"off"!==i.loggingLevel),this.address=t,this.options=i,this.#M=s,this.#b=new O(this);const r=[new e,new n,...i?.codecs??[]];this.#v=new Map(r.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{address:this.address,encryptionKey:this.#M,options:this.options});this.#y=e.inboxId,this.#I=e.installationId,this.#h=!0}static async create(e,t,s){const n=new W(e,t,s);return await n.init(),n}get isReady(){return this.#h}get inboxId(){return this.#y}get installationId(){return this.#I}async getCreateInboxSignatureText(){return this.sendMessage("getCreateInboxSignatureText",void 0)}async getAddWalletSignatureText(e){return this.sendMessage("getAddWalletSignatureText",{accountAddress:e})}async getRevokeWalletSignatureText(e){return this.sendMessage("getRevokeWalletSignatureText",{accountAddress:e})}async getRevokeInstallationsSignatureText(){return this.sendMessage("getRevokeInstallationsSignatureText",void 0)}async addSignature(e,t){return this.sendMessage("addSignature",{type:e,bytes:t})}async addScwSignature(e,t,s,n){return this.sendMessage("addScwSignature",{type:e,bytes:t,chainId:s,blockNumber:n})}async applySignatures(){return this.sendMessage("applySignatures",void 0)}async registerIdentity(){return this.sendMessage("registerIdentity",void 0)}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#b}codecFor(e){return this.#v.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),x(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==l.MembershipChange)throw new Error("Error decoding group membership change");const i=A(e.content);return n.decode(i,this)}}const $=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class K{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",$),this.#t=t}sendMessage(e,t){const s=u();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",$),this.#e.terminate()}}class _ extends K{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const z={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};export{z as ApiUrls,W as Client,q as Conversation,O as Conversations,R as DecodedMessage,_ as Utils,b as fromContentTypeId,S as fromEncodedContent,E as fromSafeConsent,M as fromSafeContentTypeId,P as fromSafeCreateGroupOptions,A as fromSafeEncodedContent,j as fromSafeGroupMember,U as fromSafeListConversationsOptions,G as fromSafeListMessagesOptions,I as toContentTypeId,w as toEncodedContent,F as toSafeConsent,v as toSafeContentTypeId,L as toSafeConversation,C as toSafeCreateGroupOptions,x as toSafeEncodedContent,D as toSafeGroupMember,B as toSafeInboxState,T as toSafeInstallation,N as toSafeListConversationsOptions,k as toSafeListMessagesOptions,f as toSafeMessage};
2
2
  //# sourceMappingURL=index.js.map