@xmtp/browser-sdk 0.0.5 → 0.0.7
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 +40 -0
- 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 +8 -9
- package/src/Client.ts +32 -6
- package/src/Conversations.ts +4 -0
- package/src/WorkerClient.ts +38 -4
- package/src/WorkerConversations.ts +4 -0
- package/src/types/clientEvents.ts +34 -0
- package/src/workers/client.ts +44 -0
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ type ClientEvents =
|
|
|
69
69
|
result: {
|
|
70
70
|
inboxId: string;
|
|
71
71
|
installationId: string;
|
|
72
|
+
installationIdBytes: Uint8Array;
|
|
72
73
|
};
|
|
73
74
|
data: {
|
|
74
75
|
address: string;
|
|
@@ -175,6 +176,30 @@ type ClientEvents =
|
|
|
175
176
|
data: {
|
|
176
177
|
address: string;
|
|
177
178
|
};
|
|
179
|
+
} | {
|
|
180
|
+
action: "signWithInstallationKey";
|
|
181
|
+
id: string;
|
|
182
|
+
result: Uint8Array;
|
|
183
|
+
data: {
|
|
184
|
+
signatureText: string;
|
|
185
|
+
};
|
|
186
|
+
} | {
|
|
187
|
+
action: "verifySignedWithInstallationKey";
|
|
188
|
+
id: string;
|
|
189
|
+
result: boolean;
|
|
190
|
+
data: {
|
|
191
|
+
signatureText: string;
|
|
192
|
+
signatureBytes: Uint8Array;
|
|
193
|
+
};
|
|
194
|
+
} | {
|
|
195
|
+
action: "verifySignedWithPublicKey";
|
|
196
|
+
id: string;
|
|
197
|
+
result: boolean;
|
|
198
|
+
data: {
|
|
199
|
+
signatureText: string;
|
|
200
|
+
signatureBytes: Uint8Array;
|
|
201
|
+
publicKey: Uint8Array;
|
|
202
|
+
};
|
|
178
203
|
}
|
|
179
204
|
/**
|
|
180
205
|
* Conversations actions
|
|
@@ -241,6 +266,11 @@ type ClientEvents =
|
|
|
241
266
|
id: string;
|
|
242
267
|
result: undefined;
|
|
243
268
|
data: undefined;
|
|
269
|
+
} | {
|
|
270
|
+
action: "syncAllConversations";
|
|
271
|
+
id: string;
|
|
272
|
+
result: undefined;
|
|
273
|
+
data: undefined;
|
|
244
274
|
}
|
|
245
275
|
/**
|
|
246
276
|
* Group actions
|
|
@@ -513,6 +543,7 @@ declare class WorkerConversations {
|
|
|
513
543
|
#private;
|
|
514
544
|
constructor(client: WorkerClient, conversations: Conversations$1);
|
|
515
545
|
sync(): Promise<void>;
|
|
546
|
+
syncAll(): Promise<number>;
|
|
516
547
|
getConversationById(id: string): WorkerConversation | undefined;
|
|
517
548
|
getMessageById(id: string): SafeMessage | undefined;
|
|
518
549
|
getDmByInboxId(inboxId: string): WorkerConversation | undefined;
|
|
@@ -530,6 +561,7 @@ declare class WorkerClient {
|
|
|
530
561
|
get accountAddress(): string;
|
|
531
562
|
get inboxId(): string;
|
|
532
563
|
get installationId(): string;
|
|
564
|
+
get installationIdBytes(): Uint8Array;
|
|
533
565
|
get isRegistered(): boolean;
|
|
534
566
|
createInboxSignatureText(): Promise<string | undefined>;
|
|
535
567
|
addAccountSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
@@ -546,6 +578,9 @@ declare class WorkerClient {
|
|
|
546
578
|
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
547
579
|
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
548
580
|
get conversations(): WorkerConversations;
|
|
581
|
+
signWithInstallationKey(signatureText: string): Uint8Array;
|
|
582
|
+
verifySignedWithInstallationKey(signatureText: string, signatureBytes: Uint8Array): boolean;
|
|
583
|
+
verifySignedWithPublicKey(signatureText: string, signatureBytes: Uint8Array, publicKey: Uint8Array): boolean;
|
|
549
584
|
}
|
|
550
585
|
|
|
551
586
|
declare class WorkerConversation {
|
|
@@ -797,6 +832,7 @@ declare class Conversations {
|
|
|
797
832
|
#private;
|
|
798
833
|
constructor(client: Client);
|
|
799
834
|
sync(): Promise<undefined>;
|
|
835
|
+
syncAll(): Promise<undefined>;
|
|
800
836
|
getConversationById(id: string): Promise<SafeConversation | undefined>;
|
|
801
837
|
getMessageById(id: string): Promise<SafeMessage | undefined>;
|
|
802
838
|
getDmByInboxId(inboxId: string): Promise<SafeConversation | undefined>;
|
|
@@ -830,6 +866,7 @@ declare class Client extends ClientWorkerClass {
|
|
|
830
866
|
get isReady(): boolean;
|
|
831
867
|
get inboxId(): string | undefined;
|
|
832
868
|
get installationId(): string | undefined;
|
|
869
|
+
get installationIdBytes(): Uint8Array | undefined;
|
|
833
870
|
register(): Promise<undefined>;
|
|
834
871
|
addAccount(newAccountSigner: Signer): Promise<void>;
|
|
835
872
|
removeAccount(accountAddress: string): Promise<void>;
|
|
@@ -846,6 +883,9 @@ declare class Client extends ClientWorkerClass {
|
|
|
846
883
|
codecFor(contentType: ContentTypeId$1): ContentCodec | undefined;
|
|
847
884
|
encodeContent(content: any, contentType: ContentTypeId$1): SafeEncodedContent;
|
|
848
885
|
decodeContent(message: SafeMessage, contentType: ContentTypeId$1): any;
|
|
886
|
+
signWithInstallationKey(signatureText: string): Promise<Uint8Array>;
|
|
887
|
+
verifySignedWithInstallationKey(signatureText: string, signatureBytes: Uint8Array): Promise<boolean>;
|
|
888
|
+
verifySignedWithPublicKey(signatureText: string, signatureBytes: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
|
|
849
889
|
}
|
|
850
890
|
|
|
851
891
|
declare class UtilsWorkerClass {
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as a,ListConversationsOptions as o,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};
|
|
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 g,SignatureRequestType as u}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}),f=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),k=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),B=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}),L=e=>({id:e.id,clientTimestampNs:e.clientTimestampNs}),F=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(L),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 K{#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 g.Unpublished:this.deliveryStatus="unpublished";break;case g.Published:this.deliveryStatus="published";break;case g.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 W{#n;#i;#r;#a;#o;#d;#c;#l;#p;#g;#u;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.#g=e?.permissions??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#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.#u}get createdAt(){return this.#u?(e=this.#u,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.#g}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 K(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 q{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async syncAll(){return this.#n.sendMessage("syncAllConversations",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 W(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 W(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new W(this.#n,t.id,t)}}const O=e=>"getBlockNumber"in e&&"getChainId"in e;class $ extends I{#m;#y;#I;#b;#v;#w;#M;#A=!1;#S;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.#S=t,this.#I=new q(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=e.installationIdBytes,this.#A=!0}static async create(e,t,s){const n=await e.getAddress(),i=new $(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#A}get inboxId(){return this.#v}get installationId(){return this.#w}get installationIdBytes(){return this.#M}async#x(){return this.sendMessage("createInboxSignatureText",void 0)}async#f(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#k(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#G(){return this.sendMessage("revokeInstallationsSignatureText",void 0)}async#U(e,t,s){const n=await s.signMessage(t);O(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#N(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#x();if(e)return await this.#U(u.CreateInbox,e,this.#S),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#f(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#U(u.AddWallet,t,e),await this.#N()}async removeAccount(e){const t=await this.#k(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#U(u.RevokeWallet,t,this.#S),await this.#N()}async revokeInstallations(){const e=await this.#G();if(!e)throw new Error("Unable to generate revoke installations signature text");await this.#U(u.RevokeInstallations,e,this.#S),await this.#N()}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 $.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=f(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const 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,$ as Client,W as Conversation,q as Conversations,K as DecodedMessage,z as Utils,v as fromContentTypeId,S as fromEncodedContent,D as fromSafeConsent,M as fromSafeContentTypeId,T as fromSafeCreateGroupOptions,f as fromSafeEncodedContent,R as fromSafeGroupMember,C as fromSafeListConversationsOptions,U as fromSafeListMessagesOptions,O as isSmartContractSigner,b as toContentTypeId,A as toEncodedContent,E as toSafeConsent,w as toSafeContentTypeId,B as toSafeConversation,P as toSafeCreateGroupOptions,x as toSafeEncodedContent,j as toSafeGroupMember,F as toSafeInboxState,L as toSafeInstallation,N as toSafeListConversationsOptions,G as toSafeListMessagesOptions,k 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/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","gener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WAAAG,CAAYH,GAIVgM,MAHe,IAAIC,OAAO,IAAIC,IAAI,8BAA+BC,KAAM,CACrE1J,KAAM,WAEMzC,IAAiB,GAC/BI,MAAKJ,EAAiBA,IAAiB,EAGzC,qBAAM8P,CAAgBpD,GACpB,OAAOtM,KAAKG,YAAY,kBAAmB,CACzCmM,UACA1M,cAAeI,MAAKJ,IAIxB,0BAAM+P,CAAqBrD,EAAiBgC,GAC1C,OAAOtO,KAAKG,YAAY,uBAAwB,CAC9CmM,UACAgC,MACA1O,cAAeI,MAAKJ,KCxBb,MAAAgQ,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 syncAll() {\n return this.#client.sendMessage(\"syncAllConversations\", 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 #installationIdBytes: Uint8Array | 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.#installationIdBytes = result.installationIdBytes;\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 get installationIdBytes() {\n return this.#installationIdBytes;\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 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 signWithInstallationKey(signatureText: string) {\n return this.sendMessage(\"signWithInstallationKey\", { signatureText });\n }\n\n verifySignedWithInstallationKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n ) {\n return this.sendMessage(\"verifySignedWithInstallationKey\", {\n signatureText,\n signatureBytes,\n });\n }\n\n verifySignedWithPublicKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n publicKey: Uint8Array,\n ) {\n return this.sendMessage(\"verifySignedWithPublicKey\", {\n signatureText,\n signatureBytes,\n publicKey,\n });\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","syncAll","getConversationById","getMessageById","getDmByInboxId","list","listGroups","listDms","newGroup","newDm","accountAddress","isSmartContractSigner","signer","Client","codecs","conversations","encryptionKey","installationId","installationIdBytes","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","signWithInstallationKey","verifySignedWithInstallationKey","signatureBytes","verifySignedWithPublicKey","publicKey","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,EAGxB,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,IAKtDV,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,UAKhC,KAAAC,GACErB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";import t,{EncodedContent as n,ContentTypeId as r,Consent as o,ListConversationsOptions as i,CreateGroupOptions as s,ListMessagesOptions as a,getInboxIdForAddress as d,generateInboxId as c,createClient as u,LogOptions as p}from"@xmtp/wasm-bindings";const l=e=>{return new n((t=e.type,new r(t.authorityId,t.typeId,t.versionMajor,t.versionMinor)),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content);var t},m=e=>{return{type:(t=e.type,{authorityId:t.authorityId,typeId:t.typeId,versionMajor:t.versionMajor,versionMinor:t.versionMinor}),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content};var t},g=t=>{return{type:(n=t.type,new e({authorityId:n.authorityId,typeId:n.typeId,versionMajor:n.versionMajor,versionMinor:n.versionMinor})),parameters:t.parameters,fallback:t.fallback,compression:t.compression,content:t.content};var n},y=t=>{return{content:m((n=t.content,{type:(r=n.type,new e({authorityId:r.authorityId,typeId:r.typeId,versionMajor:r.versionMajor,versionMinor:r.versionMinor})),parameters:Object.fromEntries(n.parameters),fallback:n.fallback,compression:n.compression,content:n.content})),convoId:t.convoId,deliveryStatus:t.deliveryStatus,id:t.id,kind:t.kind,senderInboxId:t.senderInboxId,sentAtNs:t.sentAtNs};var n,r},v=e=>new i(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),I=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}),h=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(b),recoveryAddress:e.recoveryAddress}),S=e=>new o(e.entityType,e.state,e.entity),w={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};class x{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get id(){return this.#t.id()}get name(){return this.#t.groupName()}async updateName(e){return this.#t.updateGroupName(e)}get imageUrl(){return this.#t.groupImageUrlSquare()}async updateImageUrl(e){return this.#t.updateGroupImageUrlSquare(e)}get description(){return this.#t.groupDescription()}async updateDescription(e){return this.#t.updateGroupDescription(e)}get pinnedFrameUrl(){return this.#t.groupPinnedFrameUrl()}async updatePinnedFrameUrl(e){return this.#t.updateGroupPinnedFrameUrl(e)}get isActive(){return this.#t.isActive()}get addedByInboxId(){return this.#t.addedByInboxId()}get createdAtNs(){return this.#t.createdAtNs()}get metadata(){const e=this.#t.groupMetadata();return{creatorInboxId:e.creatorInboxId(),conversationType:e.conversationType()}}async members(){return(await this.#t.listMembers()).map((e=>(e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}))(e)))}get admins(){return this.#t.adminList()}get superAdmins(){return this.#t.superAdminList()}get permissions(){const e=this.#t.groupPermissions();return{policyType:e.policyType(),policySet:e.policySet()}}isAdmin(e){return this.#t.isAdmin(e)}isSuperAdmin(e){return this.#t.isSuperAdmin(e)}async sync(){return this.#t.sync()}async addMembers(e){return this.#t.addMembers(e)}async addMembersByInboxId(e){return this.#t.addMembersByInboxId(e)}async removeMembers(e){return this.#t.removeMembers(e)}async removeMembersByInboxId(e){return this.#t.removeMembersByInboxId(e)}async addAdmin(e){return this.#t.addAdmin(e)}async removeAdmin(e){return this.#t.removeAdmin(e)}async addSuperAdmin(e){return this.#t.addSuperAdmin(e)}async removeSuperAdmin(e){return this.#t.removeSuperAdmin(e)}async publishMessages(){return this.#t.publishMessages()}sendOptimistic(e){return this.#t.sendOptimistic(e)}async send(e){return this.#t.send(e)}messages(e){return this.#t.findMessages(e?(e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction))(e):void 0)}get consentState(){return this.#t.consentState()}updateConsentState(e){this.#t.updateConsentState(e)}dmPeerInboxId(){return this.#t.dmPeerInboxId()}}class A{#e;#n;constructor(e,t){this.#e=e,this.#n=t}async sync(){return this.#n.sync()}getConversationById(e){try{const t=this.#n.findGroupById(e);return new x(this.#e,t)}catch{return}}getMessageById(e){try{const t=this.#n.findMessageById(e);return y(t)}catch{return}}getDmByInboxId(e){try{const t=this.#n.findDmByTargetInboxId(e);return new x(this.#e,t)}catch{return}}async list(e){return(await this.#n.list(e?v(e):void 0)).map((e=>new x(this.#e,e)))}async listGroups(e){return(await this.#n.listGroups(e?v(e):void 0)).map((e=>new x(this.#e,e)))}async listDms(e){return(await this.#n.listDms(e?v(e):void 0)).map((e=>new x(this.#e,e)))}async newGroup(e,t){const n=await this.#n.createGroup(e,t?(e=>new s(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl))(t):void 0);return new x(this.#e,n)}async newDm(e){const t=await this.#n.createDm(e);return new x(this.#e,t)}}class G{#e;#n;#r;constructor(e){this.#e=e,this.#r=e.accountAddress,this.#n=new A(this,e.conversations())}static async create(e,n,r){const o=await(async(e,n,r)=>{await t();const o=r?.apiUrl??w[r?.env??"dev"],i=r?.dbPath??`xmtp-${r?.env??"dev"}-${e}.db3`,s=await d(o,e)||c(e),a=r&&(void 0!==r.loggingLevel||r.structuredLogging||r.performanceLogging);return u(o,s,e,i,n,void 0,a?new p(r.structuredLogging??!1,r.performanceLogging??!1,r.loggingLevel):void 0)})(e,n,r);return new G(o)}get accountAddress(){return this.#r}get inboxId(){return this.#e.inboxId}get installationId(){return this.#e.installationId}get isRegistered(){return this.#e.isRegistered}async createInboxSignatureText(){try{return await this.#e.createInboxSignatureText()}catch{return}}async addAccountSignatureText(e){try{return await this.#e.addWalletSignatureText(this.#r,e)}catch{return}}async removeAccountSignatureText(e){try{return await this.#e.revokeWalletSignatureText(e)}catch{return}}async revokeInstallationsSignatureText(){try{return await this.#e.revokeInstallationsSignatureText()}catch{return}}async addSignature(e,t){return this.#e.addSignature(e,t)}async addScwSignature(e,t,n,r){return this.#e.addScwSignature(e,t,n,r)}async applySignatures(){return this.#e.applySignatureRequests()}async canMessage(e){return this.#e.canMessage(e)}async registerIdentity(){return this.#e.registerIdentity()}async findInboxIdByAddress(e){return this.#e.findInboxIdByAddress(e)}async inboxState(e){return this.#e.inboxState(e)}async getLatestInboxState(e){return this.#e.getLatestInboxState(e)}async setConsentStates(e){return this.#e.setConsentStates(e.map(S))}async getConsentState(e,t){return this.#e.getConsentState(e,t)}get conversations(){return this.#n}}let k,f=!1;const M=e=>{self.postMessage(e)},B=e=>{self.postMessage(e)};self.onmessage=async e=>{const{action:t,id:n,data:r}=e.data;if(f&&console.log("client worker received event data",e.data),"init"===t||k)try{switch(t){case"init":k=await G.create(r.address,r.encryptionKey,r.options),f=void 0!==r.options?.loggingLevel&&"off"!==r.options.loggingLevel,M({id:n,action:t,result:{inboxId:k.inboxId,installationId:k.installationId}});break;case"createInboxSignatureText":{const e=await k.createInboxSignatureText();M({id:n,action:t,result:e});break}case"addAccountSignatureText":{const e=await k.addAccountSignatureText(r.newAccountAddress);M({id:n,action:t,result:e});break}case"removeAccountSignatureText":{const e=await k.removeAccountSignatureText(r.accountAddress);M({id:n,action:t,result:e});break}case"revokeInstallationsSignatureText":{const e=await k.revokeInstallationsSignatureText();M({id:n,action:t,result:e});break}case"addSignature":await k.addSignature(r.type,r.bytes),M({id:n,action:t,result:void 0});break;case"addScwSignature":await k.addScwSignature(r.type,r.bytes,r.chainId,r.blockNumber),M({id:n,action:t,result:void 0});break;case"applySignatures":await k.applySignatures(),M({id:n,action:t,result:void 0});break;case"registerIdentity":await k.registerIdentity(),M({id:n,action:t,result:void 0});break;case"isRegistered":{const e=k.isRegistered;M({id:n,action:t,result:e});break}case"canMessage":{const e=await k.canMessage(r.accountAddresses);M({id:n,action:t,result:e});break}case"inboxState":{const e=await k.inboxState(r.refreshFromNetwork);M({id:n,action:t,result:h(e)});break}case"getLatestInboxState":{const e=await k.getLatestInboxState(r.inboxId);M({id:n,action:t,result:h(e)});break}case"setConsentStates":await k.setConsentStates(r.records),M({id:n,action:t,result:void 0});break;case"getConsentState":{const e=await k.getConsentState(r.entityType,r.entity);M({id:n,action:t,result:e});break}case"findInboxIdByAddress":{const e=await k.findInboxIdByAddress(r.address);M({id:n,action:t,result:e});break}case"getConversations":{const e=await k.conversations.list(r.options);M({id:n,action:t,result:e.map((e=>I(e)))});break}case"getGroups":{const e=await k.conversations.listGroups(r.options);M({id:n,action:t,result:e.map((e=>I(e)))});break}case"getDms":{const e=await k.conversations.listDms(r.options);M({id:n,action:t,result:e.map((e=>I(e)))});break}case"newGroup":{const e=await k.conversations.newGroup(r.accountAddresses,r.options);M({id:n,action:t,result:I(e)});break}case"newDm":{const e=await k.conversations.newDm(r.accountAddress);M({id:n,action:t,result:I(e)});break}case"syncConversations":await k.conversations.sync(),M({id:n,action:t,result:void 0});break;case"getConversationById":{const e=k.conversations.getConversationById(r.id);M({id:n,action:t,result:e?I(e):void 0});break}case"getMessageById":{const e=k.conversations.getMessageById(r.id);M({id:n,action:t,result:e});break}case"getDmByInboxId":{const e=k.conversations.getDmByInboxId(r.inboxId);M({id:n,action:t,result:e?I(e):void 0});break}case"syncGroup":{const e=k.conversations.getConversationById(r.id);e?(await e.sync(),M({id:n,action:t,result:I(e)})):B({id:n,action:t,error:"Group not found"});break}case"updateGroupName":{const e=k.conversations.getConversationById(r.id);e?(await e.updateName(r.name),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"updateGroupDescription":{const e=k.conversations.getConversationById(r.id);e?(await e.updateDescription(r.description),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"updateGroupImageUrlSquare":{const e=k.conversations.getConversationById(r.id);e?(await e.updateImageUrl(r.imageUrl),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"updateGroupPinnedFrameUrl":{const e=k.conversations.getConversationById(r.id);e?(await e.updatePinnedFrameUrl(r.pinnedFrameUrl),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"sendGroupMessage":{const e=k.conversations.getConversationById(r.id);if(e){const o=await e.send(l(g(r.content)));M({id:n,action:t,result:o})}else B({id:n,action:t,error:"Group not found"});break}case"sendOptimisticGroupMessage":{const e=k.conversations.getConversationById(r.id);if(e){const o=e.sendOptimistic(l(g(r.content)));M({id:n,action:t,result:o})}else B({id:n,action:t,error:"Group not found"});break}case"publishGroupMessages":{const e=k.conversations.getConversationById(r.id);e?(await e.publishMessages(),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"getGroupMessages":{const e=k.conversations.getConversationById(r.id);if(e){const o=e.messages(r.options);M({id:n,action:t,result:o.map((e=>y(e)))})}else B({id:n,action:t,error:"Group not found"});break}case"getGroupMembers":{const e=k.conversations.getConversationById(r.id);if(e){const r=await e.members();M({id:n,action:t,result:r})}else B({id:n,action:t,error:"Group not found"});break}case"getGroupAdmins":{const e=k.conversations.getConversationById(r.id);e?M({id:n,action:t,result:e.admins}):B({id:n,action:t,error:"Group not found"});break}case"getGroupSuperAdmins":{const e=k.conversations.getConversationById(r.id);e?M({id:n,action:t,result:e.superAdmins}):B({id:n,action:t,error:"Group not found"});break}case"getGroupConsentState":{const e=k.conversations.getConversationById(r.id);e?M({id:n,action:t,result:e.consentState}):B({id:n,action:t,error:"Group not found"});break}case"updateGroupConsentState":{const e=k.conversations.getConversationById(r.id);e?(e.updateConsentState(r.state),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"addGroupAdmin":{const e=k.conversations.getConversationById(r.id);e?(await e.addAdmin(r.inboxId),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"removeGroupAdmin":{const e=k.conversations.getConversationById(r.id);e?(await e.removeAdmin(r.inboxId),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"addGroupSuperAdmin":{const e=k.conversations.getConversationById(r.id);e?(await e.addSuperAdmin(r.inboxId),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"removeGroupSuperAdmin":{const e=k.conversations.getConversationById(r.id);e?(await e.removeSuperAdmin(r.inboxId),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"addGroupMembers":{const e=k.conversations.getConversationById(r.id);e?(await e.addMembers(r.accountAddresses),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"removeGroupMembers":{const e=k.conversations.getConversationById(r.id);e?(await e.removeMembers(r.accountAddresses),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"addGroupMembersByInboxId":{const e=k.conversations.getConversationById(r.id);e?(await e.addMembersByInboxId(r.inboxIds),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"removeGroupMembersByInboxId":{const e=k.conversations.getConversationById(r.id);e?(await e.removeMembersByInboxId(r.inboxIds),M({id:n,action:t,result:void 0})):B({id:n,action:t,error:"Group not found"});break}case"isGroupAdmin":{const e=k.conversations.getConversationById(r.id);if(e){const o=e.isAdmin(r.inboxId);M({id:n,action:t,result:o})}else B({id:n,action:t,error:"Group not found"});break}case"isGroupSuperAdmin":{const e=k.conversations.getConversationById(r.id);if(e){const o=e.isSuperAdmin(r.inboxId);M({id:n,action:t,result:o})}else B({id:n,action:t,error:"Group not found"});break}case"getDmPeerInboxId":{const e=k.conversations.getConversationById(r.id);if(e){const r=e.dmPeerInboxId();M({id:n,action:t,result:r})}else B({id:n,action:t,error:"Group not found"});break}}}catch(e){B({id:n,action:t,error:e.message})}else B({id:n,action:t,error:"Client not initialized"})};
|
|
1
|
+
import{ContentTypeId as e}from"@xmtp/content-type-primitives";import t,{EncodedContent as n,ContentTypeId as i,Consent as r,ListConversationsOptions as s,CreateGroupOptions as o,ListMessagesOptions as a,getInboxIdForAddress as d,generateInboxId as c,createClient as u,LogOptions as p,verifySignedWithPublicKey as l}from"@xmtp/wasm-bindings";const g=e=>{return new n((t=e.type,new i(t.authorityId,t.typeId,t.versionMajor,t.versionMinor)),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content);var t},y=e=>{return{type:(t=e.type,{authorityId:t.authorityId,typeId:t.typeId,versionMajor:t.versionMajor,versionMinor:t.versionMinor}),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content};var t},m=t=>{return{type:(n=t.type,new e({authorityId:n.authorityId,typeId:n.typeId,versionMajor:n.versionMajor,versionMinor:n.versionMinor})),parameters:t.parameters,fallback:t.fallback,compression:t.compression,content:t.content};var n},v=t=>{return{content:y((n=t.content,{type:(i=n.type,new e({authorityId:i.authorityId,typeId:i.typeId,versionMajor:i.versionMajor,versionMinor:i.versionMinor})),parameters:Object.fromEntries(n.parameters),fallback:n.fallback,compression:n.compression,content:n.content})),convoId:t.convoId,deliveryStatus:t.deliveryStatus,id:t.id,kind:t.kind,senderInboxId:t.senderInboxId,sentAtNs:t.sentAtNs};var n,i},I=e=>new s(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),b=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}),h=e=>({id:e.id,clientTimestampNs:e.clientTimestampNs}),S=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(h),recoveryAddress:e.recoveryAddress}),w=e=>new r(e.entityType,e.state,e.entity),x={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};class A{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get id(){return this.#t.id()}get name(){return this.#t.groupName()}async updateName(e){return this.#t.updateGroupName(e)}get imageUrl(){return this.#t.groupImageUrlSquare()}async updateImageUrl(e){return this.#t.updateGroupImageUrlSquare(e)}get description(){return this.#t.groupDescription()}async updateDescription(e){return this.#t.updateGroupDescription(e)}get pinnedFrameUrl(){return this.#t.groupPinnedFrameUrl()}async updatePinnedFrameUrl(e){return this.#t.updateGroupPinnedFrameUrl(e)}get isActive(){return this.#t.isActive()}get addedByInboxId(){return this.#t.addedByInboxId()}get createdAtNs(){return this.#t.createdAtNs()}get metadata(){const e=this.#t.groupMetadata();return{creatorInboxId:e.creatorInboxId(),conversationType:e.conversationType()}}async members(){return(await this.#t.listMembers()).map((e=>(e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}))(e)))}get admins(){return this.#t.adminList()}get superAdmins(){return this.#t.superAdminList()}get permissions(){const e=this.#t.groupPermissions();return{policyType:e.policyType(),policySet:e.policySet()}}isAdmin(e){return this.#t.isAdmin(e)}isSuperAdmin(e){return this.#t.isSuperAdmin(e)}async sync(){return this.#t.sync()}async addMembers(e){return this.#t.addMembers(e)}async addMembersByInboxId(e){return this.#t.addMembersByInboxId(e)}async removeMembers(e){return this.#t.removeMembers(e)}async removeMembersByInboxId(e){return this.#t.removeMembersByInboxId(e)}async addAdmin(e){return this.#t.addAdmin(e)}async removeAdmin(e){return this.#t.removeAdmin(e)}async addSuperAdmin(e){return this.#t.addSuperAdmin(e)}async removeSuperAdmin(e){return this.#t.removeSuperAdmin(e)}async publishMessages(){return this.#t.publishMessages()}sendOptimistic(e){return this.#t.sendOptimistic(e)}async send(e){return this.#t.send(e)}messages(e){return this.#t.findMessages(e?(e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction))(e):void 0)}get consentState(){return this.#t.consentState()}updateConsentState(e){this.#t.updateConsentState(e)}dmPeerInboxId(){return this.#t.dmPeerInboxId()}}class k{#e;#n;constructor(e,t){this.#e=e,this.#n=t}async sync(){return this.#n.sync()}async syncAll(){return this.#n.syncAllConversations()}getConversationById(e){try{const t=this.#n.findGroupById(e);return new A(this.#e,t)}catch{return}}getMessageById(e){try{const t=this.#n.findMessageById(e);return v(t)}catch{return}}getDmByInboxId(e){try{const t=this.#n.findDmByTargetInboxId(e);return new A(this.#e,t)}catch{return}}async list(e){return(await this.#n.list(e?I(e):void 0)).map((e=>new A(this.#e,e)))}async listGroups(e){return(await this.#n.listGroups(e?I(e):void 0)).map((e=>new A(this.#e,e)))}async listDms(e){return(await this.#n.listDms(e?I(e):void 0)).map((e=>new A(this.#e,e)))}async newGroup(e,t){const n=await this.#n.createGroup(e,t?(e=>new o(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl))(t):void 0);return new A(this.#e,n)}async newDm(e){const t=await this.#n.createDm(e);return new A(this.#e,t)}}class f{#e;#n;#i;constructor(e){this.#e=e,this.#i=e.accountAddress,this.#n=new k(this,e.conversations())}static async create(e,n,i){const r=await(async(e,n,i)=>{await t();const r=i?.apiUrl??x[i?.env??"dev"],s=i?.dbPath??`xmtp-${i?.env??"dev"}-${e}.db3`,o=await d(r,e)||c(e),a=i&&(void 0!==i.loggingLevel||i.structuredLogging||i.performanceLogging);return u(r,o,e,s,n,void 0,a?new p(i.structuredLogging??!1,i.performanceLogging??!1,i.loggingLevel):void 0)})(e,n,i);return new f(r)}get accountAddress(){return this.#i}get inboxId(){return this.#e.inboxId}get installationId(){return this.#e.installationId}get installationIdBytes(){return this.#e.installationIdBytes}get isRegistered(){return this.#e.isRegistered}async createInboxSignatureText(){try{return await this.#e.createInboxSignatureText()}catch{return}}async addAccountSignatureText(e){try{return await this.#e.addWalletSignatureText(e)}catch{return}}async removeAccountSignatureText(e){try{return await this.#e.revokeWalletSignatureText(e)}catch{return}}async revokeInstallationsSignatureText(){try{return await this.#e.revokeInstallationsSignatureText()}catch{return}}async addSignature(e,t){return this.#e.addSignature(e,t)}async addScwSignature(e,t,n,i){return this.#e.addScwSignature(e,t,n,i)}async applySignatures(){return this.#e.applySignatureRequests()}async canMessage(e){return this.#e.canMessage(e)}async registerIdentity(){return this.#e.registerIdentity()}async findInboxIdByAddress(e){return this.#e.findInboxIdByAddress(e)}async inboxState(e){return this.#e.inboxState(e)}async getLatestInboxState(e){return this.#e.getLatestInboxState(e)}async setConsentStates(e){return this.#e.setConsentStates(e.map(w))}async getConsentState(e,t){return this.#e.getConsentState(e,t)}get conversations(){return this.#n}signWithInstallationKey(e){return this.#e.signWithInstallationKey(e)}verifySignedWithInstallationKey(e,t){try{return this.#e.verifySignedWithInstallationKey(e,t),!0}catch{return!1}}verifySignedWithPublicKey(e,t,n){try{return l(e,t,n),!0}catch{return!1}}}let G,B=!1;const M=e=>{self.postMessage(e)},C=e=>{self.postMessage(e)};self.onmessage=async e=>{const{action:t,id:n,data:i}=e.data;if(B&&console.log("client worker received event data",e.data),"init"===t||G)try{switch(t){case"init":G=await f.create(i.address,i.encryptionKey,i.options),B=void 0!==i.options?.loggingLevel&&"off"!==i.options.loggingLevel,M({id:n,action:t,result:{inboxId:G.inboxId,installationId:G.installationId,installationIdBytes:G.installationIdBytes}});break;case"createInboxSignatureText":{const e=await G.createInboxSignatureText();M({id:n,action:t,result:e});break}case"addAccountSignatureText":{const e=await G.addAccountSignatureText(i.newAccountAddress);M({id:n,action:t,result:e});break}case"removeAccountSignatureText":{const e=await G.removeAccountSignatureText(i.accountAddress);M({id:n,action:t,result:e});break}case"revokeInstallationsSignatureText":{const e=await G.revokeInstallationsSignatureText();M({id:n,action:t,result:e});break}case"addSignature":await G.addSignature(i.type,i.bytes),M({id:n,action:t,result:void 0});break;case"addScwSignature":await G.addScwSignature(i.type,i.bytes,i.chainId,i.blockNumber),M({id:n,action:t,result:void 0});break;case"applySignatures":await G.applySignatures(),M({id:n,action:t,result:void 0});break;case"registerIdentity":await G.registerIdentity(),M({id:n,action:t,result:void 0});break;case"isRegistered":{const e=G.isRegistered;M({id:n,action:t,result:e});break}case"canMessage":{const e=await G.canMessage(i.accountAddresses);M({id:n,action:t,result:e});break}case"inboxState":{const e=await G.inboxState(i.refreshFromNetwork);M({id:n,action:t,result:S(e)});break}case"getLatestInboxState":{const e=await G.getLatestInboxState(i.inboxId);M({id:n,action:t,result:S(e)});break}case"setConsentStates":await G.setConsentStates(i.records),M({id:n,action:t,result:void 0});break;case"getConsentState":{const e=await G.getConsentState(i.entityType,i.entity);M({id:n,action:t,result:e});break}case"findInboxIdByAddress":{const e=await G.findInboxIdByAddress(i.address);M({id:n,action:t,result:e});break}case"signWithInstallationKey":{const e=G.signWithInstallationKey(i.signatureText);M({id:n,action:t,result:e});break}case"verifySignedWithInstallationKey":{const e=G.verifySignedWithInstallationKey(i.signatureText,i.signatureBytes);M({id:n,action:t,result:e});break}case"verifySignedWithPublicKey":{const e=G.verifySignedWithPublicKey(i.signatureText,i.signatureBytes,i.publicKey);M({id:n,action:t,result:e});break}case"getConversations":{const e=await G.conversations.list(i.options);M({id:n,action:t,result:e.map((e=>b(e)))});break}case"getGroups":{const e=await G.conversations.listGroups(i.options);M({id:n,action:t,result:e.map((e=>b(e)))});break}case"getDms":{const e=await G.conversations.listDms(i.options);M({id:n,action:t,result:e.map((e=>b(e)))});break}case"newGroup":{const e=await G.conversations.newGroup(i.accountAddresses,i.options);M({id:n,action:t,result:b(e)});break}case"newDm":{const e=await G.conversations.newDm(i.accountAddress);M({id:n,action:t,result:b(e)});break}case"syncConversations":await G.conversations.sync(),M({id:n,action:t,result:void 0});break;case"syncAllConversations":await G.conversations.syncAll(),M({id:n,action:t,result:void 0});break;case"getConversationById":{const e=G.conversations.getConversationById(i.id);M({id:n,action:t,result:e?b(e):void 0});break}case"getMessageById":{const e=G.conversations.getMessageById(i.id);M({id:n,action:t,result:e});break}case"getDmByInboxId":{const e=G.conversations.getDmByInboxId(i.inboxId);M({id:n,action:t,result:e?b(e):void 0});break}case"syncGroup":{const e=G.conversations.getConversationById(i.id);e?(await e.sync(),M({id:n,action:t,result:b(e)})):C({id:n,action:t,error:"Group not found"});break}case"updateGroupName":{const e=G.conversations.getConversationById(i.id);e?(await e.updateName(i.name),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"updateGroupDescription":{const e=G.conversations.getConversationById(i.id);e?(await e.updateDescription(i.description),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"updateGroupImageUrlSquare":{const e=G.conversations.getConversationById(i.id);e?(await e.updateImageUrl(i.imageUrl),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"updateGroupPinnedFrameUrl":{const e=G.conversations.getConversationById(i.id);e?(await e.updatePinnedFrameUrl(i.pinnedFrameUrl),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"sendGroupMessage":{const e=G.conversations.getConversationById(i.id);if(e){const r=await e.send(g(m(i.content)));M({id:n,action:t,result:r})}else C({id:n,action:t,error:"Group not found"});break}case"sendOptimisticGroupMessage":{const e=G.conversations.getConversationById(i.id);if(e){const r=e.sendOptimistic(g(m(i.content)));M({id:n,action:t,result:r})}else C({id:n,action:t,error:"Group not found"});break}case"publishGroupMessages":{const e=G.conversations.getConversationById(i.id);e?(await e.publishMessages(),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"getGroupMessages":{const e=G.conversations.getConversationById(i.id);if(e){const r=e.messages(i.options);M({id:n,action:t,result:r.map((e=>v(e)))})}else C({id:n,action:t,error:"Group not found"});break}case"getGroupMembers":{const e=G.conversations.getConversationById(i.id);if(e){const i=await e.members();M({id:n,action:t,result:i})}else C({id:n,action:t,error:"Group not found"});break}case"getGroupAdmins":{const e=G.conversations.getConversationById(i.id);e?M({id:n,action:t,result:e.admins}):C({id:n,action:t,error:"Group not found"});break}case"getGroupSuperAdmins":{const e=G.conversations.getConversationById(i.id);e?M({id:n,action:t,result:e.superAdmins}):C({id:n,action:t,error:"Group not found"});break}case"getGroupConsentState":{const e=G.conversations.getConversationById(i.id);e?M({id:n,action:t,result:e.consentState}):C({id:n,action:t,error:"Group not found"});break}case"updateGroupConsentState":{const e=G.conversations.getConversationById(i.id);e?(e.updateConsentState(i.state),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"addGroupAdmin":{const e=G.conversations.getConversationById(i.id);e?(await e.addAdmin(i.inboxId),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"removeGroupAdmin":{const e=G.conversations.getConversationById(i.id);e?(await e.removeAdmin(i.inboxId),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"addGroupSuperAdmin":{const e=G.conversations.getConversationById(i.id);e?(await e.addSuperAdmin(i.inboxId),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"removeGroupSuperAdmin":{const e=G.conversations.getConversationById(i.id);e?(await e.removeSuperAdmin(i.inboxId),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"addGroupMembers":{const e=G.conversations.getConversationById(i.id);e?(await e.addMembers(i.accountAddresses),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"removeGroupMembers":{const e=G.conversations.getConversationById(i.id);e?(await e.removeMembers(i.accountAddresses),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"addGroupMembersByInboxId":{const e=G.conversations.getConversationById(i.id);e?(await e.addMembersByInboxId(i.inboxIds),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"removeGroupMembersByInboxId":{const e=G.conversations.getConversationById(i.id);e?(await e.removeMembersByInboxId(i.inboxIds),M({id:n,action:t,result:void 0})):C({id:n,action:t,error:"Group not found"});break}case"isGroupAdmin":{const e=G.conversations.getConversationById(i.id);if(e){const r=e.isAdmin(i.inboxId);M({id:n,action:t,result:r})}else C({id:n,action:t,error:"Group not found"});break}case"isGroupSuperAdmin":{const e=G.conversations.getConversationById(i.id);if(e){const r=e.isSuperAdmin(i.inboxId);M({id:n,action:t,result:r})}else C({id:n,action:t,error:"Group not found"});break}case"getDmPeerInboxId":{const e=G.conversations.getConversationById(i.id);if(e){const i=e.dmPeerInboxId();M({id:n,action:t,result:i})}else C({id:n,action:t,error:"Group not found"});break}}}catch(e){C({id:n,action:t,error:e.message})}else C({id:n,action:t,error:"Client not initialized"})};
|
|
2
2
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../src/utils/conversions.ts","../../src/constants.ts","../../src/WorkerConversation.ts","../../src/WorkerConversations.ts","../../src/WorkerClient.ts","../../src/utils/createClient.ts","../../src/workers/client.ts"],"sourcesContent":["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","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n","import type {\n ConsentState,\n Conversation,\n EncodedContent,\n GroupMember,\n} from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeListMessagesOptions,\n toSafeGroupMember,\n type SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\n\nexport class WorkerConversation {\n // eslint-disable-next-line no-unused-private-class-members\n #client: WorkerClient;\n\n #group: Conversation;\n\n constructor(client: WorkerClient, group: Conversation) {\n this.#client = client;\n this.#group = group;\n }\n\n get id() {\n return this.#group.id();\n }\n\n get name() {\n return this.#group.groupName();\n }\n\n async updateName(name: string) {\n return this.#group.updateGroupName(name);\n }\n\n get imageUrl() {\n return this.#group.groupImageUrlSquare();\n }\n\n async updateImageUrl(imageUrl: string) {\n return this.#group.updateGroupImageUrlSquare(imageUrl);\n }\n\n get description() {\n return this.#group.groupDescription();\n }\n\n async updateDescription(description: string) {\n return this.#group.updateGroupDescription(description);\n }\n\n get pinnedFrameUrl() {\n return this.#group.groupPinnedFrameUrl();\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);\n }\n\n get isActive() {\n return this.#group.isActive();\n }\n\n get addedByInboxId() {\n return this.#group.addedByInboxId();\n }\n\n get createdAtNs() {\n return this.#group.createdAtNs();\n }\n\n get metadata() {\n const metadata = this.#group.groupMetadata();\n return {\n creatorInboxId: metadata.creatorInboxId(),\n conversationType: metadata.conversationType(),\n };\n }\n\n async members() {\n const members = (await this.#group.listMembers()) as GroupMember[];\n return members.map((member) => toSafeGroupMember(member));\n }\n\n get admins() {\n return this.#group.adminList();\n }\n\n get superAdmins() {\n return this.#group.superAdminList();\n }\n\n get permissions() {\n const permissions = this.#group.groupPermissions();\n return {\n policyType: permissions.policyType(),\n policySet: permissions.policySet(),\n };\n }\n\n isAdmin(inboxId: string) {\n return this.#group.isAdmin(inboxId);\n }\n\n isSuperAdmin(inboxId: string) {\n return this.#group.isSuperAdmin(inboxId);\n }\n\n async sync() {\n return this.#group.sync();\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#group.addMembers(accountAddresses);\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#group.addMembersByInboxId(inboxIds);\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#group.removeMembers(accountAddresses);\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#group.removeMembersByInboxId(inboxIds);\n }\n\n async addAdmin(inboxId: string) {\n return this.#group.addAdmin(inboxId);\n }\n\n async removeAdmin(inboxId: string) {\n return this.#group.removeAdmin(inboxId);\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#group.addSuperAdmin(inboxId);\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#group.removeSuperAdmin(inboxId);\n }\n\n async publishMessages() {\n return this.#group.publishMessages();\n }\n\n sendOptimistic(encodedContent: EncodedContent) {\n return this.#group.sendOptimistic(encodedContent);\n }\n\n async send(encodedContent: EncodedContent) {\n return this.#group.send(encodedContent);\n }\n\n messages(options?: SafeListMessagesOptions) {\n return this.#group.findMessages(\n options ? fromSafeListMessagesOptions(options) : undefined,\n );\n }\n\n get consentState() {\n return this.#group.consentState();\n }\n\n updateConsentState(state: ConsentState) {\n this.#group.updateConsentState(state);\n }\n\n dmPeerInboxId() {\n return this.#group.dmPeerInboxId();\n }\n}\n","import type { Conversation, Conversations } from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeCreateGroupOptions,\n fromSafeListConversationsOptions,\n toSafeMessage,\n type SafeCreateGroupOptions,\n type SafeListConversationsOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\nimport { WorkerConversation } from \"@/WorkerConversation\";\n\nexport class WorkerConversations {\n #client: WorkerClient;\n\n #conversations: Conversations;\n\n constructor(client: WorkerClient, conversations: Conversations) {\n this.#client = client;\n this.#conversations = conversations;\n }\n\n async sync() {\n return this.#conversations.sync();\n }\n\n getConversationById(id: string) {\n try {\n const group = this.#conversations.findGroupById(id);\n // findGroupById will throw if group is not found\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n getMessageById(id: string) {\n try {\n // findMessageById will throw if message is not found\n const message = this.#conversations.findMessageById(id);\n return toSafeMessage(message);\n } catch {\n return undefined;\n }\n }\n\n getDmByInboxId(inboxId: string) {\n try {\n const group = this.#conversations.findDmByTargetInboxId(inboxId);\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n async list(options?: SafeListConversationsOptions) {\n const groups = (await this.#conversations.list(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listGroups(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listDms(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const group = await this.#conversations.createGroup(\n accountAddresses,\n options ? fromSafeCreateGroupOptions(options) : undefined,\n );\n return new WorkerConversation(this.#client, group);\n }\n\n async newDm(accountAddress: string) {\n const group = await this.#conversations.createDm(accountAddress);\n return new WorkerConversation(this.#client, group);\n }\n}\n","import {\n type Client,\n type ConsentEntityType,\n type SignatureRequestType,\n} from \"@xmtp/wasm-bindings\";\nimport type { ClientOptions } from \"@/types\";\nimport { fromSafeConsent, type SafeConsent } from \"@/utils/conversions\";\nimport { createClient } from \"@/utils/createClient\";\nimport { WorkerConversations } from \"@/WorkerConversations\";\n\nexport class WorkerClient {\n #client: Client;\n\n #conversations: WorkerConversations;\n\n #accountAddress: string;\n\n constructor(client: Client) {\n this.#client = client;\n this.#accountAddress = client.accountAddress;\n this.#conversations = new WorkerConversations(this, client.conversations());\n }\n\n static async create(\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n ) {\n const client = await createClient(accountAddress, encryptionKey, options);\n return new WorkerClient(client);\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n get inboxId() {\n return this.#client.inboxId;\n }\n\n get installationId() {\n return this.#client.installationId;\n }\n\n get isRegistered() {\n return this.#client.isRegistered;\n }\n\n async createInboxSignatureText() {\n try {\n return await this.#client.createInboxSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addAccountSignatureText(accountAddress: string) {\n try {\n return await this.#client.addWalletSignatureText(\n this.#accountAddress,\n accountAddress,\n );\n } catch {\n return undefined;\n }\n }\n\n async removeAccountSignatureText(accountAddress: string) {\n try {\n return await this.#client.revokeWalletSignatureText(accountAddress);\n } catch {\n return undefined;\n }\n }\n\n async revokeInstallationsSignatureText() {\n try {\n return await this.#client.revokeInstallationsSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addSignature(type: SignatureRequestType, bytes: Uint8Array) {\n return this.#client.addSignature(type, bytes);\n }\n\n async addScwSignature(\n type: SignatureRequestType,\n bytes: Uint8Array,\n chainId: bigint,\n blockNumber?: bigint,\n ) {\n return this.#client.addScwSignature(type, bytes, chainId, blockNumber);\n }\n\n async applySignatures() {\n return this.#client.applySignatureRequests();\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.#client.canMessage(accountAddresses) as Promise<\n Map<string, boolean>\n >;\n }\n\n async registerIdentity() {\n return this.#client.registerIdentity();\n }\n\n async findInboxIdByAddress(address: string) {\n return this.#client.findInboxIdByAddress(address);\n }\n\n async inboxState(refreshFromNetwork: boolean) {\n return this.#client.inboxState(refreshFromNetwork);\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.#client.getLatestInboxState(inboxId);\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.#client.setConsentStates(records.map(fromSafeConsent));\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.#client.getConsentState(entityType, entity);\n }\n\n get conversations() {\n return this.#conversations;\n }\n}\n","import init, {\n createClient as createWasmClient,\n generateInboxId,\n getInboxIdForAddress,\n LogOptions,\n} from \"@xmtp/wasm-bindings\";\nimport { ApiUrls } from \"@/constants\";\nimport type { ClientOptions } from \"@/types\";\n\nexport const createClient = async (\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n) => {\n // initialize WASM module\n await init();\n\n const host = options?.apiUrl ?? ApiUrls[options?.env ?? \"dev\"];\n // TODO: add db path validation\n // - must end with .db3\n // - must not contain invalid characters\n // - must not start with a dot\n const dbPath =\n options?.dbPath ?? `xmtp-${options?.env ?? \"dev\"}-${accountAddress}.db3`;\n\n const inboxId =\n (await getInboxIdForAddress(host, accountAddress)) ||\n generateInboxId(accountAddress);\n\n const isLogging =\n options &&\n (options.loggingLevel !== undefined ||\n options.structuredLogging ||\n options.performanceLogging);\n\n return createWasmClient(\n host,\n inboxId,\n accountAddress,\n dbPath,\n encryptionKey,\n undefined,\n isLogging\n ? new LogOptions(\n options.structuredLogging ?? false,\n options.performanceLogging ?? false,\n options.loggingLevel,\n )\n : undefined,\n );\n};\n","import type {\n ClientEventsActions,\n ClientEventsClientMessageData,\n ClientEventsErrorData,\n ClientEventsWorkerPostMessageData,\n} from \"@/types\";\nimport {\n fromEncodedContent,\n fromSafeEncodedContent,\n toSafeConversation,\n toSafeInboxState,\n toSafeMessage,\n} from \"@/utils/conversions\";\nimport { WorkerClient } from \"@/WorkerClient\";\n\nlet client: WorkerClient;\nlet enableLogging = false;\n\n/**\n * Type-safe postMessage\n */\nconst postMessage = <A extends ClientEventsActions>(\n data: ClientEventsWorkerPostMessageData<A>,\n) => {\n self.postMessage(data);\n};\n\n/**\n * Type-safe postMessage for errors\n */\nconst postMessageError = (data: ClientEventsErrorData) => {\n self.postMessage(data);\n};\n\nself.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {\n const { action, id, data } = event.data;\n\n if (enableLogging) {\n console.log(\"client worker received event data\", event.data);\n }\n\n // a client is required for all actions except init\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (action !== \"init\" && !client) {\n postMessageError({\n id,\n action,\n error: \"Client not initialized\",\n });\n return;\n }\n\n try {\n switch (action) {\n /**\n * Client actions\n */\n case \"init\":\n client = await WorkerClient.create(\n data.address,\n data.encryptionKey,\n data.options,\n );\n enableLogging =\n data.options?.loggingLevel !== undefined &&\n data.options.loggingLevel !== \"off\";\n postMessage({\n id,\n action,\n result: {\n inboxId: client.inboxId,\n installationId: client.installationId,\n },\n });\n break;\n case \"createInboxSignatureText\": {\n const result = await client.createInboxSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addAccountSignatureText\": {\n const result = await client.addAccountSignatureText(\n data.newAccountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"removeAccountSignatureText\": {\n const result = await client.removeAccountSignatureText(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"revokeInstallationsSignatureText\": {\n const result = await client.revokeInstallationsSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addSignature\":\n await client.addSignature(data.type, data.bytes);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"addScwSignature\":\n await client.addScwSignature(\n data.type,\n data.bytes,\n data.chainId,\n data.blockNumber,\n );\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"applySignatures\":\n await client.applySignatures();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"registerIdentity\":\n await client.registerIdentity();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"isRegistered\": {\n const result = client.isRegistered;\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"canMessage\": {\n const result = await client.canMessage(data.accountAddresses);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"inboxState\": {\n const result = await client.inboxState(data.refreshFromNetwork);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"getLatestInboxState\": {\n const result = await client.getLatestInboxState(data.inboxId);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"setConsentStates\": {\n await client.setConsentStates(data.records);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConsentState\": {\n const result = await client.getConsentState(\n data.entityType,\n data.entity,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"findInboxIdByAddress\": {\n const result = await client.findInboxIdByAddress(data.address);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n /**\n * Conversations actions\n */\n case \"getConversations\": {\n const conversations = await client.conversations.list(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getGroups\": {\n const conversations = await client.conversations.listGroups(\n data.options,\n );\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getDms\": {\n const conversations = await client.conversations.listDms(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"newGroup\": {\n const conversation = await client.conversations.newGroup(\n data.accountAddresses,\n data.options,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"newDm\": {\n const conversation = await client.conversations.newDm(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"syncConversations\": {\n await client.conversations.sync();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConversationById\": {\n const conversation = client.conversations.getConversationById(data.id);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n case \"getMessageById\": {\n const message = client.conversations.getMessageById(data.id);\n postMessage({\n id,\n action,\n result: message,\n });\n break;\n }\n case \"getDmByInboxId\": {\n const conversation = client.conversations.getDmByInboxId(data.inboxId);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n /**\n * Group actions\n */\n case \"syncGroup\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.sync();\n postMessage({\n id,\n action,\n result: toSafeConversation(group),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupName\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateName(data.name);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupDescription\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateDescription(data.description);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupImageUrlSquare\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateImageUrl(data.imageUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupPinnedFrameUrl\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updatePinnedFrameUrl(data.pinnedFrameUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.send(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendOptimisticGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.sendOptimistic(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"publishGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.publishMessages();\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const messages = group.messages(data.options);\n postMessage({\n id,\n action,\n result: messages.map((message) => toSafeMessage(message)),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.members();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.admins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupSuperAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.superAdmins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.consentState,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n group.updateConsentState(data.state);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getDmPeerInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.dmPeerInboxId();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n }\n } catch (e) {\n postMessageError({\n id,\n action,\n error: (e as Error).message,\n });\n }\n};\n"],"names":["fromEncodedContent","content","WasmEncodedContent","contentTypeId","type","WasmContentTypeId","authorityId","typeId","versionMajor","versionMinor","Map","Object","entries","parameters","fallback","compression","toSafeEncodedContent","fromSafeEncodedContent","ContentTypeId","toSafeMessage","message","fromEntries","convoId","deliveryStatus","id","kind","senderInboxId","sentAtNs","fromSafeListConversationsOptions","options","ListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","limit","toSafeConversation","conversation","name","imageUrl","description","pinnedFrameUrl","permissions","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","fromSafeConsent","consent","Consent","entityType","state","entity","ApiUrls","local","dev","production","WorkerConversation","client","group","constructor","this","groupName","updateName","updateGroupName","groupImageUrlSquare","updateImageUrl","updateGroupImageUrlSquare","groupDescription","updateDescription","updateGroupDescription","groupPinnedFrameUrl","updatePinnedFrameUrl","updateGroupPinnedFrameUrl","groupMetadata","creatorInboxId","members","listMembers","member","consentState","installationIds","permissionLevel","toSafeGroupMember","adminList","superAdminList","groupPermissions","isAdmin","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","encodedContent","send","messages","findMessages","ListMessagesOptions","sentBeforeNs","sentAfterNs","direction","fromSafeListMessagesOptions","undefined","updateConsentState","dmPeerInboxId","WorkerConversations","conversations","getConversationById","findGroupById","getMessageById","findMessageById","getDmByInboxId","findDmByTargetInboxId","list","listGroups","listDms","newGroup","createGroup","CreateGroupOptions","imageUrlSquare","fromSafeCreateGroupOptions","newDm","accountAddress","createDm","WorkerClient","create","encryptionKey","async","init","host","apiUrl","env","dbPath","getInboxIdForAddress","generateInboxId","isLogging","loggingLevel","structuredLogging","performanceLogging","createWasmClient","LogOptions","createClient","installationId","isRegistered","createInboxSignatureText","addAccountSignatureText","addWalletSignatureText","removeAccountSignatureText","revokeWalletSignatureText","revokeInstallationsSignatureText","addSignature","bytes","addScwSignature","chainId","blockNumber","applySignatures","applySignatureRequests","canMessage","registerIdentity","findInboxIdByAddress","address","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","enableLogging","postMessage","data","self","postMessageError","onmessage","event","action","console","log","result","newAccountAddress","error","e"],"mappings":"sTA4BO,MAyDMA,EACXC,IAEA,WAAIC,GAjDJC,EAkDoBF,EAAQG,KAhD5B,IAAIC,EACFF,EAAcG,YACdH,EAAcI,OACdJ,EAAcK,aACdL,EAAcM,eA6Cd,IAAIC,IAAIC,OAAOC,QAAQX,EAAQY,aAC/BZ,EAAQa,SACRb,EAAQc,YACRd,EAAQA,SAvDqB,IAC/BE,CAuDC,EAUUa,EACXf,IACwB,OACxBG,MAnDAD,EAmD0BF,EAAQG,KAlDX,CACvBE,YAAaH,EAAcG,YAC3BC,OAAQJ,EAAcI,OACtBC,aAAcL,EAAcK,aAC5BC,aAAcN,EAAcM,eA+C5BI,WAAYZ,EAAQY,WACpBC,SAAUb,EAAQa,SAClBC,YAAad,EAAQc,YACrBd,QAASA,EAAQA,SAxDgB,IACjCE,CAwDA,EAEWc,EACXhB,IACoB,OACpBG,MApDAD,EAoD4BF,EAAQG,KAlDpC,IAAIc,EAAc,CAChBZ,YAAaH,EAAcG,YAC3BC,OAAQJ,EAAcI,OACtBC,aAAcL,EAAcK,aAC5BC,aAAcN,EAAcM,gBA+C9BI,WAAYZ,EAAQY,WACpBC,SAAUb,EAAQa,SAClBC,YAAad,EAAQc,YACrBd,QAASA,EAAQA,SAzDkB,IACnCE,CAyDA,EAYWgB,EAAiBC,IAAmC,OAC/DnB,QAASe,GA5DTf,EA4D+CmB,EAAQnB,QA3DnC,CAEpBG,MAjDAD,EAiDsBF,EAAQG,KA/C9B,IAAIc,EAAc,CAChBZ,YAAaH,EAAcG,YAC3BC,OAAQJ,EAAcI,OACtBC,aAAcL,EAAcK,aAC5BC,aAAcN,EAAcM,gBA4C9BI,WAAYF,OAAOU,YAAYpB,EAAQY,YACvCC,SAAUb,EAAQa,SAClBC,YAAad,EAAQc,YACrBd,QAASA,EAAQA,WAsDjBqB,QAASF,EAAQE,QACjBC,eAAgBH,EAAQG,eACxBC,GAAIJ,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EF,IAAK,8BAA+B,CAClC,MAAM9H,EAAQD,EAAOuD,cAAcC,oBAAoB6D,EAAK7K,IACxDyD,SACIA,EAAMkC,uBAAuBkF,EAAKpF,UACxCmF,EAAY,CACV5K,KACAkL,SACAG,YAAQ1E,KAGVoE,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,MAEF,IAAK,eAAgB,CACnB,MAAM9H,EAAQD,EAAOuD,cAAcC,oBAAoB6D,EAAK7K,IAC5D,GAAIyD,EAAO,CACT,MAAM4H,EAAS5H,EAAM2B,QAAQyF,EAAKpI,SAClCmI,EAAY,CACV5K,KACAkL,SACAG,gBAGFN,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,MAEF,IAAK,oBAAqB,CACxB,MAAM9H,EAAQD,EAAOuD,cAAcC,oBAAoB6D,EAAK7K,IAC5D,GAAIyD,EAAO,CACT,MAAM4H,EAAS5H,EAAM4B,aAAawF,EAAKpI,SACvCmI,EAAY,CACV5K,KACAkL,SACAG,gBAGFN,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,MAEF,IAAK,mBAAoB,CACvB,MAAM9H,EAAQD,EAAOuD,cAAcC,oBAAoB6D,EAAK7K,IAC5D,GAAIyD,EAAO,CACT,MAAM4H,EAAS5H,EAAMoD,gBACrB+D,EAAY,CACV5K,KACAkL,SACAG,gBAGFN,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,QAGJ,MAAOC,GACPT,EAAiB,CACf/K,KACAkL,SACAK,MAAQC,EAAY5L,eA1tBtBmL,EAAiB,CACf/K,KACAkL,SACAK,MAAO"}
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/utils/conversions.ts","../../src/constants.ts","../../src/WorkerConversation.ts","../../src/WorkerConversations.ts","../../src/WorkerClient.ts","../../src/utils/createClient.ts","../../src/workers/client.ts"],"sourcesContent":["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","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n","import type {\n ConsentState,\n Conversation,\n EncodedContent,\n GroupMember,\n} from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeListMessagesOptions,\n toSafeGroupMember,\n type SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\n\nexport class WorkerConversation {\n // eslint-disable-next-line no-unused-private-class-members\n #client: WorkerClient;\n\n #group: Conversation;\n\n constructor(client: WorkerClient, group: Conversation) {\n this.#client = client;\n this.#group = group;\n }\n\n get id() {\n return this.#group.id();\n }\n\n get name() {\n return this.#group.groupName();\n }\n\n async updateName(name: string) {\n return this.#group.updateGroupName(name);\n }\n\n get imageUrl() {\n return this.#group.groupImageUrlSquare();\n }\n\n async updateImageUrl(imageUrl: string) {\n return this.#group.updateGroupImageUrlSquare(imageUrl);\n }\n\n get description() {\n return this.#group.groupDescription();\n }\n\n async updateDescription(description: string) {\n return this.#group.updateGroupDescription(description);\n }\n\n get pinnedFrameUrl() {\n return this.#group.groupPinnedFrameUrl();\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);\n }\n\n get isActive() {\n return this.#group.isActive();\n }\n\n get addedByInboxId() {\n return this.#group.addedByInboxId();\n }\n\n get createdAtNs() {\n return this.#group.createdAtNs();\n }\n\n get metadata() {\n const metadata = this.#group.groupMetadata();\n return {\n creatorInboxId: metadata.creatorInboxId(),\n conversationType: metadata.conversationType(),\n };\n }\n\n async members() {\n const members = (await this.#group.listMembers()) as GroupMember[];\n return members.map((member) => toSafeGroupMember(member));\n }\n\n get admins() {\n return this.#group.adminList();\n }\n\n get superAdmins() {\n return this.#group.superAdminList();\n }\n\n get permissions() {\n const permissions = this.#group.groupPermissions();\n return {\n policyType: permissions.policyType(),\n policySet: permissions.policySet(),\n };\n }\n\n isAdmin(inboxId: string) {\n return this.#group.isAdmin(inboxId);\n }\n\n isSuperAdmin(inboxId: string) {\n return this.#group.isSuperAdmin(inboxId);\n }\n\n async sync() {\n return this.#group.sync();\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#group.addMembers(accountAddresses);\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#group.addMembersByInboxId(inboxIds);\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#group.removeMembers(accountAddresses);\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#group.removeMembersByInboxId(inboxIds);\n }\n\n async addAdmin(inboxId: string) {\n return this.#group.addAdmin(inboxId);\n }\n\n async removeAdmin(inboxId: string) {\n return this.#group.removeAdmin(inboxId);\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#group.addSuperAdmin(inboxId);\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#group.removeSuperAdmin(inboxId);\n }\n\n async publishMessages() {\n return this.#group.publishMessages();\n }\n\n sendOptimistic(encodedContent: EncodedContent) {\n return this.#group.sendOptimistic(encodedContent);\n }\n\n async send(encodedContent: EncodedContent) {\n return this.#group.send(encodedContent);\n }\n\n messages(options?: SafeListMessagesOptions) {\n return this.#group.findMessages(\n options ? fromSafeListMessagesOptions(options) : undefined,\n );\n }\n\n get consentState() {\n return this.#group.consentState();\n }\n\n updateConsentState(state: ConsentState) {\n this.#group.updateConsentState(state);\n }\n\n dmPeerInboxId() {\n return this.#group.dmPeerInboxId();\n }\n}\n","import type { Conversation, Conversations } from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeCreateGroupOptions,\n fromSafeListConversationsOptions,\n toSafeMessage,\n type SafeCreateGroupOptions,\n type SafeListConversationsOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\nimport { WorkerConversation } from \"@/WorkerConversation\";\n\nexport class WorkerConversations {\n #client: WorkerClient;\n\n #conversations: Conversations;\n\n constructor(client: WorkerClient, conversations: Conversations) {\n this.#client = client;\n this.#conversations = conversations;\n }\n\n async sync() {\n return this.#conversations.sync();\n }\n\n async syncAll() {\n return this.#conversations.syncAllConversations();\n }\n\n getConversationById(id: string) {\n try {\n const group = this.#conversations.findGroupById(id);\n // findGroupById will throw if group is not found\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n getMessageById(id: string) {\n try {\n // findMessageById will throw if message is not found\n const message = this.#conversations.findMessageById(id);\n return toSafeMessage(message);\n } catch {\n return undefined;\n }\n }\n\n getDmByInboxId(inboxId: string) {\n try {\n const group = this.#conversations.findDmByTargetInboxId(inboxId);\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n async list(options?: SafeListConversationsOptions) {\n const groups = (await this.#conversations.list(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listGroups(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listDms(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const group = await this.#conversations.createGroup(\n accountAddresses,\n options ? fromSafeCreateGroupOptions(options) : undefined,\n );\n return new WorkerConversation(this.#client, group);\n }\n\n async newDm(accountAddress: string) {\n const group = await this.#conversations.createDm(accountAddress);\n return new WorkerConversation(this.#client, group);\n }\n}\n","import {\n verifySignedWithPublicKey,\n type Client,\n type ConsentEntityType,\n type SignatureRequestType,\n} from \"@xmtp/wasm-bindings\";\nimport type { ClientOptions } from \"@/types\";\nimport { fromSafeConsent, type SafeConsent } from \"@/utils/conversions\";\nimport { createClient } from \"@/utils/createClient\";\nimport { WorkerConversations } from \"@/WorkerConversations\";\n\nexport class WorkerClient {\n #client: Client;\n\n #conversations: WorkerConversations;\n\n #accountAddress: string;\n\n constructor(client: Client) {\n this.#client = client;\n this.#accountAddress = client.accountAddress;\n this.#conversations = new WorkerConversations(this, client.conversations());\n }\n\n static async create(\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n ) {\n const client = await createClient(accountAddress, encryptionKey, options);\n return new WorkerClient(client);\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n get inboxId() {\n return this.#client.inboxId;\n }\n\n get installationId() {\n return this.#client.installationId;\n }\n\n get installationIdBytes() {\n return this.#client.installationIdBytes;\n }\n\n get isRegistered() {\n return this.#client.isRegistered;\n }\n\n async createInboxSignatureText() {\n try {\n return await this.#client.createInboxSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addAccountSignatureText(accountAddress: string) {\n try {\n return await this.#client.addWalletSignatureText(accountAddress);\n } catch {\n return undefined;\n }\n }\n\n async removeAccountSignatureText(accountAddress: string) {\n try {\n return await this.#client.revokeWalletSignatureText(accountAddress);\n } catch {\n return undefined;\n }\n }\n\n async revokeInstallationsSignatureText() {\n try {\n return await this.#client.revokeInstallationsSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addSignature(type: SignatureRequestType, bytes: Uint8Array) {\n return this.#client.addSignature(type, bytes);\n }\n\n async addScwSignature(\n type: SignatureRequestType,\n bytes: Uint8Array,\n chainId: bigint,\n blockNumber?: bigint,\n ) {\n return this.#client.addScwSignature(type, bytes, chainId, blockNumber);\n }\n\n async applySignatures() {\n return this.#client.applySignatureRequests();\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.#client.canMessage(accountAddresses) as Promise<\n Map<string, boolean>\n >;\n }\n\n async registerIdentity() {\n return this.#client.registerIdentity();\n }\n\n async findInboxIdByAddress(address: string) {\n return this.#client.findInboxIdByAddress(address);\n }\n\n async inboxState(refreshFromNetwork: boolean) {\n return this.#client.inboxState(refreshFromNetwork);\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.#client.getLatestInboxState(inboxId);\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.#client.setConsentStates(records.map(fromSafeConsent));\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.#client.getConsentState(entityType, entity);\n }\n\n get conversations() {\n return this.#conversations;\n }\n\n signWithInstallationKey(signatureText: string) {\n return this.#client.signWithInstallationKey(signatureText);\n }\n\n verifySignedWithInstallationKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n ) {\n try {\n this.#client.verifySignedWithInstallationKey(\n signatureText,\n signatureBytes,\n );\n return true;\n } catch {\n return false;\n }\n }\n\n verifySignedWithPublicKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n publicKey: Uint8Array,\n ) {\n try {\n verifySignedWithPublicKey(signatureText, signatureBytes, publicKey);\n return true;\n } catch {\n return false;\n }\n }\n}\n","import init, {\n createClient as createWasmClient,\n generateInboxId,\n getInboxIdForAddress,\n LogOptions,\n} from \"@xmtp/wasm-bindings\";\nimport { ApiUrls } from \"@/constants\";\nimport type { ClientOptions } from \"@/types\";\n\nexport const createClient = async (\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n) => {\n // initialize WASM module\n await init();\n\n const host = options?.apiUrl ?? ApiUrls[options?.env ?? \"dev\"];\n // TODO: add db path validation\n // - must end with .db3\n // - must not contain invalid characters\n // - must not start with a dot\n const dbPath =\n options?.dbPath ?? `xmtp-${options?.env ?? \"dev\"}-${accountAddress}.db3`;\n\n const inboxId =\n (await getInboxIdForAddress(host, accountAddress)) ||\n generateInboxId(accountAddress);\n\n const isLogging =\n options &&\n (options.loggingLevel !== undefined ||\n options.structuredLogging ||\n options.performanceLogging);\n\n return createWasmClient(\n host,\n inboxId,\n accountAddress,\n dbPath,\n encryptionKey,\n undefined,\n isLogging\n ? new LogOptions(\n options.structuredLogging ?? false,\n options.performanceLogging ?? false,\n options.loggingLevel,\n )\n : undefined,\n );\n};\n","import type {\n ClientEventsActions,\n ClientEventsClientMessageData,\n ClientEventsErrorData,\n ClientEventsWorkerPostMessageData,\n} from \"@/types\";\nimport {\n fromEncodedContent,\n fromSafeEncodedContent,\n toSafeConversation,\n toSafeInboxState,\n toSafeMessage,\n} from \"@/utils/conversions\";\nimport { WorkerClient } from \"@/WorkerClient\";\n\nlet client: WorkerClient;\nlet enableLogging = false;\n\n/**\n * Type-safe postMessage\n */\nconst postMessage = <A extends ClientEventsActions>(\n data: ClientEventsWorkerPostMessageData<A>,\n) => {\n self.postMessage(data);\n};\n\n/**\n * Type-safe postMessage for errors\n */\nconst postMessageError = (data: ClientEventsErrorData) => {\n self.postMessage(data);\n};\n\nself.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {\n const { action, id, data } = event.data;\n\n if (enableLogging) {\n console.log(\"client worker received event data\", event.data);\n }\n\n // a client is required for all actions except init\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (action !== \"init\" && !client) {\n postMessageError({\n id,\n action,\n error: \"Client not initialized\",\n });\n return;\n }\n\n try {\n switch (action) {\n /**\n * Client actions\n */\n case \"init\":\n client = await WorkerClient.create(\n data.address,\n data.encryptionKey,\n data.options,\n );\n enableLogging =\n data.options?.loggingLevel !== undefined &&\n data.options.loggingLevel !== \"off\";\n postMessage({\n id,\n action,\n result: {\n inboxId: client.inboxId,\n installationId: client.installationId,\n installationIdBytes: client.installationIdBytes,\n },\n });\n break;\n case \"createInboxSignatureText\": {\n const result = await client.createInboxSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addAccountSignatureText\": {\n const result = await client.addAccountSignatureText(\n data.newAccountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"removeAccountSignatureText\": {\n const result = await client.removeAccountSignatureText(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"revokeInstallationsSignatureText\": {\n const result = await client.revokeInstallationsSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addSignature\":\n await client.addSignature(data.type, data.bytes);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"addScwSignature\":\n await client.addScwSignature(\n data.type,\n data.bytes,\n data.chainId,\n data.blockNumber,\n );\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"applySignatures\":\n await client.applySignatures();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"registerIdentity\":\n await client.registerIdentity();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"isRegistered\": {\n const result = client.isRegistered;\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"canMessage\": {\n const result = await client.canMessage(data.accountAddresses);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"inboxState\": {\n const result = await client.inboxState(data.refreshFromNetwork);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"getLatestInboxState\": {\n const result = await client.getLatestInboxState(data.inboxId);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"setConsentStates\": {\n await client.setConsentStates(data.records);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConsentState\": {\n const result = await client.getConsentState(\n data.entityType,\n data.entity,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"findInboxIdByAddress\": {\n const result = await client.findInboxIdByAddress(data.address);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"signWithInstallationKey\": {\n const result = client.signWithInstallationKey(data.signatureText);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"verifySignedWithInstallationKey\": {\n const result = client.verifySignedWithInstallationKey(\n data.signatureText,\n data.signatureBytes,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"verifySignedWithPublicKey\": {\n const result = client.verifySignedWithPublicKey(\n data.signatureText,\n data.signatureBytes,\n data.publicKey,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n /**\n * Conversations actions\n */\n case \"getConversations\": {\n const conversations = await client.conversations.list(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getGroups\": {\n const conversations = await client.conversations.listGroups(\n data.options,\n );\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getDms\": {\n const conversations = await client.conversations.listDms(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"newGroup\": {\n const conversation = await client.conversations.newGroup(\n data.accountAddresses,\n data.options,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"newDm\": {\n const conversation = await client.conversations.newDm(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"syncConversations\": {\n await client.conversations.sync();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"syncAllConversations\": {\n await client.conversations.syncAll();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConversationById\": {\n const conversation = client.conversations.getConversationById(data.id);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n case \"getMessageById\": {\n const message = client.conversations.getMessageById(data.id);\n postMessage({\n id,\n action,\n result: message,\n });\n break;\n }\n case \"getDmByInboxId\": {\n const conversation = client.conversations.getDmByInboxId(data.inboxId);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n /**\n * Group actions\n */\n case \"syncGroup\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.sync();\n postMessage({\n id,\n action,\n result: toSafeConversation(group),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupName\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateName(data.name);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupDescription\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateDescription(data.description);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupImageUrlSquare\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateImageUrl(data.imageUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupPinnedFrameUrl\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updatePinnedFrameUrl(data.pinnedFrameUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.send(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendOptimisticGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.sendOptimistic(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"publishGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.publishMessages();\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const messages = group.messages(data.options);\n postMessage({\n id,\n action,\n result: messages.map((message) => toSafeMessage(message)),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.members();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.admins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupSuperAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.superAdmins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.consentState,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n group.updateConsentState(data.state);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getDmPeerInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.dmPeerInboxId();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n }\n } catch (e) {\n postMessageError({\n id,\n action,\n error: (e as Error).message,\n });\n }\n};\n"],"names":["fromEncodedContent","content","WasmEncodedContent","contentTypeId","type","WasmContentTypeId","authorityId","typeId","versionMajor","versionMinor","Map","Object","entries","parameters","fallback","compression","toSafeEncodedContent","fromSafeEncodedContent","ContentTypeId","toSafeMessage","message","fromEntries","convoId","deliveryStatus","id","kind","senderInboxId","sentAtNs","fromSafeListConversationsOptions","options","ListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","limit","toSafeConversation","conversation","name","imageUrl","description","pinnedFrameUrl","permissions","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","fromSafeConsent","consent","Consent","entityType","state","entity","ApiUrls","local","dev","production","WorkerConversation","client","group","constructor","this","groupName","updateName","updateGroupName","groupImageUrlSquare","updateImageUrl","updateGroupImageUrlSquare","groupDescription","updateDescription","updateGroupDescription","groupPinnedFrameUrl","updatePinnedFrameUrl","updateGroupPinnedFrameUrl","groupMetadata","creatorInboxId","members","listMembers","member","consentState","installationIds","permissionLevel","toSafeGroupMember","adminList","superAdminList","groupPermissions","isAdmin","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","encodedContent","send","messages","findMessages","ListMessagesOptions","sentBeforeNs","sentAfterNs","direction","fromSafeListMessagesOptions","undefined","updateConsentState","dmPeerInboxId","WorkerConversations","conversations","syncAll","syncAllConversations","getConversationById","findGroupById","getMessageById","findMessageById","getDmByInboxId","findDmByTargetInboxId","list","listGroups","listDms","newGroup","createGroup","CreateGroupOptions","imageUrlSquare","fromSafeCreateGroupOptions","newDm","accountAddress","createDm","WorkerClient","create","encryptionKey","async","init","host","apiUrl","env","dbPath","getInboxIdForAddress","generateInboxId","isLogging","loggingLevel","structuredLogging","performanceLogging","createWasmClient","LogOptions","createClient","installationId","installationIdBytes","isRegistered","createInboxSignatureText","addAccountSignatureText","addWalletSignatureText","removeAccountSignatureText","revokeWalletSignatureText","revokeInstallationsSignatureText","addSignature","bytes","addScwSignature","chainId","blockNumber","applySignatures","applySignatureRequests","canMessage","registerIdentity","findInboxIdByAddress","address","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","signWithInstallationKey","signatureText","verifySignedWithInstallationKey","signatureBytes","verifySignedWithPublicKey","publicKey","enableLogging","postMessage","data","self","postMessageError","onmessage","event","action","console","log","result","newAccountAddress","error","e"],"mappings":"qVA4BO,MAyDMA,EACXC,IAEA,WAAI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ASrI,EAAM4B,aAAaiG,EAAK7I,SACvC4I,EAAY,CACVrL,KACA2L,SACAG,gBAGFN,EAAiB,CACfxL,KACA2L,SACAK,MAAO,oBAGX,MAEF,IAAK,mBAAoB,CACvB,MAAMvI,EAAQD,EAAOuD,cAAcG,oBAAoBoE,EAAKtL,IAC5D,GAAIyD,EAAO,CACT,MAAMqI,EAASrI,EAAMoD,gBACrBwE,EAAY,CACVrL,KACA2L,SACAG,gBAGFN,EAAiB,CACfxL,KACA2L,SACAK,MAAO,oBAGX,QAGJ,MAAOC,GACPT,EAAiB,CACfxL,KACA2L,SACAK,MAAQC,EAAYrM,eAtwBtB4L,EAAiB,CACfxL,KACA2L,SACAK,MAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmtp/browser-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "XMTP client SDK for browsers written in TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xmtp",
|
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"./package.json": "./package.json"
|
|
34
34
|
},
|
|
35
|
-
"
|
|
36
|
-
"browser": "dist/index.js",
|
|
35
|
+
"main": "dist/index.js",
|
|
37
36
|
"types": "dist/index.d.ts",
|
|
38
37
|
"files": [
|
|
39
38
|
"dist",
|
|
@@ -61,11 +60,11 @@
|
|
|
61
60
|
]
|
|
62
61
|
},
|
|
63
62
|
"dependencies": {
|
|
64
|
-
"@xmtp/content-type-group-updated": "^
|
|
65
|
-
"@xmtp/content-type-primitives": "^
|
|
66
|
-
"@xmtp/content-type-text": "^
|
|
67
|
-
"@xmtp/proto": "^3.72.
|
|
68
|
-
"@xmtp/wasm-bindings": "^0.0.
|
|
63
|
+
"@xmtp/content-type-group-updated": "^2.0.0",
|
|
64
|
+
"@xmtp/content-type-primitives": "^2.0.0",
|
|
65
|
+
"@xmtp/content-type-text": "^2.0.0",
|
|
66
|
+
"@xmtp/proto": "^3.72.3",
|
|
67
|
+
"@xmtp/wasm-bindings": "^0.0.7",
|
|
69
68
|
"uuid": "^11.0.3"
|
|
70
69
|
},
|
|
71
70
|
"devDependencies": {
|
|
@@ -77,7 +76,7 @@
|
|
|
77
76
|
"@vitest/browser": "^2.1.3",
|
|
78
77
|
"@vitest/coverage-v8": "^2.0.3",
|
|
79
78
|
"@web/rollup-plugin-copy": "^0.5.1",
|
|
80
|
-
"playwright": "^1.
|
|
79
|
+
"playwright": "^1.49.0",
|
|
81
80
|
"rollup": "^4.27.3",
|
|
82
81
|
"rollup-plugin-dts": "^6.1.1",
|
|
83
82
|
"rollup-plugin-filesize": "^10.0.0",
|
package/src/Client.ts
CHANGED
|
@@ -30,6 +30,7 @@ export class Client extends ClientWorkerClass {
|
|
|
30
30
|
#encryptionKey: Uint8Array;
|
|
31
31
|
#inboxId: string | undefined;
|
|
32
32
|
#installationId: string | undefined;
|
|
33
|
+
#installationIdBytes: Uint8Array | undefined;
|
|
33
34
|
#isReady = false;
|
|
34
35
|
#signer: Signer;
|
|
35
36
|
options?: ClientOptions;
|
|
@@ -74,6 +75,7 @@ export class Client extends ClientWorkerClass {
|
|
|
74
75
|
});
|
|
75
76
|
this.#inboxId = result.inboxId;
|
|
76
77
|
this.#installationId = result.installationId;
|
|
78
|
+
this.#installationIdBytes = result.installationIdBytes;
|
|
77
79
|
this.#isReady = true;
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -106,6 +108,10 @@ export class Client extends ClientWorkerClass {
|
|
|
106
108
|
return this.#installationId;
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
get installationIdBytes() {
|
|
112
|
+
return this.#installationIdBytes;
|
|
113
|
+
}
|
|
114
|
+
|
|
109
115
|
async #createInboxSignatureText() {
|
|
110
116
|
return this.sendMessage("createInboxSignatureText", undefined);
|
|
111
117
|
}
|
|
@@ -176,12 +182,6 @@ export class Client extends ClientWorkerClass {
|
|
|
176
182
|
throw new Error("Unable to generate add account signature text");
|
|
177
183
|
}
|
|
178
184
|
|
|
179
|
-
await this.#addSignature(
|
|
180
|
-
SignatureRequestType.AddWallet,
|
|
181
|
-
signatureText,
|
|
182
|
-
this.#signer,
|
|
183
|
-
);
|
|
184
|
-
|
|
185
185
|
await this.#addSignature(
|
|
186
186
|
SignatureRequestType.AddWallet,
|
|
187
187
|
signatureText,
|
|
@@ -314,4 +314,30 @@ export class Client extends ClientWorkerClass {
|
|
|
314
314
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
315
315
|
return codec.decode(encodedContent, this);
|
|
316
316
|
}
|
|
317
|
+
|
|
318
|
+
signWithInstallationKey(signatureText: string) {
|
|
319
|
+
return this.sendMessage("signWithInstallationKey", { signatureText });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
verifySignedWithInstallationKey(
|
|
323
|
+
signatureText: string,
|
|
324
|
+
signatureBytes: Uint8Array,
|
|
325
|
+
) {
|
|
326
|
+
return this.sendMessage("verifySignedWithInstallationKey", {
|
|
327
|
+
signatureText,
|
|
328
|
+
signatureBytes,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
verifySignedWithPublicKey(
|
|
333
|
+
signatureText: string,
|
|
334
|
+
signatureBytes: Uint8Array,
|
|
335
|
+
publicKey: Uint8Array,
|
|
336
|
+
) {
|
|
337
|
+
return this.sendMessage("verifySignedWithPublicKey", {
|
|
338
|
+
signatureText,
|
|
339
|
+
signatureBytes,
|
|
340
|
+
publicKey,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
317
343
|
}
|
package/src/Conversations.ts
CHANGED
|
@@ -16,6 +16,10 @@ export class Conversations {
|
|
|
16
16
|
return this.#client.sendMessage("syncConversations", undefined);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
async syncAll() {
|
|
20
|
+
return this.#client.sendMessage("syncAllConversations", undefined);
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
async getConversationById(id: string) {
|
|
20
24
|
return this.#client.sendMessage("getConversationById", {
|
|
21
25
|
id,
|
package/src/WorkerClient.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
verifySignedWithPublicKey,
|
|
2
3
|
type Client,
|
|
3
4
|
type ConsentEntityType,
|
|
4
5
|
type SignatureRequestType,
|
|
@@ -42,6 +43,10 @@ export class WorkerClient {
|
|
|
42
43
|
return this.#client.installationId;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
get installationIdBytes() {
|
|
47
|
+
return this.#client.installationIdBytes;
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
get isRegistered() {
|
|
46
51
|
return this.#client.isRegistered;
|
|
47
52
|
}
|
|
@@ -56,10 +61,7 @@ export class WorkerClient {
|
|
|
56
61
|
|
|
57
62
|
async addAccountSignatureText(accountAddress: string) {
|
|
58
63
|
try {
|
|
59
|
-
return await this.#client.addWalletSignatureText(
|
|
60
|
-
this.#accountAddress,
|
|
61
|
-
accountAddress,
|
|
62
|
-
);
|
|
64
|
+
return await this.#client.addWalletSignatureText(accountAddress);
|
|
63
65
|
} catch {
|
|
64
66
|
return undefined;
|
|
65
67
|
}
|
|
@@ -131,4 +133,36 @@ export class WorkerClient {
|
|
|
131
133
|
get conversations() {
|
|
132
134
|
return this.#conversations;
|
|
133
135
|
}
|
|
136
|
+
|
|
137
|
+
signWithInstallationKey(signatureText: string) {
|
|
138
|
+
return this.#client.signWithInstallationKey(signatureText);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
verifySignedWithInstallationKey(
|
|
142
|
+
signatureText: string,
|
|
143
|
+
signatureBytes: Uint8Array,
|
|
144
|
+
) {
|
|
145
|
+
try {
|
|
146
|
+
this.#client.verifySignedWithInstallationKey(
|
|
147
|
+
signatureText,
|
|
148
|
+
signatureBytes,
|
|
149
|
+
);
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
verifySignedWithPublicKey(
|
|
157
|
+
signatureText: string,
|
|
158
|
+
signatureBytes: Uint8Array,
|
|
159
|
+
publicKey: Uint8Array,
|
|
160
|
+
) {
|
|
161
|
+
try {
|
|
162
|
+
verifySignedWithPublicKey(signatureText, signatureBytes, publicKey);
|
|
163
|
+
return true;
|
|
164
|
+
} catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
134
168
|
}
|
|
@@ -23,6 +23,10 @@ export class WorkerConversations {
|
|
|
23
23
|
return this.#conversations.sync();
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
async syncAll() {
|
|
27
|
+
return this.#conversations.syncAllConversations();
|
|
28
|
+
}
|
|
29
|
+
|
|
26
30
|
getConversationById(id: string) {
|
|
27
31
|
try {
|
|
28
32
|
const group = this.#conversations.findGroupById(id);
|
|
@@ -35,6 +35,7 @@ export type ClientEvents =
|
|
|
35
35
|
result: {
|
|
36
36
|
inboxId: string;
|
|
37
37
|
installationId: string;
|
|
38
|
+
installationIdBytes: Uint8Array;
|
|
38
39
|
};
|
|
39
40
|
data: {
|
|
40
41
|
address: string;
|
|
@@ -157,6 +158,33 @@ export type ClientEvents =
|
|
|
157
158
|
address: string;
|
|
158
159
|
};
|
|
159
160
|
}
|
|
161
|
+
| {
|
|
162
|
+
action: "signWithInstallationKey";
|
|
163
|
+
id: string;
|
|
164
|
+
result: Uint8Array;
|
|
165
|
+
data: {
|
|
166
|
+
signatureText: string;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
| {
|
|
170
|
+
action: "verifySignedWithInstallationKey";
|
|
171
|
+
id: string;
|
|
172
|
+
result: boolean;
|
|
173
|
+
data: {
|
|
174
|
+
signatureText: string;
|
|
175
|
+
signatureBytes: Uint8Array;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
| {
|
|
179
|
+
action: "verifySignedWithPublicKey";
|
|
180
|
+
id: string;
|
|
181
|
+
result: boolean;
|
|
182
|
+
data: {
|
|
183
|
+
signatureText: string;
|
|
184
|
+
signatureBytes: Uint8Array;
|
|
185
|
+
publicKey: Uint8Array;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
160
188
|
/**
|
|
161
189
|
* Conversations actions
|
|
162
190
|
*/
|
|
@@ -231,6 +259,12 @@ export type ClientEvents =
|
|
|
231
259
|
result: undefined;
|
|
232
260
|
data: undefined;
|
|
233
261
|
}
|
|
262
|
+
| {
|
|
263
|
+
action: "syncAllConversations";
|
|
264
|
+
id: string;
|
|
265
|
+
result: undefined;
|
|
266
|
+
data: undefined;
|
|
267
|
+
}
|
|
234
268
|
/**
|
|
235
269
|
* Group actions
|
|
236
270
|
*/
|
package/src/workers/client.ts
CHANGED
|
@@ -70,6 +70,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
70
70
|
result: {
|
|
71
71
|
inboxId: client.inboxId,
|
|
72
72
|
installationId: client.installationId,
|
|
73
|
+
installationIdBytes: client.installationIdBytes,
|
|
73
74
|
},
|
|
74
75
|
});
|
|
75
76
|
break;
|
|
@@ -216,6 +217,40 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
216
217
|
});
|
|
217
218
|
break;
|
|
218
219
|
}
|
|
220
|
+
case "signWithInstallationKey": {
|
|
221
|
+
const result = client.signWithInstallationKey(data.signatureText);
|
|
222
|
+
postMessage({
|
|
223
|
+
id,
|
|
224
|
+
action,
|
|
225
|
+
result,
|
|
226
|
+
});
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case "verifySignedWithInstallationKey": {
|
|
230
|
+
const result = client.verifySignedWithInstallationKey(
|
|
231
|
+
data.signatureText,
|
|
232
|
+
data.signatureBytes,
|
|
233
|
+
);
|
|
234
|
+
postMessage({
|
|
235
|
+
id,
|
|
236
|
+
action,
|
|
237
|
+
result,
|
|
238
|
+
});
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "verifySignedWithPublicKey": {
|
|
242
|
+
const result = client.verifySignedWithPublicKey(
|
|
243
|
+
data.signatureText,
|
|
244
|
+
data.signatureBytes,
|
|
245
|
+
data.publicKey,
|
|
246
|
+
);
|
|
247
|
+
postMessage({
|
|
248
|
+
id,
|
|
249
|
+
action,
|
|
250
|
+
result,
|
|
251
|
+
});
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
219
254
|
/**
|
|
220
255
|
* Conversations actions
|
|
221
256
|
*/
|
|
@@ -286,6 +321,15 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
286
321
|
});
|
|
287
322
|
break;
|
|
288
323
|
}
|
|
324
|
+
case "syncAllConversations": {
|
|
325
|
+
await client.conversations.syncAll();
|
|
326
|
+
postMessage({
|
|
327
|
+
id,
|
|
328
|
+
action,
|
|
329
|
+
result: undefined,
|
|
330
|
+
});
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
289
333
|
case "getConversationById": {
|
|
290
334
|
const conversation = client.conversations.getConversationById(data.id);
|
|
291
335
|
postMessage({
|