UNPKG

@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.13 kB
import {e,a,i}from'./chunk-7K44U4PL.mjs';var l=class n{auth;ecdsa;eddsa;account;loyalty;clientShareStorage;tpp;domains;constructor(e,t){Object.assign(this,e),this.domains=t,window.addEventListener("message",this.handleMessage);}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,submitAccountSetup:true},clientShareStorage:{get:true,set:true},tpp:{claim:true}};handleMessage=async e$1=>{if(e$1.data.__KEYBAN_RPC)try{if(!(await this.domains).includes(e$1.origin))throw new e(e.types.InvalidOrigin,"RpcServer");let{service:s,method:r}=e$1.data;if(!n.#e[s]?.[r])throw new e(e.types.InvalidCall,`RpcServer:${s}.${r}`);let a=this[s]?.[r];if(!a)throw new e(e.types.InvalidCall,`RpcServer:${s}.${r}`);let o=await a.apply(this[s],e$1.data.params);e$1.ports[0].postMessage([o,null]);}catch(t){let s=t;s instanceof a||(console.error(t),s=new i(i.types.UnknownIframeRpcError,"RpcServer",t)),e$1.ports[0].postMessage([null,JSON.stringify(s)]);}}},g=class n{#e;#t;static#s=new Map;static#r({apiUrl:e,appId:t,network:s}){let r=new URL("/signer-client/",e);return r.searchParams.set("appId",t),r.searchParams.set("network",s),r}static getInstance(e){let t=n.#r(e).toString();return n.#s.has(t)||n.#s.set(t,new n(e)),n.#s.get(t)}constructor(e){this.#e=n.#r(e),this.#t=new Promise((t,s)=>{let r=Object.assign(document.createElement("iframe"),{src:this.#e,hidden:true,onload:()=>t(r),onerror:s});document.body.appendChild(r);});}destroy(){this.#t.then(e=>document.body.removeChild(e));}async call(e,t,...s){let r=await this.#t,a$1=new MessageChannel;return await new Promise((o,u)=>{a$1.port1.onmessage=({data:[y,d]})=>(a$1.port1.close(),d!=null?u(new a(JSON.parse(d))):o(y));let m={__KEYBAN_RPC:true,service:e,method:t,params:s};r.contentWindow?.postMessage(m,this.#e.origin,[a$1.port2]);})}};export{l as a,g as b};//# sourceMappingURL=chunk-DWBGILVH.mjs.map //# sourceMappingURL=chunk-DWBGILVH.mjs.map