@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.
- package/README.md +2 -1
- package/dist/index.d.ts +93 -72
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/utils.js +1 -1
- package/dist/workers/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/Client.ts +55 -64
- package/src/Conversation.ts +6 -0
- package/src/Conversations.ts +28 -64
- package/src/Group.ts +7 -6
- package/src/Preferences.ts +75 -0
- package/src/Utils.ts +6 -5
- package/src/WorkerClient.ts +28 -41
- package/src/WorkerConversation.ts +11 -6
- package/src/WorkerConversations.ts +13 -34
- package/src/WorkerPreferences.ts +58 -0
- package/src/index.ts +6 -1
- package/src/types/clientEvents.ts +24 -15
- package/src/types/utilsEvents.ts +4 -3
- package/src/utils/conversions.ts +8 -7
- package/src/utils/createClient.ts +9 -13
- package/src/utils/signer.ts +10 -5
- package/src/workers/client.ts +47 -38
- package/src/workers/utils.ts +14 -13
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
2
|
-
import { SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Consent, UserPreference, Client as Client$1, EncodedContent, MessageDisappearingSettings, GroupPermissionsOptions, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, PermissionLevel, ContentTypeId, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, CreateGroupOptions, CreateDMOptions, HmacKey, Installation, InboxState, GroupMember } from '@xmtp/wasm-bindings';
|
|
3
|
-
export { Consent, ConsentEntityType, ConsentState, ContentType, ContentTypeId, ConversationListItem, ConversationType, CreateDMOptions, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
4
1
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
2
|
+
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
3
|
+
import { Identifier, SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Client as Client$1, Consent, UserPreference, EncodedContent, MessageDisappearingSettings, GroupPermissionsOptions, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, PermissionLevel, ContentTypeId, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, CreateGroupOptions, CreateDMOptions, HmacKey, Installation, InboxState, GroupMember } from '@xmtp/wasm-bindings';
|
|
4
|
+
export { Consent, ConsentEntityType, ConsentState, ContentType, ContentTypeId, ConversationListItem, ConversationType, CreateDMOptions, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, Identifier, IdentifierKind, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, Opfs, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
5
5
|
|
|
6
6
|
type ResolveValue<T> = {
|
|
7
7
|
value: T | undefined;
|
|
@@ -112,7 +112,7 @@ type ClientEvents =
|
|
|
112
112
|
installationIdBytes: Uint8Array;
|
|
113
113
|
};
|
|
114
114
|
data: {
|
|
115
|
-
|
|
115
|
+
identifier: Identifier;
|
|
116
116
|
encryptionKey: Uint8Array;
|
|
117
117
|
options?: ClientOptions;
|
|
118
118
|
};
|
|
@@ -126,14 +126,14 @@ type ClientEvents =
|
|
|
126
126
|
id: string;
|
|
127
127
|
result: string | undefined;
|
|
128
128
|
data: {
|
|
129
|
-
|
|
129
|
+
newIdentifier: Identifier;
|
|
130
130
|
};
|
|
131
131
|
} | {
|
|
132
132
|
action: "removeAccountSignatureText";
|
|
133
133
|
id: string;
|
|
134
134
|
result: string | undefined;
|
|
135
135
|
data: {
|
|
136
|
-
|
|
136
|
+
identifier: Identifier;
|
|
137
137
|
};
|
|
138
138
|
} | {
|
|
139
139
|
action: "revokeAllOtherInstallationsSignatureText";
|
|
@@ -148,7 +148,7 @@ type ClientEvents =
|
|
|
148
148
|
installationIds: Uint8Array[];
|
|
149
149
|
};
|
|
150
150
|
} | {
|
|
151
|
-
action: "
|
|
151
|
+
action: "addEcdsaSignature";
|
|
152
152
|
id: string;
|
|
153
153
|
result: undefined;
|
|
154
154
|
data: {
|
|
@@ -185,7 +185,7 @@ type ClientEvents =
|
|
|
185
185
|
id: string;
|
|
186
186
|
result: Map<string, boolean>;
|
|
187
187
|
data: {
|
|
188
|
-
|
|
188
|
+
identifiers: Identifier[];
|
|
189
189
|
};
|
|
190
190
|
} | {
|
|
191
191
|
action: "inboxState";
|
|
@@ -217,11 +217,11 @@ type ClientEvents =
|
|
|
217
217
|
entity: string;
|
|
218
218
|
};
|
|
219
219
|
} | {
|
|
220
|
-
action: "
|
|
220
|
+
action: "findInboxIdByIdentifier";
|
|
221
221
|
id: string;
|
|
222
222
|
result: string | undefined;
|
|
223
223
|
data: {
|
|
224
|
-
|
|
224
|
+
identifier: Identifier;
|
|
225
225
|
};
|
|
226
226
|
} | {
|
|
227
227
|
action: "signWithInstallationKey";
|
|
@@ -294,15 +294,15 @@ type ClientEvents =
|
|
|
294
294
|
options?: Omit<SafeListConversationsOptions, "conversation_type">;
|
|
295
295
|
};
|
|
296
296
|
} | {
|
|
297
|
-
action: "
|
|
297
|
+
action: "newGroupWithIdentifiers";
|
|
298
298
|
id: string;
|
|
299
299
|
result: SafeConversation;
|
|
300
300
|
data: {
|
|
301
|
-
|
|
301
|
+
identifiers: Identifier[];
|
|
302
302
|
options?: SafeCreateGroupOptions;
|
|
303
303
|
};
|
|
304
304
|
} | {
|
|
305
|
-
action: "
|
|
305
|
+
action: "newGroupWithInboxIds";
|
|
306
306
|
id: string;
|
|
307
307
|
result: SafeConversation;
|
|
308
308
|
data: {
|
|
@@ -310,15 +310,15 @@ type ClientEvents =
|
|
|
310
310
|
options?: SafeCreateGroupOptions;
|
|
311
311
|
};
|
|
312
312
|
} | {
|
|
313
|
-
action: "
|
|
313
|
+
action: "newDmWithIdentifier";
|
|
314
314
|
id: string;
|
|
315
315
|
result: SafeConversation;
|
|
316
316
|
data: {
|
|
317
|
-
|
|
317
|
+
identifier: Identifier;
|
|
318
318
|
options?: SafeCreateDmOptions;
|
|
319
319
|
};
|
|
320
320
|
} | {
|
|
321
|
-
action: "
|
|
321
|
+
action: "newDmWithInboxId";
|
|
322
322
|
id: string;
|
|
323
323
|
result: SafeConversation;
|
|
324
324
|
data: {
|
|
@@ -457,7 +457,7 @@ type ClientEvents =
|
|
|
457
457
|
result: undefined;
|
|
458
458
|
data: {
|
|
459
459
|
id: string;
|
|
460
|
-
|
|
460
|
+
identifiers: Identifier[];
|
|
461
461
|
};
|
|
462
462
|
} | {
|
|
463
463
|
action: "removeGroupMembers";
|
|
@@ -465,7 +465,7 @@ type ClientEvents =
|
|
|
465
465
|
result: undefined;
|
|
466
466
|
data: {
|
|
467
467
|
id: string;
|
|
468
|
-
|
|
468
|
+
identifiers: Identifier[];
|
|
469
469
|
};
|
|
470
470
|
} | {
|
|
471
471
|
action: "addGroupMembersByInboxId";
|
|
@@ -614,6 +614,13 @@ type ClientEvents =
|
|
|
614
614
|
groupId: string;
|
|
615
615
|
streamId: string;
|
|
616
616
|
};
|
|
617
|
+
} | {
|
|
618
|
+
action: "getGroupPausedForVersion";
|
|
619
|
+
id: string;
|
|
620
|
+
result: string | undefined;
|
|
621
|
+
data: {
|
|
622
|
+
id: string;
|
|
623
|
+
};
|
|
617
624
|
};
|
|
618
625
|
type ClientEventsActions = ClientEvents["action"];
|
|
619
626
|
type ClientEventsClientMessageData = EventsClientMessageData<ClientEvents>;
|
|
@@ -629,15 +636,15 @@ type UtilsEvents = {
|
|
|
629
636
|
id: string;
|
|
630
637
|
result: string;
|
|
631
638
|
data: {
|
|
632
|
-
|
|
639
|
+
identifier: Identifier;
|
|
633
640
|
enableLogging: boolean;
|
|
634
641
|
};
|
|
635
642
|
} | {
|
|
636
|
-
action: "
|
|
643
|
+
action: "getInboxIdForIdentifier";
|
|
637
644
|
id: string;
|
|
638
645
|
result: string | undefined;
|
|
639
646
|
data: {
|
|
640
|
-
|
|
647
|
+
identifier: Identifier;
|
|
641
648
|
env?: XmtpEnv;
|
|
642
649
|
enableLogging: boolean;
|
|
643
650
|
};
|
|
@@ -717,15 +724,24 @@ declare class WorkerConversations {
|
|
|
717
724
|
list(options?: SafeListConversationsOptions): WorkerConversation[];
|
|
718
725
|
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
|
|
719
726
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
727
|
+
newGroupWithIdentifiers(identifiers: Identifier[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
|
|
728
|
+
newGroup(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
|
|
729
|
+
newDmWithIdentifier(identifier: Identifier, options?: SafeCreateDmOptions): Promise<WorkerConversation>;
|
|
730
|
+
newDm(inboxId: string, options?: SafeCreateDmOptions): Promise<WorkerConversation>;
|
|
724
731
|
getHmacKeys(): HmacKeys;
|
|
725
732
|
stream(callback?: StreamCallback<Conversation$1>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
|
|
726
733
|
streamGroups(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
727
734
|
streamDms(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
728
735
|
streamAllMessages(callback?: StreamCallback<Message>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
declare class WorkerPreferences {
|
|
739
|
+
#private;
|
|
740
|
+
constructor(client: Client$1, conversations: Conversations$1);
|
|
741
|
+
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
742
|
+
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
743
|
+
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
744
|
+
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
729
745
|
streamConsent(callback?: StreamCallback<Consent[]>): _xmtp_wasm_bindings.StreamCloser;
|
|
730
746
|
streamPreferences(callback?: StreamCallback<UserPreference[]>): _xmtp_wasm_bindings.StreamCloser;
|
|
731
747
|
}
|
|
@@ -733,28 +749,25 @@ declare class WorkerConversations {
|
|
|
733
749
|
declare class WorkerClient {
|
|
734
750
|
#private;
|
|
735
751
|
constructor(client: Client$1);
|
|
736
|
-
static create(
|
|
737
|
-
get
|
|
752
|
+
static create(identifier: Identifier, encryptionKey: Uint8Array, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
|
|
753
|
+
get accountIdentifier(): Identifier;
|
|
738
754
|
get inboxId(): string;
|
|
739
755
|
get installationId(): string;
|
|
740
756
|
get installationIdBytes(): Uint8Array<ArrayBufferLike>;
|
|
741
757
|
get isRegistered(): boolean;
|
|
758
|
+
get conversations(): WorkerConversations;
|
|
759
|
+
get preferences(): WorkerPreferences;
|
|
742
760
|
createInboxSignatureText(): string | undefined;
|
|
743
|
-
addAccountSignatureText(
|
|
744
|
-
removeAccountSignatureText(
|
|
761
|
+
addAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
762
|
+
removeAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
745
763
|
revokeAllAOtherInstallationsSignatureText(): Promise<string | undefined>;
|
|
746
764
|
revokeInstallationsSignatureText(installationIds: Uint8Array[]): Promise<string | undefined>;
|
|
747
|
-
|
|
765
|
+
addEcdsaSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<void>;
|
|
748
766
|
addScwSignature(type: SignatureRequestType, bytes: Uint8Array, chainId: bigint, blockNumber?: bigint): Promise<void>;
|
|
749
767
|
applySignatures(): Promise<void>;
|
|
750
|
-
canMessage(
|
|
768
|
+
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
751
769
|
registerIdentity(): Promise<void>;
|
|
752
|
-
|
|
753
|
-
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
754
|
-
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
755
|
-
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
756
|
-
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
757
|
-
get conversations(): WorkerConversations;
|
|
770
|
+
findInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
758
771
|
signWithInstallationKey(signatureText: string): Uint8Array<ArrayBufferLike>;
|
|
759
772
|
verifySignedWithInstallationKey(signatureText: string, signatureBytes: Uint8Array): boolean;
|
|
760
773
|
verifySignedWithPublicKey(signatureText: string, signatureBytes: Uint8Array, publicKey: Uint8Array): boolean;
|
|
@@ -788,10 +801,10 @@ declare class WorkerConversation {
|
|
|
788
801
|
isAdmin(inboxId: string): boolean;
|
|
789
802
|
isSuperAdmin(inboxId: string): boolean;
|
|
790
803
|
sync(): Promise<void>;
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
804
|
+
addMembersByIdentifiers(identifiers: Identifier[]): Promise<void>;
|
|
805
|
+
addMembers(inboxIds: string[]): Promise<void>;
|
|
806
|
+
removeMembersByIdentifiers(identifiers: Identifier[]): Promise<void>;
|
|
807
|
+
removeMembers(inboxIds: string[]): Promise<void>;
|
|
795
808
|
addAdmin(inboxId: string): Promise<void>;
|
|
796
809
|
removeAdmin(inboxId: string): Promise<void>;
|
|
797
810
|
addSuperAdmin(inboxId: string): Promise<void>;
|
|
@@ -808,6 +821,7 @@ declare class WorkerConversation {
|
|
|
808
821
|
removeMessageDisappearingSettings(): Promise<void>;
|
|
809
822
|
isMessageDisappearingEnabled(): boolean;
|
|
810
823
|
stream(callback?: StreamCallback<Message>): _xmtp_wasm_bindings.StreamCloser;
|
|
824
|
+
pausedForVersion(): string | undefined;
|
|
811
825
|
}
|
|
812
826
|
|
|
813
827
|
declare const toContentTypeId: (contentTypeId: ContentTypeId) => ContentTypeId$1;
|
|
@@ -923,10 +937,10 @@ type SafeInstallation = {
|
|
|
923
937
|
};
|
|
924
938
|
declare const toSafeInstallation: (installation: Installation) => SafeInstallation;
|
|
925
939
|
type SafeInboxState = {
|
|
926
|
-
|
|
940
|
+
accountIdentifiers: Identifier[];
|
|
927
941
|
inboxId: string;
|
|
928
942
|
installations: SafeInstallation[];
|
|
929
|
-
|
|
943
|
+
recoveryIdentifier: Identifier;
|
|
930
944
|
};
|
|
931
945
|
declare const toSafeInboxState: (inboxState: InboxState) => SafeInboxState;
|
|
932
946
|
type SafeConsent = {
|
|
@@ -937,7 +951,7 @@ type SafeConsent = {
|
|
|
937
951
|
declare const toSafeConsent: (consent: Consent) => SafeConsent;
|
|
938
952
|
declare const fromSafeConsent: (consent: SafeConsent) => Consent;
|
|
939
953
|
type SafeGroupMember = {
|
|
940
|
-
|
|
954
|
+
accountIdentifiers: Identifier[];
|
|
941
955
|
consentState: ConsentState;
|
|
942
956
|
inboxId: string;
|
|
943
957
|
installationIds: string[];
|
|
@@ -1030,6 +1044,7 @@ declare class Conversation {
|
|
|
1030
1044
|
removeMessageDisappearingSettings(): Promise<undefined>;
|
|
1031
1045
|
isMessageDisappearingEnabled(): Promise<boolean>;
|
|
1032
1046
|
stream(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
1047
|
+
pausedForVersion(): Promise<string | undefined>;
|
|
1033
1048
|
}
|
|
1034
1049
|
|
|
1035
1050
|
declare class Dm extends Conversation {
|
|
@@ -1068,10 +1083,10 @@ declare class Group extends Conversation {
|
|
|
1068
1083
|
updatePermission(permissionType: PermissionUpdateType, policy: PermissionPolicy, metadataField?: MetadataField): Promise<undefined>;
|
|
1069
1084
|
isAdmin(inboxId: string): Promise<boolean>;
|
|
1070
1085
|
isSuperAdmin(inboxId: string): Promise<boolean>;
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1086
|
+
addMembersByIdentifiers(identifiers: Identifier[]): Promise<undefined>;
|
|
1087
|
+
addMembers(inboxIds: string[]): Promise<undefined>;
|
|
1088
|
+
removeMembersByIdentifiers(identifiers: Identifier[]): Promise<undefined>;
|
|
1089
|
+
removeMembers(inboxIds: string[]): Promise<undefined>;
|
|
1075
1090
|
addAdmin(inboxId: string): Promise<undefined>;
|
|
1076
1091
|
removeAdmin(inboxId: string): Promise<undefined>;
|
|
1077
1092
|
addSuperAdmin(inboxId: string): Promise<undefined>;
|
|
@@ -1089,10 +1104,10 @@ declare class Conversations {
|
|
|
1089
1104
|
list(options?: SafeListConversationsOptions): Promise<(Dm | Group)[]>;
|
|
1090
1105
|
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Group[]>;
|
|
1091
1106
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Dm[]>;
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1107
|
+
newGroupWithIdentifiers(identifiers: Identifier[], options?: SafeCreateGroupOptions): Promise<Group>;
|
|
1108
|
+
newGroup(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<Group>;
|
|
1109
|
+
newDmWithIdentifier(identifier: Identifier, options?: SafeCreateDmOptions): Promise<Dm>;
|
|
1110
|
+
newDm(inboxId: string, options?: SafeCreateDmOptions): Promise<Dm>;
|
|
1096
1111
|
getHmacKeys(): Promise<SafeHmacKeys>;
|
|
1097
1112
|
stream<T extends Group | Dm = Group | Dm>(callback?: StreamCallback<T>, conversationType?: ConversationType): Promise<AsyncStream<T>>;
|
|
1098
1113
|
streamGroups(callback?: StreamCallback<Group>): Promise<AsyncStream<Group>>;
|
|
@@ -1100,21 +1115,30 @@ declare class Conversations {
|
|
|
1100
1115
|
streamAllMessages(callback?: StreamCallback<DecodedMessage>, conversationType?: ConversationType): Promise<AsyncStream<DecodedMessage>>;
|
|
1101
1116
|
streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
1102
1117
|
streamAllDmMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
declare class Preferences {
|
|
1121
|
+
#private;
|
|
1122
|
+
constructor(client: Client);
|
|
1123
|
+
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
1124
|
+
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
1125
|
+
setConsentStates(records: SafeConsent[]): Promise<undefined>;
|
|
1126
|
+
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
1103
1127
|
streamConsent(callback?: StreamCallback<SafeConsent[]>): Promise<AsyncStream<SafeConsent[]>>;
|
|
1104
1128
|
streamPreferences(callback?: StreamCallback<UserPreference[]>): Promise<AsyncStream<UserPreference[]>>;
|
|
1105
1129
|
}
|
|
1106
1130
|
|
|
1107
1131
|
type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
|
|
1108
|
-
type
|
|
1132
|
+
type GetIdentifier = () => Promise<Identifier> | Identifier;
|
|
1109
1133
|
type GetChainId = () => bigint;
|
|
1110
1134
|
type GetBlockNumber = () => bigint;
|
|
1111
1135
|
type Signer = {
|
|
1112
|
-
|
|
1113
|
-
|
|
1136
|
+
type: "EOA";
|
|
1137
|
+
getIdentifier: GetIdentifier;
|
|
1114
1138
|
signMessage: SignMessage;
|
|
1115
1139
|
} | {
|
|
1116
|
-
|
|
1117
|
-
|
|
1140
|
+
type: "SCW";
|
|
1141
|
+
getIdentifier: GetIdentifier;
|
|
1118
1142
|
signMessage: SignMessage;
|
|
1119
1143
|
getBlockNumber?: GetBlockNumber;
|
|
1120
1144
|
getChainId: GetChainId;
|
|
@@ -1123,14 +1147,16 @@ type Signer = {
|
|
|
1123
1147
|
declare class Client extends ClientWorkerClass {
|
|
1124
1148
|
#private;
|
|
1125
1149
|
options?: ClientOptions;
|
|
1126
|
-
constructor(signer: Signer,
|
|
1127
|
-
get accountAddress(): string;
|
|
1150
|
+
constructor(signer: Signer, encryptionKey: Uint8Array, options?: ClientOptions);
|
|
1128
1151
|
init(): Promise<void>;
|
|
1129
1152
|
static create(signer: Signer, encryptionKey: Uint8Array, options?: ClientOptions): Promise<Client>;
|
|
1130
1153
|
get isReady(): boolean;
|
|
1131
1154
|
get inboxId(): string | undefined;
|
|
1155
|
+
accountIdentifier(): Promise<Identifier>;
|
|
1132
1156
|
get installationId(): string | undefined;
|
|
1133
1157
|
get installationIdBytes(): Uint8Array<ArrayBufferLike> | undefined;
|
|
1158
|
+
get conversations(): Conversations;
|
|
1159
|
+
get preferences(): Preferences;
|
|
1134
1160
|
/**
|
|
1135
1161
|
* WARNING: This function should be used with caution. It is only provided
|
|
1136
1162
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1149,7 +1175,7 @@ declare class Client extends ClientWorkerClass {
|
|
|
1149
1175
|
* The `allowInboxReassign` parameter must be true or this function will
|
|
1150
1176
|
* throw an error.
|
|
1151
1177
|
*/
|
|
1152
|
-
unsafe_addAccountSignatureText(
|
|
1178
|
+
unsafe_addAccountSignatureText(newIdentifier: Identifier, allowInboxReassign?: boolean): Promise<string | undefined>;
|
|
1153
1179
|
/**
|
|
1154
1180
|
* WARNING: This function should be used with caution. It is only provided
|
|
1155
1181
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1157,7 +1183,7 @@ declare class Client extends ClientWorkerClass {
|
|
|
1157
1183
|
*
|
|
1158
1184
|
* It is highly recommended to use the `removeAccount` function instead.
|
|
1159
1185
|
*/
|
|
1160
|
-
unsafe_removeAccountSignatureText(
|
|
1186
|
+
unsafe_removeAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
1161
1187
|
/**
|
|
1162
1188
|
* WARNING: This function should be used with caution. It is only provided
|
|
1163
1189
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1205,18 +1231,13 @@ declare class Client extends ClientWorkerClass {
|
|
|
1205
1231
|
* already associated with a different account.
|
|
1206
1232
|
*/
|
|
1207
1233
|
unsafe_addAccount(newAccountSigner: Signer, allowInboxReassign?: boolean): Promise<void>;
|
|
1208
|
-
removeAccount(
|
|
1234
|
+
removeAccount(accountIdentifier: Identifier): Promise<void>;
|
|
1209
1235
|
revokeAllOtherInstallations(): Promise<void>;
|
|
1210
1236
|
revokeInstallations(installationIds: Uint8Array[]): Promise<void>;
|
|
1211
1237
|
isRegistered(): Promise<boolean>;
|
|
1212
|
-
canMessage(
|
|
1213
|
-
static canMessage(
|
|
1214
|
-
|
|
1215
|
-
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
1216
|
-
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
1217
|
-
setConsentStates(records: SafeConsent[]): Promise<undefined>;
|
|
1218
|
-
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
1219
|
-
get conversations(): Conversations;
|
|
1238
|
+
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
1239
|
+
static canMessage(identifiers: Identifier[], env?: XmtpEnv): Promise<Map<string, boolean>>;
|
|
1240
|
+
findInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
1220
1241
|
codecFor(contentType: ContentTypeId$1): ContentCodec | undefined;
|
|
1221
1242
|
encodeContent(content: any, contentType: ContentTypeId$1): SafeEncodedContent;
|
|
1222
1243
|
decodeContent(message: SafeMessage, contentType: ContentTypeId$1): any;
|
|
@@ -1236,8 +1257,8 @@ declare class UtilsWorkerClass {
|
|
|
1236
1257
|
declare class Utils extends UtilsWorkerClass {
|
|
1237
1258
|
#private;
|
|
1238
1259
|
constructor(enableLogging?: boolean);
|
|
1239
|
-
generateInboxId(
|
|
1240
|
-
|
|
1260
|
+
generateInboxId(identifier: Identifier): Promise<string>;
|
|
1261
|
+
getInboxIdForIdentifier(identifier: Identifier, env?: XmtpEnv): Promise<string | undefined>;
|
|
1241
1262
|
}
|
|
1242
1263
|
|
|
1243
1264
|
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, Dm, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type GenericStreamEvent, Group, HistorySyncUrls, type HmacKeys, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateDmOptions, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeHmacKey, type SafeHmacKeys, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SafeMessageDisappearingSettings, type SafePermissionPolicySet, type SendMessageData, type Signer, type StorageOptions, type StreamEventsClientMessageData, type StreamEventsClientPostMessageData, type StreamEventsErrorData, type StreamEventsResult, 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, fromSafeCreateDmOptions, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, fromSafeMessageDisappearingSettings, fromSafePermissionPolicySet, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateDmOptions, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafeMessageDisappearingSettings, toSafePermissionPolicySet };
|
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{ContentTypeId as i,EncodedContent as a,ListMessagesOptions as r,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,CreateDMOptions as l,Consent as u,GroupMember as g,MessageDisappearingSettings as p,GroupPermissionsOptions as h,GroupMessageKind as m,DeliveryStatus as y,ConversationType as v,SignatureRequestType as w}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentType,ContentTypeId,ConversationListItem,ConversationType,CreateDMOptions,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,LogOptions,Message,MessageDisappearingSettings,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as M}from"uuid";import{ContentTypeId as I}from"@xmtp/content-type-primitives";const b=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class S{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",b),this.#t=t}sendMessage(e,t){const s=M();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))};handleStreamMessage=(e,t)=>{const s=s=>{const n=s.data;n.streamId===e&&("error"in n?t(new Error(n.error),null):t(null,n.result))};return this.#e.addEventListener("message",s),()=>{this.#e.removeEventListener("message",s)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",b),this.#e.terminate()}}class A{#n=!1;#i;#a;onReturn=void 0;constructor(){this.#a=[],this.#i=null,this.#n=!1}get isDone(){return this.#n}callback=(e,t)=>{if(e)throw e;this.#n||(this.#i?(this.#i({done:!1,value:t}),this.#i=null):this.#a.push(t))};next=()=>this.#a.length>0?Promise.resolve({done:!1,value:this.#a.shift()}):this.#n?Promise.resolve({done:!0,value:void 0}):new Promise((e=>{this.#i=e}));return=e=>(this.#n=!0,this.onReturn?.(),Promise.resolve({done:!0,value:e}));[Symbol.asyncIterator](){return this}}const x=e=>new I({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),f=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),k=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>new I({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),D=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>new a(f(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(D(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),B=e=>({contentTypes:e.contentTypes,deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),L=e=>new r(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction,e.contentTypes),E=e=>({consentStates:e.consentStates,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit}),U=e=>new o(e.consentStates,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.limit),R=e=>({addAdminPolicy:e.addAdminPolicy,addMemberPolicy:e.addMemberPolicy,removeAdminPolicy:e.removeAdminPolicy,removeMemberPolicy:e.removeMemberPolicy,updateGroupDescriptionPolicy:e.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.updateGroupNamePolicy,updateMessageDisappearingPolicy:e.updateMessageDisappearingPolicy}),_=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),q=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),O=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===h.CustomPolicy?_(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),K=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),j=e=>new l(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),W=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,a=e.permissions,r=e.isActive,o=e.addedByInboxId,d=await e.metadata(),c=e.admins,l=e.superAdmins,u=e.createdAtNs,g=a.policyType,p=a.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:g,policySet:{addAdminPolicy:p.addAdminPolicy,addMemberPolicy:p.addMemberPolicy,removeAdminPolicy:p.removeAdminPolicy,removeMemberPolicy:p.removeMemberPolicy,updateGroupDescriptionPolicy:p.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:p.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:p.updateGroupNamePolicy,updateMessageDisappearingPolicy:p.updateMessageDisappearingPolicy}},isActive:r,addedByInboxId:o,metadata:d,admins:c,superAdmins:l,createdAtNs:u}},F=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),$=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(F),recoveryAddress:e.recoveryAddress}),H=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),V=e=>new u(e.entityType,e.state,e.entity),z=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),J=e=>new g(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState),Q=e=>({key:e.key,epoch:e.epoch}),X=e=>({fromNs:e.fromNs,inNs:e.inNs}),Y=e=>new p(e.fromNs,e.inNs);class Z{#r;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#r=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,this.encodedContent=t.content,t.kind){case m.Application:this.kind="application";break;case m.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case y.Unpublished:this.deliveryStatus="unpublished";break;case y.Published:this.deliveryStatus="published";break;case y.Failed:this.deliveryStatus="failed"}this.contentType=P(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.#r.decodeContent(t,this.contentType)}}class ee{#r;#o;#d;#c;#l;#u;constructor(e,t,s){this.#r=e,this.#o=t,this.#g(s)}#g(e){this.#d=e?.isActive??void 0,this.#c=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#o}get isActive(){return this.#d}get addedByInboxId(){return this.#c}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.#r.sendMessage("getGroupMembers",{id:this.#o})}async sync(){const e=await this.#r.sendMessage("syncGroup",{id:this.#o});return this.#g(e),e}async publishMessages(){return this.#r.sendMessage("publishGroupMessages",{id:this.#o})}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.#r.encodeContent(e,t??s):this.#r.encodeContent(e,t);return this.#r.sendMessage("sendOptimisticGroupMessage",{id:this.#o,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.#r.encodeContent(e,t??s):this.#r.encodeContent(e,t);return this.#r.sendMessage("sendGroupMessage",{id:this.#o,content:n})}async messages(e){return(await this.#r.sendMessage("getGroupMessages",{id:this.#o,options:e})).map((e=>new Z(this.#r,e)))}async consentState(){return this.#r.sendMessage("getGroupConsentState",{id:this.#o})}async updateConsentState(e){return this.#r.sendMessage("updateGroupConsentState",{id:this.#o,state:e})}async messageDisappearingSettings(){return this.#r.sendMessage("getGroupMessageDisappearingSettings",{id:this.#o})}async updateMessageDisappearingSettings(e,t){return this.#r.sendMessage("updateGroupMessageDisappearingSettings",{id:this.#o,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#r.sendMessage("removeGroupMessageDisappearingSettings",{id:this.#o})}async isMessageDisappearingEnabled(){return this.#r.sendMessage("isGroupMessageDisappearingEnabled",{id:this.#o})}async stream(e){const t=M(),s=new A,n=this.#r.handleStreamMessage(t,((t,n)=>{if(t)return s.callback(t,void 0),void e?.(t,void 0);const i=n?new Z(this.#r,n):void 0;s.callback(null,i),e?.(null,i)}));return await this.#r.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:t}),n()},s}}class te extends ee{#r;#o;constructor(e,t,s){super(e,t,s),this.#r=e,this.#o=t}async peerInboxId(){return this.#r.sendMessage("getDmPeerInboxId",{id:this.#o})}}class se extends ee{#r;#o;#p;#h;#m;#y=[];#v=[];#g(e){this.#p=e?.name??"",this.#h=e?.imageUrl??"",this.#m=e?.description??"",this.#y=e?.admins??[],this.#v=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#r=e,this.#o=t,this.#g(s)}async sync(){const e=await super.sync();return this.#g(e),e}get name(){return this.#p}async updateName(e){await this.#r.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#p=e}get imageUrl(){return this.#h}async updateImageUrl(e){await this.#r.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#h=e}get description(){return this.#m}async updateDescription(e){await this.#r.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#m=e}get admins(){return this.#y}get superAdmins(){return this.#v}async listAdmins(){const e=await this.#r.sendMessage("getGroupAdmins",{id:this.#o});return this.#y=e,e}async listSuperAdmins(){const e=await this.#r.sendMessage("getGroupSuperAdmins",{id:this.#o});return this.#v=e,e}async permissions(){return this.#r.sendMessage("getGroupPermissions",{id:this.#o})}async updatePermission(e,t,s){return this.#r.sendMessage("updateGroupPermissionPolicy",{id:this.#o,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return(await this.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembers(e){return this.#r.sendMessage("addGroupMembers",{id:this.#o,accountAddresses:e})}async addMembersByInboxId(e){return this.#r.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembers(e){return this.#r.sendMessage("removeGroupMembers",{id:this.#o,accountAddresses:e})}async removeMembersByInboxId(e){return this.#r.sendMessage("removeGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async addAdmin(e){return this.#r.sendMessage("addGroupAdmin",{id:this.#o,inboxId:e})}async removeAdmin(e){return this.#r.sendMessage("removeGroupAdmin",{id:this.#o,inboxId:e})}async addSuperAdmin(e){return this.#r.sendMessage("addGroupSuperAdmin",{id:this.#o,inboxId:e})}async removeSuperAdmin(e){return this.#r.sendMessage("removeGroupSuperAdmin",{id:this.#o,inboxId:e})}}class ne{#r;constructor(e){this.#r=e}async sync(){return this.#r.sendMessage("syncConversations",void 0)}async syncAll(e){return this.#r.sendMessage("syncAllConversations",{consentStates:e})}async getConversationById(e){const t=await this.#r.sendMessage("getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new se(this.#r,t.id,t):new te(this.#r,t.id,t)}async getMessageById(e){const t=await this.#r.sendMessage("getMessageById",{id:e});return t?new Z(this.#r,t):void 0}async getDmByInboxId(e){const t=await this.#r.sendMessage("getDmByInboxId",{inboxId:e});return t?new te(this.#r,t.id,t):void 0}async list(e){return(await this.#r.sendMessage("getConversations",{options:e})).map((e=>"group"===e.metadata.conversationType?new se(this.#r,e.id,e):new te(this.#r,e.id,e)))}async listGroups(e){return(await this.#r.sendMessage("getGroups",{options:e})).map((e=>new se(this.#r,e.id,e)))}async listDms(e){return(await this.#r.sendMessage("getDms",{options:e})).map((e=>new te(this.#r,e.id,e)))}async newGroup(e,t){const s=await this.#r.sendMessage("newGroup",{accountAddresses:e,options:t});return new se(this.#r,s.id,s)}async newGroupByInboxIds(e,t){const s=await this.#r.sendMessage("newGroupByInboxIds",{inboxIds:e,options:t});return new se(this.#r,s.id,s)}async newDm(e,t){const s=await this.#r.sendMessage("newDm",{accountAddress:e,options:t});return new te(this.#r,s.id,s)}async newDmByInboxId(e,t){const s=await this.#r.sendMessage("newDmByInboxId",{inboxId:e,options:t});return new te(this.#r,s.id,s)}async getHmacKeys(){return this.#r.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=M(),n=new A,i=this.#r.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);let i;s&&(i="group"===s.metadata.conversationType?new se(this.#r,s.id,s):new te(this.#r,s.id,s)),n.callback(null,i),e?.(null,i)}));return await this.#r.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:s}),i()},n}async streamGroups(e){return this.stream(e,v.Group)}async streamDms(e){return this.stream(e,v.Dm)}async streamAllMessages(e,t){const s=M(),n=new A,i=this.#r.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);const i=s?new Z(this.#r,s):void 0;n.callback(null,i),e?.(null,i)}));return await this.#r.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:s}),i()},n}async streamAllGroupMessages(e){return this.streamAllMessages(e,v.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,v.Dm)}async streamConsent(e){const t=M(),s=new A,n=this.#r.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#r.sendMessage("streamConsent",{streamId:t}),s.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:t}),n()},s}async streamPreferences(e){const t=M(),s=new A,n=this.#r.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#r.sendMessage("streamPreferences",{streamId:t}),s.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:t}),n()},s}}class ie extends S{#w;#M;#I;#b;#S;#A;#x;#f=!1;#k;options;constructor(t,s,i,a){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==a?.loggingLevel&&"off"!==a.loggingLevel),this.#w=s,this.options=a,this.#b=i,this.#k=t,this.#I=new ne(this);const r=[new e,new n,...a?.codecs??[]];this.#M=new Map(r.map((e=>[e.contentType.toString(),e])))}get accountAddress(){return this.#w}async init(){const e=await this.sendMessage("init",{address:this.accountAddress,encryptionKey:this.#b,options:this.options});this.#S=e.inboxId,this.#A=e.installationId,this.#x=e.installationIdBytes,this.#f=!0}static async create(e,t,s){const n=await e.getAddress(),i=new ie(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#f}get inboxId(){return this.#S}get installationId(){return this.#A}get installationIdBytes(){return this.#x}async unsafe_createInboxSignatureText(){return this.sendMessage("createInboxSignatureText",void 0)}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Error("Unable to create add account signature text, `allowInboxReassign` must be true");return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async unsafe_addSignature(e,t,s){const n=await s.signMessage(t);"SCW"===s.walletType?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber?.()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async unsafe_applySignatures(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.unsafe_createInboxSignatureText();if(e)return await this.unsafe_addSignature(w.CreateInbox,e,this.#k),this.sendMessage("registerIdentity",void 0)}async unsafe_addAccount(e,t=!1){const s=await this.findInboxIdByAddress(await e.getAddress());if(s&&!t)throw new Error(`Signer address already associated with inbox ${s}`);const n=await this.unsafe_addAccountSignatureText(await e.getAddress(),!0);if(!n)throw new Error("Unable to generate add account signature text");await this.unsafe_addSignature(w.AddWallet,n,e),await this.unsafe_applySignatures()}async removeAccount(e){const t=await this.unsafe_removeAccountSignatureText(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.unsafe_addSignature(w.RevokeWallet,t,this.#k),await this.unsafe_applySignatures()}async revokeAllOtherInstallations(){const e=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.unsafe_addSignature(w.RevokeInstallations,e,this.#k),await this.unsafe_applySignatures()}async revokeInstallations(e){const t=await this.unsafe_revokeInstallationsSignatureText(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.unsafe_addSignature(w.RevokeInstallations,t,this.#k),await this.unsafe_applySignatures()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={walletType:"EOA",getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await ie.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(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.#I}codecFor(e){return this.#M.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),N(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!==m.MembershipChange)throw new Error("Error decoding group membership change");const i=T(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const ae=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class re{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",ae),this.#t=t}sendMessage(e,t){const s=M();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",ae),this.#e.terminate()}}class oe extends re{#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 de={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},ce={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{de as ApiUrls,ie as Client,ee as Conversation,ne as Conversations,Z as DecodedMessage,te as Dm,se as Group,ce as HistorySyncUrls,oe as Utils,f as fromContentTypeId,G as fromEncodedContent,V as fromSafeConsent,P as fromSafeContentTypeId,j as fromSafeCreateDmOptions,O as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,U as fromSafeListConversationsOptions,L as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,_ as fromSafePermissionPolicySet,x as toContentTypeId,D as toEncodedContent,H as toSafeConsent,k as toSafeContentTypeId,W as toSafeConversation,K as toSafeCreateDmOptions,q as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,$ as toSafeInboxState,F as toSafeInstallation,E as toSafeListConversationsOptions,B as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R as toSafePermissionPolicySet};
|
|
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 a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,CreateDMOptions as l,Consent as u,GroupMember as g,MessageDisappearingSettings as p,GroupPermissionsOptions as h,GroupMessageKind as m,DeliveryStatus as y,ConversationType as I,SignatureRequestType as v}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentType,ContentTypeId,ConversationListItem,ConversationType,CreateDMOptions,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,LogOptions,Message,MessageDisappearingSettings,MetadataField,Opfs,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as w}from"uuid";import{ContentTypeId as M}from"@xmtp/content-type-primitives";const b=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class f{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",b),this.#t=t}sendMessage(e,t){const s=w();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))};handleStreamMessage=(e,t)=>{const s=s=>{const n=s.data;n.streamId===e&&("error"in n?t(new Error(n.error),null):t(null,n.result))};return this.#e.addEventListener("message",s),()=>{this.#e.removeEventListener("message",s)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",b),this.#e.terminate()}}class S{#n=!1;#i;#r;onReturn=void 0;constructor(){this.#r=[],this.#i=null,this.#n=!1}get isDone(){return this.#n}callback=(e,t)=>{if(e)throw e;this.#n||(this.#i?(this.#i({done:!1,value:t}),this.#i=null):this.#r.push(t))};next=()=>this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):this.#n?Promise.resolve({done:!0,value:void 0}):new Promise((e=>{this.#i=e}));return=e=>(this.#n=!0,this.onReturn?.(),Promise.resolve({done:!0,value:e}));[Symbol.asyncIterator](){return this}}const x=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),A=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),k=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),D=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>new r(A(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(D(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),L=e=>({contentTypes:e.contentTypes,deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),B=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction,e.contentTypes),E=e=>({consentStates:e.consentStates,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit}),U=e=>new o(e.consentStates,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.limit),R=e=>({addAdminPolicy:e.addAdminPolicy,addMemberPolicy:e.addMemberPolicy,removeAdminPolicy:e.removeAdminPolicy,removeMemberPolicy:e.removeMemberPolicy,updateGroupDescriptionPolicy:e.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.updateGroupNamePolicy,updateMessageDisappearingPolicy:e.updateMessageDisappearingPolicy}),_=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),W=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),O=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===h.CustomPolicy?_(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),q=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),K=e=>new l(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),j=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,r=e.permissions,a=e.isActive,o=e.addedByInboxId,d=await e.metadata(),c=e.admins,l=e.superAdmins,u=e.createdAtNs,g=r.policyType,p=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:g,policySet:{addAdminPolicy:p.addAdminPolicy,addMemberPolicy:p.addMemberPolicy,removeAdminPolicy:p.removeAdminPolicy,removeMemberPolicy:p.removeMemberPolicy,updateGroupDescriptionPolicy:p.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:p.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:p.updateGroupNamePolicy,updateMessageDisappearingPolicy:p.updateMessageDisappearingPolicy}},isActive:a,addedByInboxId:o,metadata:d,admins:c,superAdmins:l,createdAtNs:u}},F=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),$=e=>({accountIdentifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(F),recoveryIdentifier:e.recoveryIdentifier}),H=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),V=e=>new u(e.entityType,e.state,e.entity),z=e=>({accountIdentifiers:e.accountIdentifiers,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),J=e=>new g(e.inboxId,e.accountIdentifiers,e.installationIds,e.permissionLevel,e.consentState),Q=e=>({key:e.key,epoch:e.epoch}),X=e=>({fromNs:e.fromNs,inNs:e.inNs}),Y=e=>new p(e.fromNs,e.inNs);class Z{#a;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#a=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,this.encodedContent=t.content,t.kind){case m.Application:this.kind="application";break;case m.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case y.Unpublished:this.deliveryStatus="unpublished";break;case y.Published:this.deliveryStatus="published";break;case y.Failed:this.deliveryStatus="failed"}this.contentType=P(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.#a.decodeContent(t,this.contentType)}}class ee{#a;#o;#d;#c;#l;#u;constructor(e,t,s){this.#a=e,this.#o=t,this.#g(s)}#g(e){this.#d=e?.isActive??void 0,this.#c=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#o}get isActive(){return this.#d}get addedByInboxId(){return this.#c}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.#a.sendMessage("getGroupMembers",{id:this.#o})}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});return this.#g(e),e}async publishMessages(){return this.#a.sendMessage("publishGroupMessages",{id:this.#o})}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.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendOptimisticGroupMessage",{id:this.#o,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.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendGroupMessage",{id:this.#o,content:n})}async messages(e){return(await this.#a.sendMessage("getGroupMessages",{id:this.#o,options:e})).map((e=>new Z(this.#a,e)))}async consentState(){return this.#a.sendMessage("getGroupConsentState",{id:this.#o})}async updateConsentState(e){return this.#a.sendMessage("updateGroupConsentState",{id:this.#o,state:e})}async messageDisappearingSettings(){return this.#a.sendMessage("getGroupMessageDisappearingSettings",{id:this.#o})}async updateMessageDisappearingSettings(e,t){return this.#a.sendMessage("updateGroupMessageDisappearingSettings",{id:this.#o,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#a.sendMessage("removeGroupMessageDisappearingSettings",{id:this.#o})}async isMessageDisappearingEnabled(){return this.#a.sendMessage("isGroupMessageDisappearingEnabled",{id:this.#o})}async stream(e){const t=w(),s=new S,n=this.#a.handleStreamMessage(t,((t,n)=>{if(t)return s.callback(t,void 0),void e?.(t,void 0);const i=n?new Z(this.#a,n):void 0;s.callback(null,i),e?.(null,i)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}async pausedForVersion(){return this.#a.sendMessage("getGroupPausedForVersion",{id:this.#o})}}class te extends ee{#a;#o;constructor(e,t,s){super(e,t,s),this.#a=e,this.#o=t}async peerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}}class se extends ee{#a;#o;#p;#h;#m;#y=[];#I=[];#g(e){this.#p=e?.name??"",this.#h=e?.imageUrl??"",this.#m=e?.description??"",this.#y=e?.admins??[],this.#I=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#a=e,this.#o=t,this.#g(s)}async sync(){const e=await super.sync();return this.#g(e),e}get name(){return this.#p}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#p=e}get imageUrl(){return this.#h}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#h=e}get description(){return this.#m}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#m=e}get admins(){return this.#y}get superAdmins(){return this.#I}async listAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});return this.#y=e,e}async listSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});return this.#I=e,e}async permissions(){return this.#a.sendMessage("getGroupPermissions",{id:this.#o})}async updatePermission(e,t,s){return this.#a.sendMessage("updateGroupPermissionPolicy",{id:this.#o,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return(await this.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembersByIdentifiers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,identifiers:e})}async addMembers(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,identifiers:e})}async removeMembers(e){return this.#a.sendMessage("removeGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async addAdmin(e){return this.#a.sendMessage("addGroupAdmin",{id:this.#o,inboxId:e})}async removeAdmin(e){return this.#a.sendMessage("removeGroupAdmin",{id:this.#o,inboxId:e})}async addSuperAdmin(e){return this.#a.sendMessage("addGroupSuperAdmin",{id:this.#o,inboxId:e})}async removeSuperAdmin(e){return this.#a.sendMessage("removeGroupSuperAdmin",{id:this.#o,inboxId:e})}}class ne{#a;constructor(e){this.#a=e}async sync(){return this.#a.sendMessage("syncConversations",void 0)}async syncAll(e){return this.#a.sendMessage("syncAllConversations",{consentStates:e})}async getConversationById(e){const t=await this.#a.sendMessage("getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new se(this.#a,t.id,t):new te(this.#a,t.id,t)}async getMessageById(e){const t=await this.#a.sendMessage("getMessageById",{id:e});return t?new Z(this.#a,t):void 0}async getDmByInboxId(e){const t=await this.#a.sendMessage("getDmByInboxId",{inboxId:e});return t?new te(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>"group"===e.metadata.conversationType?new se(this.#a,e.id,e):new te(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new se(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new te(this.#a,e.id,e)))}async newGroupWithIdentifiers(e,t){const s=await this.#a.sendMessage("newGroupWithIdentifiers",{identifiers:e,options:t});return new se(this.#a,s.id,s)}async newGroup(e,t){const s=await this.#a.sendMessage("newGroupWithInboxIds",{inboxIds:e,options:t});return new se(this.#a,s.id,s)}async newDmWithIdentifier(e,t){const s=await this.#a.sendMessage("newDmWithIdentifier",{identifier:e,options:t});return new te(this.#a,s.id,s)}async newDm(e,t){const s=await this.#a.sendMessage("newDmWithInboxId",{inboxId:e,options:t});return new te(this.#a,s.id,s)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=w(),n=new S,i=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);let i;s&&(i="group"===s.metadata.conversationType?new se(this.#a,s.id,s):new te(this.#a,s.id,s)),n.callback(null,i),e?.(null,i)}));return await this.#a.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),i()},n}async streamGroups(e){return this.stream(e,I.Group)}async streamDms(e){return this.stream(e,I.Dm)}async streamAllMessages(e,t){const s=w(),n=new S,i=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);const i=s?new Z(this.#a,s):void 0;n.callback(null,i),e?.(null,i)}));return await this.#a.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),i()},n}async streamAllGroupMessages(e){return this.streamAllMessages(e,I.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,I.Dm)}}class ie{#a;constructor(e){this.#a=e}async inboxState(e){return this.#a.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.#a.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.#a.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.#a.sendMessage("getConsentState",{entityType:e,entity:t})}async streamConsent(e){const t=w(),s=new S,n=this.#a.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#a.sendMessage("streamConsent",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}async streamPreferences(e){const t=w(),s=new S,n=this.#a.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#a.sendMessage("streamPreferences",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}}class re extends f{#v;#w;#M;#b;#f;#S;#x=!1;#A;#k;options;constructor(t,s,i){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==i?.loggingLevel&&"off"!==i.loggingLevel),this.options=i,this.#M=s,this.#k=t,this.#w=new ne(this),this.#A=new ie(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",{identifier:await this.#k.getIdentifier(),encryptionKey:this.#M,options:this.options});this.#b=e.inboxId,this.#f=e.installationId,this.#S=e.installationIdBytes,this.#x=!0}static async create(e,t,s){const n=new re(e,t,s);return await n.init(),s?.disableAutoRegister||await n.register(),n}get isReady(){return this.#x}get inboxId(){return this.#b}async accountIdentifier(){return this.#k.getIdentifier()}get installationId(){return this.#f}get installationIdBytes(){return this.#S}get conversations(){return this.#w}get preferences(){return this.#A}async unsafe_createInboxSignatureText(){return this.sendMessage("createInboxSignatureText",void 0)}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Error("Unable to create add account signature text, `allowInboxReassign` must be true");return this.sendMessage("addAccountSignatureText",{newIdentifier:e})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("removeAccountSignatureText",{identifier:e})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async unsafe_addSignature(e,t,s){const n=await s.signMessage(t);switch(s.type){case"SCW":await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber?.()});break;case"EOA":await this.sendMessage("addEcdsaSignature",{type:e,bytes:n})}}async unsafe_applySignatures(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.unsafe_createInboxSignatureText();if(e)return await this.unsafe_addSignature(v.CreateInbox,e,this.#k),this.sendMessage("registerIdentity",void 0)}async unsafe_addAccount(e,t=!1){const s=await this.findInboxIdByIdentifier(await e.getIdentifier());if(s&&!t)throw new Error(`Signer address already associated with inbox ${s}`);const n=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0);if(!n)throw new Error("Unable to generate add account signature text");await this.unsafe_addSignature(v.AddWallet,n,e),await this.unsafe_applySignatures()}async removeAccount(e){const t=await this.unsafe_removeAccountSignatureText(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.unsafe_addSignature(v.RevokeWallet,t,this.#k),await this.unsafe_applySignatures()}async revokeAllOtherInstallations(){const e=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.unsafe_addSignature(v.RevokeInstallations,e,this.#k),await this.unsafe_applySignatures()}async revokeInstallations(e){const t=await this.unsafe_revokeInstallationsSignatureText(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.unsafe_addSignature(v.RevokeInstallations,t,this.#k),await this.unsafe_applySignatures()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{identifiers:e})}static async canMessage(e,t){const s={type:"EOA",getIdentifier:()=>({identifier:"0x0000000000000000000000000000000000000000",identifierKind:"Ethereum"}),signMessage:()=>new Uint8Array};return(await re.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(e)}async findInboxIdByIdentifier(e){return this.sendMessage("findInboxIdByIdentifier",{identifier:e})}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),N(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!==m.MembershipChange)throw new Error("Error decoding group membership change");const i=T(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const ae=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class oe{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",ae),this.#t=t}sendMessage(e,t){const s=w();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",ae),this.#e.terminate()}}class de extends oe{#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",{identifier:e,enableLogging:this.#t})}async getInboxIdForIdentifier(e,t){return this.sendMessage("getInboxIdForIdentifier",{identifier:e,env:t,enableLogging:this.#t})}}const ce={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},le={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{ce as ApiUrls,re as Client,ee as Conversation,ne as Conversations,Z as DecodedMessage,te as Dm,se as Group,le as HistorySyncUrls,de as Utils,A as fromContentTypeId,G as fromEncodedContent,V as fromSafeConsent,P as fromSafeContentTypeId,K as fromSafeCreateDmOptions,O as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,U as fromSafeListConversationsOptions,B as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,_ as fromSafePermissionPolicySet,x as toContentTypeId,D as toEncodedContent,H as toSafeConsent,k as toSafeContentTypeId,j as toSafeConversation,q as toSafeCreateDmOptions,W as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,$ as toSafeInboxState,F as toSafeInstallation,E as toSafeListConversationsOptions,L as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R as toSafePermissionPolicySet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|