New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dao-dao/cosmiframe

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dao-dao/cosmiframe - npm Package Compare versions

Comparing version 1.0.0-rc.0 to 1.0.0-rc.1

dist/client-BBLGHYRw.d.ts

2

dist/client.d.ts
import '@keplr-wallet/types';
export { C as Cosmiframe } from './client-BwsaPS7g.js';
export { C as Cosmiframe } from './client-BBLGHYRw.js';
import './types.js';
import '@cosmjs/amino';
import '@cosmjs/proto-signing';

@@ -1,2 +0,2 @@

"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 a=(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)},v=(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:()=>F});module.exports=se(oe);var K=class K extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o(K,"CosmiframeTimeoutError");var x=K;var z=require("uuid");var B="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((r,i)=>{let d=null,E=(0,z.v4)(),u=o(({origin:g,source:S,data:w})=>{!e.includes("*")&&!e.includes(g)||S!==window.parent||w.id!==E||(window.removeEventListener("message",u),d!==null&&clearTimeout(d),w.type==="success"?r({result:w.response,origin:g}):i(new Error(w.error)))},"listener");window.addEventListener("message",u);try{let g={...n,id:E};e.forEach(S=>window.parent.postMessage(g,S))}catch(g){window.removeEventListener("message",u),i(g)}t&&(d=setTimeout(()=>{window.removeEventListener("message",u),i(new x(`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 M,$=class ${constructor(e,t){A(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($,"CosmiframeDirectSigner");var W=$,T,R=class R{constructor(e,t){A(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(R,"CosmiframeAminoSigner");var _=R,f,Y=class Y{constructor(e,t){A(this,"chainId");O(this,f,void 0);this.chainId=e,v(this,f,t)}async getAccounts(){try{return(await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"amino"},a(this,f))).result}catch{return(await p({method:"getAccounts",params:[],chainId:this.chainId,signerType:"direct"},a(this,f))).result}}async signDirect(e,t){return(await p({method:"signDirect",params:[e,t],chainId:this.chainId,signerType:"direct"},a(this,f))).result}async signAmino(e,t){return(await p({method:"signAmino",params:[e,t],chainId:this.chainId,signerType:"amino"},a(this,f))).result}};f=new WeakMap,o(Y,"CosmiframeEitherSigner");var G=Y;var I;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(I||(I={}));var m,k=class k{constructor(e){O(this,m,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`.");v(this,m,e.includes(B)?["*"]:[...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:d})=>d)})}callParentMethod(e,t){return p(e,a(this,m),t)}async isReady(){if(!J())return!1;try{let{origin:e,result:t}=await this.callParentMethod({internal:!0,method:I.IsCosmiframe,params:[]},500);return e||t}catch(e){if(e instanceof x)return!1;throw e}}async getMetadata(){return(await this.callParentMethod({internal:!0,method:I.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:d})=>d)});return e}getOfflineSigner(e){return new G(e,a(this,m))}getOfflineSignerAmino(e){return new _(e,a(this,m))}getOfflineSignerDirect(e){return new W(e,a(this,m))}static listen(e){let{iframe:t,target:r,getOfflineSignerDirect:i,getOfflineSignerAmino:d,nonSignerOverrides:E,signerOverrides:u,origins:g,metadata:S}=e,w=g?.length?g:["*"],H={[I.IsCosmiframe]:()=>!0,[I.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||!w.includes("*")&&!w.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 l;try{if(Z){if(typeof H[s]!="function")throw new Error(`Unknown internal method: ${s}`);l={type:"success",response:await H[s](...L)}}else if(D){if(!P)throw new Error("Missing chainId in signer message request");let c=typeof u=="function"?await u():u;if(c&&s in c){let h=U(await c[s](...L));h&&(l=h)}if(!l){let h=D==="direct"?await i(P):await d(P);if(!(s in h)||typeof h[s]!="function")throw new Error(`No ${D} signer method '${s}' for chain ID '${P}'.`);l={type:"success",response:await h[s](...L)}}}else{let c=typeof E=="function"?await E():E;if(c&&s in c){let h=U(await c[s](...L));h&&(l=h)}if(!l){if(!(s in r)||typeof r[s]!="function")throw new Error(`No method '${s}' on target.`);l={type:"success",response:await r[s](...L)}}}}catch(c){l={type:"error",error:c instanceof Error?c.message:`${c}`}}t.contentWindow?.postMessage({...l,id:V},C)},"listener");return window.addEventListener("message",q),()=>window.removeEventListener("message",q)}};m=new WeakMap,o(k,"Cosmiframe");var F=k;0&&(module.exports={Cosmiframe});
"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 A=(n,e,t)=>(re(n,typeof e!="symbol"?e+"":e,t),t),z=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var a=(n,e,t)=>(z(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)=>(z(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t);var ae={};ie(ae,{Cosmiframe:()=>k});module.exports=oe(ae);var K=class K extends Error{constructor(e){super(e),this.name="CosmiframeTimeoutError"}};o(K,"CosmiframeTimeoutError");var x=K;var B=require("uuid");var J="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((r,i)=>{let h=null,I=(0,B.v4)(),l=o(({origin:d,source:G,data:E})=>{!$(e,d)||G!==window.parent||E.id!==I||(window.removeEventListener("message",l),h!==null&&clearTimeout(h),E.type==="success"?r({result:E.response,origin:d}):i(new Error(E.error)))},"listener");window.addEventListener("message",l);try{let d={...n,id:I};window.parent.postMessage(d,"*")}catch(d){window.removeEventListener("message",l),i(d)}t&&(h=setTimeout(()=>{window.removeEventListener("message",l),i(new x(`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"),Q=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe"),$=o((n,e)=>n.some(t=>t==="*"||typeof t=="string"&&e===t||t instanceof RegExp&&t.test(e)),"isOriginAllowed");var M,R=class R{constructor(e,t){A(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(R,"CosmiframeDirectSigner");var D=R,T,Y=class Y{constructor(e,t){A(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(Y,"CosmiframeAminoSigner");var W=Y,u,F=class F{constructor(e,t){A(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(F,"CosmiframeEitherSigner");var _=F;var w;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(w||(w={}));var m,H=class H{constructor(e){O(this,m,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`.");v(this,m,e.includes(J)?["*"]:[...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,m),t)}async isReady(){if(!Q())return!1;try{let{origin:e,result:t}=await this.callParentMethod({internal:!0,method:w.IsCosmiframe,params:[]},500);return e||t}catch(e){if(e instanceof x)return!1;throw e}}async getMetadata(){return(await this.callParentMethod({internal:!0,method:w.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 _(e,a(this,m))}getOfflineSignerAmino(e){return new W(e,a(this,m))}getOfflineSignerDirect(e){return new D(e,a(this,m))}static listen(e){let{iframe:t,target:r,getOfflineSignerDirect:i,getOfflineSignerAmino:h,nonSignerOverrides:I,signerOverrides:l,origins:d,metadata:G}=e,E=d?.length?d:["*"],q={[w.IsCosmiframe]:()=>!0,[w.GetMetadata]:()=>G||null},C=o(async({source:V,origin:b,data:y})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(V!==t.contentWindow||!$(E,b)||!y||typeof y!="object"||!("id"in y)||!("method"in y)||!("params"in y))return;let{id:X,params:S,chainId:L,signType:Z,internal:j}=y,{method:s,signerType:P}=y;P||(P=Z),s=s.replace(/^signer:/,"");let f;try{if(j){if(typeof q[s]!="function")throw new Error(`Unknown internal method: ${s}`);f={type:"success",response:await q[s](...S)}}else if(P){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=U(await c[s](...S));g&&(f=g)}if(!f){let g=P==="direct"?await i(L):await h(L);if(!(s in g)||typeof g[s]!="function")throw new Error(`No ${P} signer method '${s}' for chain ID '${L}'.`);f={type:"success",response:await g[s](...S)}}}else{let c=typeof I=="function"?await I():I;if(c&&s in c){let g=U(await c[s](...S));g&&(f=g)}if(!f){if(!(s in r)||typeof r[s]!="function")throw new Error(`No method '${s}' on target.`);f={type:"success",response:await r[s](...S)}}}}catch(c){f={type:"error",error:c instanceof Error?c.message:`${c}`}}t.contentWindow?.postMessage({...f,id:X},b)},"listener");return window.addEventListener("message",C),()=>window.removeEventListener("message",C)}};m=new WeakMap,o(H,"Cosmiframe");var k=H;0&&(module.exports={Cosmiframe});
//# sourceMappingURL=client.js.map

@@ -1,4 +0,4 @@

export { C as Cosmiframe, b as CosmiframeAminoSigner, a as CosmiframeDirectSigner, c as CosmiframeEitherSigner } from './client-BwsaPS7g.js';
export { CalledParentMethodResult, InternalMethod, ListenOptions, MethodCallResultMessage, MethodCallResultMessageNoId, OverrideHandler, OverrideHandlerCall, OverrideHandlerError, OverrideHandlerSuccess, Overrides, ParentMetadata, RequestMethodCallMessage, RequestMethodCallMessageNoId, SignerType } from './types.js';
export { UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler } from './utils.js';
export { C as Cosmiframe, b as CosmiframeAminoSigner, a as CosmiframeDirectSigner, c as CosmiframeEitherSigner } from './client-BBLGHYRw.js';
export { CalledParentMethodResult, InternalMethod, ListenOptions, MethodCallResultMessage, MethodCallResultMessageNoId, Origin, OverrideHandler, OverrideHandlerCall, OverrideHandlerError, OverrideHandlerSuccess, Overrides, ParentMetadata, RequestMethodCallMessage, RequestMethodCallMessageNoId, SignerType } from './types.js';
export { UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, isOriginAllowed, processOverrideHandler } from './utils.js';
import '@keplr-wallet/types';

@@ -5,0 +5,0 @@ import '@cosmjs/amino';

@@ -1,2 +0,2 @@

"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 x=(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 a=(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)},v=(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:()=>E,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 E=U;var J=require("uuid");var $="UNSAFE_ALLOW_ANY_ORIGIN",p=o((n,e,t)=>new Promise((r,i)=>{let d=null,A=(0,J.v4)(),f=o(({origin:g,source:S,data:y})=>{!e.includes("*")&&!e.includes(g)||S!==window.parent||y.id!==A||(window.removeEventListener("message",f),d!==null&&clearTimeout(d),y.type==="success"?r({result:y.response,origin:g}):i(new Error(y.error)))},"listener");window.addEventListener("message",f);try{let g={...n,id:A};e.forEach(S=>window.parent.postMessage(g,S))}catch(g){window.removeEventListener("message",f),i(g)}t&&(d=setTimeout(()=>{window.removeEventListener("message",f),i(new E(`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 M,Y=class Y{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(Y,"CosmiframeDirectSigner");var P=Y,T,F=class F{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(F,"CosmiframeAminoSigner");var D=F,u,k=class k{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(k,"CosmiframeEitherSigner");var W=k;var m;(function(n){n.IsCosmiframe="isCosmiframe",n.GetMetadata="getMetadata"})(m||(m={}));var w,q=class q{constructor(e){O(this,w,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,w,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}).then(({result:d})=>d)})}callParentMethod(e,t){return p(e,a(this,w),t)}async isReady(){if(!R())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 E)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:d})=>d)});return e}getOfflineSigner(e){return new W(e,a(this,w))}getOfflineSignerAmino(e){return new D(e,a(this,w))}getOfflineSignerDirect(e){return new P(e,a(this,w))}static listen(e){let{iframe:t,target:r,getOfflineSignerDirect:i,getOfflineSignerAmino:d,nonSignerOverrides:A,signerOverrides:f,origins:g,metadata:S}=e,y=g?.length?g:["*"],C={[m.IsCosmiframe]:()=>!0,[m.GetMetadata]:()=>S||null},b=o(async({source:Q,origin:z,data:I})=>{if(!t.contentWindow)throw new Error("Iframe contentWindow does not exist.");if(Q!==t.contentWindow||!y.includes("*")&&!y.includes(z)||!I||typeof I!="object"||!("id"in I)||!("method"in I)||!("params"in I))return;let{id:V,params:L,chainId:_,signType:X,internal:Z}=I,{method:s,signerType:G}=I;G||(G=X),s=s.replace(/^signer:/,"");let l;try{if(Z){if(typeof C[s]!="function")throw new Error(`Unknown internal method: ${s}`);l={type:"success",response:await C[s](...L)}}else if(G){if(!_)throw new Error("Missing chainId in signer message request");let c=typeof f=="function"?await f():f;if(c&&s in c){let h=K(await c[s](...L));h&&(l=h)}if(!l){let h=G==="direct"?await i(_):await d(_);if(!(s in h)||typeof h[s]!="function")throw new Error(`No ${G} signer method '${s}' for chain ID '${_}'.`);l={type:"success",response:await h[s](...L)}}}else{let c=typeof A=="function"?await A():A;if(c&&s in c){let h=K(await c[s](...L));h&&(l=h)}if(!l){if(!(s in r)||typeof r[s]!="function")throw new Error(`No method '${s}' on target.`);l={type:"success",response:await r[s](...L)}}}}catch(c){l={type:"error",error:c instanceof Error?c.message:`${c}`}}t.contentWindow?.postMessage({...l,id:V},z)},"listener");return window.addEventListener("message",b),()=>window.removeEventListener("message",b)}};w=new WeakMap,o(q,"Cosmiframe");var H=q;0&&(module.exports={Cosmiframe,CosmiframeAminoSigner,CosmiframeDirectSigner,CosmiframeEitherSigner,CosmiframeTimeoutError,InternalMethod,UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,processOverrideHandler});
"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

@@ -9,2 +9,6 @@ import { OfflineAminoSigner } from '@cosmjs/amino';

/**
* The types of origins accepted.
*/
type Origin = string | RegExp;
/**
* A message sent from the iframe to the parent requesting a method be called.

@@ -114,3 +118,3 @@ */

*/
signerOverrides?: Overrides | (() => Overrides) | (() => Promise<Overrides>);
signerOverrides?: Overrides | ((chainId: string) => Overrides) | ((chainId: string) => Promise<Overrides>);
/**

@@ -124,3 +128,3 @@ * Restrict iframe origins that are allowed to connect to this listening

*/
origins?: string[];
origins?: Origin[];
/**

@@ -144,2 +148,2 @@ * Optionally set a name and imageUrl that represent the parent window to be

export { type CalledParentMethodResult, InternalMethod, type ListenOptions, type MethodCallResultMessage, type MethodCallResultMessageNoId, type OverrideHandler, type OverrideHandlerCall, type OverrideHandlerError, type OverrideHandlerSuccess, type Overrides, type ParentMetadata, type RequestMethodCallMessage, type RequestMethodCallMessageNoId, type SignerType };
export { type CalledParentMethodResult, InternalMethod, type ListenOptions, type MethodCallResultMessage, type MethodCallResultMessageNoId, type Origin, type OverrideHandler, type OverrideHandlerCall, type OverrideHandlerError, type OverrideHandlerSuccess, type Overrides, type ParentMetadata, type RequestMethodCallMessage, type RequestMethodCallMessageNoId, type SignerType };

@@ -1,2 +0,2 @@

import { RequestMethodCallMessageNoId, CalledParentMethodResult, OverrideHandler, MethodCallResultMessageNoId } from './types.js';
import { RequestMethodCallMessageNoId, Origin, CalledParentMethodResult, OverrideHandler, MethodCallResultMessageNoId } from './types.js';
import '@cosmjs/amino';

@@ -11,7 +11,7 @@ import '@cosmjs/proto-signing';

/**
* Send message call request to parent of allowed origin and listen for the
* result. Returns a promise that resolves with the result on success or rejects
* with an error.
* Send message call request to parent and listen for the result, only accepting
* results from parents of allowed origins. Returns a promise that resolves with
* the result on success or rejects with an error.
*/
declare const callParentMethod: <T = any>(message: RequestMethodCallMessageNoId, origins: string[], timeout?: number) => Promise<CalledParentMethodResult<T>>;
declare const callParentMethod: <T = any>(message: RequestMethodCallMessageNoId, origins: Origin[], timeout?: number) => Promise<CalledParentMethodResult<T>>;
/**

@@ -26,3 +26,7 @@ * Convert override handler into a method call result message. If the override

declare const isInIframe: () => boolean;
/**
* Returns whether or not the origin is allowed.
*/
declare const isOriginAllowed: (allowedOrigins: Origin[], origin: string) => boolean;
export { UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, processOverrideHandler };
export { UNSAFE_ALLOW_ANY_ORIGIN, callParentMethod, isInIframe, isOriginAllowed, processOverrideHandler };

@@ -1,2 +0,2 @@

"use strict";var c=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var o=(e,r)=>c(e,"name",{value:r,configurable:!0});var L=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:!0})},I=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of y(r))!E.call(e,s)&&s!==t&&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"}};o(a,"CosmiframeTimeoutError");var u=a;var A="UNSAFE_ALLOW_ANY_ORIGIN",N=o((e,r,t)=>new Promise((i,s)=>{let d=null,f=(0,l.v4)(),p=o(({origin:n,source:m,data:w})=>{!r.includes("*")&&!r.includes(n)||m!==window.parent||w.id!==f||(window.removeEventListener("message",p),d!==null&&clearTimeout(d),w.type==="success"?i({result:w.response,origin:n}):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)}t&&(d=setTimeout(()=>{window.removeEventListener("message",p),s(new u(`Timed out after ${t}ms waiting for parent to respond.`))},t))}),"callParentMethod"),O=o(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"),_=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe");0&&(module.exports={UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,processOverrideHandler});
"use strict";var w=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var o=(e,r)=>w(e,"name",{value:r,configurable:!0});var g=(e,r)=>{for(var s in r)w(e,s,{get:r[s],enumerable:!0})},l=(e,r,s,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of x(r))!L.call(e,t)&&t!==s&&w(e,t,{get:()=>r[t],enumerable:!(i=E(r,t))||i.enumerable});return e};var A=e=>l(w({},"__esModule",{value:!0}),e);var R={};g(R,{UNSAFE_ALLOW_ANY_ORIGIN:()=>I,callParentMethod:()=>N,isInIframe:()=>_,isOriginAllowed:()=>v,processOverrideHandler:()=>O});module.exports=A(R);var a=require("uuid");var f=class f extends Error{constructor(r){super(r),this.name="CosmiframeTimeoutError"}};o(f,"CosmiframeTimeoutError");var m=f;var I="UNSAFE_ALLOW_ANY_ORIGIN",N=o((e,r,s)=>new Promise((i,t)=>{let u=null,d=(0,a.v4)(),p=o(({origin:n,source:y,data:c})=>{!v(r,n)||y!==window.parent||c.id!==d||(window.removeEventListener("message",p),u!==null&&clearTimeout(u),c.type==="success"?i({result:c.response,origin:n}):t(new Error(c.error)))},"listener");window.addEventListener("message",p);try{let n={...e,id:d};window.parent.postMessage(n,"*")}catch(n){window.removeEventListener("message",p),t(n)}s&&(u=setTimeout(()=>{window.removeEventListener("message",p),t(new m(`Timed out after ${s}ms waiting for parent to respond.`))},s))}),"callParentMethod"),O=o(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"),_=o(()=>typeof window<"u"&&window.self!==window.parent,"isInIframe"),v=o((e,r)=>e.some(s=>s==="*"||typeof s=="string"&&r===s||s instanceof RegExp&&s.test(r)),"isOriginAllowed");0&&(module.exports={UNSAFE_ALLOW_ANY_ORIGIN,callParentMethod,isInIframe,isOriginAllowed,processOverrideHandler});
//# sourceMappingURL=utils.js.map
{
"name": "@dao-dao/cosmiframe",
"version": "1.0.0-rc.0",
"version": "1.0.0-rc.1",
"description": "Facilitate iframe message passthrough for Cosmos wallets",

@@ -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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc