@dao-dao/cosmiframe
Advanced tools
Comparing version 0.1.0-rc.9 to 0.1.0-rc.10
@@ -1,2 +0,2 @@ | ||
"use strict";var P=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e,t)=>e in n?P(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e)=>P(n,"name",{value:e,configurable:!0});var ie=(n,e)=>{for(var t in e)P(n,t,{get:e[t],enumerable:!0})},re=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ee(e))!te.call(n,s)&&s!==t&&P(n,s,{get:()=>e[s],enumerable:!(i=j(e,s))||i.enumerable});return n};var se=n=>re(P({},"__esModule",{value:!0}),n);var E=(n,e,t)=>(ne(n,typeof e!="symbol"?e+"":e,t),t),b=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var c=(n,e,t)=>(b(n,e,"read from private field"),t?t.call(n):e.get(n)),A=(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)},O=(n,e,t,i)=>(b(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t);var oe={};ie(oe,{Cosmiframe:()=>Y});module.exports=se(oe);var G=class G extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o(G,"CosmiframeTimeoutError");var v=G;var z=require("uuid");var K="cosmiframe_internal:",B="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((i,s)=>{let T=null,I=(0,z.v4)(),h=o(({origin:f,source:N,data:m})=>{!e.includes("*")&&!e.includes(f)||N!==window.parent||m.id!==I||(window.removeEventListener("message",h),T!==null&&clearTimeout(T),m.type==="success"?i(m.response):s(new Error(m.error)))},"listener");window.addEventListener("message",h);try{let f={...n,id:I};e.forEach(N=>window.parent.postMessage(f,N))}catch(f){window.removeEventListener("message",h),s(f)}t&&(T=setTimeout(()=>{window.removeEventListener("message",h),s(new v(`Timed out after ${t}ms waiting for parent to respond.`))},t))}),"callParentMethod"),U=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"),J=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");var x,$=class ${constructor(e,t){E(this,"chainId");A(this,x,void 0);this.chainId=e,O(this,x,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,x))}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,x))}};x=new WeakMap,o($,"CosmiframeDirectSigner");var D=$,M,F=class F{constructor(e,t){E(this,"chainId");A(this,M,void 0);this.chainId=e,O(this,M,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,M))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,M))}};M=new WeakMap,o(F,"CosmiframeAminoSigner");var R=F,l,H=class H{constructor(e,t){E(this,"chainId");A(this,l,void 0);this.chainId=e,O(this,l,t)}async getAccounts(){try{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,l))}catch{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,l))}}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,l))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,l))}};l=new WeakMap,o(H,"CosmiframeEitherSigner");var W=H;var w;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(w||(w={}));var u,k=class k{constructor(e){A(this,u,void 0);E(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`.");O(this,u,e.includes(B)?["*"]:[...e]),this.p=new Proxy({getEnigmaUtils:t=>({getPubkey:()=>this.p.getEnigmaPubKey(t),decrypt:(...i)=>this.p.enigmaDecrypt(t,...i),encrypt:(...i)=>this.p.enigmaEncrypt(t,...i),getTxEncryptionKey:(...i)=>this.p.getEnigmaTxEncryptionKey(t,...i)})},{get:(t,i)=>i in t&&typeof t[i]!="function"?t[i]:(...s)=>i in t&&typeof t[i]=="function"?t[i](...s):this.callParentMethod({method:i.toString(),params:s})})}callParentMethod(e,t){return p(e,c(this,u),t)}async isReady(){return J()?this.callParentMethod({internal:!0,method:w.IsCosmiframe,params:[]},500).catch(e=>e instanceof v?!1:Promise.reject(e)):!1}async getMetadata(){return this.callParentMethod({internal:!0,method:w.GetMetadata,params:[]},500)}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:(...i)=>e.enigmaDecrypt(t,...i),encrypt:(...i)=>e.enigmaEncrypt(t,...i),getTxEncryptionKey:(...i)=>e.getEnigmaTxEncryptionKey(t,...i)})},{get:(t,i)=>i in t&&typeof t[i]!="function"?t[i]:(...s)=>i in t&&typeof t[i]=="function"?t[i](...s):this.callParentMethod({method:i.toString(),params:s})});return e}getOfflineSigner(e){return new W(e,c(this,u))}getOfflineSignerAmino(e){return new R(e,c(this,u))}getOfflineSignerDirect(e){return new D(e,c(this,u))}static listen(e){let{iframe:t,target:i,getOfflineSignerDirect:s,getOfflineSignerAmino:T,nonSignerOverrides:I,signerOverrides:h,origins:f,metadata:N}=e,m=f?.length?f:["*"],X={[w.IsCosmiframe]:()=>!0,[w.GetMetadata]:()=>N||null},q=o(async({source:Q,origin:C,data:y})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(Q!==t.contentWindow||!m.includes("*")&&!m.includes(C)||!y||typeof y!="object"||!("id"in y)||!("method"in y)||!("params"in y))return;let{id:V,params:L,chainId:S,signType:Z}=y,{method:r,signerType:_}=y;_||(_=Z),r=r.replace(/^signer:/,"");let g;try{if(r.startsWith(K)){if(r=r.slice(K.length),typeof X[r]!="function")throw new Error(`Unknown internal method: ${r}`);g={type:"success",response:await X[r](...L)}}else if(_){if(!S)throw new Error("Missing chainId in signer message request");let a=typeof h=="function"?await h():h;if(a&&r in a){let d=U(await a[r](...L));d&&(g=d)}if(!g){let d=_==="direct"?await s(S):await T(S);if(!(r in d)||typeof d[r]!="function")throw new Error(`No ${_} signer method '${r}' for chain ID '${S}'.`);g={type:"success",response:await d[r](...L)}}}else{let a=typeof I=="function"?await I():I;if(a&&r in a){let d=U(await a[r](...L));d&&(g=d)}if(!g){if(!(r in i)||typeof i[r]!="function")throw new Error(`No method '${r}' on target.`);g={type:"success",response:await i[r](...L)}}}}catch(a){g={type:"error",error:a instanceof Error?a.message:`${a}`}}t.contentWindow?.postMessage({...g,id:V},C)},"listener");return window.addEventListener("message",q),()=>window.removeEventListener("message",q)}};u=new WeakMap,o(k,"Cosmiframe");var Y=k;0&&(module.exports={Cosmiframe}); | ||
"use strict";var N=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(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})},re=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ee(e))!te.call(n,r)&&r!==t&&N(n,r,{get:()=>e[r],enumerable:!(i=j(e,r))||i.enumerable});return n};var se=n=>re(N({},"__esModule",{value:!0}),n);var E=(n,e,t)=>(ne(n,typeof e!="symbol"?e+"":e,t),t),b=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var c=(n,e,t)=>(b(n,e,"read from private field"),t?t.call(n):e.get(n)),A=(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)},O=(n,e,t,i)=>(b(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t);var oe={};ie(oe,{Cosmiframe:()=>F});module.exports=se(oe);var K=class K extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o(K,"CosmiframeTimeoutError");var v=K;var z=require("uuid");var B="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((i,r)=>{let T=null,I=(0,z.v4)(),h=o(({origin:f,source:S,data:m})=>{!e.includes("*")&&!e.includes(f)||S!==window.parent||m.id!==I||(window.removeEventListener("message",h),T!==null&&clearTimeout(T),m.type==="success"?i(m.response):r(new Error(m.error)))},"listener");window.addEventListener("message",h);try{let f={...n,id:I};e.forEach(S=>window.parent.postMessage(f,S))}catch(f){window.removeEventListener("message",h),r(f)}t&&(T=setTimeout(()=>{window.removeEventListener("message",h),r(new v(`Timed out after ${t}ms waiting for parent to respond.`))},t))}),"callParentMethod"),U=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"),J=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");var x,$=class ${constructor(e,t){E(this,"chainId");A(this,x,void 0);this.chainId=e,O(this,x,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,x))}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,x))}};x=new WeakMap,o($,"CosmiframeDirectSigner");var W=$,M,R=class R{constructor(e,t){E(this,"chainId");A(this,M,void 0);this.chainId=e,O(this,M,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,M))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,M))}};M=new WeakMap,o(R,"CosmiframeAminoSigner");var _=R,l,Y=class Y{constructor(e,t){E(this,"chainId");A(this,l,void 0);this.chainId=e,O(this,l,t)}async getAccounts(){try{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,l))}catch{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,l))}}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,l))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,l))}};l=new WeakMap,o(Y,"CosmiframeEitherSigner");var G=Y;var w;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(w||(w={}));var u,k=class k{constructor(e){A(this,u,void 0);E(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`.");O(this,u,e.includes(B)?["*"]:[...e]),this.p=new Proxy({getEnigmaUtils:t=>({getPubkey:()=>this.p.getEnigmaPubKey(t),decrypt:(...i)=>this.p.enigmaDecrypt(t,...i),encrypt:(...i)=>this.p.enigmaEncrypt(t,...i),getTxEncryptionKey:(...i)=>this.p.getEnigmaTxEncryptionKey(t,...i)})},{get:(t,i)=>i in t&&typeof t[i]!="function"?t[i]:(...r)=>i in t&&typeof t[i]=="function"?t[i](...r):this.callParentMethod({method:i.toString(),params:r})})}callParentMethod(e,t){return p(e,c(this,u),t)}async isReady(){return J()?this.callParentMethod({internal:!0,method:w.IsCosmiframe,params:[]},500).catch(e=>e instanceof v?!1:Promise.reject(e)):!1}async getMetadata(){return this.callParentMethod({internal:!0,method:w.GetMetadata,params:[]},500)}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:(...i)=>e.enigmaDecrypt(t,...i),encrypt:(...i)=>e.enigmaEncrypt(t,...i),getTxEncryptionKey:(...i)=>e.getEnigmaTxEncryptionKey(t,...i)})},{get:(t,i)=>i in t&&typeof t[i]!="function"?t[i]:(...r)=>i in t&&typeof t[i]=="function"?t[i](...r):this.callParentMethod({method:i.toString(),params:r})});return e}getOfflineSigner(e){return new G(e,c(this,u))}getOfflineSignerAmino(e){return new _(e,c(this,u))}getOfflineSignerDirect(e){return new W(e,c(this,u))}static listen(e){let{iframe:t,target:i,getOfflineSignerDirect:r,getOfflineSignerAmino:T,nonSignerOverrides:I,signerOverrides:h,origins:f,metadata:S}=e,m=f?.length?f:["*"],H={[w.IsCosmiframe]:()=>!0,[w.GetMetadata]:()=>S||null},q=o(async({source:Q,origin:C,data:y})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(Q!==t.contentWindow||!m.includes("*")&&!m.includes(C)||!y||typeof y!="object"||!("id"in y)||!("method"in y)||!("params"in y))return;let{id:V,params:L,chainId:P,signType:X,internal:Z}=y,{method:s,signerType:D}=y;D||(D=X),s=s.replace(/^signer:/,"");let g;try{if(Z){if(typeof H[s]!="function")throw new Error(`Unknown internal method: ${s}`);g={type:"success",response:await H[s](...L)}}else if(D){if(!P)throw new Error("Missing chainId in signer message request");let a=typeof h=="function"?await h():h;if(a&&s in a){let d=U(await a[s](...L));d&&(g=d)}if(!g){let d=D==="direct"?await r(P):await T(P);if(!(s in d)||typeof d[s]!="function")throw new Error(`No ${D} signer method '${s}' for chain ID '${P}'.`);g={type:"success",response:await d[s](...L)}}}else{let a=typeof I=="function"?await I():I;if(a&&s in a){let d=U(await a[s](...L));d&&(g=d)}if(!g){if(!(s in i)||typeof i[s]!="function")throw new Error(`No method '${s}' on target.`);g={type:"success",response:await i[s](...L)}}}}catch(a){g={type:"error",error:a instanceof Error?a.message:`${a}`}}t.contentWindow?.postMessage({...g,id:V},C)},"listener");return window.addEventListener("message",q),()=>window.removeEventListener("message",q)}};u=new WeakMap,o(k,"Cosmiframe");var F=k;0&&(module.exports={Cosmiframe}); | ||
//# sourceMappingURL=client.js.map |
export { C as Cosmiframe, b as CosmiframeAminoSigner, a as CosmiframeDirectSigner, c as CosmiframeEitherSigner } from './client-DcGSOj8B.js'; | ||
export { InternalMethod, ListenOptions, MethodCallResultMessage, MethodCallResultMessageNoId, OverrideHandler, OverrideHandlerCall, OverrideHandlerError, OverrideHandlerSuccess, Overrides, ParentMetadata, RequestMethodCallMessage, RequestMethodCallMessageNoId, SignerType } from './types.js'; | ||
export { INTERNAL_METHOD_PREFIX, UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler } from './utils.js'; | ||
export { UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler } from './utils.js'; | ||
import '@keplr-wallet/types'; | ||
@@ -5,0 +5,0 @@ import '@cosmjs/amino'; |
@@ -1,2 +0,2 @@ | ||
"use strict";var P=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e,t)=>e in n?P(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e)=>P(n,"name",{value:e,configurable:!0});var re=(n,e)=>{for(var t in e)P(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ee(e))!te.call(n,s)&&s!==t&&P(n,s,{get:()=>e[s],enumerable:!(r=j(e,s))||r.enumerable});return n};var se=n=>ie(P({},"__esModule",{value:!0}),n);var A=(n,e,t)=>(ne(n,typeof e!="symbol"?e+"":e,t),t),B=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var c=(n,e,t)=>(B(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)},x=(n,e,t,r)=>(B(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t);var oe={};re(oe,{Cosmiframe:()=>X,CosmiframeAminoSigner:()=>_,CosmiframeDirectSigner:()=>S,CosmiframeEitherSigner:()=>D,CosmiframeTimeoutError:()=>I,INTERNAL_METHOD_PREFIX:()=>G,InternalMethod:()=>m,UNSAFE_ALLOW_ANY_ORIGIN:()=>$,callParentMethod:()=>p,isInIframe:()=>F,processOverrideHandler:()=>K});module.exports=se(oe);var U=class U extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o(U,"CosmiframeTimeoutError");var I=U;var J=require("uuid");var G="cosmiframe_internal:",$="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((r,s)=>{let T=null,E=(0,J.v4)(),h=o(({origin:f,source:N,data:y})=>{!e.includes("*")&&!e.includes(f)||N!==window.parent||y.id!==E||(window.removeEventListener("message",h),T!==null&&clearTimeout(T),y.type==="success"?r(y.response):s(new Error(y.error)))},"listener");window.addEventListener("message",h);try{let f={...n,id:E};e.forEach(N=>window.parent.postMessage(f,N))}catch(f){window.removeEventListener("message",h),s(f)}t&&(T=setTimeout(()=>{window.removeEventListener("message",h),s(new I(`Timed out after ${t}ms waiting for parent to respond.`))},t))}),"callParentMethod"),K=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"),F=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");var v,H=class H{constructor(e,t){A(this,"chainId");O(this,v,void 0);this.chainId=e,x(this,v,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,v))}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,v))}};v=new WeakMap,o(H,"CosmiframeDirectSigner");var S=H,M,Y=class Y{constructor(e,t){A(this,"chainId");O(this,M,void 0);this.chainId=e,x(this,M,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,M))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,M))}};M=new WeakMap,o(Y,"CosmiframeAminoSigner");var _=Y,l,k=class k{constructor(e,t){A(this,"chainId");O(this,l,void 0);this.chainId=e,x(this,l,t)}async getAccounts(){try{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,l))}catch{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,l))}}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,l))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,l))}};l=new WeakMap,o(k,"CosmiframeEitherSigner");var D=k;var m;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(m||(m={}));var u,q=class q{constructor(e){O(this,u,void 0);A(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`.");x(this,u,e.includes($)?["*"]:[...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]:(...s)=>r in t&&typeof t[r]=="function"?t[r](...s):this.callParentMethod({method:r.toString(),params:s})})}callParentMethod(e,t){return p(e,c(this,u),t)}async isReady(){return F()?this.callParentMethod({internal:!0,method:m.IsCosmiframe,params:[]},500).catch(e=>e instanceof I?!1:Promise.reject(e)):!1}async getMetadata(){return this.callParentMethod({internal:!0,method:m.GetMetadata,params:[]},500)}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]:(...s)=>r in t&&typeof t[r]=="function"?t[r](...s):this.callParentMethod({method:r.toString(),params:s})});return e}getOfflineSigner(e){return new D(e,c(this,u))}getOfflineSignerAmino(e){return new _(e,c(this,u))}getOfflineSignerDirect(e){return new S(e,c(this,u))}static listen(e){let{iframe:t,target:r,getOfflineSignerDirect:s,getOfflineSignerAmino:T,nonSignerOverrides:E,signerOverrides:h,origins:f,metadata:N}=e,y=f?.length?f:["*"],C={[m.IsCosmiframe]:()=>!0,[m.GetMetadata]:()=>N||null},b=o(async({source:Q,origin:z,data:w})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(Q!==t.contentWindow||!y.includes("*")&&!y.includes(z)||!w||typeof w!="object"||!("id"in w)||!("method"in w)||!("params"in w))return;let{id:V,params:L,chainId:R,signType:Z}=w,{method:i,signerType:W}=w;W||(W=Z),i=i.replace(/^signer:/,"");let g;try{if(i.startsWith(G)){if(i=i.slice(G.length),typeof C[i]!="function")throw new Error(`Unknown internal method: ${i}`);g={type:"success",response:await C[i](...L)}}else if(W){if(!R)throw new Error("Missing chainId in signer message request");let a=typeof h=="function"?await h():h;if(a&&i in a){let d=K(await a[i](...L));d&&(g=d)}if(!g){let d=W==="direct"?await s(R):await T(R);if(!(i in d)||typeof d[i]!="function")throw new Error(`No ${W} signer method '${i}' for chain ID '${R}'.`);g={type:"success",response:await d[i](...L)}}}else{let a=typeof E=="function"?await E():E;if(a&&i in a){let d=K(await a[i](...L));d&&(g=d)}if(!g){if(!(i in r)||typeof r[i]!="function")throw new Error(`No method '${i}' on target.`);g={type:"success",response:await r[i](...L)}}}}catch(a){g={type:"error",error:a instanceof Error?a.message:`${a}`}}t.contentWindow?.postMessage({...g,id:V},z)},"listener");return window.addEventListener("message",b),()=>window.removeEventListener("message",b)}};u=new WeakMap,o(q,"Cosmiframe");var X=q;0&&(module.exports={Cosmiframe,CosmiframeAminoSigner,CosmiframeDirectSigner,CosmiframeEitherSigner,CosmiframeTimeoutError,INTERNAL_METHOD_PREFIX,InternalMethod,UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,processOverrideHandler}); | ||
"use strict";var N=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(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 re=(n,e)=>{for(var t in e)N(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ee(e))!te.call(n,i)&&i!==t&&N(n,i,{get:()=>e[i],enumerable:!(r=j(e,i))||r.enumerable});return n};var se=n=>ie(N({},"__esModule",{value:!0}),n);var A=(n,e,t)=>(ne(n,typeof e!="symbol"?e+"":e,t),t),B=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var c=(n,e,t)=>(B(n,e,"read from private field"),t?t.call(n):e.get(n)),x=(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)},O=(n,e,t,r)=>(B(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t);var oe={};re(oe,{Cosmiframe:()=>H,CosmiframeAminoSigner:()=>D,CosmiframeDirectSigner:()=>P,CosmiframeEitherSigner:()=>W,CosmiframeTimeoutError:()=>I,InternalMethod:()=>m,UNSAFE_ALLOW_ANY_ORIGIN:()=>$,callParentMethod:()=>p,isInIframe:()=>R,processOverrideHandler:()=>K});module.exports=se(oe);var U=class U extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o(U,"CosmiframeTimeoutError");var I=U;var J=require("uuid");var $="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((r,i)=>{let T=null,E=(0,J.v4)(),h=o(({origin:f,source:S,data:y})=>{!e.includes("*")&&!e.includes(f)||S!==window.parent||y.id!==E||(window.removeEventListener("message",h),T!==null&&clearTimeout(T),y.type==="success"?r(y.response):i(new Error(y.error)))},"listener");window.addEventListener("message",h);try{let f={...n,id:E};e.forEach(S=>window.parent.postMessage(f,S))}catch(f){window.removeEventListener("message",h),i(f)}t&&(T=setTimeout(()=>{window.removeEventListener("message",h),i(new I(`Timed out after ${t}ms waiting for parent to respond.`))},t))}),"callParentMethod"),K=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"),R=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");var v,Y=class Y{constructor(e,t){A(this,"chainId");x(this,v,void 0);this.chainId=e,O(this,v,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,v))}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,v))}};v=new WeakMap,o(Y,"CosmiframeDirectSigner");var P=Y,M,F=class F{constructor(e,t){A(this,"chainId");x(this,M,void 0);this.chainId=e,O(this,M,t)}async getAccounts(){return p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,M))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,M))}};M=new WeakMap,o(F,"CosmiframeAminoSigner");var D=F,l,k=class k{constructor(e,t){A(this,"chainId");x(this,l,void 0);this.chainId=e,O(this,l,t)}async getAccounts(){try{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},c(this,l))}catch{return await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},c(this,l))}}async signDirect(e,t){return p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},c(this,l))}async signAmino(e,t){return p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},c(this,l))}};l=new WeakMap,o(k,"CosmiframeEitherSigner");var W=k;var m;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(m||(m={}));var u,q=class q{constructor(e){x(this,u,void 0);A(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`.");O(this,u,e.includes($)?["*"]:[...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})})}callParentMethod(e,t){return p(e,c(this,u),t)}async isReady(){return R()?this.callParentMethod({internal:!0,method:m.IsCosmiframe,params:[]},500).catch(e=>e instanceof I?!1:Promise.reject(e)):!1}async getMetadata(){return this.callParentMethod({internal:!0,method:m.GetMetadata,params:[]},500)}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})});return e}getOfflineSigner(e){return new W(e,c(this,u))}getOfflineSignerAmino(e){return new D(e,c(this,u))}getOfflineSignerDirect(e){return new P(e,c(this,u))}static listen(e){let{iframe:t,target:r,getOfflineSignerDirect:i,getOfflineSignerAmino:T,nonSignerOverrides:E,signerOverrides:h,origins:f,metadata:S}=e,y=f?.length?f:["*"],C={[m.IsCosmiframe]:()=>!0,[m.GetMetadata]:()=>S||null},b=o(async({source:Q,origin:z,data:w})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(Q!==t.contentWindow||!y.includes("*")&&!y.includes(z)||!w||typeof w!="object"||!("id"in w)||!("method"in w)||!("params"in w))return;let{id:V,params:L,chainId:_,signType:X,internal:Z}=w,{method:s,signerType:G}=w;G||(G=X),s=s.replace(/^signer:/,"");let g;try{if(Z){if(typeof C[s]!="function")throw new Error(`Unknown internal method: ${s}`);g={type:"success",response:await C[s](...L)}}else if(G){if(!_)throw new Error("Missing chainId in signer message request");let a=typeof h=="function"?await h():h;if(a&&s in a){let d=K(await a[s](...L));d&&(g=d)}if(!g){let d=G==="direct"?await i(_):await T(_);if(!(s in d)||typeof d[s]!="function")throw new Error(`No ${G} signer method '${s}' for chain ID '${_}'.`);g={type:"success",response:await d[s](...L)}}}else{let a=typeof E=="function"?await E():E;if(a&&s in a){let d=K(await a[s](...L));d&&(g=d)}if(!g){if(!(s in r)||typeof r[s]!="function")throw new Error(`No method '${s}' on target.`);g={type:"success",response:await r[s](...L)}}}}catch(a){g={type:"error",error:a instanceof Error?a.message:`${a}`}}t.contentWindow?.postMessage({...g,id:V},z)},"listener");return window.addEventListener("message",b),()=>window.removeEventListener("message",b)}};u=new WeakMap,o(q,"Cosmiframe");var H=q;0&&(module.exports={Cosmiframe,CosmiframeAminoSigner,CosmiframeDirectSigner,CosmiframeEitherSigner,CosmiframeTimeoutError,InternalMethod,UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,processOverrideHandler}); | ||
//# sourceMappingURL=index.js.map |
@@ -6,6 +6,2 @@ import { RequestMethodCallMessageNoId, OverrideHandler, MethodCallResultMessageNoId } from './types.js'; | ||
/** | ||
* Prefix for internal methods. | ||
*/ | ||
declare const INTERNAL_METHOD_PREFIX = "cosmiframe_internal:"; | ||
/** | ||
* Origin specified by the iframe to allow all origins. This is unsafe and | ||
@@ -31,2 +27,2 @@ * should not be done. | ||
export { INTERNAL_METHOD_PREFIX, UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler }; | ||
export { UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler }; |
@@ -1,2 +0,2 @@ | ||
"use strict";var w=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var t=(e,r)=>w(e,"name",{value:r,configurable:!0});var I=(e,r)=>{for(var o in r)w(e,o,{get:r[o],enumerable:!0})},L=(e,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of v(r))!y.call(e,s)&&s!==o&&w(e,s,{get:()=>r[s],enumerable:!(i=E(r,s))||i.enumerable});return e};var N=e=>L(w({},"__esModule",{value:!0}),e);var g={};I(g,{INTERNAL_METHOD_PREFIX:()=>_,UNSAFE_ALLOW_ANY_ORIGIN:()=>x,callParentMethod:()=>A,isInIframe:()=>T,processOverrideHandler:()=>O});module.exports=N(g);var l=require("uuid");var a=class a extends Error{constructor(r){super(r),this.name="CosmiframeTimeoutError"}};t(a,"CosmiframeTimeoutError");var d=a;var _="cosmiframe_internal:",x="UNSAFE_ALLOW_ANY_ORIGIN",A=t((e,r,o)=>new Promise((i,s)=>{let m=null,f=(0,l.v4)(),p=t(({origin:n,source:u,data:c})=>{!r.includes("*")&&!r.includes(n)||u!==window.parent||c.id!==f||(window.removeEventListener("message",p),m!==null&&clearTimeout(m),c.type==="success"?i(c.response):s(new Error(c.error)))},"listener");window.addEventListener("message",p);try{let n={...e,id:f};r.forEach(u=>window.parent.postMessage(n,u))}catch(n){window.removeEventListener("message",p),s(n)}o&&(m=setTimeout(()=>{window.removeEventListener("message",p),s(new d(`Timed out after ${o}ms waiting for parent to respond.`))},o))}),"callParentMethod"),O=t(e=>{if(!e||e.type==="error")return{type:"error",error:e&&e.type==="error"&&e.error||"Handled by outer wallet."};if(e.type==="success")return{type:"success",response:e.value}},"processOverrideHandler"),T=t(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");0&&(module.exports={INTERNAL_METHOD_PREFIX,UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,processOverrideHandler}); | ||
"use strict";var c=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var t=(e,r)=>c(e,"name",{value:r,configurable:!0});var L=(e,r)=>{for(var o in r)c(e,o,{get:r[o],enumerable:!0})},I=(e,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of y(r))!E.call(e,s)&&s!==o&&c(e,s,{get:()=>r[s],enumerable:!(i=v(r,s))||i.enumerable});return e};var x=e=>I(c({},"__esModule",{value:!0}),e);var g={};L(g,{UNSAFE_ALLOW_ANY_ORIGIN:()=>A,callParentMethod:()=>N,isInIframe:()=>_,processOverrideHandler:()=>O});module.exports=x(g);var l=require("uuid");var a=class a extends Error{constructor(r){super(r),this.name="CosmiframeTimeoutError"}};t(a,"CosmiframeTimeoutError");var d=a;var A="UNSAFE_ALLOW_ANY_ORIGIN",N=t((e,r,o)=>new Promise((i,s)=>{let u=null,f=(0,l.v4)(),p=t(({origin:n,source:m,data:w})=>{!r.includes("*")&&!r.includes(n)||m!==window.parent||w.id!==f||(window.removeEventListener("message",p),u!==null&&clearTimeout(u),w.type==="success"?i(w.response):s(new Error(w.error)))},"listener");window.addEventListener("message",p);try{let n={...e,id:f};r.forEach(m=>window.parent.postMessage(n,m))}catch(n){window.removeEventListener("message",p),s(n)}o&&(u=setTimeout(()=>{window.removeEventListener("message",p),s(new d(`Timed out after ${o}ms waiting for parent to respond.`))},o))}),"callParentMethod"),O=t(e=>{if(!e||e.type==="error")return{type:"error",error:e&&e.type==="error"&&e.error||"Handled by outer wallet."};if(e.type==="success")return{type:"success",response:e.value}},"processOverrideHandler"),_=t(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");0&&(module.exports={UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,processOverrideHandler}); | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@dao-dao/cosmiframe", | ||
"version": "0.1.0-rc.9", | ||
"version": "0.1.0-rc.10", | ||
"description": "Facilitate iframe message passthrough for wallet connections", | ||
@@ -5,0 +5,0 @@ "author": "Noah Saso <noah@daodao.zone>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
219693
393