/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@dao-dao/cosmiframe@1.0.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var N=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(n,e,t)=>e in n?N(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e)=>N(n,"name",{value:e,configurable:!0});var ie=(n,e)=>{for(var t in e)N(n,t,{get:e[t],enumerable:!0})},se=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of te(e))!ne.call(n,i)&&i!==t&&N(n,i,{get:()=>e[i],enumerable:!(r=ee(e,i))||r.enumerable});return n};var oe=n=>se(N({},"__esModule",{value:!0}),n);var x=(n,e,t)=>(re(n,typeof e!="symbol"?e+"":e,t),t),J=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var a=(n,e,t)=>(J(n,e,"read from private field"),t?t.call(n):e.get(n)),O=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},v=(n,e,t,r)=>(J(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t);var ae={};ie(ae,{Cosmiframe:()=>q,CosmiframeAminoSigner:()=>D,CosmiframeDirectSigner:()=>P,CosmiframeEitherSigner:()=>W,CosmiframeTimeoutError:()=>I,InternalMethod:()=>m,UNSAFE_ALLOW_ANY_ORIGIN:()=>R,callParentMethod:()=>p,isInIframe:()=>Y,isOriginAllowed:()=>K,processOverrideHandler:()=>G});module.exports=oe(ae);var $=class $ extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o($,"CosmiframeTimeoutError");var I=$;var Q=require("uuid");var R="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((r,i)=>{let h=null,E=(0,Q.v4)(),l=o(({origin:f,source:U,data:A})=>{!K(e,f)||U!==window.parent||A.id!==E||(window.removeEventListener("message",l),h!==null&&clearTimeout(h),A.type==="success"?r({result:A.response,origin:f}):i(new Error(A.error)))},"listener");window.addEventListener("message",l);try{let f={...n,id:E};window.parent.postMessage(f,"*")}catch(f){window.removeEventListener("message",l),i(f)}t&&(h=setTimeout(()=>{window.removeEventListener("message",l),i(new I(`Timed out after ${t}ms waiting for parent to respond.`))},t))}),"callParentMethod"),G=o(n=>{if(!n||n.type==="error")return{type:"error",error:n&&n.type==="error"&&n.error||"Handled by outer wallet."};if(n.type==="success")return{type:"success",response:n.value}},"processOverrideHandler"),Y=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe"),K=o((n,e)=>n.some(t=>t==="*"||typeof t=="string"&&e===t||t instanceof RegExp&&t.test(e)),"isOriginAllowed");var M,F=class F{constructor(e,t){x(this,"chainId");O(this,M,void 0);this.chainId=e,v(this,M,t)}async getAccounts(){return(await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},a(this,M))).result}async signDirect(e,t){return(await p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},a(this,M))).result}};M=new WeakMap,o(F,"CosmiframeDirectSigner");var P=F,T,k=class k{constructor(e,t){x(this,"chainId");O(this,T,void 0);this.chainId=e,v(this,T,t)}async getAccounts(){return(await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},a(this,T))).result}async signAmino(e,t){return(await p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},a(this,T))).result}};T=new WeakMap,o(k,"CosmiframeAminoSigner");var D=k,u,H=class H{constructor(e,t){x(this,"chainId");O(this,u,void 0);this.chainId=e,v(this,u,t)}async getAccounts(){try{return(await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},a(this,u))).result}catch{return(await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},a(this,u))).result}}async signDirect(e,t){return(await p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},a(this,u))).result}async signAmino(e,t){return(await p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},a(this,u))).result}};u=new WeakMap,o(H,"CosmiframeEitherSigner");var W=H;var m;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(m||(m={}));var y,C=class C{constructor(e){O(this,y,void 0);x(this,"p");if(!e.length)throw new Error("You must explicitly allow parent origins.");if(e.includes("*"))throw new Error("It is very unsafe to allow all origins because a controlling app has the power to manipulate messages before they are signed. If you really want to do this, pass in `UNSAFE_ALLOW_ANY_ORIGIN`.");v(this,y,e.includes(R)?["*"]:[...e]),this.p=new Proxy({getEnigmaUtils:t=>({getPubkey:()=>this.p.getEnigmaPubKey(t),decrypt:(...r)=>this.p.enigmaDecrypt(t,...r),encrypt:(...r)=>this.p.enigmaEncrypt(t,...r),getTxEncryptionKey:(...r)=>this.p.getEnigmaTxEncryptionKey(t,...r)})},{get:(t,r)=>r in t&&typeof t[r]!="function"?t[r]:(...i)=>r in t&&typeof t[r]=="function"?t[r](...i):this.callParentMethod({method:r.toString(),params:i}).then(({result:h})=>h)})}callParentMethod(e,t){return p(e,a(this,y),t)}async isReady(){if(!Y())return!1;try{let{origin:e,result:t}=await this.callParentMethod({internal:!0,method:m.IsCosmiframe,params:[]},500);return e||t}catch(e){if(e instanceof I)return!1;throw e}}async getMetadata(){return(await this.callParentMethod({internal:!0,method:m.GetMetadata,params:[]},500)).result}getKeplrClient(){let e=new Proxy({version:"cosmiframe",mode:"extension",defaultOptions:{},getOfflineSigner:this.getOfflineSigner.bind(this),getOfflineSignerOnlyAmino:this.getOfflineSignerAmino.bind(this),getOfflineSignerAuto:t=>Promise.resolve(this.getOfflineSigner(t)),getEnigmaUtils:t=>({getPubkey:()=>e.getEnigmaPubKey(t),decrypt:(...r)=>e.enigmaDecrypt(t,...r),encrypt:(...r)=>e.enigmaEncrypt(t,...r),getTxEncryptionKey:(...r)=>e.getEnigmaTxEncryptionKey(t,...r)})},{get:(t,r)=>r in t&&typeof t[r]!="function"?t[r]:(...i)=>r in t&&typeof t[r]=="function"?t[r](...i):this.callParentMethod({method:r.toString(),params:i}).then(({result:h})=>h)});return e}getOfflineSigner(e){return new W(e,a(this,y))}getOfflineSignerAmino(e){return new D(e,a(this,y))}getOfflineSignerDirect(e){return new P(e,a(this,y))}static listen(e){let{iframe:t,target:r,getOfflineSignerDirect:i,getOfflineSignerAmino:h,nonSignerOverrides:E,signerOverrides:l,origins:f,metadata:U}=e,A=f?.length?f:["*"],b={[m.IsCosmiframe]:()=>!0,[m.GetMetadata]:()=>U||null},z=o(async({source:V,origin:B,data:w})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(V!==t.contentWindow||!K(A,B)||!w||typeof w!="object"||!("id"in w)||!("method"in w)||!("params"in w))return;let{id:X,params:S,chainId:L,signType:Z,internal:j}=w,{method:s,signerType:_}=w;_||(_=Z),s=s.replace(/^signer:/,"");let d;try{if(j){if(typeof b[s]!="function")throw new Error(`Unknown internal method: ${s}`);d={type:"success",response:await b[s](...S)}}else if(_){if(!L)throw new Error("Missing chainId in signer message request");let c=typeof l=="function"?await l(L):l;if(c&&s in c){let g=G(await c[s](...S));g&&(d=g)}if(!d){let g=_==="direct"?await i(L):await h(L);if(!(s in g)||typeof g[s]!="function")throw new Error(`No ${_} signer method '${s}' for chain ID '${L}'.`);d={type:"success",response:await g[s](...S)}}}else{let c=typeof E=="function"?await E():E;if(c&&s in c){let g=G(await c[s](...S));g&&(d=g)}if(!d){if(!(s in r)||typeof r[s]!="function")throw new Error(`No method '${s}' on target.`);d={type:"success",response:await r[s](...S)}}}}catch(c){d={type:"error",error:c instanceof Error?c.message:`${c}`}}t.contentWindow?.postMessage({...d,id:X},B)},"listener");return window.addEventListener("message",z),()=>window.removeEventListener("message",z)}};y=new WeakMap,o(C,"Cosmiframe");var q=C;0&&(module.exports={Cosmiframe,CosmiframeAminoSigner,CosmiframeDirectSigner,CosmiframeEitherSigner,CosmiframeTimeoutError,InternalMethod,UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,isOriginAllowed,processOverrideHandler});
//# sourceMappingURL=index.js.map