@xmtp/browser-sdk 0.0.18 → 0.0.20
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 -3
- package/dist/index.d.ts +84 -8
- 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/package.json +2 -2
- package/src/Conversation.ts +26 -0
- package/src/Conversations.ts +29 -4
- package/src/WorkerConversation.ts +27 -9
- package/src/WorkerConversations.ts +42 -10
- package/src/types/clientEvents.ts +56 -1
- package/src/utils/conversions.ts +57 -1
- package/src/utils/signer.ts +3 -3
- package/src/workers/client.ts +101 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ To keep up with the latest SDK developments, see the [Issues tab](https://githu
|
|
|
7
7
|
To learn more about XMTP and get answers to frequently asked questions, see the [XMTP documentation](https://xmtp.org/docs).
|
|
8
8
|
|
|
9
9
|
> [!CAUTION]
|
|
10
|
-
> This SDK is
|
|
10
|
+
> This SDK is in beta status and ready for you to build with in production. Software in this status may change based on feedback.
|
|
11
11
|
|
|
12
12
|
## Requirements
|
|
13
13
|
|
|
@@ -79,8 +79,7 @@ import { defineConfig } from "vite";
|
|
|
79
79
|
|
|
80
80
|
export default defineConfig({
|
|
81
81
|
optimizeDeps: {
|
|
82
|
-
exclude: ["@xmtp/
|
|
83
|
-
include: ["@xmtp/proto"],
|
|
82
|
+
exclude: ["@xmtp/wasm-bindings"],
|
|
84
83
|
},
|
|
85
84
|
});
|
|
86
85
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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, Client as Client$1, EncodedContent, ContentTypeId, DeliveryStatus, GroupMessageKind, SortDirection, ListMessagesOptions, GroupMembershipState, ListConversationsOptions, PermissionPolicySet, GroupPermissionsOptions, CreateGroupOptions, Installation, InboxState, Consent, PermissionLevel, GroupMember, HmacKey } from '@xmtp/wasm-bindings';
|
|
2
|
+
import { SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Client as Client$1, EncodedContent, MessageDisappearingSettings, ContentTypeId, DeliveryStatus, GroupMessageKind, SortDirection, ListMessagesOptions, GroupMembershipState, ListConversationsOptions, PermissionPolicySet, GroupPermissionsOptions, CreateGroupOptions, CreateDMOptions, Installation, InboxState, Consent, PermissionLevel, GroupMember, HmacKey } from '@xmtp/wasm-bindings';
|
|
3
3
|
export { Consent, ConsentEntityType, ConsentState, ContentTypeId, ConversationType, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, Message, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection } from '@xmtp/wasm-bindings';
|
|
4
4
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
5
5
|
|
|
@@ -301,12 +301,29 @@ type ClientEvents =
|
|
|
301
301
|
accountAddresses: string[];
|
|
302
302
|
options?: SafeCreateGroupOptions;
|
|
303
303
|
};
|
|
304
|
+
} | {
|
|
305
|
+
action: "newGroupByInboxIds";
|
|
306
|
+
id: string;
|
|
307
|
+
result: SafeConversation;
|
|
308
|
+
data: {
|
|
309
|
+
inboxIds: string[];
|
|
310
|
+
options?: SafeCreateGroupOptions;
|
|
311
|
+
};
|
|
304
312
|
} | {
|
|
305
313
|
action: "newDm";
|
|
306
314
|
id: string;
|
|
307
315
|
result: SafeConversation;
|
|
308
316
|
data: {
|
|
309
317
|
accountAddress: string;
|
|
318
|
+
options?: SafeCreateDmOptions;
|
|
319
|
+
};
|
|
320
|
+
} | {
|
|
321
|
+
action: "newDmByInboxId";
|
|
322
|
+
id: string;
|
|
323
|
+
result: SafeConversation;
|
|
324
|
+
data: {
|
|
325
|
+
inboxId: string;
|
|
326
|
+
options?: SafeCreateDmOptions;
|
|
310
327
|
};
|
|
311
328
|
} | {
|
|
312
329
|
action: "syncConversations";
|
|
@@ -317,7 +334,9 @@ type ClientEvents =
|
|
|
317
334
|
action: "syncAllConversations";
|
|
318
335
|
id: string;
|
|
319
336
|
result: undefined;
|
|
320
|
-
data:
|
|
337
|
+
data: {
|
|
338
|
+
consentStates?: ConsentState[];
|
|
339
|
+
};
|
|
321
340
|
} | {
|
|
322
341
|
action: "getHmacKeys";
|
|
323
342
|
id: string;
|
|
@@ -545,6 +564,34 @@ type ClientEvents =
|
|
|
545
564
|
data: {
|
|
546
565
|
id: string;
|
|
547
566
|
};
|
|
567
|
+
} | {
|
|
568
|
+
action: "getGroupMessageDisappearingSettings";
|
|
569
|
+
id: string;
|
|
570
|
+
result: SafeMessageDisappearingSettings | undefined;
|
|
571
|
+
data: {
|
|
572
|
+
id: string;
|
|
573
|
+
};
|
|
574
|
+
} | {
|
|
575
|
+
action: "updateGroupMessageDisappearingSettings";
|
|
576
|
+
id: string;
|
|
577
|
+
result: undefined;
|
|
578
|
+
data: SafeMessageDisappearingSettings & {
|
|
579
|
+
id: string;
|
|
580
|
+
};
|
|
581
|
+
} | {
|
|
582
|
+
action: "removeGroupMessageDisappearingSettings";
|
|
583
|
+
id: string;
|
|
584
|
+
result: undefined;
|
|
585
|
+
data: {
|
|
586
|
+
id: string;
|
|
587
|
+
};
|
|
588
|
+
} | {
|
|
589
|
+
action: "isGroupMessageDisappearingEnabled";
|
|
590
|
+
id: string;
|
|
591
|
+
result: boolean;
|
|
592
|
+
data: {
|
|
593
|
+
id: string;
|
|
594
|
+
};
|
|
548
595
|
} | {
|
|
549
596
|
action: "streamGroupMessages";
|
|
550
597
|
id: string;
|
|
@@ -649,7 +696,7 @@ declare class WorkerConversations {
|
|
|
649
696
|
#private;
|
|
650
697
|
constructor(client: WorkerClient, conversations: Conversations$1);
|
|
651
698
|
sync(): Promise<void>;
|
|
652
|
-
syncAll(): Promise<number>;
|
|
699
|
+
syncAll(consentStates?: ConsentState[]): Promise<number>;
|
|
653
700
|
getConversationById(id: string): WorkerConversation | undefined;
|
|
654
701
|
getMessageById(id: string): Message | undefined;
|
|
655
702
|
getDmByInboxId(inboxId: string): WorkerConversation | undefined;
|
|
@@ -657,7 +704,9 @@ declare class WorkerConversations {
|
|
|
657
704
|
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
|
|
658
705
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
|
|
659
706
|
newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
|
|
660
|
-
|
|
707
|
+
newGroupByInboxIds(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
|
|
708
|
+
newDm(accountAddress: string, options?: SafeCreateDmOptions): Promise<WorkerConversation>;
|
|
709
|
+
newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions): Promise<WorkerConversation>;
|
|
661
710
|
getHmacKeys(): HmacKeys;
|
|
662
711
|
stream(callback?: StreamCallback<Conversation$1>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
|
|
663
712
|
streamGroups(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
@@ -684,7 +733,7 @@ declare class WorkerClient {
|
|
|
684
733
|
applySignatures(): Promise<void>;
|
|
685
734
|
canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
|
|
686
735
|
registerIdentity(): Promise<void>;
|
|
687
|
-
findInboxIdByAddress(address: string): Promise<string>;
|
|
736
|
+
findInboxIdByAddress(address: string): Promise<string | undefined>;
|
|
688
737
|
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
689
738
|
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
690
739
|
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
@@ -738,6 +787,10 @@ declare class WorkerConversation {
|
|
|
738
787
|
get consentState(): ConsentState;
|
|
739
788
|
updateConsentState(state: ConsentState): void;
|
|
740
789
|
dmPeerInboxId(): string;
|
|
790
|
+
messageDisappearingSettings(): MessageDisappearingSettings | undefined;
|
|
791
|
+
updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint): Promise<void>;
|
|
792
|
+
removeMessageDisappearingSettings(): Promise<void>;
|
|
793
|
+
isMessageDisappearingEnabled(): boolean;
|
|
741
794
|
stream(callback?: StreamCallback<Message>): _xmtp_wasm_bindings.StreamCloser;
|
|
742
795
|
}
|
|
743
796
|
|
|
@@ -783,9 +836,12 @@ declare const toSafeListMessagesOptions: (options: ListMessagesOptions) => SafeL
|
|
|
783
836
|
declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => ListMessagesOptions;
|
|
784
837
|
type SafeListConversationsOptions = {
|
|
785
838
|
allowedStates?: GroupMembershipState[];
|
|
839
|
+
consentStates?: ConsentState[];
|
|
786
840
|
conversationType?: ConversationType;
|
|
787
841
|
createdAfterNs?: bigint;
|
|
788
842
|
createdBeforeNs?: bigint;
|
|
843
|
+
includeDuplicateDms?: boolean;
|
|
844
|
+
includeSyncGroups?: boolean;
|
|
789
845
|
limit?: bigint;
|
|
790
846
|
};
|
|
791
847
|
declare const toSafeListConversationsOptions: (options: ListConversationsOptions) => SafeListConversationsOptions;
|
|
@@ -806,11 +862,17 @@ type SafeCreateGroupOptions = {
|
|
|
806
862
|
customPermissionPolicySet?: SafePermissionPolicySet;
|
|
807
863
|
description?: string;
|
|
808
864
|
imageUrlSquare?: string;
|
|
865
|
+
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
809
866
|
name?: string;
|
|
810
867
|
permissions?: GroupPermissionsOptions;
|
|
811
868
|
};
|
|
812
869
|
declare const toSafeCreateGroupOptions: (options: CreateGroupOptions) => SafeCreateGroupOptions;
|
|
813
870
|
declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) => CreateGroupOptions;
|
|
871
|
+
type SafeCreateDmOptions = {
|
|
872
|
+
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
873
|
+
};
|
|
874
|
+
declare const toSafeCreateDmOptions: (options: CreateDMOptions) => SafeCreateDmOptions;
|
|
875
|
+
declare const fromSafeCreateDmOptions: (options: SafeCreateDmOptions) => CreateDMOptions;
|
|
814
876
|
type SafeConversation = {
|
|
815
877
|
id: string;
|
|
816
878
|
name: string;
|
|
@@ -876,6 +938,12 @@ type SafeHmacKey = {
|
|
|
876
938
|
declare const toSafeHmacKey: (hmacKey: HmacKey) => SafeHmacKey;
|
|
877
939
|
type HmacKeys = Map<string, HmacKey[]>;
|
|
878
940
|
type SafeHmacKeys = Record<string, SafeHmacKey[]>;
|
|
941
|
+
type SafeMessageDisappearingSettings = {
|
|
942
|
+
fromNs: bigint;
|
|
943
|
+
inNs: bigint;
|
|
944
|
+
};
|
|
945
|
+
declare const toSafeMessageDisappearingSettings: (settings: MessageDisappearingSettings) => SafeMessageDisappearingSettings;
|
|
946
|
+
declare const fromSafeMessageDisappearingSettings: (settings: SafeMessageDisappearingSettings) => MessageDisappearingSettings;
|
|
879
947
|
|
|
880
948
|
type ClientStreamEvents = {
|
|
881
949
|
type: "message";
|
|
@@ -970,6 +1038,10 @@ declare class Conversation {
|
|
|
970
1038
|
consentState(): Promise<ConsentState>;
|
|
971
1039
|
updateConsentState(state: ConsentState): Promise<undefined>;
|
|
972
1040
|
dmPeerInboxId(): Promise<string>;
|
|
1041
|
+
messageDisappearingSettings(): Promise<SafeMessageDisappearingSettings | undefined>;
|
|
1042
|
+
updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint): Promise<undefined>;
|
|
1043
|
+
removeMessageDisappearingSettings(): Promise<undefined>;
|
|
1044
|
+
isMessageDisappearingEnabled(): Promise<boolean>;
|
|
973
1045
|
stream(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
974
1046
|
}
|
|
975
1047
|
|
|
@@ -977,7 +1049,7 @@ declare class Conversations {
|
|
|
977
1049
|
#private;
|
|
978
1050
|
constructor(client: Client);
|
|
979
1051
|
sync(): Promise<undefined>;
|
|
980
|
-
syncAll(): Promise<undefined>;
|
|
1052
|
+
syncAll(consentStates?: ConsentState[]): Promise<undefined>;
|
|
981
1053
|
getConversationById(id: string): Promise<Conversation | undefined>;
|
|
982
1054
|
getMessageById(id: string): Promise<DecodedMessage | undefined>;
|
|
983
1055
|
getDmByInboxId(inboxId: string): Promise<Conversation | undefined>;
|
|
@@ -985,7 +1057,9 @@ declare class Conversations {
|
|
|
985
1057
|
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Conversation[]>;
|
|
986
1058
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Conversation[]>;
|
|
987
1059
|
newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
|
|
988
|
-
|
|
1060
|
+
newGroupByInboxIds(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
|
|
1061
|
+
newDm(accountAddress: string, options?: SafeCreateDmOptions): Promise<Conversation>;
|
|
1062
|
+
newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions): Promise<Conversation>;
|
|
989
1063
|
getHmacKeys(): Promise<SafeHmacKeys>;
|
|
990
1064
|
stream(callback?: StreamCallback<Conversation>, conversationType?: ConversationType): Promise<AsyncStream<Conversation>>;
|
|
991
1065
|
streamGroups(callback?: StreamCallback<Conversation>): Promise<AsyncStream<Conversation>>;
|
|
@@ -999,9 +1073,11 @@ type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
|
|
|
999
1073
|
type GetAddress = () => Promise<string> | string;
|
|
1000
1074
|
type GetChainId = () => bigint;
|
|
1001
1075
|
type GetBlockNumber = () => bigint;
|
|
1076
|
+
type WalletType = () => "EOA" | "SCW";
|
|
1002
1077
|
type Signer = {
|
|
1003
1078
|
getAddress: GetAddress;
|
|
1004
1079
|
signMessage: SignMessage;
|
|
1080
|
+
walletType?: WalletType;
|
|
1005
1081
|
getBlockNumber?: GetBlockNumber;
|
|
1006
1082
|
getChainId?: GetChainId;
|
|
1007
1083
|
};
|
|
@@ -1056,4 +1132,4 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
1056
1132
|
getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
|
|
1057
1133
|
}
|
|
1058
1134
|
|
|
1059
|
-
export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type GenericStreamEvent, HistorySyncUrls, type HmacKeys, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeHmacKey, type SafeHmacKeys, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SafePermissionPolicySet, type SendMessageData, type Signer, type SmartContractSigner, 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, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, fromSafePermissionPolicySet, isSmartContractSigner, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafePermissionPolicySet };
|
|
1135
|
+
export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type GenericStreamEvent, 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 SmartContractSigner, 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, isSmartContractSigner, 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 r,ListMessagesOptions as a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,GroupPermissionsOptions as l,Consent as u,GroupMember as h,GroupMessageKind as p,DeliveryStatus as g,ConversationType as m,SignatureRequestType as y}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as v}from"uuid";import{ContentTypeId as w}from"@xmtp/content-type-primitives";const I=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class M{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",I),this.#t=t}sendMessage(e,t){const s=v();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",I),this.#e.terminate()}}class b{#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 A=e=>new w({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),S=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),x=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),k=e=>new w({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>({type:A(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),f=e=>new r(S(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),G=e=>({type:x(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({content:G(P(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),C=e=>({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),L=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),D=e=>new o(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),U=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=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),R=e=>({description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,name:e.groupName,permissions:e.permissions,customPermissionPolicySet:e.customPermissionPolicySet}),q=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?E(e.customPermissionPolicySet):void 0),K=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,h=r.policyType,p=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:h,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}},j=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),O=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(j),recoveryAddress:e.recoveryAddress}),W=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),F=e=>new u(e.entityType,e.state,e.entity),$=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),H=e=>new h(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState),V=e=>({key:e.key,epoch:e.epoch});class _{#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 p.Application:this.kind="application";break;case p.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case g.Unpublished:this.deliveryStatus="unpublished";break;case g.Published:this.deliveryStatus="published";break;case g.Failed:this.deliveryStatus="failed"}this.contentType=k(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 z{#a;#o;#d;#c;#l;#u;#h;#p;#g;#m=[];#y=[];constructor(e,t,s){this.#a=e,this.#o=t,this.#v(s)}#v(e){this.#d=e?.name??"",this.#c=e?.imageUrl??"",this.#l=e?.description??"",this.#u=e?.isActive??void 0,this.#h=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#g=e?.createdAtNs??void 0,this.#m=e?.admins??[],this.#y=e?.superAdmins??[]}get id(){return this.#o}get name(){return this.#d}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#d=e}get imageUrl(){return this.#c}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#c=e}get description(){return this.#l}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#l=e}get isActive(){return this.#u}get addedByInboxId(){return this.#h}get createdAtNs(){return this.#g}get createdAt(){return this.#g?(e=this.#g,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#p}async members(){return this.#a.sendMessage("getGroupMembers",{id:this.#o})}get admins(){return this.#m}get superAdmins(){return this.#y}async syncAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});this.#m=e}async syncSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});this.#y=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.syncAdmins(),this.#m.includes(e)}async isSuperAdmin(e){return await this.syncSuperAdmins(),this.#y.includes(e)}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});this.#v(e)}async addMembers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,accountAddresses:e})}async addMembersByInboxId(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,accountAddresses:e})}async removeMembersByInboxId(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})}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 _(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 dmPeerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}async stream(e){const t=v(),s=new b,n=this.#a.handleStreamMessage(t,((t,n)=>{const i=n?new _(this.#a,n):void 0;s.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}}class J{#a;constructor(e){this.#a=e}async sync(){return this.#a.sendMessage("syncConversations",void 0)}async syncAll(){return this.#a.sendMessage("syncAllConversations",void 0)}async getConversationById(e){const t=await this.#a.sendMessage("getConversationById",{id:e});return t?new z(this.#a,e,t):void 0}async getMessageById(e){const t=await this.#a.sendMessage("getMessageById",{id:e});return t?new _(this.#a,t):void 0}async getDmByInboxId(e){const t=await this.#a.sendMessage("getDmByInboxId",{inboxId:e});return t?new z(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>new z(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new z(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new z(this.#a,e.id,e)))}async newGroup(e,t){const s=await this.#a.sendMessage("newGroup",{accountAddresses:e,options:t});return new z(this.#a,s.id,s)}async newDm(e){const t=await this.#a.sendMessage("newDm",{accountAddress:e});return new z(this.#a,t.id,t)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=v(),n=new b,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new z(this.#a,s.id,s):void 0;n.callback(t,i),e?.(t,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,m.Group)}async streamDms(e){return this.stream(e,m.Dm)}async streamAllMessages(e,t){const s=v(),n=new b,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new _(this.#a,s):void 0;n.callback(t,i),e?.(t,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,m.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,m.Dm)}}const Q=e=>"getBlockNumber"in e&&"getChainId"in e;class X extends M{#w;#I;#M;#b;#A;#S;#x;#k=!1;#P;options;constructor(t,s,i,r){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==r?.loggingLevel&&"off"!==r.loggingLevel),this.#w=s,this.options=r,this.#b=i,this.#P=t,this.#M=new J(this);const a=[new e,new n,...r?.codecs??[]];this.#I=new Map(a.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.#A=e.inboxId,this.#S=e.installationId,this.#x=e.installationIdBytes,this.#k=!0}static async create(e,t,s){const n=await e.getAddress(),i=new X(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#k}get inboxId(){return this.#A}get installationId(){return this.#S}get installationIdBytes(){return this.#x}async#f(){return this.sendMessage("createInboxSignatureText",void 0)}async#G(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#N(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#T(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async#C(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async#B(e,t,s){const n=await s.signMessage(t);Q(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#L(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#f();if(e)return await this.#B(y.CreateInbox,e,this.#P),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#G(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#B(y.AddWallet,t,e),await this.#L()}async removeAccount(e){const t=await this.#N(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#B(y.RevokeWallet,t,this.#P),await this.#L()}async revokeAllOtherInstallations(){const e=await this.#T();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.#B(y.RevokeInstallations,e,this.#P),await this.#L()}async revokeInstallations(e){const t=await this.#C(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.#B(y.RevokeInstallations,t,this.#P),await this.#L()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await X.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.#M}codecFor(e){return this.#I.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),G(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!==p.MembershipChange)throw new Error("Error decoding group membership change");const i=N(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 Y=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class Z{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",Y),this.#t=t}sendMessage(e,t){const s=v();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",Y),this.#e.terminate()}}class ee extends Z{#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 te={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},se={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{te as ApiUrls,X as Client,z as Conversation,J as Conversations,_ as DecodedMessage,se as HistorySyncUrls,ee as Utils,S as fromContentTypeId,f as fromEncodedContent,F as fromSafeConsent,k as fromSafeContentTypeId,q as fromSafeCreateGroupOptions,N as fromSafeEncodedContent,H as fromSafeGroupMember,D as fromSafeListConversationsOptions,B as fromSafeListMessagesOptions,E as fromSafePermissionPolicySet,Q as isSmartContractSigner,A as toContentTypeId,P as toEncodedContent,W as toSafeConsent,x as toSafeContentTypeId,K as toSafeConversation,R as toSafeCreateGroupOptions,G as toSafeEncodedContent,$ as toSafeGroupMember,V as toSafeHmacKey,O as toSafeInboxState,j as toSafeInstallation,L as toSafeListConversationsOptions,C as toSafeListMessagesOptions,T as toSafeMessage,U 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,GroupPermissionsOptions as l,CreateDMOptions as u,Consent as p,GroupMember as g,MessageDisappearingSettings as h,GroupMessageKind as m,DeliveryStatus as y,ConversationType as v,SignatureRequestType as w}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,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;#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 I({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),k=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),P=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),f=e=>new I({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),G=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),D=e=>new r(k(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:f(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(G(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),B=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),L=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),U=e=>({allowedStates:e.allowedStates,consentStates:e.consentStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,includeSyncGroups:e.includeSyncGroups,limit:e.limit}),E=e=>new o(e.allowedStates,e.consentStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.includeSyncGroups??!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}),q=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),K=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),j=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?q(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),O=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),W=e=>new u(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),F=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,p=r.policyType,g=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:p,policySet:{addAdminPolicy:g.addAdminPolicy,addMemberPolicy:g.addMemberPolicy,removeAdminPolicy:g.removeAdminPolicy,removeMemberPolicy:g.removeMemberPolicy,updateGroupDescriptionPolicy:g.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:g.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:g.updateGroupNamePolicy,updateMessageDisappearingPolicy:g.updateMessageDisappearingPolicy}},isActive:a,addedByInboxId:o,metadata:d,admins:c,superAdmins:l,createdAtNs:u}},$=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),H=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map($),recoveryAddress:e.recoveryAddress}),V=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),_=e=>new p(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 h(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=f(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;#p;#g;#h;#m=[];#y=[];constructor(e,t,s){this.#a=e,this.#o=t,this.#v(s)}#v(e){this.#d=e?.name??"",this.#c=e?.imageUrl??"",this.#l=e?.description??"",this.#u=e?.isActive??void 0,this.#p=e?.addedByInboxId??"",this.#g=e?.metadata??void 0,this.#h=e?.createdAtNs??void 0,this.#m=e?.admins??[],this.#y=e?.superAdmins??[]}get id(){return this.#o}get name(){return this.#d}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#d=e}get imageUrl(){return this.#c}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#c=e}get description(){return this.#l}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#l=e}get isActive(){return this.#u}get addedByInboxId(){return this.#p}get createdAtNs(){return this.#h}get createdAt(){return this.#h?(e=this.#h,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#g}async members(){return this.#a.sendMessage("getGroupMembers",{id:this.#o})}get admins(){return this.#m}get superAdmins(){return this.#y}async syncAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});this.#m=e}async syncSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});this.#y=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.syncAdmins(),this.#m.includes(e)}async isSuperAdmin(e){return await this.syncSuperAdmins(),this.#y.includes(e)}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});this.#v(e)}async addMembers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,accountAddresses:e})}async addMembersByInboxId(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,accountAddresses:e})}async removeMembersByInboxId(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})}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 dmPeerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}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=M(),s=new A,n=this.#a.handleStreamMessage(t,((t,n)=>{const i=n?new Z(this.#a,n):void 0;s.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}}class te{#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});return t?new ee(this.#a,e,t):void 0}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 ee(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>new ee(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new ee(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new ee(this.#a,e.id,e)))}async newGroup(e,t){const s=await this.#a.sendMessage("newGroup",{accountAddresses:e,options:t});return new ee(this.#a,s.id,s)}async newGroupByInboxIds(e,t){const s=await this.#a.sendMessage("newGroupByInboxIds",{inboxIds:e,options:t});return new ee(this.#a,s.id,s)}async newDm(e,t){const s=await this.#a.sendMessage("newDm",{accountAddress:e,options:t});return new ee(this.#a,s.id,s)}async newDmByInboxId(e,t){const s=await this.#a.sendMessage("newDmByInboxId",{inboxId:e,options:t});return new ee(this.#a,s.id,s)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=M(),n=new A,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new ee(this.#a,s.id,s):void 0;n.callback(t,i),e?.(t,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,v.Group)}async streamDms(e){return this.stream(e,v.Dm)}async streamAllMessages(e,t){const s=M(),n=new A,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new Z(this.#a,s):void 0;n.callback(t,i),e?.(t,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,v.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,v.Dm)}}const se=e=>"SCW"===e.walletType?.();class ne extends S{#w;#M;#I;#b;#S;#A;#x;#k=!1;#P;options;constructor(t,s,i,r){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==r?.loggingLevel&&"off"!==r.loggingLevel),this.#w=s,this.options=r,this.#b=i,this.#P=t,this.#I=new te(this);const a=[new e,new n,...r?.codecs??[]];this.#M=new Map(a.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.#k=!0}static async create(e,t,s){const n=await e.getAddress(),i=new ne(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#k}get inboxId(){return this.#S}get installationId(){return this.#A}get installationIdBytes(){return this.#x}async#f(){return this.sendMessage("createInboxSignatureText",void 0)}async#G(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#D(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#N(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async#T(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async#C(e,t,s){const n=await s.signMessage(t);se(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#B(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#f();if(e)return await this.#C(w.CreateInbox,e,this.#P),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#G(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#C(w.AddWallet,t,e),await this.#B()}async removeAccount(e){const t=await this.#D(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#C(w.RevokeWallet,t,this.#P),await this.#B()}async revokeAllOtherInstallations(){const e=await this.#N();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.#C(w.RevokeInstallations,e,this.#P),await this.#B()}async revokeInstallations(e){const t=await this.#T(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.#C(w.RevokeInstallations,t,this.#P),await this.#B()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await ne.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 ie=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",ie),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",ie),this.#e.terminate()}}class ae 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 oe={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},de={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{oe as ApiUrls,ne as Client,ee as Conversation,te as Conversations,Z as DecodedMessage,de as HistorySyncUrls,ae as Utils,k as fromContentTypeId,D as fromEncodedContent,_ as fromSafeConsent,f as fromSafeContentTypeId,W as fromSafeCreateDmOptions,j as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,E as fromSafeListConversationsOptions,L as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,q as fromSafePermissionPolicySet,se as isSmartContractSigner,x as toContentTypeId,G as toEncodedContent,V as toSafeConsent,P as toSafeContentTypeId,F as toSafeConversation,O as toSafeCreateDmOptions,K as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,H as toSafeInboxState,$ as toSafeInstallation,U as toSafeListConversationsOptions,B as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R as toSafePermissionPolicySet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|