@dao-dao/cosmiframe
Advanced tools
Comparing version 0.1.0-rc.7 to 0.1.0-rc.8
import '@keplr-wallet/types'; | ||
export { C as Cosmiframe } from './client-ubUNfEvj.js'; | ||
export { C as Cosmiframe } from './client-BxM1Q4lx.js'; | ||
import './types.js'; | ||
import '@cosmjs/amino'; | ||
import '@cosmjs/proto-signing'; |
@@ -1,2 +0,2 @@ | ||
"use strict";var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e,t)=>e in n?L(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e)=>L(n,"name",{value:e,configurable:!0});var ie=(n,e)=>{for(var t in e)L(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&&L(n,s,{get:()=>e[s],enumerable:!(i=j(e,s))||i.enumerable});return n};var se=n=>re(L({},"__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 getParentMetadata(){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:P,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](...P)}}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](...P));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](...P)}}}else{let a=typeof I=="function"?await I():I;if(a&&r in a){let d=U(await a[r](...P));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](...P)}}}}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 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}); | ||
//# sourceMappingURL=client.js.map |
@@ -1,2 +0,2 @@ | ||
export { C as Cosmiframe, b as CosmiframeAminoSigner, a as CosmiframeDirectSigner, c as CosmiframeEitherSigner } from './client-ubUNfEvj.js'; | ||
export { C as Cosmiframe, b as CosmiframeAminoSigner, a as CosmiframeDirectSigner, c as CosmiframeEitherSigner } from './client-BxM1Q4lx.js'; | ||
export { InternalMethod, ListenOptions, MethodCallResultMessage, MethodCallResultMessageNoId, OverrideHandler, OverrideHandlerCall, OverrideHandlerError, OverrideHandlerSuccess, Overrides, ParentMetadata, RequestMethodCallMessage, RequestMethodCallMessageNoId, SignerType } from './types.js'; | ||
@@ -3,0 +3,0 @@ export { INTERNAL_METHOD_PREFIX, UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler } from './utils.js'; |
@@ -1,2 +0,2 @@ | ||
"use strict";var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e,t)=>e in n?L(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e)=>L(n,"name",{value:e,configurable:!0});var re=(n,e)=>{for(var t in e)L(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&&L(n,s,{get:()=>e[s],enumerable:!(r=j(e,s))||r.enumerable});return n};var se=n=>ie(L({},"__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 getParentMetadata(){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:P,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](...P)}}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](...P));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](...P)}}}else{let a=typeof E=="function"?await E():E;if(a&&i in a){let d=K(await a[i](...P));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](...P)}}}}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 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}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dao-dao/cosmiframe", | ||
"version": "0.1.0-rc.7", | ||
"version": "0.1.0-rc.8", | ||
"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
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
222056