@simplito/privmx-webendpoint 2.2.9 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/FinalizationHelper.d.ts +18 -0
  2. package/FinalizationHelper.js +49 -0
  3. package/Types.d.ts +77 -21
  4. package/Types.js +3 -0
  5. package/api/ApiStatic.d.ts +16 -0
  6. package/api/ApiStatic.js +26 -0
  7. package/api/ConnectionNative.d.ts +7 -1
  8. package/api/ConnectionNative.js +24 -0
  9. package/api/CryptoApiNative.d.ts +14 -0
  10. package/api/CryptoApiNative.js +30 -0
  11. package/api/EventApiNative.d.ts +20 -0
  12. package/api/EventApiNative.js +36 -0
  13. package/api/ExtKeyNative.d.ts +23 -0
  14. package/api/ExtKeyNative.js +66 -0
  15. package/assets/driver-web-context.js +1 -1
  16. package/assets/endpoint-wasm-module.js +1 -1
  17. package/assets/endpoint-wasm-module.wasm +0 -0
  18. package/bundle/privmx-endpoint-web.js +1 -1
  19. package/extra/PrivmxClient.d.ts +133 -0
  20. package/extra/PrivmxClient.js +271 -0
  21. package/extra/PublicConnection.d.ts +70 -0
  22. package/extra/PublicConnection.js +118 -0
  23. package/extra/events.d.ts +2 -2
  24. package/extra/inbox.d.ts +3 -3
  25. package/extra/inbox.js +1 -1
  26. package/extra/index.d.ts +10 -8
  27. package/extra/index.js +6 -1
  28. package/index.d.ts +2 -2
  29. package/index.js +2 -1
  30. package/package.json +5 -1
  31. package/service/Connection.d.ts +27 -1
  32. package/service/Connection.js +29 -0
  33. package/service/CryptoApi.d.ts +48 -1
  34. package/service/CryptoApi.js +59 -1
  35. package/service/EndpointFactory.d.ts +9 -0
  36. package/service/EndpointFactory.js +24 -0
  37. package/service/EventApi.d.ts +40 -0
  38. package/service/EventApi.js +60 -0
  39. package/service/ExtKey.d.ts +103 -0
  40. package/service/ExtKey.js +167 -0
  41. package/service/UserVerifierInterface.d.ts +18 -0
  42. package/service/UserVerifierInterface.js +2 -0
  43. package/service/index.d.ts +2 -1
  44. package/service/index.js +3 -1
  45. package/assets/privmx-endpoint-web.js +0 -2
Binary file
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see privmx-endpoint-web.js.LICENSE.txt */
2
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["privmx-webendpoint"]=t():e.PrivmxWebEndpoint=t()}(self,(()=>(()=>{"use strict";var e={667:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Api=void 0;const s=i(785);t.Api=class{lib;promises;taskIdGenerator;constructor(e){this.lib=e,this.taskIdGenerator=new s.IdGenerator,this.promises=new Map,this.setResultsCallback()}async runAsync(e){return new Promise(((t,i)=>{const s=this.generateId();this.promises.set(s,{resolve:t,reject:i}),e(s)}))}resolveResult(e){1==e.status?this.promises.get(e.taskId).resolve(e.result):this.promises.get(e.taskId).reject(e.error),this.promises.delete(e.taskId)}generateId(){return this.taskIdGenerator.generateId()}setResultsCallback(){this.lib.setResultsCallback((e=>this.resolveResult(e)))}}},361:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BaseNative=void 0,t.BaseNative=class{_api;constructor(e){this._api=e}get api(){if(!this._api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._api}deleteApiRef(){this._api=null}async runAsync(e){if(!this.api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this.api.runAsync(e)}}},140:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConnectionNative=void 0;const s=i(361);class n extends s.BaseNative{lastConnectionId=-1;async newApi(e){throw new Error("Use the newConnection() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async newConnection(){return this.runAsync((e=>this.api.lib.Connection_newConnection(e)))}async deleteConnection(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async connect(e,t){await this.runAsync((i=>this.api.lib.Connection_connect(i,e,t))),await this.getConnectionId(e,[])}async connectPublic(e,t){return this.runAsync((i=>this.api.lib.Connection_connectPublic(i,e,t)))}async getConnectionId(e,t){return this.lastConnectionId<0&&(this.lastConnectionId=await this.runAsync((i=>this.api.lib.Connection_getConnectionId(i,e,t)))),this.lastConnectionId}async listContexts(e,t){return this.runAsync((i=>this.api.lib.Connection_listContexts(i,e,t)))}async disconnect(e,t){await this.runAsync((i=>this.api.lib.Connection_disconnect(i,e,t)))}}t.ConnectionNative=n},711:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(){return this.runAsync((e=>this.api.lib.CryptoApi_newCryptoApi(e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.CryptoApi_deleteCryptoApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_create(i,e,t)))}async signData(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_signData(i,e,t)))}async verifySignature(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_verifySignature(i,e,t)))}async generatePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generatePrivateKey(i,e,t)))}async derivePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey(i,e,t)))}async derivePrivateKey2(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey2(i,e,t)))}async derivePublicKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePublicKey(i,e,t)))}async generateKeySymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generateKeySymmetric(i,e,t)))}async encryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_encryptDataSymmetric(i,e,t)))}async decryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_decryptDataSymmetric(i,e,t)))}async convertPEMKeytoWIFKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_convertPEMKeytoWIFKey(i,e,t)))}}t.CryptoApiNative=n},467:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueueNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){throw new Error("Use the newEventQueue() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async newEventQueue(){return this.runAsync((e=>this.api.lib.EventQueue_newEventQueue(e)))}async deleteEventQueue(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async waitEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_waitEvent(i,e,t)))}async emitBreakEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_emitBreakEvent(i,e,t)))}}t.EventQueueNative=n},785:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IdGenerator=void 0,t.IdGenerator=class{_id=0;generateId(){return this._id++,this._id}}},252:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e,t,i){return this.runAsync((s=>this.api.lib.InboxApi_newInboxApi(s,e,t,i)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.InboxApi_deleteInboxApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.InboxApi_create(i,e,t)))}async createInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createInbox(i,e,t)))}async updateInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_updateInbox(i,e,t)))}async getInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInbox(i,e,t)))}async listInboxes(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listInboxes(i,e,t)))}async getInboxPublicView(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInboxPublicView(i,e,t)))}async deleteInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteInbox(i,e,t)))}async prepareEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_prepareEntry(i,e,t)))}async sendEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_sendEntry(i,e,t)))}async readEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readEntry(i,e,t)))}async deleteEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteEntry(i,e,t)))}async listEntries(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listEntries(i,e,t)))}async createFileHandle(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createFileHandle(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_writeToFile(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_closeFile(i,e,t)))}async subscribeForInboxEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeForInboxEvents(i,e,t)))}async unsubscribeFromInboxEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFromInboxEvents(i,e,t)))}async subscribeForEntryEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeForEntryEvents(i,e,t)))}async unsubscribeFromEntryEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFromEntryEvents(i,e,t)))}}t.InboxApiNative=n},243:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.StoreApi_newStoreApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.StoreApi_deleteStoreApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.StoreApi_create(i,e,t)))}async createStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createStore(i,e,t)))}async updateStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateStore(i,e,t)))}async deleteStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteStore(i,e,t)))}async getStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getStore(i,e,t)))}async listStores(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listStores(i,e,t)))}async createFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createFile(i,e,t)))}async updateFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFile(i,e,t)))}async updateFileMeta(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFileMeta(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_writeToFile(i,e,t)))}async deleteFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteFile(i,e,t)))}async getFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getFile(i,e,t)))}async listFiles(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listFiles(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_closeFile(i,e,t)))}async subscribeForStoreEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeForStoreEvents(i,e,t)))}async unsubscribeFromStoreEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFromStoreEvents(i,e,t)))}async subscribeForFileEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeForFileEvents(i,e,t)))}async unsubscribeFromFileEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFromFileEvents(i,e,t)))}}t.StoreApiNative=n},272:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.ThreadApi_newThreadApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.ThreadApi_deleteThreadApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_create(i,e,t)))}async createThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_createThread(i,e,t)))}async updateThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateThread(i,e,t)))}async deleteThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteThread(i,e,t)))}async getThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getThread(i,e,t)))}async listThreads(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listThreads(i,e,t)))}async getMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getMessage(i,e,t)))}async listMessages(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listMessages(i,e,t)))}async sendMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_sendMessage(i,e,t)))}async deleteMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteMessage(i,e,t)))}async updateMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateMessage(i,e,t)))}async subscribeForThreadEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeForThreadEvents(i,e,t)))}async unsubscribeFromThreadEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFromThreadEvents(i,e,t)))}async subscribeForMessageEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeForMessageEvents(i,e,t)))}async unsubscribeFromMessageEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFromMessageEvents(i,e,t)))}}t.ThreadApiNative=n},647:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BaseApi=void 0,t.BaseApi=class{_servicePtr;constructor(e){this._servicePtr=e}get servicePtr(){if(this._servicePtr<0)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._servicePtr}destroyRefs(){this._servicePtr=-1}}},262:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;const s=i(647);class n extends s.BaseApi{native;apisRefs={};nativeApisDeps={};constructor(e,t){super(t),this.native=e}async getConnectionId(){return this.native.getConnectionId(this.servicePtr,[])}async listContexts(e){return this.native.listContexts(this.servicePtr,[e])}async disconnect(){await this.native.disconnect(this.servicePtr,[]),await this.freeApis(),await this.native.deleteConnection(this.servicePtr)}async freeApis(){for(const e in this.apisRefs)this.nativeApisDeps[e]&&await this.nativeApisDeps[e].deleteApi(this.apisRefs[e]._apiServicePtr)}}t.Connection=n},11:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async signData(e,t){return this.native.signData(this.servicePtr,[e,t])}async verifySignature(e,t,i){return this.native.verifySignature(this.servicePtr,[e,t,i])}async generatePrivateKey(e){return this.native.generatePrivateKey(this.servicePtr,[e])}async derivePrivateKey(e,t){return this.native.derivePrivateKey(this.servicePtr,[e,t])}async derivePrivateKey2(e,t){return this.native.derivePrivateKey2(this.servicePtr,[e,t])}async derivePublicKey(e){return this.native.derivePublicKey(this.servicePtr,[e])}async generateKeySymmetric(){return this.native.generateKeySymmetric(this.servicePtr,[])}async encryptDataSymmetric(e,t){return this.native.encryptDataSymmetric(this.servicePtr,[e,t])}async decryptDataSymmetric(e,t){return this.native.decryptDataSymmetric(this.servicePtr,[e,t])}async convertPEMKeytoWIFKey(e){return this.native.convertPEMKeytoWIFKey(this.servicePtr,[e])}}t.CryptoApi=n},181:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EndpointFactory=void 0;const s=i(667),n=i(140),r=i(711),a=i(467),c=i(252),o=i(243),u=i(272),h=i(262),p=i(11),y=i(297),l=i(134),v=i(985),d=i(148);class b{static api;static eventQueueInstance;static async setup(e){const t=e||document.currentScript.src.split("/").slice(0,-1).join("/"),i=["driver-web-context.js","endpoint-wasm-module.js"];for(const e of i)await this.loadScript(t+"/"+e);const s=await endpointWasmModule();b.init(s)}static async loadScript(e){return new Promise((t=>{const i=document.getElementsByTagName("head")[0],s=document.createElement("script");s.type="text/javascript",s.src=e,s.onload=()=>{t()},i.appendChild(s)}))}static init(e){this.api=new s.Api(e)}static async getEventQueue(){if(!this.eventQueueInstance){const e=new a.EventQueueNative(this.api),t=await e.newEventQueue();this.eventQueueInstance=new y.EventQueue(e,t)}return this.eventQueueInstance}static async connect(e,t,i){const s=new n.ConnectionNative(this.api),r=await s.newConnection();return await s.connect(r,[e,t,i]),new h.Connection(s,r)}static async connectPublic(e,t){const i=new n.ConnectionNative(this.api),s=await i.newConnection();return await i.connectPublic(s,[e,t]),new h.Connection(i,s)}static async createThreadApi(e){if("threads"in e.apisRefs)throw new Error("ThreadApi already registered for given connection.");const t=new u.ThreadApiNative(this.api),i=await t.newApi(e.servicePtr);return await t.create(i,[]),e.apisRefs.threads={_apiServicePtr:i},e.nativeApisDeps.threads=t,new d.ThreadApi(t,i)}static async createStoreApi(e){if("stores"in e.apisRefs)throw new Error("StoreApi already registered for given connection.");const t=new o.StoreApiNative(this.api),i=await t.newApi(e.servicePtr);return e.apisRefs.stores={_apiServicePtr:i},e.nativeApisDeps.stores=t,await t.create(i,[]),new v.StoreApi(t,i)}static async createInboxApi(e,t,i){if("inboxes"in e.apisRefs)throw new Error("InboxApi already registered for given connection.");const s=new c.InboxApiNative(this.api),n=await s.newApi(e.servicePtr,t.servicePtr,i.servicePtr);return e.apisRefs.inboxes={_apiServicePtr:n},e.nativeApisDeps.inboxes=s,await s.create(n,[]),new l.InboxApi(s,n)}static async createCryptoApi(){const e=new r.CryptoApiNative(this.api),t=await e.newApi();return await e.create(t,[]),new p.CryptoApi(e,t)}}t.EndpointFactory=b},297:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueue=void 0;const s=i(647);class n extends s.BaseApi{native;isPending=!1;constructor(e,t){super(t),this.native=e}async waitEvent(){if(this.isPending)throw"WaitEvent() is already in a pending state waiting for new events";try{return await this.native.waitEvent(this.servicePtr,[])}finally{this.isPending=!1}}async emitBreakEvent(){return this.native.emitBreakEvent(this.servicePtr,[])}}t.EventQueue=n},134:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createInbox(e,t,i,s,n,r,a){return this.native.createInbox(this.servicePtr,[e,t,i,s,n,r,a])}async updateInbox(e,t,i,s,n,r,a,c,o,u){return this.native.updateInbox(this.servicePtr,[e,t,i,s,n,r,a,c,o,u])}async getInbox(e){return this.native.getInbox(this.servicePtr,[e])}async listInboxes(e,t){return this.native.listInboxes(this.servicePtr,[e,t])}async getInboxPublicView(e){return this.native.getInboxPublicView(this.servicePtr,[e])}async deleteInbox(e){return this.native.deleteInbox(this.servicePtr,[e])}async prepareEntry(e,t,i,s){return this.native.prepareEntry(this.servicePtr,[e,t,i,s])}async sendEntry(e){return this.native.sendEntry(this.servicePtr,[e])}async readEntry(e){return this.native.readEntry(this.servicePtr,[e])}async listEntries(e,t){return this.native.listEntries(this.servicePtr,[e,t])}async deleteEntry(e){return this.native.deleteEntry(this.servicePtr,[e])}async createFileHandle(e,t,i){return this.native.createFileHandle(this.servicePtr,[e,t,i])}async writeToFile(e,t,i){return this.native.writeToFile(this.servicePtr,[e,t,i])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeForInboxEvents(){return this.native.subscribeForInboxEvents(this.servicePtr,[])}async unsubscribeFromInboxEvents(){return this.native.unsubscribeFromInboxEvents(this.servicePtr,[])}async subscribeForEntryEvents(e){return this.native.subscribeForEntryEvents(this.servicePtr,[e])}async unsubscribeFromEntryEvents(e){return this.native.unsubscribeFromEntryEvents(this.servicePtr,[e])}}t.InboxApi=n},985:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createStore(e,t,i,s,n,r){return this.native.createStore(this.servicePtr,[e,t,i,s,n,r])}async updateStore(e,t,i,s,n,r,a,c,o){return this.native.updateStore(this.servicePtr,[e,t,i,s,n,r,a,c,o])}async deleteStore(e){return this.native.deleteStore(this.servicePtr,[e])}async getStore(e){return this.native.getStore(this.servicePtr,[e])}async listStores(e,t){return this.native.listStores(this.servicePtr,[e,t])}async createFile(e,t,i,s){return this.native.createFile(this.servicePtr,[e,t,i,s])}async updateFile(e,t,i,s){return this.native.updateFile(this.servicePtr,[e,t,i,s])}async updateFileMeta(e,t,i){return this.native.updateFileMeta(this.servicePtr,[e,t,i])}async writeToFile(e,t){return this.native.writeToFile(this.servicePtr,[e,t])}async deleteFile(e){return this.native.deleteFile(this.servicePtr,[e])}async getFile(e){return this.native.getFile(this.servicePtr,[e])}async listFiles(e,t){return this.native.listFiles(this.servicePtr,[e,t])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeForStoreEvents(){return this.native.subscribeForStoreEvents(this.servicePtr,[])}async unsubscribeFromStoreEvents(){return this.native.unsubscribeFromStoreEvents(this.servicePtr,[])}async subscribeForFileEvents(e){return this.native.subscribeForFileEvents(this.servicePtr,[e])}async unsubscribeFromFileEvents(e){return this.native.unsubscribeFromFileEvents(this.servicePtr,[e])}}t.StoreApi=n},148:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createThread(e,t,i,s,n,r){return this.native.createThread(this.servicePtr,[e,t,i,s,n,r])}async updateThread(e,t,i,s,n,r,a,c,o){return this.native.updateThread(this.servicePtr,[e,t,i,s,n,r,a,c,o])}async deleteThread(e){return this.native.deleteThread(this.servicePtr,[e])}async getThread(e){return this.native.getThread(this.servicePtr,[e])}async listThreads(e,t){return this.native.listThreads(this.servicePtr,[e,t])}async getMessage(e){return this.native.getMessage(this.servicePtr,[e])}async listMessages(e,t){return this.native.listMessages(this.servicePtr,[e,t])}async sendMessage(e,t,i,s){return this.native.sendMessage(this.servicePtr,[e,t,i,s])}async deleteMessage(e){return this.native.deleteMessage(this.servicePtr,[e])}async updateMessage(e,t,i,s){return this.native.updateMessage(this.servicePtr,[e,t,i,s])}async subscribeForThreadEvents(){return this.native.subscribeForThreadEvents(this.servicePtr,[])}async unsubscribeFromThreadEvents(){return this.native.unsubscribeFromThreadEvents(this.servicePtr,[])}async subscribeForMessageEvents(e){return this.native.subscribeForMessageEvents(this.servicePtr,[e])}async unsubscribeFromMessageEvents(e){return this.native.unsubscribeFromMessageEvents(this.servicePtr,[e])}}t.ThreadApi=n}},t={};function i(s){var n=t[s];if(void 0!==n)return n.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,i),r.exports}var s={};return(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0}),e.Endpoint=void 0;const t=i(181);Object.defineProperty(e,"Endpoint",{enumerable:!0,get:function(){return t.EndpointFactory}})})(),s})()));
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["privmx-webendpoint"]=t():e.PrivmxWebEndpoint=t()}(self,(()=>(()=>{"use strict";var e={54:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FinalizationHelper=void 0;const s=i(457);class n{wasmLib;static instance;static wasmLib;static init(e){n.wasmLib=e}static getInstance(){if(!n.wasmLib)throw new Error("Initialize first with the WASM Library object");return this.instance||(this.instance=new n(n.wasmLib)),this.instance}finalizationRegistry;finalizationQueue=[];scheduler=null;constructor(e){this.wasmLib=e,this.finalizationRegistry=new FinalizationRegistry((e=>{s.ApiStatic.getInstance(),this.finalizationQueue.push(e.onFree),this.scheduleCleanup()}))}scheduleCleanup(){this.scheduler||(this.scheduler=setTimeout((async()=>{for(const e of this.finalizationQueue)await e();this.finalizationQueue=[],clearTimeout(this.scheduler),this.scheduler=null}),1e3))}register(e,t){this.finalizationRegistry.register(e,t,e)}}t.FinalizationHelper=n},667:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Api=void 0;const s=i(785);t.Api=class{lib;promises;taskIdGenerator;constructor(e){this.lib=e,this.taskIdGenerator=new s.IdGenerator,this.promises=new Map,this.setResultsCallback()}async runAsync(e){return new Promise(((t,i)=>{const s=this.generateId();this.promises.set(s,{resolve:t,reject:i}),e(s)}))}resolveResult(e){1==e.status?this.promises.get(e.taskId).resolve(e.result):this.promises.get(e.taskId).reject(e.error),this.promises.delete(e.taskId)}generateId(){return this.taskIdGenerator.generateId()}setResultsCallback(){this.lib.setResultsCallback((e=>this.resolveResult(e)))}}},457:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ApiStatic=void 0,t.ApiStatic=class{static instance;static init(e){this.instance=e}static getInstance(){if(!this.instance)throw new Error("API Static not initialized");return this.instance}}},361:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BaseNative=void 0,t.BaseNative=class{_api;constructor(e){this._api=e}get api(){if(!this._api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._api}deleteApiRef(){this._api=null}async runAsync(e){if(!this.api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this.api.runAsync(e)}}},140:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConnectionNative=void 0;const s=i(361);class n extends s.BaseNative{lastConnectionId=-1;userVerifierPtr=-1;async newApi(e){throw new Error("Use the newConnection() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async newConnection(){return this.runAsync((e=>this.api.lib.Connection_newConnection(e)))}async deleteConnection(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async connect(e,t){await this.runAsync((i=>this.api.lib.Connection_connect(i,e,t))),await this.getConnectionId(e,[])}async connectPublic(e,t){return this.runAsync((i=>this.api.lib.Connection_connectPublic(i,e,t)))}async getConnectionId(e,t){return this.lastConnectionId<0&&(this.lastConnectionId=await this.runAsync((i=>this.api.lib.Connection_getConnectionId(i,e,t)))),this.lastConnectionId}async listContexts(e,t){return this.runAsync((i=>this.api.lib.Connection_listContexts(i,e,t)))}async getContextUsers(e,t){return this.runAsync((i=>this.api.lib.Connection_getContextUsers(i,e,t)))}async disconnect(e,t){await this.runAsync((i=>this.api.lib.Connection_disconnect(i,e,t)))}async setUserVerifier(e,t){this.userVerifierPtr>-1&&(await this.deleteUserVerifierInterface(this.userVerifierPtr),this.userVerifierPtr=-1);const[i,s]=t;window.userVierifier_verify=async e=>{if(s&&"function"==typeof s.verify)return s.verify(e);throw new Error("Call on UserVerifierInterface with missing implementation")},this.userVerifierPtr=await this.runAsync((e=>this.api.lib.Connection_newUserVerifierInterface(e,i)))}async newUserVerifierInterface(e){return this.runAsync((t=>this.api.lib.Connection_newUserVerifierInterface(t,e)))}async deleteUserVerifierInterface(e){await this.runAsync((t=>this.api.lib.Connection_deleteUserVerifierInterface(t,e)))}}t.ConnectionNative=n},711:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApiNative=void 0;const s=i(504),n=i(361);class r extends n.BaseNative{async newApi(){return this.runAsync((e=>this.api.lib.CryptoApi_newCryptoApi(e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.CryptoApi_deleteCryptoApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_create(i,e,t)))}async signData(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_signData(i,e,t)))}async verifySignature(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_verifySignature(i,e,t)))}async generatePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generatePrivateKey(i,e,t)))}async derivePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey(i,e,t)))}async derivePrivateKey2(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey2(i,e,t)))}async derivePublicKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePublicKey(i,e,t)))}async generateKeySymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generateKeySymmetric(i,e,t)))}async encryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_encryptDataSymmetric(i,e,t)))}async decryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_decryptDataSymmetric(i,e,t)))}async convertPEMKeytoWIFKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_convertPEMKeytoWIFKey(i,e,t)))}async generateBip39(e,t){const i=await this.runAsync((i=>this.api.lib.CryptoApi_generateBip39(i,e,t)));return this.convertBIP(i)}async fromMnemonic(e,t){const i=await this.runAsync((i=>this.api.lib.CryptoApi_fromMnemonic(i,e,t)));return this.convertBIP(i)}async fromEntropy(e,t){const i=await this.runAsync((i=>this.api.lib.CryptoApi_fromEntropy(i,e,t)));return this.convertBIP(i)}async entropyToMnemonic(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_entropyToMnemonic(i,e,t)))}async mnemonicToEntropy(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_mnemonicToEntropy(i,e,t)))}async mnemonicToSeed(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_mnemonicToSeed(i,e,t)))}convertBIP(e){return{mnemonic:e.mnemonic,entropy:e.entropy,extKey:s.ExtKey.fromPtr(e.extKey)}}}t.CryptoApiNative=r},688:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.EventApi_newEventApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.EventApi_deleteEventApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.EventApi_create(i,e,t)))}async emitEvent(e,t){return this.runAsync((i=>this.api.lib.EventApi_emitEvent(i,e,t)))}async subscribeForCustomEvents(e,t){return this.runAsync((i=>this.api.lib.EventApi_subscribeForCustomEvents(i,e,t)))}async unsubscribeFromCustomEvents(e,t){return this.runAsync((i=>this.api.lib.EventApi_unsubscribeFromCustomEvents(i,e,t)))}}t.EventApiNative=n},467:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueueNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){throw new Error("Use the newEventQueue() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async newEventQueue(){return this.runAsync((e=>this.api.lib.EventQueue_newEventQueue(e)))}async deleteEventQueue(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async waitEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_waitEvent(i,e,t)))}async emitBreakEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_emitBreakEvent(i,e,t)))}}t.EventQueueNative=n},614:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ExtKeyNative=void 0;const s=i(457),n=i(361);class r extends n.BaseNative{async newApi(){throw new Error("Use the specialized version of method instead.")}async deleteApi(e){return this.runAsync((t=>this.api.lib.ExtKey_deleteExtKey(t,e)))}async deleteExtKey(e){return this.runAsync((t=>this.api.lib.ExtKey_deleteExtKey(t,e)))}static async fromSeed(e){const t=s.ApiStatic.getInstance();return t.runAsync((i=>t.lib.ExtKey_fromSeed(i,e)))}static async fromBase58(e){const t=s.ApiStatic.getInstance();return t.runAsync((i=>t.lib.ExtKey_fromBase58(i,e)))}static async generateRandom(e){const t=s.ApiStatic.getInstance();return t.runAsync((i=>t.lib.ExtKey_generateRandom(i,e)))}async derive(e,t){return this.runAsync((i=>this.api.lib.ExtKey_derive(i,e,t)))}async deriveHardened(e,t){return this.runAsync((i=>this.api.lib.ExtKey_deriveHardened(i,e,t)))}getPrivatePartAsBase58(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPrivatePartAsBase58(i,e,t)))}getPublicPartAsBase58(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPublicPartAsBase58(i,e,t)))}getPrivateKey(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPrivateKey(i,e,t)))}getPublicKey(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPublicKey(i,e,t)))}getPrivateEncKey(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPrivateEncKey(i,e,t)))}getPublicKeyAsBase58Address(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPublicKeyAsBase58Address(i,e,t)))}getChainCode(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getChainCode(i,e,t)))}verifyCompactSignatureWithHash(e,t){return this.runAsync((i=>this.api.lib.ExtKey_verifyCompactSignatureWithHash(i,e,t)))}isPrivate(e,t){return this.runAsync((i=>this.api.lib.ExtKey_isPrivate(i,e,t)))}}t.ExtKeyNative=r},785:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IdGenerator=void 0,t.IdGenerator=class{_id=0;generateId(){return this._id++,this._id}}},252:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e,t,i){return this.runAsync((s=>this.api.lib.InboxApi_newInboxApi(s,e,t,i)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.InboxApi_deleteInboxApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.InboxApi_create(i,e,t)))}async createInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createInbox(i,e,t)))}async updateInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_updateInbox(i,e,t)))}async getInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInbox(i,e,t)))}async listInboxes(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listInboxes(i,e,t)))}async getInboxPublicView(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInboxPublicView(i,e,t)))}async deleteInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteInbox(i,e,t)))}async prepareEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_prepareEntry(i,e,t)))}async sendEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_sendEntry(i,e,t)))}async readEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readEntry(i,e,t)))}async deleteEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteEntry(i,e,t)))}async listEntries(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listEntries(i,e,t)))}async createFileHandle(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createFileHandle(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_writeToFile(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_closeFile(i,e,t)))}async subscribeForInboxEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeForInboxEvents(i,e,t)))}async unsubscribeFromInboxEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFromInboxEvents(i,e,t)))}async subscribeForEntryEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeForEntryEvents(i,e,t)))}async unsubscribeFromEntryEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFromEntryEvents(i,e,t)))}}t.InboxApiNative=n},243:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.StoreApi_newStoreApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.StoreApi_deleteStoreApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.StoreApi_create(i,e,t)))}async createStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createStore(i,e,t)))}async updateStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateStore(i,e,t)))}async deleteStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteStore(i,e,t)))}async getStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getStore(i,e,t)))}async listStores(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listStores(i,e,t)))}async createFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createFile(i,e,t)))}async updateFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFile(i,e,t)))}async updateFileMeta(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFileMeta(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_writeToFile(i,e,t)))}async deleteFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteFile(i,e,t)))}async getFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getFile(i,e,t)))}async listFiles(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listFiles(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_closeFile(i,e,t)))}async subscribeForStoreEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeForStoreEvents(i,e,t)))}async unsubscribeFromStoreEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFromStoreEvents(i,e,t)))}async subscribeForFileEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeForFileEvents(i,e,t)))}async unsubscribeFromFileEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFromFileEvents(i,e,t)))}}t.StoreApiNative=n},272:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.ThreadApi_newThreadApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.ThreadApi_deleteThreadApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_create(i,e,t)))}async createThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_createThread(i,e,t)))}async updateThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateThread(i,e,t)))}async deleteThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteThread(i,e,t)))}async getThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getThread(i,e,t)))}async listThreads(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listThreads(i,e,t)))}async getMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getMessage(i,e,t)))}async listMessages(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listMessages(i,e,t)))}async sendMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_sendMessage(i,e,t)))}async deleteMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteMessage(i,e,t)))}async updateMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateMessage(i,e,t)))}async subscribeForThreadEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeForThreadEvents(i,e,t)))}async unsubscribeFromThreadEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFromThreadEvents(i,e,t)))}async subscribeForMessageEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeForMessageEvents(i,e,t)))}async unsubscribeFromMessageEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFromMessageEvents(i,e,t)))}}t.ThreadApiNative=n},647:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BaseApi=void 0,t.BaseApi=class{_servicePtr;constructor(e){this._servicePtr=e}get servicePtr(){if(this._servicePtr<0)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._servicePtr}destroyRefs(){this._servicePtr=-1}}},262:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;const s=i(647);class n extends s.BaseApi{native;apisRefs={};nativeApisDeps={};constructor(e,t){super(t),this.native=e}async getConnectionId(){return this.native.getConnectionId(this.servicePtr,[])}async listContexts(e){return this.native.listContexts(this.servicePtr,[e])}async getContextUsers(e){return this.native.getContextUsers(this.servicePtr,[e])}async disconnect(){await this.native.disconnect(this.servicePtr,[]),await this.freeApis(),await this.native.deleteConnection(this.servicePtr)}setUserVerifier(e){return this.native.setUserVerifier(this.servicePtr,[this.servicePtr,e])}async freeApis(){for(const e in this.apisRefs)this.nativeApisDeps[e]&&await this.nativeApisDeps[e].deleteApi(this.apisRefs[e]._apiServicePtr)}}t.Connection=n},11:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async signData(e,t){return this.native.signData(this.servicePtr,[e,t])}async verifySignature(e,t,i){return this.native.verifySignature(this.servicePtr,[e,t,i])}async generatePrivateKey(e){return this.native.generatePrivateKey(this.servicePtr,[e])}async derivePrivateKey(e,t){return this.native.derivePrivateKey(this.servicePtr,[e,t])}async derivePrivateKey2(e,t){return this.native.derivePrivateKey2(this.servicePtr,[e,t])}async derivePublicKey(e){return this.native.derivePublicKey(this.servicePtr,[e])}async generateKeySymmetric(){return this.native.generateKeySymmetric(this.servicePtr,[])}async encryptDataSymmetric(e,t){return this.native.encryptDataSymmetric(this.servicePtr,[e,t])}async decryptDataSymmetric(e,t){return this.native.decryptDataSymmetric(this.servicePtr,[e,t])}async convertPEMKeytoWIFKey(e){return this.native.convertPEMKeytoWIFKey(this.servicePtr,[e])}async generateBip39(e,t=""){return this.native.generateBip39(this.servicePtr,[e,t])}async fromMnemonic(e,t=""){return this.native.fromMnemonic(this.servicePtr,[e,t])}async fromEntropy(e,t=""){return this.native.fromEntropy(this.servicePtr,[e,t])}async entropyToMnemonic(e){return this.native.entropyToMnemonic(this.servicePtr,[e])}async mnemonicToEntropy(e){return this.native.mnemonicToEntropy(this.servicePtr,[e])}async mnemonicToSeed(e,t=""){return this.native.mnemonicToSeed(this.servicePtr,[e,t])}}t.CryptoApi=n},181:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EndpointFactory=void 0;const s=i(667),n=i(457),r=i(140),a=i(711),c=i(688),o=i(467),u=i(252),h=i(243),y=i(272),p=i(54),v=i(262),l=i(11),d=i(590),b=i(297),A=i(134),P=i(985),E=i(148);class _{static api;static eventQueueInstance;static async setup(e){const t=e||document.currentScript.src.split("/").slice(0,-1).join("/"),i=["driver-web-context.js","endpoint-wasm-module.js"];for(const e of i)await this.loadScript(t+"/"+e);const s=await endpointWasmModule();_.init(s)}static async loadScript(e){return new Promise((t=>{const i=document.getElementsByTagName("head")[0],s=document.createElement("script");s.type="text/javascript",s.src=e,s.onload=()=>{t()},i.appendChild(s)}))}static init(e){this.api=new s.Api(e),n.ApiStatic.init(this.api),p.FinalizationHelper.init(e)}static async getEventQueue(){if(!this.eventQueueInstance){const e=new o.EventQueueNative(this.api),t=await e.newEventQueue();this.eventQueueInstance=new b.EventQueue(e,t)}return this.eventQueueInstance}static async connect(e,t,i){const s=new r.ConnectionNative(this.api),n=await s.newConnection();return await s.connect(n,[e,t,i]),new v.Connection(s,n)}static async connectPublic(e,t){const i=new r.ConnectionNative(this.api),s=await i.newConnection();return await i.connectPublic(s,[e,t]),new v.Connection(i,s)}static async createThreadApi(e){if("threads"in e.apisRefs)throw new Error("ThreadApi already registered for given connection.");const t=new y.ThreadApiNative(this.api),i=await t.newApi(e.servicePtr);return await t.create(i,[]),e.apisRefs.threads={_apiServicePtr:i},e.nativeApisDeps.threads=t,new E.ThreadApi(t,i)}static async createStoreApi(e){if("stores"in e.apisRefs)throw new Error("StoreApi already registered for given connection.");const t=new h.StoreApiNative(this.api),i=await t.newApi(e.servicePtr);return e.apisRefs.stores={_apiServicePtr:i},e.nativeApisDeps.stores=t,await t.create(i,[]),new P.StoreApi(t,i)}static async createInboxApi(e,t,i){if("inboxes"in e.apisRefs)throw new Error("InboxApi already registered for given connection.");const s=new u.InboxApiNative(this.api),n=await s.newApi(e.servicePtr,t.servicePtr,i.servicePtr);return e.apisRefs.inboxes={_apiServicePtr:n},e.nativeApisDeps.inboxes=s,await s.create(n,[]),new A.InboxApi(s,n)}static async createCryptoApi(){const e=new a.CryptoApiNative(this.api),t=await e.newApi();return await e.create(t,[]),new l.CryptoApi(e,t)}static async createEventApi(e){if("events"in e.apisRefs)throw new Error("EventApi already registered for given connection.");const t=new c.EventApiNative(this.api),i=await t.newApi(e.servicePtr);return e.apisRefs.events={_apiServicePtr:i},e.nativeApisDeps.events=t,await t.create(i,[]),new d.EventApi(t,i)}}t.EndpointFactory=_},590:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async emitEvent(e,t,i,s){return this.native.emitEvent(this.servicePtr,[e,t,i,s])}async subscribeForCustomEvents(e,t){return this.native.subscribeForCustomEvents(this.servicePtr,[e,t])}async unsubscribeFromCustomEvents(e,t){return this.native.unsubscribeFromCustomEvents(this.servicePtr,[e,t])}}t.EventApi=n},297:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueue=void 0;const s=i(647);class n extends s.BaseApi{native;isPending=!1;constructor(e,t){super(t),this.native=e}async waitEvent(){if(this.isPending)throw"WaitEvent() is already in a pending state waiting for new events";try{return await this.native.waitEvent(this.servicePtr,[])}finally{this.isPending=!1}}async emitBreakEvent(){return this.native.emitBreakEvent(this.servicePtr,[])}}t.EventQueue=n},504:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ExtKey=void 0;const s=i(457),n=i(614),r=i(54),a=i(647);class c extends a.BaseApi{native;ptr;static async freeExtKey(e){const t=new n.ExtKeyNative(s.ApiStatic.getInstance());await t.deleteExtKey(e)}static async fromSeed(e){const t=await n.ExtKeyNative.fromSeed([e]),i=new n.ExtKeyNative(s.ApiStatic.getInstance()),a=new c(i,t);return r.FinalizationHelper.getInstance().register(a,{ptr:t,onFree:()=>this.freeExtKey(t)}),a}static async fromBase58(e){const t=await n.ExtKeyNative.fromBase58([e]),i=new n.ExtKeyNative(s.ApiStatic.getInstance()),a=new c(i,t);return r.FinalizationHelper.getInstance().register(a,{ptr:t,onFree:()=>this.freeExtKey(t)}),a}static async generateRandom(){const e=await n.ExtKeyNative.generateRandom([]),t=new n.ExtKeyNative(s.ApiStatic.getInstance()),i=new c(t,e);return r.FinalizationHelper.getInstance().register(i,{ptr:e,onFree:()=>this.freeExtKey(e)}),i}constructor(e,t){super(t),this.native=e,this.ptr=t}static fromPtr(e){const t=new n.ExtKeyNative(s.ApiStatic.getInstance());return new c(t,e)}async derive(e){const t=await this.native.derive(this.servicePtr,[e]),i=new c(this.native,t);return r.FinalizationHelper.getInstance().register(i,{ptr:t,onFree:()=>c.freeExtKey(t)}),i}async deriveHardened(e){const t=await this.native.deriveHardened(this.servicePtr,[e]);return new c(this.native,t)}async getPrivatePartAsBase58(){return this.native.getPrivatePartAsBase58(this.servicePtr,[])}async getPublicPartAsBase58(){return this.native.getPublicPartAsBase58(this.servicePtr,[])}async getPrivateKey(){return this.native.getPrivateKey(this.servicePtr,[])}async getPublicKey(){return this.native.getPublicKey(this.servicePtr,[])}async getPrivateEncKey(){return this.native.getPrivateEncKey(this.servicePtr,[])}async getPublicKeyAsBase58Address(){return this.native.getPublicKeyAsBase58Address(this.servicePtr,[])}async getChainCode(){return this.native.getChainCode(this.servicePtr,[])}async verifyCompactSignatureWithHash(e,t){return this.native.verifyCompactSignatureWithHash(this.servicePtr,[e,t])}async isPrivate(){return this.native.isPrivate(this.servicePtr,[])}}t.ExtKey=c},134:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createInbox(e,t,i,s,n,r,a){return this.native.createInbox(this.servicePtr,[e,t,i,s,n,r,a])}async updateInbox(e,t,i,s,n,r,a,c,o,u){return this.native.updateInbox(this.servicePtr,[e,t,i,s,n,r,a,c,o,u])}async getInbox(e){return this.native.getInbox(this.servicePtr,[e])}async listInboxes(e,t){return this.native.listInboxes(this.servicePtr,[e,t])}async getInboxPublicView(e){return this.native.getInboxPublicView(this.servicePtr,[e])}async deleteInbox(e){return this.native.deleteInbox(this.servicePtr,[e])}async prepareEntry(e,t,i,s){return this.native.prepareEntry(this.servicePtr,[e,t,i,s])}async sendEntry(e){return this.native.sendEntry(this.servicePtr,[e])}async readEntry(e){return this.native.readEntry(this.servicePtr,[e])}async listEntries(e,t){return this.native.listEntries(this.servicePtr,[e,t])}async deleteEntry(e){return this.native.deleteEntry(this.servicePtr,[e])}async createFileHandle(e,t,i){return this.native.createFileHandle(this.servicePtr,[e,t,i])}async writeToFile(e,t,i){return this.native.writeToFile(this.servicePtr,[e,t,i])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeForInboxEvents(){return this.native.subscribeForInboxEvents(this.servicePtr,[])}async unsubscribeFromInboxEvents(){return this.native.unsubscribeFromInboxEvents(this.servicePtr,[])}async subscribeForEntryEvents(e){return this.native.subscribeForEntryEvents(this.servicePtr,[e])}async unsubscribeFromEntryEvents(e){return this.native.unsubscribeFromEntryEvents(this.servicePtr,[e])}}t.InboxApi=n},985:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createStore(e,t,i,s,n,r){return this.native.createStore(this.servicePtr,[e,t,i,s,n,r])}async updateStore(e,t,i,s,n,r,a,c,o){return this.native.updateStore(this.servicePtr,[e,t,i,s,n,r,a,c,o])}async deleteStore(e){return this.native.deleteStore(this.servicePtr,[e])}async getStore(e){return this.native.getStore(this.servicePtr,[e])}async listStores(e,t){return this.native.listStores(this.servicePtr,[e,t])}async createFile(e,t,i,s){return this.native.createFile(this.servicePtr,[e,t,i,s])}async updateFile(e,t,i,s){return this.native.updateFile(this.servicePtr,[e,t,i,s])}async updateFileMeta(e,t,i){return this.native.updateFileMeta(this.servicePtr,[e,t,i])}async writeToFile(e,t){return this.native.writeToFile(this.servicePtr,[e,t])}async deleteFile(e){return this.native.deleteFile(this.servicePtr,[e])}async getFile(e){return this.native.getFile(this.servicePtr,[e])}async listFiles(e,t){return this.native.listFiles(this.servicePtr,[e,t])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeForStoreEvents(){return this.native.subscribeForStoreEvents(this.servicePtr,[])}async unsubscribeFromStoreEvents(){return this.native.unsubscribeFromStoreEvents(this.servicePtr,[])}async subscribeForFileEvents(e){return this.native.subscribeForFileEvents(this.servicePtr,[e])}async unsubscribeFromFileEvents(e){return this.native.unsubscribeFromFileEvents(this.servicePtr,[e])}}t.StoreApi=n},148:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createThread(e,t,i,s,n,r){return this.native.createThread(this.servicePtr,[e,t,i,s,n,r])}async updateThread(e,t,i,s,n,r,a,c,o){return this.native.updateThread(this.servicePtr,[e,t,i,s,n,r,a,c,o])}async deleteThread(e){return this.native.deleteThread(this.servicePtr,[e])}async getThread(e){return this.native.getThread(this.servicePtr,[e])}async listThreads(e,t){return this.native.listThreads(this.servicePtr,[e,t])}async getMessage(e){return this.native.getMessage(this.servicePtr,[e])}async listMessages(e,t){return this.native.listMessages(this.servicePtr,[e,t])}async sendMessage(e,t,i,s){return this.native.sendMessage(this.servicePtr,[e,t,i,s])}async deleteMessage(e){return this.native.deleteMessage(this.servicePtr,[e])}async updateMessage(e,t,i,s){return this.native.updateMessage(this.servicePtr,[e,t,i,s])}async subscribeForThreadEvents(){return this.native.subscribeForThreadEvents(this.servicePtr,[])}async unsubscribeFromThreadEvents(){return this.native.unsubscribeFromThreadEvents(this.servicePtr,[])}async subscribeForMessageEvents(e){return this.native.subscribeForMessageEvents(this.servicePtr,[e])}async unsubscribeFromMessageEvents(e){return this.native.unsubscribeFromMessageEvents(this.servicePtr,[e])}}t.ThreadApi=n}},t={};function i(s){var n=t[s];if(void 0!==n)return n.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,i),r.exports}var s={};return(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0}),e.Endpoint=void 0;const t=i(181);Object.defineProperty(e,"Endpoint",{enumerable:!0,get:function(){return t.EndpointFactory}})})(),s})()));
@@ -0,0 +1,133 @@
1
+ import { Connection, CryptoApi, EventQueue, InboxApi, StoreApi, ThreadApi } from '../service';
2
+ import { ConnectionEventsManager, EventManager, InboxEventsManager, StoreEventsManager, ThreadEventsManager } from './events';
3
+ import { PublicConnection } from './PublicConnection';
4
+ /**
5
+ * @class PrivmxClient
6
+ * @classdesc A client for interacting with the PrivMX Endpoint API.
7
+ * @example
8
+ * // Initialize the PrivMX client
9
+ * await PrivmxClient.setup('/path/to/privmx/assets');
10
+ *
11
+ * // Connect to the PrivMX bridge
12
+ * const privateKey = 'your-private-key';
13
+ * const solutionId = 'your-solution-id';
14
+ * const contextId = 'your-context-id';
15
+ * const bridgeUrl = 'https://your-bridge-url.com';
16
+ * const client = await PrivmxClient.connect(privateKey, solutionId, bridgeUrl);
17
+ *
18
+ * // Get the Thread API and list threads
19
+ * const threadApi = await client.getThreadApi();
20
+ * const threads = await threadApi.listThreads(contextId, {
21
+ * skip: 0,
22
+ * limit: 100,
23
+ * sort: 'desc'
24
+ * })
25
+ *
26
+ * // Disconnect when done
27
+ * await client.disconnect();
28
+ */
29
+ export declare class PrivmxClient {
30
+ private connection;
31
+ private static cryptoApi;
32
+ private static eventQueue;
33
+ private static isSetup;
34
+ private static eventManager;
35
+ private threadApi;
36
+ private storeApi;
37
+ private inboxApi;
38
+ private connectionEventManager;
39
+ private threadEventManager;
40
+ private storeEventManager;
41
+ private inboxEventManager;
42
+ /**
43
+ * @constructor
44
+ * @param {Connection} connection - The connection object.
45
+ */
46
+ private constructor();
47
+ /**
48
+ * @description Sets up the PrivMX endpoint if it hasn't been set up yet.
49
+ * @param {string} folderPath - The path to the folder where PrivMX assets are stored.
50
+ * @returns {Promise<void>}
51
+ */
52
+ static setup(folderPath: string): Promise<void>;
53
+ private static checkSetup;
54
+ /**
55
+ * @description Gets the Crypto API.
56
+ * @returns {Promise<CryptoApi>}
57
+ */
58
+ static getCryptoApi(): Promise<CryptoApi>;
59
+ /**
60
+ * @description Gets the Event Queue.
61
+ * @returns {Promise<EventQueue>}
62
+ */
63
+ static getEventQueue(): Promise<EventQueue>;
64
+ /**
65
+ * @description Gets the Event Manager.
66
+ * @returns {Promise<EventManager>}
67
+ */
68
+ static getEventManager(): Promise<EventManager>;
69
+ /**
70
+ * @description Connects to the PrivMX bridge.
71
+ * @param {string} privateKey user's private key
72
+ * @param {string} solutionId ID of the Solution
73
+ * @param {string} bridgeUrl the Bridge Server URL
74
+ * @returns {Promise<PrivmxClient>}
75
+ * @throws {Error} If the connection to the bridge fails.
76
+ */
77
+ static connect(privateKey: string, solutionId: string, bridgeUrl: string): Promise<PrivmxClient>;
78
+ /**
79
+ * Connects to the Platform backend as a guest user.
80
+ *
81
+ * @param {string} solutionId ID of the Solution
82
+ * @param {string} bridgeUrl the Bridge Server URL
83
+ *
84
+ * @returns {Promise<PublicConnection>} Promised instance of Connection
85
+ */
86
+ static connectPublic(solutionId: string, bridgeUrl: string): Promise<PublicConnection>;
87
+ /**
88
+ * @description Gets the connection object.
89
+ * @returns {Connection}
90
+ * @throws {Error} If there is no active connection.
91
+ */
92
+ getConnection(): Connection;
93
+ /**
94
+ * @description Gets the Thread API.
95
+ * @returns {Promise<ThreadApi>}
96
+ */
97
+ getThreadApi(): Promise<ThreadApi>;
98
+ /**
99
+ * @description Gets the Store API.
100
+ * @returns {Promise<StoreApi>}
101
+ */
102
+ getStoreApi(): Promise<StoreApi>;
103
+ /**
104
+ * @description Gets the Inbox API.
105
+ * @returns {Promise<InboxApi>}
106
+ */
107
+ getInboxApi(): Promise<InboxApi>;
108
+ /**
109
+ * @description Gets the Connection Event Manager.
110
+ * @returns {Promise<ConnectionEventsManager>}
111
+ */
112
+ getConnectionEventManager(): Promise<ConnectionEventsManager>;
113
+ /**
114
+ * @description Gets the Thread Event Manager.
115
+ * @returns {Promise<ThreadEventsManager>}
116
+ */
117
+ getThreadEventManager(): Promise<ThreadEventsManager>;
118
+ /**
119
+ * @description Gets the Store Event Manager.
120
+ * @returns {Promise<StoreEventsManager>}
121
+ */
122
+ getStoreEventManager(): Promise<StoreEventsManager>;
123
+ /**
124
+ * @description Gets the Inbox Event Manager.
125
+ * @returns {Promise<InboxEventsManager>}
126
+ */
127
+ getInboxEventManager(): Promise<InboxEventsManager>;
128
+ /**
129
+ * @description Disconnects from the PrivMX bridge.
130
+ * @returns {Promise<void>}
131
+ */
132
+ disconnect(): Promise<void>;
133
+ }
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrivmxClient = void 0;
4
+ const service_1 = require("../service");
5
+ const events_1 = require("./events");
6
+ const PublicConnection_1 = require("./PublicConnection");
7
+ /**
8
+ * @class PrivmxClient
9
+ * @classdesc A client for interacting with the PrivMX Endpoint API.
10
+ * @example
11
+ * // Initialize the PrivMX client
12
+ * await PrivmxClient.setup('/path/to/privmx/assets');
13
+ *
14
+ * // Connect to the PrivMX bridge
15
+ * const privateKey = 'your-private-key';
16
+ * const solutionId = 'your-solution-id';
17
+ * const contextId = 'your-context-id';
18
+ * const bridgeUrl = 'https://your-bridge-url.com';
19
+ * const client = await PrivmxClient.connect(privateKey, solutionId, bridgeUrl);
20
+ *
21
+ * // Get the Thread API and list threads
22
+ * const threadApi = await client.getThreadApi();
23
+ * const threads = await threadApi.listThreads(contextId, {
24
+ * skip: 0,
25
+ * limit: 100,
26
+ * sort: 'desc'
27
+ * })
28
+ *
29
+ * // Disconnect when done
30
+ * await client.disconnect();
31
+ */
32
+ class PrivmxClient {
33
+ connection;
34
+ static cryptoApi = null;
35
+ static eventQueue = null;
36
+ static isSetup = false;
37
+ static eventManager = null;
38
+ threadApi = null;
39
+ storeApi = null;
40
+ inboxApi = null;
41
+ connectionEventManager = null;
42
+ threadEventManager = null;
43
+ storeEventManager = null;
44
+ inboxEventManager = null;
45
+ /**
46
+ * @constructor
47
+ * @param {Connection} connection - The connection object.
48
+ */
49
+ constructor(connection) {
50
+ this.connection = connection;
51
+ }
52
+ /**
53
+ * @description Sets up the PrivMX endpoint if it hasn't been set up yet.
54
+ * @param {string} folderPath - The path to the folder where PrivMX assets are stored.
55
+ * @returns {Promise<void>}
56
+ */
57
+ static async setup(folderPath) {
58
+ if (!PrivmxClient.isSetup) {
59
+ await service_1.EndpointFactory.setup(folderPath);
60
+ PrivmxClient.isSetup = true;
61
+ }
62
+ }
63
+ static checkSetup() {
64
+ if (!this.isSetup) {
65
+ throw new Error('Endpoint not initialized, use PrivMXClient.setup(folderPath).');
66
+ }
67
+ }
68
+ /**
69
+ * @description Gets the Crypto API.
70
+ * @returns {Promise<CryptoApi>}
71
+ */
72
+ static async getCryptoApi() {
73
+ if (this.cryptoApi) {
74
+ return this.cryptoApi;
75
+ }
76
+ this.checkSetup();
77
+ this.cryptoApi = (async () => {
78
+ return service_1.EndpointFactory.createCryptoApi();
79
+ })();
80
+ return this.cryptoApi;
81
+ }
82
+ /**
83
+ * @description Gets the Event Queue.
84
+ * @returns {Promise<EventQueue>}
85
+ */
86
+ static async getEventQueue() {
87
+ if (this.eventQueue) {
88
+ return this.eventQueue;
89
+ }
90
+ this.checkSetup();
91
+ this.eventQueue = (async () => {
92
+ return service_1.EndpointFactory.getEventQueue();
93
+ })();
94
+ return this.eventQueue;
95
+ }
96
+ /**
97
+ * @description Gets the Event Manager.
98
+ * @returns {Promise<EventManager>}
99
+ */
100
+ static async getEventManager() {
101
+ if (this.eventManager) {
102
+ return this.eventManager;
103
+ }
104
+ this.checkSetup();
105
+ this.eventManager = (async () => {
106
+ const eventQueue = await PrivmxClient.getEventQueue();
107
+ return events_1.EventManager.startEventLoop(eventQueue);
108
+ })();
109
+ return await this.eventManager;
110
+ }
111
+ /**
112
+ * @description Connects to the PrivMX bridge.
113
+ * @param {string} privateKey user's private key
114
+ * @param {string} solutionId ID of the Solution
115
+ * @param {string} bridgeUrl the Bridge Server URL
116
+ * @returns {Promise<PrivmxClient>}
117
+ * @throws {Error} If the connection to the bridge fails.
118
+ */
119
+ static async connect(privateKey, solutionId, bridgeUrl) {
120
+ this.checkSetup();
121
+ const connection = await service_1.EndpointFactory.connect(privateKey, solutionId, bridgeUrl);
122
+ if (!connection) {
123
+ throw new Error('ERROR: Could not connect to bridge');
124
+ }
125
+ return new PrivmxClient(connection);
126
+ }
127
+ /**
128
+ * Connects to the Platform backend as a guest user.
129
+ *
130
+ * @param {string} solutionId ID of the Solution
131
+ * @param {string} bridgeUrl the Bridge Server URL
132
+ *
133
+ * @returns {Promise<PublicConnection>} Promised instance of Connection
134
+ */
135
+ static async connectPublic(solutionId, bridgeUrl) {
136
+ this.checkSetup();
137
+ const connection = await service_1.EndpointFactory.connectPublic(solutionId, bridgeUrl);
138
+ if (!connection) {
139
+ throw new Error('ERROR: Could not connect to bridge');
140
+ }
141
+ return new PublicConnection_1.PublicConnection(connection);
142
+ }
143
+ /**
144
+ * @description Gets the connection object.
145
+ * @returns {Connection}
146
+ * @throws {Error} If there is no active connection.
147
+ */
148
+ getConnection() {
149
+ if (!this.connection) {
150
+ throw new Error('No active connection');
151
+ }
152
+ return this.connection;
153
+ }
154
+ /**
155
+ * @description Gets the Thread API.
156
+ * @returns {Promise<ThreadApi>}
157
+ */
158
+ async getThreadApi() {
159
+ if (!this.threadApi) {
160
+ this.threadApi = (() => {
161
+ const connection = this.getConnection();
162
+ return service_1.EndpointFactory.createThreadApi(connection);
163
+ })();
164
+ }
165
+ return this.threadApi;
166
+ }
167
+ /**
168
+ * @description Gets the Store API.
169
+ * @returns {Promise<StoreApi>}
170
+ */
171
+ async getStoreApi() {
172
+ if (!this.storeApi) {
173
+ this.storeApi = (async () => {
174
+ const connection = this.getConnection();
175
+ return service_1.EndpointFactory.createStoreApi(connection);
176
+ })();
177
+ }
178
+ return this.storeApi;
179
+ }
180
+ /**
181
+ * @description Gets the Inbox API.
182
+ * @returns {Promise<InboxApi>}
183
+ */
184
+ async getInboxApi() {
185
+ if (!this.inboxApi) {
186
+ this.inboxApi = (async () => {
187
+ const connection = this.getConnection();
188
+ return service_1.EndpointFactory.createInboxApi(connection, await this.getThreadApi(), await this.getStoreApi());
189
+ })();
190
+ }
191
+ return this.inboxApi;
192
+ }
193
+ /**
194
+ * @description Gets the Connection Event Manager.
195
+ * @returns {Promise<ConnectionEventsManager>}
196
+ */
197
+ async getConnectionEventManager() {
198
+ if (this.connectionEventManager) {
199
+ return this.connectionEventManager;
200
+ }
201
+ this.connectionEventManager = (async () => {
202
+ const eventManager = await PrivmxClient.getEventManager();
203
+ const connection = this.getConnection();
204
+ const connectionId = (await connection.getConnectionId());
205
+ return eventManager.getConnectionEventManager(connectionId);
206
+ })();
207
+ return this.connectionEventManager;
208
+ }
209
+ /**
210
+ * @description Gets the Thread Event Manager.
211
+ * @returns {Promise<ThreadEventsManager>}
212
+ */
213
+ async getThreadEventManager() {
214
+ if (this.threadEventManager) {
215
+ return this.threadEventManager;
216
+ }
217
+ this.threadEventManager = (async () => {
218
+ const eventManager = await PrivmxClient.getEventManager();
219
+ return eventManager.getThreadEventManager(await this.getThreadApi());
220
+ })();
221
+ return this.threadEventManager;
222
+ }
223
+ /**
224
+ * @description Gets the Store Event Manager.
225
+ * @returns {Promise<StoreEventsManager>}
226
+ */
227
+ async getStoreEventManager() {
228
+ if (this.storeEventManager) {
229
+ return this.storeEventManager;
230
+ }
231
+ this.storeEventManager = (async () => {
232
+ const eventManager = await PrivmxClient.getEventManager();
233
+ return eventManager.getStoreEventManager(await this.getStoreApi());
234
+ })();
235
+ return this.storeEventManager;
236
+ }
237
+ /**
238
+ * @description Gets the Inbox Event Manager.
239
+ * @returns {Promise<InboxEventsManager>}
240
+ */
241
+ async getInboxEventManager() {
242
+ if (this.inboxEventManager) {
243
+ return this.inboxEventManager;
244
+ }
245
+ this.inboxEventManager = (async () => {
246
+ const eventManager = await PrivmxClient.getEventManager();
247
+ return eventManager.getInboxEventManager(await this.getInboxApi());
248
+ })();
249
+ return this.inboxEventManager;
250
+ }
251
+ /**
252
+ * @description Disconnects from the PrivMX bridge.
253
+ * @returns {Promise<void>}
254
+ */
255
+ async disconnect() {
256
+ try {
257
+ await this.connection.disconnect();
258
+ this.threadApi = null;
259
+ this.storeApi = null;
260
+ this.inboxApi = null;
261
+ this.connectionEventManager = null;
262
+ this.threadEventManager = null;
263
+ this.storeEventManager = null;
264
+ this.inboxEventManager = null;
265
+ }
266
+ catch (e) {
267
+ console.error('Error during disconnection:', e);
268
+ }
269
+ }
270
+ }
271
+ exports.PrivmxClient = PrivmxClient;
@@ -0,0 +1,70 @@
1
+ import { Connection } from '../service';
2
+ import { InboxEntryPayload } from './inbox';
3
+ /**
4
+ * @class PublicConnection
5
+ * @classdesc A client for interacting with the PrivMX Endpoint API as a guest. The scope is limited to sending an entries to inboxes.
6
+ * @example
7
+ * // Initialize the PrivMX client
8
+ * await PrivmxClient.setup('/path/to/privmx/assets');
9
+ *
10
+ * // Connect to the PrivMX bridge
11
+ * const solutionId = 'your-solution-id';
12
+ * const bridgeUrl = 'https://your-bridge-url.com';
13
+ * const inboxId = 'your-inbox-id'
14
+ * const client = await PrivmxClient.connectPublic(solutionId, bridgeUrl);
15
+ *
16
+ * // Send entry
17
+ * const encoder = new TextEncoder();
18
+ * const encodedData = encoder.encode(JSON.stringify({ message: 'Hello, PrivMX!' }));
19
+ *
20
+ * await client.sendEntry(inboxId, {
21
+ * data: encodedData
22
+ * })
23
+ *
24
+ * // Disconnect when done
25
+ * await client.disconnect();
26
+ */
27
+ export declare class PublicConnection {
28
+ private connection;
29
+ private threadApi;
30
+ private storeApi;
31
+ private inboxApi;
32
+ /**
33
+ * @constructor
34
+ * @param {Connection} connection - The connection object.
35
+ */
36
+ constructor(connection: Connection);
37
+ /**
38
+ * @description Gets the connection object.
39
+ * @returns {Connection}
40
+ * @throws {Error} If there is no active connection.
41
+ */
42
+ private getConnection;
43
+ /**
44
+ * @description Gets the Thread API.
45
+ * @returns {Promise<ThreadApi>}
46
+ */
47
+ private getThreadApi;
48
+ /**
49
+ * @description Gets the Store API.
50
+ * @returns {Promise<StoreApi>}
51
+ */
52
+ private getStoreApi;
53
+ /**
54
+ * @description Gets the Inbox API.
55
+ * @returns {Promise<InboxApi>}
56
+ */
57
+ private getInboxApi;
58
+ /**
59
+ * @description Disconnects from the PrivMX bridge.
60
+ * @returns {Promise<void>}
61
+ */
62
+ disconnect(): Promise<void>;
63
+ /**
64
+ * @description Sends an entry to the specified inbox.
65
+ * @param {string} inboxId - The ID of the inbox to send the entry to.
66
+ * @param {InboxEntryPayload} payload - The payload of the entry to send.
67
+ * @returns {Promise<void>}
68
+ */
69
+ sendEntry(inboxId: string, payload: InboxEntryPayload): Promise<void>;
70
+ }