import{R as p}from"./Root-rl66e6VO.js";import c from"./JsonRPC-BpgGDx4C.js";import l from"./Driver-DkU17mMt.js";import{aI as a}from"./index-D02r7Zsc.js";class m extends p{constructor(){super(),this.url=this.getConfig().pmburl,this.proxy=null,this.subscribe("init",async()=>{await this.getCredentials(),this.jsonrpc=new c(this.url,this.user,this.pwd,this.getConfig().apiKey),this.init()})}async init(){try{let e=await this.createProxy();this.set("ws",new l(e)),this.publish("ws_ready",e)}catch(e){this.publish("ws_failed",e)}}async getCredentials(){let e=this.getConfig().pmburlWsUser,r=this.getConfig().pmburlWsPassword;this.user=await this.uncipher(e),this.pwd=await this.uncipher(r)}async uncipher(e){let r=atob(this.getConfig().apiKey),t=atob(e),s=t.substring(0,12),n=t.substring(12,t.length-16),o=t.substring(t.length-16),i=a.cipher.createDecipher("AES-GCM",r);i.start({iv:s,tagLength:128,tag:o}),i.update(a.util.createBuffer(n));var h=i.finish();if(h)return i.output.data}getProxy(){if(this.proxy!==null)return this.proxy;throw new Error("Le proxy n'est pas encore initialisé")}async createProxy(){let e=await this.jsonrpc.getCatalog(),r={jsonrpc:this.jsonrpc,checkLength:function(t,s){if(t.length!=s.parameters.length)throw new Error("Le nombre d'arguments ne correspond pas à la méthode ("+s.name+")")}};for(let t of e.methods)r[t.name]=async function(){try{this.checkLength(arguments,t)}catch(n){console.info(n)}return await this.jsonrpc.sendQuery(t.name,arguments)};return this.proxy=r,r}}export{m as default};
