@keyban/sdk-base
Version:
Keyban Javascript SDK provides core functionalities for the MPC wallet solution, supporting web and Node.js apps with TypeScript, custom storage, and Ethereum blockchain integration.
2 lines • 2.04 kB
JavaScript
import {e,a,i}from'./chunk-VGFAFYVC.mjs';var l=class n{constructor(){window.addEventListener("message",this.#t);}static#e={auth:{isAuthenticated:true,getUser:true,getLoginUrl:true,getLogoutUrl:true,passwordLogin:true,passwordlessStart:true,passwordlessLogin:true},ecdsa:{dkg:true,sign:true,publicKey:true},eddsa:{dkg:true,sign:true,publicKey:true},account:{getAddress:true},loyalty:{initAccountSetup:true,initAccountDestroy:true,submitAccountSetup:true,submitAccountDestroy:true},clientShareStorage:{get:true,set:true},dpp:{claim:true}};#t=async e$1=>{if(e$1.data.__KEYBAN_RPC)try{if(!await this.checkEventOrigin(e$1.origin))throw new e(e.types.InvalidOrigin,"RpcServer");let{service:t,method:s}=e$1.data;if(!n.#e[t]?.[s])throw new e(e.types.InvalidCall,`RpcServer:${t}.${s}`);let i=this[t]?.[s];if(!i)throw new e(e.types.InvalidCall,`RpcServer:${t}.${s}`);let o=await i.apply(this[t],e$1.data.params);e$1.ports[0].postMessage([o,null]);}catch(r){let t=r;t instanceof a||(console.error(r),t=new i(i.types.UnknownIframeRpcError,"RpcServer",r)),e$1.ports[0].postMessage([null,JSON.stringify(t)]);}}},u=class n{#e;#t;static#r=new Map;static#s({apiUrl:e,appId:r,network:t}){let s=new URL("/sdk-client/rpc",e);return s.searchParams.set("appId",r),s.searchParams.set("network",t),s}static getInstance(e){let r=n.#s(e).toString();return n.#r.has(r)||n.#r.set(r,new n(e)),n.#r.get(r)}constructor(e){this.#e=n.#s(e),this.#t=new Promise((r,t)=>{let s=Object.assign(document.createElement("iframe"),{src:this.#e,hidden:true,onload:()=>r(s),onerror:t});document.body.appendChild(s);});}destroy(){this.#t.then(e=>document.body.removeChild(e));}async call(e,r,...t){let s=await this.#t,i=new MessageChannel;return await new Promise((o,g)=>{i.port1.onmessage=({data:[m,d]})=>(i.port1.close(),d!=null?g(new a(JSON.parse(d))):o(m));let y={__KEYBAN_RPC:true,service:e,method:r,params:t};s.contentWindow?.postMessage(y,this.#e.origin,[i.port2]);})}};export{l as a,u as b};//# sourceMappingURL=chunk-3UK7MQXP.mjs.map
//# sourceMappingURL=chunk-3UK7MQXP.mjs.map