@xmtp/browser-sdk 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +61 -43
- 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/Client.ts +161 -31
- package/src/WorkerClient.ts +15 -5
- package/src/WorkerConversation.ts +4 -4
- package/src/index.ts +34 -2
- package/src/types/clientEvents.ts +17 -5
- package/src/types/options.ts +14 -13
- package/src/utils/conversions.ts +6 -30
- package/src/utils/createClient.ts +17 -1
- package/src/utils/signer.ts +19 -0
- package/src/workers/client.ts +30 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
2
2
|
import { SignatureRequestType, ConsentState, ConsentEntityType, Conversations as Conversations$1, Client as Client$1, Conversation as Conversation$1, EncodedContent, ContentTypeId, DeliveryStatus, GroupMessageKind, Message, SortDirection, ListMessagesOptions, GroupMembershipState, ConversationType, ListConversationsOptions, GroupPermissionsOptions, CreateGroupOptions, PermissionPolicy, Installation, InboxState, Consent, PermissionLevel, GroupMember } from '@xmtp/wasm-bindings';
|
|
3
|
-
export
|
|
3
|
+
export { Consent, ConsentEntityType, ConsentState, ContentTypeId, ConversationType, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, Message, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection } from '@xmtp/wasm-bindings';
|
|
4
4
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
5
5
|
|
|
6
6
|
declare const ApiUrls: {
|
|
@@ -24,15 +24,6 @@ type NetworkOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
apiUrl?: string;
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
28
|
-
* Encryption options
|
|
29
|
-
*/
|
|
30
|
-
type EncryptionOptions = {
|
|
31
|
-
/**
|
|
32
|
-
* Encryption key to use for the local DB
|
|
33
|
-
*/
|
|
34
|
-
encryptionKey?: Uint8Array;
|
|
35
|
-
};
|
|
36
27
|
/**
|
|
37
28
|
* Storage options
|
|
38
29
|
*/
|
|
@@ -50,11 +41,23 @@ type ContentOptions = {
|
|
|
50
41
|
};
|
|
51
42
|
type OtherOptions = {
|
|
52
43
|
/**
|
|
53
|
-
* Enable
|
|
44
|
+
* Enable structured JSON logging
|
|
45
|
+
*/
|
|
46
|
+
structuredLogging?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Enable performance metrics
|
|
49
|
+
*/
|
|
50
|
+
performanceLogging?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Logging level
|
|
54
53
|
*/
|
|
55
|
-
|
|
54
|
+
loggingLevel?: "off" | "error" | "warn" | "info" | "debug" | "trace";
|
|
55
|
+
/**
|
|
56
|
+
* Disable automatic registration when creating a client
|
|
57
|
+
*/
|
|
58
|
+
disableAutoRegister?: boolean;
|
|
56
59
|
};
|
|
57
|
-
type ClientOptions = NetworkOptions &
|
|
60
|
+
type ClientOptions = NetworkOptions & StorageOptions & ContentOptions & OtherOptions;
|
|
58
61
|
|
|
59
62
|
type ClientEvents =
|
|
60
63
|
/**
|
|
@@ -69,29 +72,30 @@ type ClientEvents =
|
|
|
69
72
|
};
|
|
70
73
|
data: {
|
|
71
74
|
address: string;
|
|
75
|
+
encryptionKey: Uint8Array;
|
|
72
76
|
options?: ClientOptions;
|
|
73
77
|
};
|
|
74
78
|
} | {
|
|
75
|
-
action: "
|
|
79
|
+
action: "createInboxSignatureText";
|
|
76
80
|
id: string;
|
|
77
81
|
result: string | undefined;
|
|
78
82
|
data: undefined;
|
|
79
83
|
} | {
|
|
80
|
-
action: "
|
|
84
|
+
action: "addAccountSignatureText";
|
|
81
85
|
id: string;
|
|
82
86
|
result: string | undefined;
|
|
83
87
|
data: {
|
|
84
|
-
|
|
88
|
+
newAccountAddress: string;
|
|
85
89
|
};
|
|
86
90
|
} | {
|
|
87
|
-
action: "
|
|
91
|
+
action: "removeAccountSignatureText";
|
|
88
92
|
id: string;
|
|
89
93
|
result: string | undefined;
|
|
90
94
|
data: {
|
|
91
95
|
accountAddress: string;
|
|
92
96
|
};
|
|
93
97
|
} | {
|
|
94
|
-
action: "
|
|
98
|
+
action: "revokeInstallationsSignatureText";
|
|
95
99
|
id: string;
|
|
96
100
|
result: string | undefined;
|
|
97
101
|
data: undefined;
|
|
@@ -103,6 +107,16 @@ type ClientEvents =
|
|
|
103
107
|
type: SignatureRequestType;
|
|
104
108
|
bytes: Uint8Array;
|
|
105
109
|
};
|
|
110
|
+
} | {
|
|
111
|
+
action: "addScwSignature";
|
|
112
|
+
id: string;
|
|
113
|
+
result: undefined;
|
|
114
|
+
data: {
|
|
115
|
+
type: SignatureRequestType;
|
|
116
|
+
bytes: Uint8Array;
|
|
117
|
+
chainId: bigint;
|
|
118
|
+
blockNumber?: bigint;
|
|
119
|
+
};
|
|
106
120
|
} | {
|
|
107
121
|
action: "applySignatures";
|
|
108
122
|
id: string;
|
|
@@ -512,16 +526,17 @@ declare class WorkerConversations {
|
|
|
512
526
|
declare class WorkerClient {
|
|
513
527
|
#private;
|
|
514
528
|
constructor(client: Client$1);
|
|
515
|
-
static create(accountAddress: string, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
|
|
529
|
+
static create(accountAddress: string, encryptionKey: Uint8Array, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
|
|
516
530
|
get accountAddress(): string;
|
|
517
531
|
get inboxId(): string;
|
|
518
532
|
get installationId(): string;
|
|
519
533
|
get isRegistered(): boolean;
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
534
|
+
createInboxSignatureText(): Promise<string | undefined>;
|
|
535
|
+
addAccountSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
536
|
+
removeAccountSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
537
|
+
revokeInstallationsSignatureText(): Promise<string | undefined>;
|
|
524
538
|
addSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<void>;
|
|
539
|
+
addScwSignature(type: SignatureRequestType, bytes: Uint8Array, chainId: bigint, blockNumber?: bigint): Promise<void>;
|
|
525
540
|
applySignatures(): Promise<void>;
|
|
526
541
|
canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
|
|
527
542
|
registerIdentity(): Promise<void>;
|
|
@@ -693,15 +708,7 @@ type SafeGroupMember = {
|
|
|
693
708
|
installationIds: string[];
|
|
694
709
|
permissionLevel: PermissionLevel;
|
|
695
710
|
};
|
|
696
|
-
declare
|
|
697
|
-
account_addresses: string[];
|
|
698
|
-
consent_state: ConsentState;
|
|
699
|
-
inbox_id: string;
|
|
700
|
-
installation_ids: string[];
|
|
701
|
-
permission_level: PermissionLevel;
|
|
702
|
-
constructor(inbox_id: string, account_addresses: string[], installation_ids: string[], permission_level: PermissionLevel, consent_state: ConsentState);
|
|
703
|
-
}
|
|
704
|
-
declare const toSafeGroupMember: (member: WasmGroupMember) => SafeGroupMember;
|
|
711
|
+
declare const toSafeGroupMember: (member: GroupMember) => SafeGroupMember;
|
|
705
712
|
declare const fromSafeGroupMember: (member: SafeGroupMember) => GroupMember;
|
|
706
713
|
|
|
707
714
|
declare class ClientWorkerClass {
|
|
@@ -800,25 +807,36 @@ declare class Conversations {
|
|
|
800
807
|
newDm(accountAddress: string): Promise<Conversation>;
|
|
801
808
|
}
|
|
802
809
|
|
|
810
|
+
type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
|
|
811
|
+
type GetAddress = () => Promise<string> | string;
|
|
812
|
+
type GetChainId = () => bigint;
|
|
813
|
+
type GetBlockNumber = () => bigint;
|
|
814
|
+
type Signer = {
|
|
815
|
+
getAddress: GetAddress;
|
|
816
|
+
signMessage: SignMessage;
|
|
817
|
+
getBlockNumber?: GetBlockNumber;
|
|
818
|
+
getChainId?: GetChainId;
|
|
819
|
+
};
|
|
820
|
+
type SmartContractSigner = Required<Signer>;
|
|
821
|
+
declare const isSmartContractSigner: (signer: Signer) => signer is SmartContractSigner;
|
|
822
|
+
|
|
803
823
|
declare class Client extends ClientWorkerClass {
|
|
804
824
|
#private;
|
|
805
|
-
address: string;
|
|
806
825
|
options?: ClientOptions;
|
|
807
|
-
constructor(
|
|
826
|
+
constructor(signer: Signer, accountAddress: string, encryptionKey: Uint8Array, options?: ClientOptions);
|
|
827
|
+
get accountAddress(): string;
|
|
808
828
|
init(): Promise<void>;
|
|
809
|
-
static create(
|
|
829
|
+
static create(signer: Signer, encryptionKey: Uint8Array, options?: ClientOptions): Promise<Client>;
|
|
810
830
|
get isReady(): boolean;
|
|
811
831
|
get inboxId(): string | undefined;
|
|
812
832
|
get installationId(): string | undefined;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
addSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<undefined>;
|
|
818
|
-
applySignatures(): Promise<undefined>;
|
|
819
|
-
registerIdentity(): Promise<undefined>;
|
|
833
|
+
register(): Promise<undefined>;
|
|
834
|
+
addAccount(newAccountSigner: Signer): Promise<void>;
|
|
835
|
+
removeAccount(accountAddress: string): Promise<void>;
|
|
836
|
+
revokeInstallations(): Promise<void>;
|
|
820
837
|
isRegistered(): Promise<boolean>;
|
|
821
838
|
canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
|
|
839
|
+
static canMessage(accountAddresses: string[], env?: XmtpEnv): Promise<Map<string, boolean>>;
|
|
822
840
|
findInboxIdByAddress(address: string): Promise<string | undefined>;
|
|
823
841
|
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
824
842
|
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
@@ -845,4 +863,4 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
845
863
|
getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
|
|
846
864
|
}
|
|
847
865
|
|
|
848
|
-
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
|
|
866
|
+
export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SendMessageData, type Signer, type SmartContractSigner, type StorageOptions, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, isSmartContractSigner, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as o,ListConversationsOptions as a,CreateGroupOptions as d,Consent as c,GroupMember as l,GroupMessageKind as p,DeliveryStatus as m}from"@xmtp/wasm-bindings";import{v4 as h}from"uuid";import{ContentTypeId as u}from"@xmtp/content-type-primitives";const g=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class y{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",g),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",g),this.#e.terminate()}}const I=e=>new u({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),b=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),v=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new u({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),w=e=>({type:I(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),x=e=>new r(b(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),A=e=>({type:v(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),S=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),k=e=>({content:A(w(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),f=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),N=e=>new o(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),U=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),G=e=>new a(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),C=e=>({permissions:e.permissions,name:e.groupName,imageUrlSquare:e.groupImageUrlSquare,description:e.groupDescription,pinnedFrameUrl:e.groupPinnedFrameUrl}),L=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl),P=e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,pinnedFrameUrl:e.pinnedFrameUrl,permissions:{policyType:e.permissions.policyType,policySet:{addAdminPolicy:e.permissions.policySet.addAdminPolicy,addMemberPolicy:e.permissions.policySet.addMemberPolicy,removeAdminPolicy:e.permissions.policySet.removeAdminPolicy,removeMemberPolicy:e.permissions.policySet.removeMemberPolicy,updateGroupDescriptionPolicy:e.permissions.policySet.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.permissions.policySet.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.permissions.policySet.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:e.permissions.policySet.updateGroupPinnedFrameUrlPolicy}},isActive:e.isActive,addedByInboxId:e.addedByInboxId,metadata:e.metadata,admins:e.admins,superAdmins:e.superAdmins,createdAtNs:e.createdAtNs}),B=e=>({id:e.id,clientTimestampNs:e.clientTimestampNs}),T=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(B),recoveryAddress:e.recoveryAddress}),F=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),E=e=>new c(e.entityType,e.state,e.entity);class D{account_addresses;consent_state;inbox_id;installation_ids;permission_level;constructor(e,t,s,n,i){this.inbox_id=e,this.account_addresses=t,this.installation_ids=s,this.permission_level=n,this.consent_state=i}}const _=e=>({accountAddresses:e.account_addresses,consentState:e.consent_state,inboxId:e.inbox_id,installationIds:e.installation_ids,permissionLevel:e.permission_level}),j=e=>new l(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState);class R{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,t.kind){case p.Application:this.kind="application";break;case p.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case m.Unpublished:this.deliveryStatus="unpublished";break;case m.Published:this.deliveryStatus="published";break;case m.Failed:this.deliveryStatus="failed"}this.contentType=M(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class q{#n;#i;#r;#o;#a;#d;#c;#l;#p;#m;#h;constructor(e,t,s){this.#n=e,this.#i=t,this.#u(s)}#u(e){this.#r=e?.name??"",this.#o=e?.imageUrl??"",this.#a=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#l=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#m=e?.permissions??void 0,this.#h=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#o}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#o=e}get description(){return this.#a}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#a=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#l}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.#p}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}async admins(){return this.#n.sendMessage("getGroupAdmins",{id:this.#i})}async superAdmins(){return this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i})}get permissions(){return this.#m}async isAdmin(e){return(await this.admins()).includes(e)}async isSuperAdmin(e){return(await this.superAdmins()).includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#u(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new R(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}async dmPeerInboxId(){return this.#n.sendMessage("getDmPeerInboxId",{id:this.#i})}}class W{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async getConversationById(e){return this.#n.sendMessage("getConversationById",{id:e})}async getMessageById(e){return this.#n.sendMessage("getMessageById",{id:e})}async getDmByInboxId(e){return this.#n.sendMessage("getDmByInboxId",{inboxId:e})}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new q(this.#n,e.id,e)))}async listGroups(e){return this.#n.sendMessage("getGroups",{options:e})}async listDms(e){return this.#n.sendMessage("getDms",{options:e})}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new q(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new q(this.#n,t.id,t)}}class $ extends y{address;options;#g=!1;#y;#I;#b;#v;constructor(t,s){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),s?.enableLogging??!1),this.address=t,this.options=s,this.#b=new W(this);const i=[new e,new n,...s?.codecs??[]];this.#v=new Map(i.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{address:this.address,options:this.options});this.#y=e.inboxId,this.#I=e.installationId,this.#g=!0}static async create(e,t){const s=new $(e,t);return await s.init(),s}get isReady(){return this.#g}get inboxId(){return this.#y}get installationId(){return this.#I}async getCreateInboxSignatureText(){return this.sendMessage("getCreateInboxSignatureText",void 0)}async getAddWalletSignatureText(e){return this.sendMessage("getAddWalletSignatureText",{accountAddress:e})}async getRevokeWalletSignatureText(e){return this.sendMessage("getRevokeWalletSignatureText",{accountAddress:e})}async getRevokeInstallationsSignatureText(){return this.sendMessage("getRevokeInstallationsSignatureText",void 0)}async addSignature(e,t){return this.sendMessage("addSignature",{type:e,bytes:t})}async applySignatures(){return this.sendMessage("applySignatures",void 0)}async registerIdentity(){return this.sendMessage("registerIdentity",void 0)}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#b}codecFor(e){return this.#v.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),A(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=S(e.content);return n.decode(i,this)}}const O=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",O),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",O),this.#e.terminate()}}class H 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 J={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};export{J as ApiUrls,$ as Client,q as Conversation,W as Conversations,R as DecodedMessage,H as Utils,D as WasmGroupMember,b as fromContentTypeId,x as fromEncodedContent,E as fromSafeConsent,M as fromSafeContentTypeId,L as fromSafeCreateGroupOptions,S as fromSafeEncodedContent,j as fromSafeGroupMember,G as fromSafeListConversationsOptions,N as fromSafeListMessagesOptions,I as toContentTypeId,w as toEncodedContent,F as toSafeConsent,v as toSafeContentTypeId,P as toSafeConversation,C as toSafeCreateGroupOptions,A as toSafeEncodedContent,_ as toSafeGroupMember,T as toSafeInboxState,B as toSafeInstallation,U as toSafeListConversationsOptions,f as toSafeListMessagesOptions,k as toSafeMessage};
|
|
1
|
+
import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as a,ListConversationsOptions as o,CreateGroupOptions as d,Consent as c,GroupMember as l,GroupMessageKind as p,DeliveryStatus as u,SignatureRequestType as g}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as h}from"uuid";import{ContentTypeId as m}from"@xmtp/content-type-primitives";const y=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class I{#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=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",y),this.#e.terminate()}}const b=e=>new m({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),v=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),w=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new m({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),A=e=>({type:b(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),S=e=>new r(v(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),x=e=>({type:w(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),k=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),f=e=>({content:x(A(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),G=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),U=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),N=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),C=e=>new o(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),P=e=>({permissions:e.permissions,name:e.groupName,imageUrlSquare:e.groupImageUrlSquare,description:e.groupDescription,pinnedFrameUrl:e.groupPinnedFrameUrl}),T=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl),L=e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,pinnedFrameUrl:e.pinnedFrameUrl,permissions:{policyType:e.permissions.policyType,policySet:{addAdminPolicy:e.permissions.policySet.addAdminPolicy,addMemberPolicy:e.permissions.policySet.addMemberPolicy,removeAdminPolicy:e.permissions.policySet.removeAdminPolicy,removeMemberPolicy:e.permissions.policySet.removeMemberPolicy,updateGroupDescriptionPolicy:e.permissions.policySet.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.permissions.policySet.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.permissions.policySet.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:e.permissions.policySet.updateGroupPinnedFrameUrlPolicy}},isActive:e.isActive,addedByInboxId:e.addedByInboxId,metadata:e.metadata,admins:e.admins,superAdmins:e.superAdmins,createdAtNs:e.createdAtNs}),B=e=>({id:e.id,clientTimestampNs:e.clientTimestampNs}),F=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(B),recoveryAddress:e.recoveryAddress}),E=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),D=e=>new c(e.entityType,e.state,e.entity),j=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),R=e=>new l(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState);class q{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,t.kind){case p.Application:this.kind="application";break;case p.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case u.Unpublished:this.deliveryStatus="unpublished";break;case u.Published:this.deliveryStatus="published";break;case u.Failed:this.deliveryStatus="failed"}this.contentType=M(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class O{#n;#i;#r;#a;#o;#d;#c;#l;#p;#u;#g;constructor(e,t,s){this.#n=e,this.#i=t,this.#h(s)}#h(e){this.#r=e?.name??"",this.#a=e?.imageUrl??"",this.#o=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#l=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#u=e?.permissions??void 0,this.#g=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#a}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#a=e}get description(){return this.#o}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#o=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#l}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.#n.sendMessage("getGroupMembers",{id:this.#i})}async admins(){return this.#n.sendMessage("getGroupAdmins",{id:this.#i})}async superAdmins(){return this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i})}get permissions(){return this.#u}async isAdmin(e){return(await this.admins()).includes(e)}async isSuperAdmin(e){return(await this.superAdmins()).includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#h(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new q(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}async dmPeerInboxId(){return this.#n.sendMessage("getDmPeerInboxId",{id:this.#i})}}class W{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async getConversationById(e){return this.#n.sendMessage("getConversationById",{id:e})}async getMessageById(e){return this.#n.sendMessage("getMessageById",{id:e})}async getDmByInboxId(e){return this.#n.sendMessage("getDmByInboxId",{inboxId:e})}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new O(this.#n,e.id,e)))}async listGroups(e){return this.#n.sendMessage("getGroups",{options:e})}async listDms(e){return this.#n.sendMessage("getDms",{options:e})}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new O(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new O(this.#n,t.id,t)}}const $=e=>"getBlockNumber"in e&&"getChainId"in e;class K extends I{#m;#y;#I;#b;#v;#w;#M=!1;#A;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.#m=s,this.options=r,this.#b=i,this.#A=t,this.#I=new W(this);const a=[new e,new n,...r?.codecs??[]];this.#y=new Map(a.map((e=>[e.contentType.toString(),e])))}get accountAddress(){return this.#m}async init(){const e=await this.sendMessage("init",{address:this.accountAddress,encryptionKey:this.#b,options:this.options});this.#v=e.inboxId,this.#w=e.installationId,this.#M=!0}static async create(e,t,s){const n=await e.getAddress(),i=new K(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#M}get inboxId(){return this.#v}get installationId(){return this.#w}async#S(){return this.sendMessage("createInboxSignatureText",void 0)}async#x(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#k(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#f(){return this.sendMessage("revokeInstallationsSignatureText",void 0)}async#G(e,t,s){const n=await s.signMessage(t);$(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#U(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#S();if(e)return await this.#G(g.CreateInbox,e,this.#A),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#x(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#G(g.AddWallet,t,this.#A),await this.#G(g.AddWallet,t,e),await this.#U()}async removeAccount(e){const t=await this.#k(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#G(g.RevokeWallet,t,this.#A),await this.#U()}async revokeInstallations(){const e=await this.#f();if(!e)throw new Error("Unable to generate revoke installations signature text");await this.#G(g.RevokeInstallations,e,this.#A),await this.#U()}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 K.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.#y.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),x(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==p.MembershipChange)throw new Error("Error decoding group membership change");const i=k(e.content);return n.decode(i,this)}}const V=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class _{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",V),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",V),this.#e.terminate()}}class z extends _{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const H={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};export{H as ApiUrls,K as Client,O as Conversation,W as Conversations,q as DecodedMessage,z as Utils,v as fromContentTypeId,S as fromEncodedContent,D as fromSafeConsent,M as fromSafeContentTypeId,T as fromSafeCreateGroupOptions,k as fromSafeEncodedContent,R as fromSafeGroupMember,C as fromSafeListConversationsOptions,U as fromSafeListMessagesOptions,$ as isSmartContractSigner,b as toContentTypeId,A as toEncodedContent,E as toSafeConsent,w as toSafeContentTypeId,L as toSafeConversation,P as toSafeCreateGroupOptions,x as toSafeEncodedContent,j as toSafeGroupMember,F as toSafeInboxState,B as toSafeInstallation,N as toSafeListConversationsOptions,G as toSafeListMessagesOptions,f as toSafeMessage};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/ClientWorkerClass.ts","../src/utils/conversions.ts","../src/DecodedMessage.ts","../src/Conversation.ts","../src/utils/date.ts","../src/Conversations.ts","../src/Client.ts","../src/UtilsWorkerClass.ts","../src/Utils.ts","../src/constants.ts"],"sourcesContent":["import { v4 } from \"uuid\";\nimport type {\n ClientEventsActions,\n ClientEventsErrorData,\n ClientEventsResult,\n ClientEventsWorkerMessageData,\n ClientSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class ClientWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends ClientEventsActions>(\n action: A,\n data: ClientSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<ClientEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<ClientEventsWorkerMessageData | ClientEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"client received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import {\n ContentTypeId,\n type EncodedContent,\n} from \"@xmtp/content-type-primitives\";\nimport {\n Consent,\n CreateGroupOptions,\n GroupMember,\n ListConversationsOptions,\n ListMessagesOptions,\n ContentTypeId as WasmContentTypeId,\n EncodedContent as WasmEncodedContent,\n type ConsentEntityType,\n type ConsentState,\n type ConversationType,\n type DeliveryStatus,\n type GroupMembershipState,\n type GroupMessageKind,\n type GroupPermissionsOptions,\n type InboxState,\n type Installation,\n type Message,\n type PermissionLevel,\n type PermissionPolicy,\n type SortDirection,\n} from \"@xmtp/wasm-bindings\";\nimport type { WorkerConversation } from \"@/WorkerConversation\";\n\nexport const toContentTypeId = (\n contentTypeId: WasmContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const fromContentTypeId = (\n contentTypeId: ContentTypeId,\n): WasmContentTypeId =>\n new WasmContentTypeId(\n contentTypeId.authorityId,\n contentTypeId.typeId,\n contentTypeId.versionMajor,\n contentTypeId.versionMinor,\n );\n\nexport type SafeContentTypeId = {\n authorityId: string;\n typeId: string;\n versionMajor: number;\n versionMinor: number;\n};\n\nexport const toSafeContentTypeId = (\n contentTypeId: ContentTypeId,\n): SafeContentTypeId => ({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n});\n\nexport const fromSafeContentTypeId = (\n contentTypeId: SafeContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const toEncodedContent = (\n content: WasmEncodedContent,\n): EncodedContent => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n type: toContentTypeId(content.type!),\n parameters: Object.fromEntries(content.parameters as Map<string, string>),\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromEncodedContent = (\n content: EncodedContent,\n): WasmEncodedContent =>\n new WasmEncodedContent(\n fromContentTypeId(content.type),\n new Map(Object.entries(content.parameters)),\n content.fallback,\n content.compression,\n content.content,\n );\n\nexport type SafeEncodedContent = {\n type: SafeContentTypeId;\n parameters: Record<string, string>;\n fallback?: string;\n compression?: number;\n content: Uint8Array;\n};\n\nexport const toSafeEncodedContent = (\n content: EncodedContent,\n): SafeEncodedContent => ({\n type: toSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromSafeEncodedContent = (\n content: SafeEncodedContent,\n): EncodedContent => ({\n type: fromSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport type SafeMessage = {\n content: SafeEncodedContent;\n convoId: string;\n deliveryStatus: DeliveryStatus;\n id: string;\n kind: GroupMessageKind;\n senderInboxId: string;\n sentAtNs: bigint;\n};\n\nexport const toSafeMessage = (message: Message): SafeMessage => ({\n content: toSafeEncodedContent(toEncodedContent(message.content)),\n convoId: message.convoId,\n deliveryStatus: message.deliveryStatus,\n id: message.id,\n kind: message.kind,\n senderInboxId: message.senderInboxId,\n sentAtNs: message.sentAtNs,\n});\n\nexport type SafeListMessagesOptions = {\n deliveryStatus?: DeliveryStatus;\n direction?: SortDirection;\n limit?: bigint;\n sentAfterNs?: bigint;\n sentBeforeNs?: bigint;\n};\n\nexport const toSafeListMessagesOptions = (\n options: ListMessagesOptions,\n): SafeListMessagesOptions => ({\n deliveryStatus: options.deliveryStatus,\n direction: options.direction,\n limit: options.limit,\n sentAfterNs: options.sentAfterNs,\n sentBeforeNs: options.sentBeforeNs,\n});\n\nexport const fromSafeListMessagesOptions = (\n options: SafeListMessagesOptions,\n): ListMessagesOptions =>\n new ListMessagesOptions(\n options.sentBeforeNs,\n options.sentAfterNs,\n options.limit,\n options.deliveryStatus,\n options.direction,\n );\n\nexport type SafeListConversationsOptions = {\n allowedStates?: GroupMembershipState[];\n conversationType?: ConversationType;\n createdAfterNs?: bigint;\n createdBeforeNs?: bigint;\n limit?: bigint;\n};\n\nexport const toSafeListConversationsOptions = (\n options: ListConversationsOptions,\n): SafeListConversationsOptions => ({\n allowedStates: options.allowedStates,\n conversationType: options.conversationType,\n createdAfterNs: options.createdAfterNs,\n createdBeforeNs: options.createdBeforeNs,\n limit: options.limit,\n});\n\nexport const fromSafeListConversationsOptions = (\n options: SafeListConversationsOptions,\n): ListConversationsOptions =>\n new ListConversationsOptions(\n options.allowedStates,\n options.conversationType,\n options.createdAfterNs,\n options.createdBeforeNs,\n options.limit,\n );\n\nexport type SafeCreateGroupOptions = {\n permissions?: GroupPermissionsOptions;\n name?: string;\n imageUrlSquare?: string;\n description?: string;\n pinnedFrameUrl?: string;\n};\n\nexport const toSafeCreateGroupOptions = (\n options: CreateGroupOptions,\n): SafeCreateGroupOptions => ({\n permissions: options.permissions,\n name: options.groupName,\n imageUrlSquare: options.groupImageUrlSquare,\n description: options.groupDescription,\n pinnedFrameUrl: options.groupPinnedFrameUrl,\n});\n\nexport const fromSafeCreateGroupOptions = (\n options: SafeCreateGroupOptions,\n): CreateGroupOptions =>\n new CreateGroupOptions(\n options.permissions,\n options.name,\n options.imageUrlSquare,\n options.description,\n options.pinnedFrameUrl,\n );\n\nexport type SafeConversation = {\n id: string;\n name: string;\n imageUrl: string;\n description: string;\n pinnedFrameUrl: string;\n permissions: {\n policyType: GroupPermissionsOptions;\n policySet: {\n addAdminPolicy: PermissionPolicy;\n addMemberPolicy: PermissionPolicy;\n removeAdminPolicy: PermissionPolicy;\n removeMemberPolicy: PermissionPolicy;\n updateGroupDescriptionPolicy: PermissionPolicy;\n updateGroupImageUrlSquarePolicy: PermissionPolicy;\n updateGroupNamePolicy: PermissionPolicy;\n updateGroupPinnedFrameUrlPolicy: PermissionPolicy;\n };\n };\n isActive: boolean;\n addedByInboxId: string;\n metadata: {\n creatorInboxId: string;\n conversationType: string;\n };\n admins: string[];\n superAdmins: string[];\n createdAtNs: bigint;\n};\n\nexport const toSafeConversation = (\n conversation: WorkerConversation,\n): SafeConversation => ({\n id: conversation.id,\n name: conversation.name,\n imageUrl: conversation.imageUrl,\n description: conversation.description,\n pinnedFrameUrl: conversation.pinnedFrameUrl,\n permissions: {\n policyType: conversation.permissions.policyType,\n policySet: {\n addAdminPolicy: conversation.permissions.policySet.addAdminPolicy,\n addMemberPolicy: conversation.permissions.policySet.addMemberPolicy,\n removeAdminPolicy: conversation.permissions.policySet.removeAdminPolicy,\n removeMemberPolicy: conversation.permissions.policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy:\n conversation.permissions.policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy:\n conversation.permissions.policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy:\n conversation.permissions.policySet.updateGroupNamePolicy,\n updateGroupPinnedFrameUrlPolicy:\n conversation.permissions.policySet.updateGroupPinnedFrameUrlPolicy,\n },\n },\n isActive: conversation.isActive,\n addedByInboxId: conversation.addedByInboxId,\n metadata: conversation.metadata,\n admins: conversation.admins,\n superAdmins: conversation.superAdmins,\n createdAtNs: conversation.createdAtNs,\n});\n\nexport type SafeInstallation = {\n id: string;\n clientTimestampNs?: bigint;\n};\n\nexport const toSafeInstallation = (\n installation: Installation,\n): SafeInstallation => ({\n id: installation.id,\n clientTimestampNs: installation.clientTimestampNs,\n});\n\nexport type SafeInboxState = {\n accountAddresses: string[];\n inboxId: string;\n installations: SafeInstallation[];\n recoveryAddress: string;\n};\n\nexport const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({\n accountAddresses: inboxState.accountAddresses,\n inboxId: inboxState.inboxId,\n installations: inboxState.installations.map(toSafeInstallation),\n recoveryAddress: inboxState.recoveryAddress,\n});\n\nexport type SafeConsent = {\n entity: string;\n entityType: ConsentEntityType;\n state: ConsentState;\n};\n\nexport const toSafeConsent = (consent: Consent): SafeConsent => ({\n entity: consent.entity,\n entityType: consent.entityType,\n state: consent.state,\n});\n\nexport const fromSafeConsent = (consent: SafeConsent): Consent =>\n new Consent(consent.entityType, consent.state, consent.entity);\n\nexport type SafeGroupMember = {\n accountAddresses: string[];\n consentState: ConsentState;\n inboxId: string;\n installationIds: string[];\n permissionLevel: PermissionLevel;\n};\n\nexport class WasmGroupMember {\n account_addresses: string[];\n consent_state: ConsentState;\n inbox_id: string;\n installation_ids: string[];\n permission_level: PermissionLevel;\n\n constructor(\n inbox_id: string,\n account_addresses: string[],\n installation_ids: string[],\n permission_level: PermissionLevel,\n consent_state: ConsentState,\n ) {\n this.inbox_id = inbox_id;\n this.account_addresses = account_addresses;\n this.installation_ids = installation_ids;\n this.permission_level = permission_level;\n this.consent_state = consent_state;\n }\n}\n\nexport const toSafeGroupMember = (\n member: WasmGroupMember,\n): SafeGroupMember => ({\n accountAddresses: member.account_addresses,\n consentState: member.consent_state,\n inboxId: member.inbox_id,\n installationIds: member.installation_ids,\n permissionLevel: member.permission_level,\n});\n\nexport const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>\n new GroupMember(\n member.inboxId,\n member.accountAddresses,\n member.installationIds,\n member.permissionLevel,\n member.consentState,\n );\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { DeliveryStatus, GroupMessageKind } from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { fromSafeContentTypeId, type SafeMessage } from \"@/utils/conversions\";\n\nexport type MessageKind = \"application\" | \"membership_change\";\nexport type MessageDeliveryStatus = \"unpublished\" | \"published\" | \"failed\";\n\nexport class DecodedMessage {\n #client: Client;\n\n content: any;\n\n contentType: ContentTypeId;\n\n conversationId: string;\n\n deliveryStatus: MessageDeliveryStatus;\n\n fallback?: string;\n\n compression?: number;\n\n id: string;\n\n kind: MessageKind;\n\n parameters: Map<string, string>;\n\n senderInboxId: string;\n\n sentAtNs: bigint;\n\n constructor(client: Client, message: SafeMessage) {\n this.#client = client;\n this.id = message.id;\n this.sentAtNs = message.sentAtNs;\n this.conversationId = message.convoId;\n this.senderInboxId = message.senderInboxId;\n\n switch (message.kind) {\n case GroupMessageKind.Application:\n this.kind = \"application\";\n break;\n case GroupMessageKind.MembershipChange:\n this.kind = \"membership_change\";\n break;\n // no default\n }\n\n switch (message.deliveryStatus) {\n case DeliveryStatus.Unpublished:\n this.deliveryStatus = \"unpublished\";\n break;\n case DeliveryStatus.Published:\n this.deliveryStatus = \"published\";\n break;\n case DeliveryStatus.Failed:\n this.deliveryStatus = \"failed\";\n break;\n // no default\n }\n\n this.contentType = fromSafeContentTypeId(message.content.type);\n this.parameters = new Map(Object.entries(message.content.parameters));\n this.fallback = message.content.fallback;\n this.compression = message.content.compression;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.content = this.#client.decodeContent(message, this.contentType);\n }\n}\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { ContentTypeText } from \"@xmtp/content-type-text\";\nimport type { ConsentState } from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { DecodedMessage } from \"@/DecodedMessage\";\nimport type {\n SafeConversation,\n SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport { nsToDate } from \"@/utils/date\";\n\nexport class Conversation {\n #client: Client;\n\n #id: string;\n\n #name?: SafeConversation[\"name\"];\n\n #imageUrl?: SafeConversation[\"imageUrl\"];\n\n #description?: SafeConversation[\"description\"];\n\n #pinnedFrameUrl?: SafeConversation[\"pinnedFrameUrl\"];\n\n #isActive?: SafeConversation[\"isActive\"];\n\n #addedByInboxId?: SafeConversation[\"addedByInboxId\"];\n\n #metadata?: SafeConversation[\"metadata\"];\n\n #permissions?: SafeConversation[\"permissions\"];\n\n #createdAtNs?: SafeConversation[\"createdAtNs\"];\n\n constructor(client: Client, id: string, data?: SafeConversation) {\n this.#client = client;\n this.#id = id;\n this.#syncData(data);\n }\n\n #syncData(data?: SafeConversation) {\n this.#name = data?.name ?? \"\";\n this.#imageUrl = data?.imageUrl ?? \"\";\n this.#description = data?.description ?? \"\";\n this.#pinnedFrameUrl = data?.pinnedFrameUrl ?? \"\";\n this.#isActive = data?.isActive ?? undefined;\n this.#addedByInboxId = data?.addedByInboxId ?? \"\";\n this.#metadata = data?.metadata ?? undefined;\n this.#permissions = data?.permissions ?? undefined;\n this.#createdAtNs = data?.createdAtNs ?? undefined;\n }\n\n get id() {\n return this.#id;\n }\n\n get name() {\n return this.#name;\n }\n\n async updateName(name: string) {\n await this.#client.sendMessage(\"updateGroupName\", {\n id: this.#id,\n name,\n });\n this.#name = name;\n }\n\n get imageUrl() {\n return this.#imageUrl;\n }\n\n async updateImageUrl(imageUrl: string) {\n await this.#client.sendMessage(\"updateGroupImageUrlSquare\", {\n id: this.#id,\n imageUrl,\n });\n this.#imageUrl = imageUrl;\n }\n\n get description() {\n return this.#description;\n }\n\n async updateDescription(description: string) {\n await this.#client.sendMessage(\"updateGroupDescription\", {\n id: this.#id,\n description,\n });\n this.#description = description;\n }\n\n get pinnedFrameUrl() {\n return this.#pinnedFrameUrl;\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n await this.#client.sendMessage(\"updateGroupPinnedFrameUrl\", {\n id: this.#id,\n pinnedFrameUrl,\n });\n this.#pinnedFrameUrl = pinnedFrameUrl;\n }\n\n get isActive() {\n return this.#isActive;\n }\n\n get addedByInboxId() {\n return this.#addedByInboxId;\n }\n\n get createdAtNs() {\n return this.#createdAtNs;\n }\n\n get createdAt() {\n return this.#createdAtNs ? nsToDate(this.#createdAtNs) : undefined;\n }\n\n get metadata() {\n return this.#metadata;\n }\n\n async members() {\n return this.#client.sendMessage(\"getGroupMembers\", {\n id: this.#id,\n });\n }\n\n async admins() {\n return this.#client.sendMessage(\"getGroupAdmins\", {\n id: this.#id,\n });\n }\n\n async superAdmins() {\n return this.#client.sendMessage(\"getGroupSuperAdmins\", {\n id: this.#id,\n });\n }\n\n get permissions() {\n return this.#permissions;\n }\n\n async isAdmin(inboxId: string) {\n const admins = await this.admins();\n return admins.includes(inboxId);\n }\n\n async isSuperAdmin(inboxId: string) {\n const superAdmins = await this.superAdmins();\n return superAdmins.includes(inboxId);\n }\n\n async sync() {\n const data = await this.#client.sendMessage(\"syncGroup\", {\n id: this.#id,\n });\n this.#syncData(data);\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"addGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"addGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"removeGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"removeGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async addAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async publishMessages() {\n return this.#client.sendMessage(\"publishGroupMessages\", {\n id: this.#id,\n });\n }\n\n async sendOptimistic(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendOptimisticGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async send(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async messages(options?: SafeListMessagesOptions) {\n const messages = await this.#client.sendMessage(\"getGroupMessages\", {\n id: this.#id,\n options,\n });\n\n return messages.map((message) => new DecodedMessage(this.#client, message));\n }\n\n async consentState() {\n return this.#client.sendMessage(\"getGroupConsentState\", {\n id: this.#id,\n });\n }\n\n async updateConsentState(state: ConsentState) {\n return this.#client.sendMessage(\"updateGroupConsentState\", {\n id: this.#id,\n state,\n });\n }\n\n async dmPeerInboxId() {\n return this.#client.sendMessage(\"getDmPeerInboxId\", {\n id: this.#id,\n });\n }\n}\n","export function nsToDate(ns: bigint): Date {\n return new Date(Number(ns / 1_000_000n));\n}\n","import type { Client } from \"@/Client\";\nimport { Conversation } from \"@/Conversation\";\nimport type {\n SafeCreateGroupOptions,\n SafeListConversationsOptions,\n} from \"@/utils/conversions\";\n\nexport class Conversations {\n #client: Client;\n\n constructor(client: Client) {\n this.#client = client;\n }\n\n async sync() {\n return this.#client.sendMessage(\"syncConversations\", undefined);\n }\n\n async getConversationById(id: string) {\n return this.#client.sendMessage(\"getConversationById\", {\n id,\n });\n }\n\n async getMessageById(id: string) {\n return this.#client.sendMessage(\"getMessageById\", {\n id,\n });\n }\n\n async getDmByInboxId(inboxId: string) {\n return this.#client.sendMessage(\"getDmByInboxId\", {\n inboxId,\n });\n }\n\n async list(options?: SafeListConversationsOptions) {\n const conversations = await this.#client.sendMessage(\"getConversations\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n return this.#client.sendMessage(\"getGroups\", {\n options,\n });\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n return this.#client.sendMessage(\"getDms\", {\n options,\n });\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const conversation = await this.#client.sendMessage(\"newGroup\", {\n accountAddresses,\n options,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n\n async newDm(accountAddress: string) {\n const conversation = await this.#client.sendMessage(\"newDm\", {\n accountAddress,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n}\n","import {\n ContentTypeGroupUpdated,\n GroupUpdatedCodec,\n} from \"@xmtp/content-type-group-updated\";\nimport type {\n ContentCodec,\n ContentTypeId,\n} from \"@xmtp/content-type-primitives\";\nimport { TextCodec } from \"@xmtp/content-type-text\";\nimport {\n GroupMessageKind,\n type ConsentEntityType,\n type SignatureRequestType,\n} from \"@xmtp/wasm-bindings\";\nimport { ClientWorkerClass } from \"@/ClientWorkerClass\";\nimport { Conversations } from \"@/Conversations\";\nimport type { ClientOptions } from \"@/types\";\nimport {\n fromSafeEncodedContent,\n toSafeEncodedContent,\n type SafeConsent,\n type SafeMessage,\n} from \"@/utils/conversions\";\n\nexport class Client extends ClientWorkerClass {\n address: string;\n\n options?: ClientOptions;\n\n #isReady = false;\n\n #inboxId: string | undefined;\n\n #installationId: string | undefined;\n\n #conversations: Conversations;\n\n #codecs: Map<string, ContentCodec>;\n\n constructor(address: string, options?: ClientOptions) {\n const worker = new Worker(new URL(\"./workers/client\", import.meta.url), {\n type: \"module\",\n });\n super(worker, options?.enableLogging ?? false);\n this.address = address;\n this.options = options;\n this.#conversations = new Conversations(this);\n const codecs = [\n new GroupUpdatedCodec(),\n new TextCodec(),\n ...(options?.codecs ?? []),\n ];\n this.#codecs = new Map(\n codecs.map((codec) => [codec.contentType.toString(), codec]),\n );\n }\n\n async init() {\n const result = await this.sendMessage(\"init\", {\n address: this.address,\n options: this.options,\n });\n this.#inboxId = result.inboxId;\n this.#installationId = result.installationId;\n this.#isReady = true;\n }\n\n static async create(address: string, options?: ClientOptions) {\n const client = new Client(address, options);\n await client.init();\n return client;\n }\n\n get isReady() {\n return this.#isReady;\n }\n\n get inboxId() {\n return this.#inboxId;\n }\n\n get installationId() {\n return this.#installationId;\n }\n\n async getCreateInboxSignatureText() {\n return this.sendMessage(\"getCreateInboxSignatureText\", undefined);\n }\n\n async getAddWalletSignatureText(accountAddress: string) {\n return this.sendMessage(\"getAddWalletSignatureText\", { accountAddress });\n }\n\n async getRevokeWalletSignatureText(accountAddress: string) {\n return this.sendMessage(\"getRevokeWalletSignatureText\", { accountAddress });\n }\n\n async getRevokeInstallationsSignatureText() {\n return this.sendMessage(\"getRevokeInstallationsSignatureText\", undefined);\n }\n\n async addSignature(type: SignatureRequestType, bytes: Uint8Array) {\n return this.sendMessage(\"addSignature\", { type, bytes });\n }\n\n async applySignatures() {\n return this.sendMessage(\"applySignatures\", undefined);\n }\n\n async registerIdentity() {\n return this.sendMessage(\"registerIdentity\", undefined);\n }\n\n async isRegistered() {\n return this.sendMessage(\"isRegistered\", undefined);\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.sendMessage(\"canMessage\", { accountAddresses });\n }\n\n async findInboxIdByAddress(address: string) {\n return this.sendMessage(\"findInboxIdByAddress\", { address });\n }\n\n async inboxState(refreshFromNetwork?: boolean) {\n return this.sendMessage(\"inboxState\", {\n refreshFromNetwork: refreshFromNetwork ?? false,\n });\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.sendMessage(\"getLatestInboxState\", { inboxId });\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.sendMessage(\"setConsentStates\", { records });\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.sendMessage(\"getConsentState\", { entityType, entity });\n }\n\n get conversations() {\n return this.#conversations;\n }\n\n codecFor(contentType: ContentTypeId) {\n return this.#codecs.get(contentType.toString());\n }\n\n encodeContent(content: any, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n const encoded = codec.encode(content, this);\n const fallback = codec.fallback(content);\n if (fallback) {\n encoded.fallback = fallback;\n }\n return toSafeEncodedContent(encoded);\n }\n\n decodeContent(message: SafeMessage, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n\n // throw an error if there's an invalid group membership change message\n if (\n contentType.sameAs(ContentTypeGroupUpdated) &&\n message.kind !== GroupMessageKind.MembershipChange\n ) {\n throw new Error(\"Error decoding group membership change\");\n }\n\n const encodedContent = fromSafeEncodedContent(message.content);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return codec.decode(encodedContent, this);\n }\n}\n","import { v4 } from \"uuid\";\nimport type {\n UtilsEventsActions,\n UtilsEventsErrorData,\n UtilsEventsResult,\n UtilsEventsWorkerMessageData,\n UtilsSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class UtilsWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends UtilsEventsActions>(\n action: A,\n data: UtilsSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<UtilsEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<UtilsEventsWorkerMessageData | UtilsEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"utils received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import type { XmtpEnv } from \"@/types/options\";\nimport { UtilsWorkerClass } from \"@/UtilsWorkerClass\";\n\nexport class Utils extends UtilsWorkerClass {\n #enableLogging: boolean;\n constructor(enableLogging?: boolean) {\n const worker = new Worker(new URL(\"./workers/utils\", import.meta.url), {\n type: \"module\",\n });\n super(worker, enableLogging ?? false);\n this.#enableLogging = enableLogging ?? false;\n }\n\n async generateInboxId(address: string) {\n return this.sendMessage(\"generateInboxId\", {\n address,\n enableLogging: this.#enableLogging,\n });\n }\n\n async getInboxIdForAddress(address: string, env?: XmtpEnv) {\n return this.sendMessage(\"getInboxIdForAddress\", {\n address,\n env,\n enableLogging: this.#enableLogging,\n });\n }\n}\n","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n"],"names":["handleError","event","console","error","lineno","filename","message","ClientWorkerClass","worker","enableLogging","promises","Map","constructor","this","addEventListener","handleMessage","sendMessage","action","data","promiseId","v4","postMessage","id","Promise","resolve","reject","set","eventData","log","promise","get","delete","Error","result","close","removeEventListener","terminate","toContentTypeId","contentTypeId","ContentTypeId","authorityId","typeId","versionMajor","versionMinor","fromContentTypeId","WasmContentTypeId","toSafeContentTypeId","fromSafeContentTypeId","toEncodedContent","content","type","parameters","Object","fromEntries","fallback","compression","fromEncodedContent","WasmEncodedContent","entries","toSafeEncodedContent","fromSafeEncodedContent","toSafeMessage","convoId","deliveryStatus","kind","senderInboxId","sentAtNs","toSafeListMessagesOptions","options","direction","limit","sentAfterNs","sentBeforeNs","fromSafeListMessagesOptions","ListMessagesOptions","toSafeListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","fromSafeListConversationsOptions","ListConversationsOptions","toSafeCreateGroupOptions","permissions","name","groupName","imageUrlSquare","groupImageUrlSquare","description","groupDescription","pinnedFrameUrl","groupPinnedFrameUrl","fromSafeCreateGroupOptions","CreateGroupOptions","toSafeConversation","conversation","imageUrl","policyType","policySet","addAdminPolicy","addMemberPolicy","removeAdminPolicy","removeMemberPolicy","updateGroupDescriptionPolicy","updateGroupImageUrlSquarePolicy","updateGroupNamePolicy","updateGroupPinnedFrameUrlPolicy","isActive","addedByInboxId","metadata","admins","superAdmins","createdAtNs","toSafeInstallation","installation","clientTimestampNs","toSafeInboxState","inboxState","accountAddresses","inboxId","installations","map","recoveryAddress","toSafeConsent","consent","entity","entityType","state","fromSafeConsent","Consent","WasmGroupMember","account_addresses","consent_state","inbox_id","installation_ids","permission_level","toSafeGroupMember","member","consentState","installationIds","permissionLevel","fromSafeGroupMember","GroupMember","DecodedMessage","client","contentType","conversationId","GroupMessageKind","Application","MembershipChange","DeliveryStatus","Unpublished","Published","Failed","decodeContent","Conversation","syncData","undefined","updateName","updateImageUrl","updateDescription","updatePinnedFrameUrl","createdAt","ns","Date","Number","members","isAdmin","includes","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","safeEncodedContent","encodeContent","ContentTypeText","send","messages","updateConsentState","dmPeerInboxId","Conversations","getConversationById","getMessageById","getDmByInboxId","list","listGroups","listDms","newGroup","newDm","accountAddress","Client","address","isReady","installationId","conversations","codecs","super","Worker","URL","url","GroupUpdatedCodec","TextCodec","codec","toString","init","create","getCreateInboxSignatureText","getAddWalletSignatureText","getRevokeWalletSignatureText","getRevokeInstallationsSignatureText","addSignature","bytes","applySignatures","registerIdentity","isRegistered","canMessage","findInboxIdByAddress","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","codecFor","encoded","encode","sameAs","ContentTypeGroupUpdated","encodedContent","decode","UtilsWorkerClass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KJ,GACPP,QAAQ0B,IAAI,4BAA6BD,GAE3C,MAAME,EAAUhB,MAAKH,EAAUoB,IAAIH,EAAUL,IACzCO,IACFhB,MAAKH,EAAUqB,OAAOJ,EAAUL,IAC5B,UAAWK,EACbE,EAAQJ,OAAO,IAAIO,MAAML,EAAUxB,QAEnC0B,EAAQL,QAAQG,EAAUM,QAE7B,EAGH,KAAAC,GACErB,MAAKL,EAAQ2B,oBAAoB,UAAWtB,KAAKE,eACjDF,MAAKL,EAAQ2B,oBAAoB,QAASnC,GAC1Ca,MAAKL,EAAQ4B,WACd,EClEG,MAAO2M,UAAcD,EACzBrO,GACA,WAAAG,CAAYH,GAIVoM,MAHe,IAAIC,OAAO,IAAIC,IAAI,8BAA+BC,KAAM,CACrE9J,KAAM,WAEMzC,IAAiB,GAC/BI,MAAKJ,EAAiBA,IAAiB,CACxC,CAED,qBAAMuO,CAAgBxC,GACpB,OAAO3L,KAAKG,YAAY,kBAAmB,CACzCwL,UACA/L,cAAeI,MAAKJ,GAEvB,CAED,0BAAMwO,CAAqBzC,EAAiB0C,GAC1C,OAAOrO,KAAKG,YAAY,uBAAwB,CAC9CwL,UACA0C,MACAzO,cAAeI,MAAKJ,GAEvB,EC1BU,MAAA0O,EAAU,CACrBC,MAAO,wBACPC,IAAK,2BACLC,WAAY"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/ClientWorkerClass.ts","../src/utils/conversions.ts","../src/DecodedMessage.ts","../src/Conversation.ts","../src/utils/date.ts","../src/Conversations.ts","../src/utils/signer.ts","../src/Client.ts","../src/UtilsWorkerClass.ts","../src/Utils.ts","../src/constants.ts"],"sourcesContent":["import { v4 } from \"uuid\";\nimport type {\n ClientEventsActions,\n ClientEventsErrorData,\n ClientEventsResult,\n ClientEventsWorkerMessageData,\n ClientSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class ClientWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends ClientEventsActions>(\n action: A,\n data: ClientSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<ClientEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<ClientEventsWorkerMessageData | ClientEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"client received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import {\n ContentTypeId,\n type EncodedContent,\n} from \"@xmtp/content-type-primitives\";\nimport {\n Consent,\n CreateGroupOptions,\n GroupMember,\n ListConversationsOptions,\n ListMessagesOptions,\n ContentTypeId as WasmContentTypeId,\n EncodedContent as WasmEncodedContent,\n type ConsentEntityType,\n type ConsentState,\n type ConversationType,\n type DeliveryStatus,\n type GroupMembershipState,\n type GroupMessageKind,\n type GroupPermissionsOptions,\n type InboxState,\n type Installation,\n type Message,\n type PermissionLevel,\n type PermissionPolicy,\n type SortDirection,\n} from \"@xmtp/wasm-bindings\";\nimport type { WorkerConversation } from \"@/WorkerConversation\";\n\nexport const toContentTypeId = (\n contentTypeId: WasmContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const fromContentTypeId = (\n contentTypeId: ContentTypeId,\n): WasmContentTypeId =>\n new WasmContentTypeId(\n contentTypeId.authorityId,\n contentTypeId.typeId,\n contentTypeId.versionMajor,\n contentTypeId.versionMinor,\n );\n\nexport type SafeContentTypeId = {\n authorityId: string;\n typeId: string;\n versionMajor: number;\n versionMinor: number;\n};\n\nexport const toSafeContentTypeId = (\n contentTypeId: ContentTypeId,\n): SafeContentTypeId => ({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n});\n\nexport const fromSafeContentTypeId = (\n contentTypeId: SafeContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const toEncodedContent = (\n content: WasmEncodedContent,\n): EncodedContent => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n type: toContentTypeId(content.type!),\n parameters: Object.fromEntries(content.parameters as Map<string, string>),\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromEncodedContent = (\n content: EncodedContent,\n): WasmEncodedContent =>\n new WasmEncodedContent(\n fromContentTypeId(content.type),\n new Map(Object.entries(content.parameters)),\n content.fallback,\n content.compression,\n content.content,\n );\n\nexport type SafeEncodedContent = {\n type: SafeContentTypeId;\n parameters: Record<string, string>;\n fallback?: string;\n compression?: number;\n content: Uint8Array;\n};\n\nexport const toSafeEncodedContent = (\n content: EncodedContent,\n): SafeEncodedContent => ({\n type: toSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromSafeEncodedContent = (\n content: SafeEncodedContent,\n): EncodedContent => ({\n type: fromSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport type SafeMessage = {\n content: SafeEncodedContent;\n convoId: string;\n deliveryStatus: DeliveryStatus;\n id: string;\n kind: GroupMessageKind;\n senderInboxId: string;\n sentAtNs: bigint;\n};\n\nexport const toSafeMessage = (message: Message): SafeMessage => ({\n content: toSafeEncodedContent(toEncodedContent(message.content)),\n convoId: message.convoId,\n deliveryStatus: message.deliveryStatus,\n id: message.id,\n kind: message.kind,\n senderInboxId: message.senderInboxId,\n sentAtNs: message.sentAtNs,\n});\n\nexport type SafeListMessagesOptions = {\n deliveryStatus?: DeliveryStatus;\n direction?: SortDirection;\n limit?: bigint;\n sentAfterNs?: bigint;\n sentBeforeNs?: bigint;\n};\n\nexport const toSafeListMessagesOptions = (\n options: ListMessagesOptions,\n): SafeListMessagesOptions => ({\n deliveryStatus: options.deliveryStatus,\n direction: options.direction,\n limit: options.limit,\n sentAfterNs: options.sentAfterNs,\n sentBeforeNs: options.sentBeforeNs,\n});\n\nexport const fromSafeListMessagesOptions = (\n options: SafeListMessagesOptions,\n): ListMessagesOptions =>\n new ListMessagesOptions(\n options.sentBeforeNs,\n options.sentAfterNs,\n options.limit,\n options.deliveryStatus,\n options.direction,\n );\n\nexport type SafeListConversationsOptions = {\n allowedStates?: GroupMembershipState[];\n conversationType?: ConversationType;\n createdAfterNs?: bigint;\n createdBeforeNs?: bigint;\n limit?: bigint;\n};\n\nexport const toSafeListConversationsOptions = (\n options: ListConversationsOptions,\n): SafeListConversationsOptions => ({\n allowedStates: options.allowedStates,\n conversationType: options.conversationType,\n createdAfterNs: options.createdAfterNs,\n createdBeforeNs: options.createdBeforeNs,\n limit: options.limit,\n});\n\nexport const fromSafeListConversationsOptions = (\n options: SafeListConversationsOptions,\n): ListConversationsOptions =>\n new ListConversationsOptions(\n options.allowedStates,\n options.conversationType,\n options.createdAfterNs,\n options.createdBeforeNs,\n options.limit,\n );\n\nexport type SafeCreateGroupOptions = {\n permissions?: GroupPermissionsOptions;\n name?: string;\n imageUrlSquare?: string;\n description?: string;\n pinnedFrameUrl?: string;\n};\n\nexport const toSafeCreateGroupOptions = (\n options: CreateGroupOptions,\n): SafeCreateGroupOptions => ({\n permissions: options.permissions,\n name: options.groupName,\n imageUrlSquare: options.groupImageUrlSquare,\n description: options.groupDescription,\n pinnedFrameUrl: options.groupPinnedFrameUrl,\n});\n\nexport const fromSafeCreateGroupOptions = (\n options: SafeCreateGroupOptions,\n): CreateGroupOptions =>\n new CreateGroupOptions(\n options.permissions,\n options.name,\n options.imageUrlSquare,\n options.description,\n options.pinnedFrameUrl,\n );\n\nexport type SafeConversation = {\n id: string;\n name: string;\n imageUrl: string;\n description: string;\n pinnedFrameUrl: string;\n permissions: {\n policyType: GroupPermissionsOptions;\n policySet: {\n addAdminPolicy: PermissionPolicy;\n addMemberPolicy: PermissionPolicy;\n removeAdminPolicy: PermissionPolicy;\n removeMemberPolicy: PermissionPolicy;\n updateGroupDescriptionPolicy: PermissionPolicy;\n updateGroupImageUrlSquarePolicy: PermissionPolicy;\n updateGroupNamePolicy: PermissionPolicy;\n updateGroupPinnedFrameUrlPolicy: PermissionPolicy;\n };\n };\n isActive: boolean;\n addedByInboxId: string;\n metadata: {\n creatorInboxId: string;\n conversationType: string;\n };\n admins: string[];\n superAdmins: string[];\n createdAtNs: bigint;\n};\n\nexport const toSafeConversation = (\n conversation: WorkerConversation,\n): SafeConversation => ({\n id: conversation.id,\n name: conversation.name,\n imageUrl: conversation.imageUrl,\n description: conversation.description,\n pinnedFrameUrl: conversation.pinnedFrameUrl,\n permissions: {\n policyType: conversation.permissions.policyType,\n policySet: {\n addAdminPolicy: conversation.permissions.policySet.addAdminPolicy,\n addMemberPolicy: conversation.permissions.policySet.addMemberPolicy,\n removeAdminPolicy: conversation.permissions.policySet.removeAdminPolicy,\n removeMemberPolicy: conversation.permissions.policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy:\n conversation.permissions.policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy:\n conversation.permissions.policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy:\n conversation.permissions.policySet.updateGroupNamePolicy,\n updateGroupPinnedFrameUrlPolicy:\n conversation.permissions.policySet.updateGroupPinnedFrameUrlPolicy,\n },\n },\n isActive: conversation.isActive,\n addedByInboxId: conversation.addedByInboxId,\n metadata: conversation.metadata,\n admins: conversation.admins,\n superAdmins: conversation.superAdmins,\n createdAtNs: conversation.createdAtNs,\n});\n\nexport type SafeInstallation = {\n id: string;\n clientTimestampNs?: bigint;\n};\n\nexport const toSafeInstallation = (\n installation: Installation,\n): SafeInstallation => ({\n id: installation.id,\n clientTimestampNs: installation.clientTimestampNs,\n});\n\nexport type SafeInboxState = {\n accountAddresses: string[];\n inboxId: string;\n installations: SafeInstallation[];\n recoveryAddress: string;\n};\n\nexport const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({\n accountAddresses: inboxState.accountAddresses,\n inboxId: inboxState.inboxId,\n installations: inboxState.installations.map(toSafeInstallation),\n recoveryAddress: inboxState.recoveryAddress,\n});\n\nexport type SafeConsent = {\n entity: string;\n entityType: ConsentEntityType;\n state: ConsentState;\n};\n\nexport const toSafeConsent = (consent: Consent): SafeConsent => ({\n entity: consent.entity,\n entityType: consent.entityType,\n state: consent.state,\n});\n\nexport const fromSafeConsent = (consent: SafeConsent): Consent =>\n new Consent(consent.entityType, consent.state, consent.entity);\n\nexport type SafeGroupMember = {\n accountAddresses: string[];\n consentState: ConsentState;\n inboxId: string;\n installationIds: string[];\n permissionLevel: PermissionLevel;\n};\n\nexport const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({\n accountAddresses: member.accountAddresses,\n consentState: member.consentState,\n inboxId: member.inboxId,\n installationIds: member.installationIds,\n permissionLevel: member.permissionLevel,\n});\n\nexport const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>\n new GroupMember(\n member.inboxId,\n member.accountAddresses,\n member.installationIds,\n member.permissionLevel,\n member.consentState,\n );\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { DeliveryStatus, GroupMessageKind } from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { fromSafeContentTypeId, type SafeMessage } from \"@/utils/conversions\";\n\nexport type MessageKind = \"application\" | \"membership_change\";\nexport type MessageDeliveryStatus = \"unpublished\" | \"published\" | \"failed\";\n\nexport class DecodedMessage {\n #client: Client;\n\n content: any;\n\n contentType: ContentTypeId;\n\n conversationId: string;\n\n deliveryStatus: MessageDeliveryStatus;\n\n fallback?: string;\n\n compression?: number;\n\n id: string;\n\n kind: MessageKind;\n\n parameters: Map<string, string>;\n\n senderInboxId: string;\n\n sentAtNs: bigint;\n\n constructor(client: Client, message: SafeMessage) {\n this.#client = client;\n this.id = message.id;\n this.sentAtNs = message.sentAtNs;\n this.conversationId = message.convoId;\n this.senderInboxId = message.senderInboxId;\n\n switch (message.kind) {\n case GroupMessageKind.Application:\n this.kind = \"application\";\n break;\n case GroupMessageKind.MembershipChange:\n this.kind = \"membership_change\";\n break;\n // no default\n }\n\n switch (message.deliveryStatus) {\n case DeliveryStatus.Unpublished:\n this.deliveryStatus = \"unpublished\";\n break;\n case DeliveryStatus.Published:\n this.deliveryStatus = \"published\";\n break;\n case DeliveryStatus.Failed:\n this.deliveryStatus = \"failed\";\n break;\n // no default\n }\n\n this.contentType = fromSafeContentTypeId(message.content.type);\n this.parameters = new Map(Object.entries(message.content.parameters));\n this.fallback = message.content.fallback;\n this.compression = message.content.compression;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.content = this.#client.decodeContent(message, this.contentType);\n }\n}\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { ContentTypeText } from \"@xmtp/content-type-text\";\nimport type { ConsentState } from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { DecodedMessage } from \"@/DecodedMessage\";\nimport type {\n SafeConversation,\n SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport { nsToDate } from \"@/utils/date\";\n\nexport class Conversation {\n #client: Client;\n\n #id: string;\n\n #name?: SafeConversation[\"name\"];\n\n #imageUrl?: SafeConversation[\"imageUrl\"];\n\n #description?: SafeConversation[\"description\"];\n\n #pinnedFrameUrl?: SafeConversation[\"pinnedFrameUrl\"];\n\n #isActive?: SafeConversation[\"isActive\"];\n\n #addedByInboxId?: SafeConversation[\"addedByInboxId\"];\n\n #metadata?: SafeConversation[\"metadata\"];\n\n #permissions?: SafeConversation[\"permissions\"];\n\n #createdAtNs?: SafeConversation[\"createdAtNs\"];\n\n constructor(client: Client, id: string, data?: SafeConversation) {\n this.#client = client;\n this.#id = id;\n this.#syncData(data);\n }\n\n #syncData(data?: SafeConversation) {\n this.#name = data?.name ?? \"\";\n this.#imageUrl = data?.imageUrl ?? \"\";\n this.#description = data?.description ?? \"\";\n this.#pinnedFrameUrl = data?.pinnedFrameUrl ?? \"\";\n this.#isActive = data?.isActive ?? undefined;\n this.#addedByInboxId = data?.addedByInboxId ?? \"\";\n this.#metadata = data?.metadata ?? undefined;\n this.#permissions = data?.permissions ?? undefined;\n this.#createdAtNs = data?.createdAtNs ?? undefined;\n }\n\n get id() {\n return this.#id;\n }\n\n get name() {\n return this.#name;\n }\n\n async updateName(name: string) {\n await this.#client.sendMessage(\"updateGroupName\", {\n id: this.#id,\n name,\n });\n this.#name = name;\n }\n\n get imageUrl() {\n return this.#imageUrl;\n }\n\n async updateImageUrl(imageUrl: string) {\n await this.#client.sendMessage(\"updateGroupImageUrlSquare\", {\n id: this.#id,\n imageUrl,\n });\n this.#imageUrl = imageUrl;\n }\n\n get description() {\n return this.#description;\n }\n\n async updateDescription(description: string) {\n await this.#client.sendMessage(\"updateGroupDescription\", {\n id: this.#id,\n description,\n });\n this.#description = description;\n }\n\n get pinnedFrameUrl() {\n return this.#pinnedFrameUrl;\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n await this.#client.sendMessage(\"updateGroupPinnedFrameUrl\", {\n id: this.#id,\n pinnedFrameUrl,\n });\n this.#pinnedFrameUrl = pinnedFrameUrl;\n }\n\n get isActive() {\n return this.#isActive;\n }\n\n get addedByInboxId() {\n return this.#addedByInboxId;\n }\n\n get createdAtNs() {\n return this.#createdAtNs;\n }\n\n get createdAt() {\n return this.#createdAtNs ? nsToDate(this.#createdAtNs) : undefined;\n }\n\n get metadata() {\n return this.#metadata;\n }\n\n async members() {\n return this.#client.sendMessage(\"getGroupMembers\", {\n id: this.#id,\n });\n }\n\n async admins() {\n return this.#client.sendMessage(\"getGroupAdmins\", {\n id: this.#id,\n });\n }\n\n async superAdmins() {\n return this.#client.sendMessage(\"getGroupSuperAdmins\", {\n id: this.#id,\n });\n }\n\n get permissions() {\n return this.#permissions;\n }\n\n async isAdmin(inboxId: string) {\n const admins = await this.admins();\n return admins.includes(inboxId);\n }\n\n async isSuperAdmin(inboxId: string) {\n const superAdmins = await this.superAdmins();\n return superAdmins.includes(inboxId);\n }\n\n async sync() {\n const data = await this.#client.sendMessage(\"syncGroup\", {\n id: this.#id,\n });\n this.#syncData(data);\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"addGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"addGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"removeGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"removeGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async addAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async publishMessages() {\n return this.#client.sendMessage(\"publishGroupMessages\", {\n id: this.#id,\n });\n }\n\n async sendOptimistic(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendOptimisticGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async send(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async messages(options?: SafeListMessagesOptions) {\n const messages = await this.#client.sendMessage(\"getGroupMessages\", {\n id: this.#id,\n options,\n });\n\n return messages.map((message) => new DecodedMessage(this.#client, message));\n }\n\n async consentState() {\n return this.#client.sendMessage(\"getGroupConsentState\", {\n id: this.#id,\n });\n }\n\n async updateConsentState(state: ConsentState) {\n return this.#client.sendMessage(\"updateGroupConsentState\", {\n id: this.#id,\n state,\n });\n }\n\n async dmPeerInboxId() {\n return this.#client.sendMessage(\"getDmPeerInboxId\", {\n id: this.#id,\n });\n }\n}\n","export function nsToDate(ns: bigint): Date {\n return new Date(Number(ns / 1_000_000n));\n}\n","import type { Client } from \"@/Client\";\nimport { Conversation } from \"@/Conversation\";\nimport type {\n SafeCreateGroupOptions,\n SafeListConversationsOptions,\n} from \"@/utils/conversions\";\n\nexport class Conversations {\n #client: Client;\n\n constructor(client: Client) {\n this.#client = client;\n }\n\n async sync() {\n return this.#client.sendMessage(\"syncConversations\", undefined);\n }\n\n async getConversationById(id: string) {\n return this.#client.sendMessage(\"getConversationById\", {\n id,\n });\n }\n\n async getMessageById(id: string) {\n return this.#client.sendMessage(\"getMessageById\", {\n id,\n });\n }\n\n async getDmByInboxId(inboxId: string) {\n return this.#client.sendMessage(\"getDmByInboxId\", {\n inboxId,\n });\n }\n\n async list(options?: SafeListConversationsOptions) {\n const conversations = await this.#client.sendMessage(\"getConversations\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n return this.#client.sendMessage(\"getGroups\", {\n options,\n });\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n return this.#client.sendMessage(\"getDms\", {\n options,\n });\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const conversation = await this.#client.sendMessage(\"newGroup\", {\n accountAddresses,\n options,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n\n async newDm(accountAddress: string) {\n const conversation = await this.#client.sendMessage(\"newDm\", {\n accountAddress,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n}\n","export type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;\nexport type GetAddress = () => Promise<string> | string;\nexport type GetChainId = () => bigint;\nexport type GetBlockNumber = () => bigint;\n\nexport type Signer = {\n getAddress: GetAddress;\n signMessage: SignMessage;\n // these fields indicate that the signer is a smart contract wallet\n getBlockNumber?: GetBlockNumber;\n getChainId?: GetChainId;\n};\n\nexport type SmartContractSigner = Required<Signer>;\n\nexport const isSmartContractSigner = (\n signer: Signer,\n): signer is SmartContractSigner =>\n \"getBlockNumber\" in signer && \"getChainId\" in signer;\n","import {\n ContentTypeGroupUpdated,\n GroupUpdatedCodec,\n} from \"@xmtp/content-type-group-updated\";\nimport type {\n ContentCodec,\n ContentTypeId,\n} from \"@xmtp/content-type-primitives\";\nimport { TextCodec } from \"@xmtp/content-type-text\";\nimport {\n GroupMessageKind,\n SignatureRequestType,\n type ConsentEntityType,\n} from \"@xmtp/wasm-bindings\";\nimport { ClientWorkerClass } from \"@/ClientWorkerClass\";\nimport { Conversations } from \"@/Conversations\";\nimport type { ClientOptions, XmtpEnv } from \"@/types\";\nimport {\n fromSafeEncodedContent,\n toSafeEncodedContent,\n type SafeConsent,\n type SafeMessage,\n} from \"@/utils/conversions\";\nimport { isSmartContractSigner, type Signer } from \"@/utils/signer\";\n\nexport class Client extends ClientWorkerClass {\n #accountAddress: string;\n #codecs: Map<string, ContentCodec>;\n #conversations: Conversations;\n #encryptionKey: Uint8Array;\n #inboxId: string | undefined;\n #installationId: string | undefined;\n #isReady = false;\n #signer: Signer;\n options?: ClientOptions;\n\n constructor(\n signer: Signer,\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: ClientOptions,\n ) {\n const worker = new Worker(new URL(\"./workers/client\", import.meta.url), {\n type: \"module\",\n });\n super(\n worker,\n options?.loggingLevel !== undefined && options.loggingLevel !== \"off\",\n );\n this.#accountAddress = accountAddress;\n this.options = options;\n this.#encryptionKey = encryptionKey;\n this.#signer = signer;\n this.#conversations = new Conversations(this);\n const codecs = [\n new GroupUpdatedCodec(),\n new TextCodec(),\n ...(options?.codecs ?? []),\n ];\n this.#codecs = new Map(\n codecs.map((codec) => [codec.contentType.toString(), codec]),\n );\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n async init() {\n const result = await this.sendMessage(\"init\", {\n address: this.accountAddress,\n encryptionKey: this.#encryptionKey,\n options: this.options,\n });\n this.#inboxId = result.inboxId;\n this.#installationId = result.installationId;\n this.#isReady = true;\n }\n\n static async create(\n signer: Signer,\n encryptionKey: Uint8Array,\n options?: ClientOptions,\n ) {\n const address = await signer.getAddress();\n const client = new Client(signer, address, encryptionKey, options);\n\n await client.init();\n\n if (!options?.disableAutoRegister) {\n await client.register();\n }\n\n return client;\n }\n\n get isReady() {\n return this.#isReady;\n }\n\n get inboxId() {\n return this.#inboxId;\n }\n\n get installationId() {\n return this.#installationId;\n }\n\n async #createInboxSignatureText() {\n return this.sendMessage(\"createInboxSignatureText\", undefined);\n }\n\n async #addAccountSignatureText(newAccountAddress: string) {\n return this.sendMessage(\"addAccountSignatureText\", {\n newAccountAddress,\n });\n }\n\n async #removeAccountSignatureText(accountAddress: string) {\n return this.sendMessage(\"removeAccountSignatureText\", { accountAddress });\n }\n\n async #revokeInstallationsSignatureText() {\n return this.sendMessage(\"revokeInstallationsSignatureText\", undefined);\n }\n\n async #addSignature(\n signatureType: SignatureRequestType,\n signatureText: string,\n signer: Signer,\n ) {\n const signature = await signer.signMessage(signatureText);\n\n if (isSmartContractSigner(signer)) {\n await this.sendMessage(\"addScwSignature\", {\n type: signatureType,\n bytes: signature,\n chainId: signer.getChainId(),\n blockNumber: signer.getBlockNumber(),\n });\n } else {\n await this.sendMessage(\"addSignature\", {\n type: signatureType,\n bytes: signature,\n });\n }\n }\n\n async #applySignatures() {\n return this.sendMessage(\"applySignatures\", undefined);\n }\n\n async register() {\n const signatureText = await this.#createInboxSignatureText();\n\n // if the signature text is not available, the client is already registered\n if (!signatureText) {\n return;\n }\n\n await this.#addSignature(\n SignatureRequestType.CreateInbox,\n signatureText,\n this.#signer,\n );\n\n return this.sendMessage(\"registerIdentity\", undefined);\n }\n\n async addAccount(newAccountSigner: Signer) {\n const signatureText = await this.#addAccountSignatureText(\n await newAccountSigner.getAddress(),\n );\n\n if (!signatureText) {\n throw new Error(\"Unable to generate add account signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.AddWallet,\n signatureText,\n this.#signer,\n );\n\n await this.#addSignature(\n SignatureRequestType.AddWallet,\n signatureText,\n newAccountSigner,\n );\n\n await this.#applySignatures();\n }\n\n async removeAccount(accountAddress: string) {\n const signatureText =\n await this.#removeAccountSignatureText(accountAddress);\n\n if (!signatureText) {\n throw new Error(\"Unable to generate remove account signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeWallet,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async revokeInstallations() {\n const signatureText = await this.#revokeInstallationsSignatureText();\n\n if (!signatureText) {\n throw new Error(\"Unable to generate revoke installations signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeInstallations,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async isRegistered() {\n return this.sendMessage(\"isRegistered\", undefined);\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.sendMessage(\"canMessage\", { accountAddresses });\n }\n\n static async canMessage(accountAddresses: string[], env?: XmtpEnv) {\n const accountAddress = \"0x0000000000000000000000000000000000000000\";\n const signer: Signer = {\n getAddress: () => accountAddress,\n signMessage: () => new Uint8Array(),\n };\n const client = await Client.create(\n signer,\n window.crypto.getRandomValues(new Uint8Array(32)),\n {\n disableAutoRegister: true,\n env,\n },\n );\n return client.canMessage(accountAddresses);\n }\n\n async findInboxIdByAddress(address: string) {\n return this.sendMessage(\"findInboxIdByAddress\", { address });\n }\n\n async inboxState(refreshFromNetwork?: boolean) {\n return this.sendMessage(\"inboxState\", {\n refreshFromNetwork: refreshFromNetwork ?? false,\n });\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.sendMessage(\"getLatestInboxState\", { inboxId });\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.sendMessage(\"setConsentStates\", { records });\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.sendMessage(\"getConsentState\", { entityType, entity });\n }\n\n get conversations() {\n return this.#conversations;\n }\n\n codecFor(contentType: ContentTypeId) {\n return this.#codecs.get(contentType.toString());\n }\n\n encodeContent(content: any, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n const encoded = codec.encode(content, this);\n const fallback = codec.fallback(content);\n if (fallback) {\n encoded.fallback = fallback;\n }\n return toSafeEncodedContent(encoded);\n }\n\n decodeContent(message: SafeMessage, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n\n // throw an error if there's an invalid group membership change message\n if (\n contentType.sameAs(ContentTypeGroupUpdated) &&\n message.kind !== GroupMessageKind.MembershipChange\n ) {\n throw new Error(\"Error decoding group membership change\");\n }\n\n const encodedContent = fromSafeEncodedContent(message.content);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return codec.decode(encodedContent, this);\n }\n}\n","import { v4 } from \"uuid\";\nimport type {\n UtilsEventsActions,\n UtilsEventsErrorData,\n UtilsEventsResult,\n UtilsEventsWorkerMessageData,\n UtilsSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class UtilsWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends UtilsEventsActions>(\n action: A,\n data: UtilsSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<UtilsEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<UtilsEventsWorkerMessageData | UtilsEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"utils received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import type { XmtpEnv } from \"@/types/options\";\nimport { UtilsWorkerClass } from \"@/UtilsWorkerClass\";\n\nexport class Utils extends UtilsWorkerClass {\n #enableLogging: boolean;\n constructor(enableLogging?: boolean) {\n const worker = new Worker(new URL(\"./workers/utils\", import.meta.url), {\n type: \"module\",\n });\n super(worker, enableLogging ?? false);\n this.#enableLogging = enableLogging ?? false;\n }\n\n async generateInboxId(address: string) {\n return this.sendMessage(\"generateInboxId\", {\n address,\n enableLogging: this.#enableLogging,\n });\n }\n\n async getInboxIdForAddress(address: string, env?: XmtpEnv) {\n return this.sendMessage(\"getInboxIdForAddress\", {\n address,\n env,\n enableLogging: this.#enableLogging,\n });\n }\n}\n","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n"],"names":["handleError","event","console","error","lineno","filename","message","ClientWorkerClass","worker","enableLogging","promises","Map","constructor","this","addEventListener","handleMessage","sendMessage","action","data","promiseId","v4","postMessage","id","Promise","resolve","reject","set","eventData","log","promise","get","delete","Error","result","close","removeEventListener","terminate","toContentTypeId","contentTypeId","ContentTypeId","authorityId","typeId","versionMajor","versionMinor","fromContentTypeId","WasmContentTypeId","toSafeContentTypeId","fromSafeContentTypeId","toEncodedContent","content","type","parameters","Object","fromEntries","fallback","compression","fromEncodedContent","WasmEncodedContent","entries","toSafeEncodedContent","fromSafeEncodedContent","toSafeMessage","convoId","deliveryStatus","kind","senderInboxId","sentAtNs","toSafeListMessagesOptions","options","direction","limit","sentAfterNs","sentBeforeNs","fromSafeListMessagesOptions","ListMessagesOptions","toSafeListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","fromSafeListConversationsOptions","ListConversationsOptions","toSafeCreateGroupOptions","permissions","name","groupName","imageUrlSquare","groupImageUrlSquare","description","groupDescription","pinnedFrameUrl","groupPinnedFrameUrl","fromSafeCreateGroupOptions","CreateGroupOptions","toSafeConversation","conversation","imageUrl","policyType","policySet","addAdminPolicy","addMemberPolicy","removeAdminPolicy","removeMemberPolicy","updateGroupDescriptionPolicy","updateGroupImageUrlSquarePolicy","updateGroupNamePolicy","updateGroupPinnedFrameUrlPolicy","isActive","addedByInboxId","metadata","admins","superAdmins","createdAtNs","toSafeInstallation","installation","clientTimestampNs","toSafeInboxState","inboxState","accountAddresses","inboxId","installations","map","recoveryAddress","toSafeConsent","consent","entity","entityType","state","fromSafeConsent","Consent","toSafeGroupMember","member","consentState","installationIds","permissionLevel","fromSafeGroupMember","GroupMember","DecodedMessage","client","contentType","conversationId","GroupMessageKind","Application","MembershipChange","DeliveryStatus","Unpublished","Published","Failed","decodeContent","Conversation","syncData","undefined","updateName","updateImageUrl","updateDescription","updatePinnedFrameUrl","createdAt","ns","Date","Number","members","isAdmin","includes","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","safeEncodedContent","encodeContent","ContentTypeText","send","messages","updateConsentState","dmPeerInboxId","Conversations","getConversationById","getMessageById","getDmByInboxId","list","listGroups","listDms","newGroup","newDm","accountAddress","isSmartContractSigner","signer","Client","codecs","conversations","encryptionKey","installationId","isReady","super","Worker","URL","url","loggingLevel","GroupUpdatedCodec","TextCodec","codec","toString","init","address","create","getAddress","disableAutoRegister","register","createInboxSignatureText","addAccountSignatureText","newAccountAddress","removeAccountSignatureText","revokeInstallationsSignatureText","addSignature","signatureType","signatureText","signature","signMessage","bytes","chainId","getChainId","blockNumber","getBlockNumber","applySignatures","SignatureRequestType","CreateInbox","addAccount","newAccountSigner","AddWallet","removeAccount","RevokeWallet","revokeInstallations","RevokeInstallations","isRegistered","canMessage","env","Uint8Array","window","crypto","getRandomValues","findInboxIdByAddress","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","codecFor","encoded","encode","sameAs","ContentTypeGroupUpdated","encodedContent","decode","UtilsWorkerClass","Utils","generateInboxId","getInboxIdForAddress","ApiUrls","local","dev","production"],"mappings":"u7BASA,MAAMA,EAAeC,IACnBC,QAAQC,MAAM,wBAAwBF,EAAMG,cAAcH,EAAMI,aAChEH,QAAQC,MAAMF,EAAMK,QAAQ,QAGjBC,EACXC,GAEAC,GAEAC,GAAY,IAAIC,IAKhB,WAAAC,CAAYJ,EAAgBC,GAC1BI,MAAKL,EAAUA,EACfK,MAAKL,EAAQM,iBAAiB,UAAWD,KAAKE,eAC9CF,MAAKL,EAAQM,iBAAiB,QAASd,GACvCa,MAAKJ,EAAiBA,CACvB,CAED,WAAAO,CACEC,EACAC,GAEA,MAAMC,EAAYC,IAClBP,MAAKL,EAAQa,YAAY,CACvBJ,SACAK,GAAIH,EACJD,SAKF,OAHgB,IAAIK,SAA+B,CAACC,EAASC,KAC3DZ,MAAKH,EAAUgB,IAAIP,EAAW,CAAEK,UAASC,UAAS,GAGrD,CAEDV,cACEd,IAEA,MAAM0B,EAAY1B,EAAMiB,KACpBL,MAAKJ,GACPP,QAAQ0B,IAAI,6BAA8BD,GAE5C,MAAME,EAAUhB,MAAKH,EAAUoB,IAAIH,EAAUL,IACzCO,IACFhB,MAAKH,EAAUqB,OAAOJ,EAAUL,IAC5B,UAAWK,EACbE,EAAQJ,OAAO,IAAIO,MAAML,EAAUxB,QAEnC0B,EAAQL,QAAQG,EAAUM,QAE7B,EAGH,KAAAC,GACErB,MAAKL,EAAQ2B,oBAAoB,UAAWtB,KAAKE,eACjDF,MAAKL,EAAQ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