@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 • 4.57 kB
JavaScript
;var o=class extends Error{type;title;instance;status;detail;timestamp;rootError;toJSON(){return {type:this.type,title:this.title,instance:this.instance,status:this.status,detail:this.detail,timestamp:this.timestamp,rootError:this.rootError}}constructor({type:e,title:t,instance:r,rootError:n,detail:i,status:d}){super(i??t??e),this.type=e,this.title=t??e,this.instance=r,this.detail=i,this.status=d,this.timestamp=new Date().toISOString(),this.rootError=n;}};var l=(t=>(t.InvalidOrigin="InvalidOrigin",t.InvalidCall="InvalidCall",t))(l||{}),c=class s extends o{static types=l;constructor(e,t,r){super({type:e,instance:t,rootError:r,title:s.#e(e)});}static#e(e){switch(e){case "InvalidOrigin":return "The current domain is not allowed for this appId";case "InvalidCall":return "Invalid method call, either the method does not exists or is not allowed";default:return `Unknown error type: ${e}`}}};var g=(a=>(a.UnknownTransactionError="UnknownTransactionError",a.UnknownIframeRpcError="UnknownIframeRpcError",a.AddressInvalid="AddressInvalid",a.AmountInvalid="AmountInvalid",a.AmountRequired="AmountRequired",a.AmountIrrelevant="AmountIrrelevant",a.RecipientAddressEqualsSender="RecipientAddressEqualsSender",a.EstimateGasExecution="EstimateGasExecution",a.InsufficientFunds="InsufficientFunds",a.InvalidNftStandard="InvalidNftStandard",a.NftNotFound="NftNotFound",a.TokenBalanceNotFound="TokenBalanceNotFound",a))(g||{}),p=class s extends o{static types=g;constructor(e,t,r){super({type:e,instance:t,rootError:r,title:s.#e(e)});}static#e(e){switch(e){case "UnknownTransactionError":return "An unknown error occurred with the transaction";case "UnknownIframeRpcError":return "An unknown error occured with iframe rpc call";case "AddressInvalid":return "Address is invalid";case "AmountInvalid":return "The specified amount is invalid";case "AmountRequired":return "An amount is required for this operation";case "AmountIrrelevant":return "The amount provided is irrelevant and should not be included";case "RecipientAddressEqualsSender":return "Recipient address cannot be the same as the sender address";case "EstimateGasExecution":return "Gas estimation failed";case "InsufficientFunds":return "Insufficient funds to complete the transaction";case "InvalidNftStandard":return "Invalid NFT standard. Supported standards are ERC721 and ERC1155";case "NftNotFound":return "NFT not found with the provided contract address and token ID";case "TokenBalanceNotFound":return "Token balance not found with the provided contract address";default:return `Unknown error type: ${e}`}}};var m=class s{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=>{if(e.data.__KEYBAN_RPC)try{if(!await this.checkEventOrigin(e.origin))throw new c(c.types.InvalidOrigin,"RpcServer");let{service:r,method:n}=e.data;if(!s.#e[r]?.[n])throw new c(c.types.InvalidCall,`RpcServer:${r}.${n}`);let i=this[r]?.[n];if(!i)throw new c(c.types.InvalidCall,`RpcServer:${r}.${n}`);let d=await i.apply(this[r],e.data.params);e.ports[0].postMessage([d,null]);}catch(t){let r=t;r instanceof o||(console.error(t),r=new p(p.types.UnknownIframeRpcError,"RpcServer",t)),e.ports[0].postMessage([null,JSON.stringify(r)]);}}},y=class s{#e;#t;static#r=new Map;static#n({apiUrl:e,appId:t,network:r}){let n=new URL("/sdk-client/rpc",e);return n.searchParams.set("appId",t),n.searchParams.set("network",r),n}static getInstance(e){let t=s.#n(e).toString();return s.#r.has(t)||s.#r.set(t,new s(e)),s.#r.get(t)}constructor(e){this.#e=s.#n(e),this.#t=new Promise((t,r)=>{let n=Object.assign(document.createElement("iframe"),{src:this.#e,hidden:true,onload:()=>t(n),onerror:r});document.body.appendChild(n);});}destroy(){this.#t.then(e=>document.body.removeChild(e));}async call(e,t,...r){let n=await this.#t,i=new MessageChannel;return await new Promise((d,h)=>{i.port1.onmessage=({data:[S,u]})=>(i.port1.close(),u!=null?h(new o(JSON.parse(u))):d(S));let I={__KEYBAN_RPC:true,service:e,method:t,params:r};n.contentWindow?.postMessage(I,this.#e.origin,[i.port2]);})}};exports.RpcClient=y;exports.RpcServer=m;//# sourceMappingURL=rpc.js.map
//# sourceMappingURL=rpc.js.map