@xmtp/browser-sdk 0.0.22 → 1.0.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.d.ts +70 -61
- 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 +4 -4
- package/src/Client.ts +44 -40
- package/src/Conversation.ts +6 -0
- package/src/Conversations.ts +28 -18
- package/src/Group.ts +7 -6
- package/src/Utils.ts +6 -5
- package/src/WorkerClient.ts +15 -17
- package/src/WorkerConversation.ts +11 -6
- package/src/WorkerConversations.ts +13 -9
- package/src/index.ts +5 -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 +37 -32
- package/src/workers/utils.ts +14 -13
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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,
|
|
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';
|
|
2
|
+
import { Identifier, 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, Identifier, IdentifierKind, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
4
4
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
5
5
|
|
|
6
6
|
type ResolveValue<T> = {
|
|
@@ -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,10 +724,10 @@ 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;
|
|
@@ -733,23 +740,23 @@ declare class WorkerConversations {
|
|
|
733
740
|
declare class WorkerClient {
|
|
734
741
|
#private;
|
|
735
742
|
constructor(client: Client$1);
|
|
736
|
-
static create(
|
|
737
|
-
get
|
|
743
|
+
static create(identifier: Identifier, encryptionKey: Uint8Array, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
|
|
744
|
+
get accountIdentifier(): Identifier;
|
|
738
745
|
get inboxId(): string;
|
|
739
746
|
get installationId(): string;
|
|
740
747
|
get installationIdBytes(): Uint8Array<ArrayBufferLike>;
|
|
741
748
|
get isRegistered(): boolean;
|
|
742
749
|
createInboxSignatureText(): string | undefined;
|
|
743
|
-
addAccountSignatureText(
|
|
744
|
-
removeAccountSignatureText(
|
|
750
|
+
addAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
751
|
+
removeAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
745
752
|
revokeAllAOtherInstallationsSignatureText(): Promise<string | undefined>;
|
|
746
753
|
revokeInstallationsSignatureText(installationIds: Uint8Array[]): Promise<string | undefined>;
|
|
747
|
-
|
|
754
|
+
addEcdsaSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<void>;
|
|
748
755
|
addScwSignature(type: SignatureRequestType, bytes: Uint8Array, chainId: bigint, blockNumber?: bigint): Promise<void>;
|
|
749
756
|
applySignatures(): Promise<void>;
|
|
750
|
-
canMessage(
|
|
757
|
+
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
751
758
|
registerIdentity(): Promise<void>;
|
|
752
|
-
|
|
759
|
+
findInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
753
760
|
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
754
761
|
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
755
762
|
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
@@ -788,10 +795,10 @@ declare class WorkerConversation {
|
|
|
788
795
|
isAdmin(inboxId: string): boolean;
|
|
789
796
|
isSuperAdmin(inboxId: string): boolean;
|
|
790
797
|
sync(): Promise<void>;
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
798
|
+
addMembersByIdentifiers(identifiers: Identifier[]): Promise<void>;
|
|
799
|
+
addMembers(inboxIds: string[]): Promise<void>;
|
|
800
|
+
removeMembersByIdentifiers(identifiers: Identifier[]): Promise<void>;
|
|
801
|
+
removeMembers(inboxIds: string[]): Promise<void>;
|
|
795
802
|
addAdmin(inboxId: string): Promise<void>;
|
|
796
803
|
removeAdmin(inboxId: string): Promise<void>;
|
|
797
804
|
addSuperAdmin(inboxId: string): Promise<void>;
|
|
@@ -808,6 +815,7 @@ declare class WorkerConversation {
|
|
|
808
815
|
removeMessageDisappearingSettings(): Promise<void>;
|
|
809
816
|
isMessageDisappearingEnabled(): boolean;
|
|
810
817
|
stream(callback?: StreamCallback<Message>): _xmtp_wasm_bindings.StreamCloser;
|
|
818
|
+
pausedForVersion(): string | undefined;
|
|
811
819
|
}
|
|
812
820
|
|
|
813
821
|
declare const toContentTypeId: (contentTypeId: ContentTypeId) => ContentTypeId$1;
|
|
@@ -923,10 +931,10 @@ type SafeInstallation = {
|
|
|
923
931
|
};
|
|
924
932
|
declare const toSafeInstallation: (installation: Installation) => SafeInstallation;
|
|
925
933
|
type SafeInboxState = {
|
|
926
|
-
|
|
934
|
+
accountIdentifiers: Identifier[];
|
|
927
935
|
inboxId: string;
|
|
928
936
|
installations: SafeInstallation[];
|
|
929
|
-
|
|
937
|
+
recoveryIdentifier: Identifier;
|
|
930
938
|
};
|
|
931
939
|
declare const toSafeInboxState: (inboxState: InboxState) => SafeInboxState;
|
|
932
940
|
type SafeConsent = {
|
|
@@ -937,7 +945,7 @@ type SafeConsent = {
|
|
|
937
945
|
declare const toSafeConsent: (consent: Consent) => SafeConsent;
|
|
938
946
|
declare const fromSafeConsent: (consent: SafeConsent) => Consent;
|
|
939
947
|
type SafeGroupMember = {
|
|
940
|
-
|
|
948
|
+
accountIdentifiers: Identifier[];
|
|
941
949
|
consentState: ConsentState;
|
|
942
950
|
inboxId: string;
|
|
943
951
|
installationIds: string[];
|
|
@@ -1030,6 +1038,7 @@ declare class Conversation {
|
|
|
1030
1038
|
removeMessageDisappearingSettings(): Promise<undefined>;
|
|
1031
1039
|
isMessageDisappearingEnabled(): Promise<boolean>;
|
|
1032
1040
|
stream(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
1041
|
+
pausedForVersion(): Promise<string | undefined>;
|
|
1033
1042
|
}
|
|
1034
1043
|
|
|
1035
1044
|
declare class Dm extends Conversation {
|
|
@@ -1068,10 +1077,10 @@ declare class Group extends Conversation {
|
|
|
1068
1077
|
updatePermission(permissionType: PermissionUpdateType, policy: PermissionPolicy, metadataField?: MetadataField): Promise<undefined>;
|
|
1069
1078
|
isAdmin(inboxId: string): Promise<boolean>;
|
|
1070
1079
|
isSuperAdmin(inboxId: string): Promise<boolean>;
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1080
|
+
addMembersByIdentifiers(identifiers: Identifier[]): Promise<undefined>;
|
|
1081
|
+
addMembers(inboxIds: string[]): Promise<undefined>;
|
|
1082
|
+
removeMembersByIdentifiers(identifiers: Identifier[]): Promise<undefined>;
|
|
1083
|
+
removeMembers(inboxIds: string[]): Promise<undefined>;
|
|
1075
1084
|
addAdmin(inboxId: string): Promise<undefined>;
|
|
1076
1085
|
removeAdmin(inboxId: string): Promise<undefined>;
|
|
1077
1086
|
addSuperAdmin(inboxId: string): Promise<undefined>;
|
|
@@ -1089,10 +1098,10 @@ declare class Conversations {
|
|
|
1089
1098
|
list(options?: SafeListConversationsOptions): Promise<(Dm | Group)[]>;
|
|
1090
1099
|
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Group[]>;
|
|
1091
1100
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Dm[]>;
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1101
|
+
newGroupWithIdentifiers(identifiers: Identifier[], options?: SafeCreateGroupOptions): Promise<Group>;
|
|
1102
|
+
newGroup(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<Group>;
|
|
1103
|
+
newDmWithIdentifier(identifier: Identifier, options?: SafeCreateDmOptions): Promise<Dm>;
|
|
1104
|
+
newDm(inboxId: string, options?: SafeCreateDmOptions): Promise<Dm>;
|
|
1096
1105
|
getHmacKeys(): Promise<SafeHmacKeys>;
|
|
1097
1106
|
stream<T extends Group | Dm = Group | Dm>(callback?: StreamCallback<T>, conversationType?: ConversationType): Promise<AsyncStream<T>>;
|
|
1098
1107
|
streamGroups(callback?: StreamCallback<Group>): Promise<AsyncStream<Group>>;
|
|
@@ -1105,16 +1114,16 @@ declare class Conversations {
|
|
|
1105
1114
|
}
|
|
1106
1115
|
|
|
1107
1116
|
type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
|
|
1108
|
-
type
|
|
1117
|
+
type GetIdentifier = () => Promise<Identifier> | Identifier;
|
|
1109
1118
|
type GetChainId = () => bigint;
|
|
1110
1119
|
type GetBlockNumber = () => bigint;
|
|
1111
1120
|
type Signer = {
|
|
1112
|
-
|
|
1113
|
-
|
|
1121
|
+
type: "EOA";
|
|
1122
|
+
getIdentifier: GetIdentifier;
|
|
1114
1123
|
signMessage: SignMessage;
|
|
1115
1124
|
} | {
|
|
1116
|
-
|
|
1117
|
-
|
|
1125
|
+
type: "SCW";
|
|
1126
|
+
getIdentifier: GetIdentifier;
|
|
1118
1127
|
signMessage: SignMessage;
|
|
1119
1128
|
getBlockNumber?: GetBlockNumber;
|
|
1120
1129
|
getChainId: GetChainId;
|
|
@@ -1123,12 +1132,12 @@ type Signer = {
|
|
|
1123
1132
|
declare class Client extends ClientWorkerClass {
|
|
1124
1133
|
#private;
|
|
1125
1134
|
options?: ClientOptions;
|
|
1126
|
-
constructor(signer: Signer,
|
|
1127
|
-
get accountAddress(): string;
|
|
1135
|
+
constructor(signer: Signer, encryptionKey: Uint8Array, options?: ClientOptions);
|
|
1128
1136
|
init(): Promise<void>;
|
|
1129
1137
|
static create(signer: Signer, encryptionKey: Uint8Array, options?: ClientOptions): Promise<Client>;
|
|
1130
1138
|
get isReady(): boolean;
|
|
1131
1139
|
get inboxId(): string | undefined;
|
|
1140
|
+
accountIdentifier(): Promise<Identifier>;
|
|
1132
1141
|
get installationId(): string | undefined;
|
|
1133
1142
|
get installationIdBytes(): Uint8Array<ArrayBufferLike> | undefined;
|
|
1134
1143
|
/**
|
|
@@ -1149,7 +1158,7 @@ declare class Client extends ClientWorkerClass {
|
|
|
1149
1158
|
* The `allowInboxReassign` parameter must be true or this function will
|
|
1150
1159
|
* throw an error.
|
|
1151
1160
|
*/
|
|
1152
|
-
unsafe_addAccountSignatureText(
|
|
1161
|
+
unsafe_addAccountSignatureText(newIdentifier: Identifier, allowInboxReassign?: boolean): Promise<string | undefined>;
|
|
1153
1162
|
/**
|
|
1154
1163
|
* WARNING: This function should be used with caution. It is only provided
|
|
1155
1164
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1157,7 +1166,7 @@ declare class Client extends ClientWorkerClass {
|
|
|
1157
1166
|
*
|
|
1158
1167
|
* It is highly recommended to use the `removeAccount` function instead.
|
|
1159
1168
|
*/
|
|
1160
|
-
unsafe_removeAccountSignatureText(
|
|
1169
|
+
unsafe_removeAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
1161
1170
|
/**
|
|
1162
1171
|
* WARNING: This function should be used with caution. It is only provided
|
|
1163
1172
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1205,13 +1214,13 @@ declare class Client extends ClientWorkerClass {
|
|
|
1205
1214
|
* already associated with a different account.
|
|
1206
1215
|
*/
|
|
1207
1216
|
unsafe_addAccount(newAccountSigner: Signer, allowInboxReassign?: boolean): Promise<void>;
|
|
1208
|
-
removeAccount(
|
|
1217
|
+
removeAccount(accountIdentifier: Identifier): Promise<void>;
|
|
1209
1218
|
revokeAllOtherInstallations(): Promise<void>;
|
|
1210
1219
|
revokeInstallations(installationIds: Uint8Array[]): Promise<void>;
|
|
1211
1220
|
isRegistered(): Promise<boolean>;
|
|
1212
|
-
canMessage(
|
|
1213
|
-
static canMessage(
|
|
1214
|
-
|
|
1221
|
+
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
1222
|
+
static canMessage(identifiers: Identifier[], env?: XmtpEnv): Promise<Map<string, boolean>>;
|
|
1223
|
+
findInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
1215
1224
|
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
1216
1225
|
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
1217
1226
|
setConsentStates(records: SafeConsent[]): Promise<undefined>;
|
|
@@ -1236,8 +1245,8 @@ declare class UtilsWorkerClass {
|
|
|
1236
1245
|
declare class Utils extends UtilsWorkerClass {
|
|
1237
1246
|
#private;
|
|
1238
1247
|
constructor(enableLogging?: boolean);
|
|
1239
|
-
generateInboxId(
|
|
1240
|
-
|
|
1248
|
+
generateInboxId(identifier: Identifier): Promise<string>;
|
|
1249
|
+
getInboxIdForIdentifier(identifier: Identifier, env?: XmtpEnv): Promise<string | undefined>;
|
|
1241
1250
|
}
|
|
1242
1251
|
|
|
1243
1252
|
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,GroupPermissionsOptions as l,CreateDMOptions as u,Consent as g,GroupMember as p,MessageDisappearingSettings 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===l.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 u(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 g(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 p(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 h(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 i}from"@xmtp/content-type-text";import{ContentTypeId as n,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,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 i=s.data;i.streamId===e&&("error"in i?t(new Error(i.error),null):t(null,i.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{#i=!1;#n;#r;onReturn=void 0;constructor(){this.#r=[],this.#n=null,this.#i=!1}get isDone(){return this.#i}callback=(e,t)=>{if(e)throw e;this.#i||(this.#n?(this.#n({done:!1,value:t}),this.#n=null):this.#r.push(t))};next=()=>this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):this.#i?Promise.resolve({done:!0,value:void 0}):new Promise((e=>{this.#n=e}));return=e=>(this.#i=!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 n(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}),q=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),O=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,i=e.imageUrl,n=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:i,description:n,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 i="string"==typeof e?this.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendOptimisticGroupMessage",{id:this.#o,content:i})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const i="string"==typeof e?this.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendGroupMessage",{id:this.#o,content:i})}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,i=this.#a.handleStreamMessage(t,((t,i)=>{if(t)return s.callback(t,void 0),void e?.(t,void 0);const n=i?new Z(this.#a,i):void 0;s.callback(null,n),e?.(null,n)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),i()},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 ie{#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(),i=new S,n=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return i.callback(t,void 0),void e?.(t,void 0);let n;s&&(n="group"===s.metadata.conversationType?new se(this.#a,s.id,s):new te(this.#a,s.id,s)),i.callback(null,n),e?.(null,n)}));return await this.#a.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),i.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),n()},i}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(),i=new S,n=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return i.callback(t,void 0),void e?.(t,void 0);const n=s?new Z(this.#a,s):void 0;i.callback(null,n),e?.(null,n)}));return await this.#a.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),i.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),n()},i}async streamAllGroupMessages(e){return this.streamAllMessages(e,I.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,I.Dm)}async streamConsent(e){const t=w(),s=new S,i=this.#a.handleStreamMessage(t,((t,i)=>{s.callback(t,i??void 0),e?.(t,i??void 0)}));return await this.#a.sendMessage("streamConsent",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),i()},s}async streamPreferences(e){const t=w(),s=new S,i=this.#a.handleStreamMessage(t,((t,i)=>{s.callback(t,i??void 0),e?.(t,i??void 0)}));return await this.#a.sendMessage("streamPreferences",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),i()},s}}class ne extends f{#v;#w;#M;#b;#f;#S;#x=!1;#A;options;constructor(t,s,n){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==n?.loggingLevel&&"off"!==n.loggingLevel),this.options=n,this.#M=s,this.#A=t,this.#w=new ie(this);const r=[new e,new i,...n?.codecs??[]];this.#v=new Map(r.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{identifier:await this.#A.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 i=new ne(e,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#x}get inboxId(){return this.#b}async accountIdentifier(){return this.#A.getIdentifier()}get installationId(){return this.#f}get installationIdBytes(){return this.#S}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 i=await s.signMessage(t);switch(s.type){case"SCW":await this.sendMessage("addScwSignature",{type:e,bytes:i,chainId:s.getChainId(),blockNumber:s.getBlockNumber?.()});break;case"EOA":await this.sendMessage("addEcdsaSignature",{type:e,bytes:i})}}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.#A),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 i=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0);if(!i)throw new Error("Unable to generate add account signature text");await this.unsafe_addSignature(v.AddWallet,i,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.#A),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.#A),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.#A),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 ne.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(e)}async findInboxIdByIdentifier(e){return this.sendMessage("findInboxIdByIdentifier",{identifier: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.#w}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 i=s.encode(e,this),n=s.fallback(e);return n&&(i.fallback=n),N(i)}decodeContent(e,s){const i=this.codecFor(s);if(!i)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 n=T(e.content);return i.decode(n,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 re=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class ae{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",re),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",re),this.#e.terminate()}}class oe extends ae{#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 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,ne as Client,ee as Conversation,ie as Conversations,Z as DecodedMessage,te as Dm,se as Group,ce as HistorySyncUrls,oe as Utils,A as fromContentTypeId,G as fromEncodedContent,V as fromSafeConsent,P as fromSafeContentTypeId,K as fromSafeCreateDmOptions,q 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,O 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
|