Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dao-dao/cosmiframe

Package Overview
Dependencies
Maintainers
4
Versions
21
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 0.1.0 to 1.0.0-rc.0

dist/client-BwsaPS7g.d.ts

2

dist/client.d.ts
import '@keplr-wallet/types';
export { C as Cosmiframe } from './client-DcGSOj8B.js';
export { C as Cosmiframe } from './client-BwsaPS7g.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 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});
"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});
//# sourceMappingURL=client.js.map

@@ -1,3 +0,3 @@

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 { 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';

@@ -4,0 +4,0 @@ import '@keplr-wallet/types';

@@ -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 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});
"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});
//# sourceMappingURL=index.js.map

@@ -41,2 +41,16 @@ import { OfflineAminoSigner } from '@cosmjs/amino';

/**
* The result with metadata from calling a parent method.
*/
type CalledParentMethodResult<T> = {
/**
* The parent's result for the requested method.
*/
result: T;
/**
* The origin of the parent response message, which should be the parent's
* origin. This is pulled directly from the `MessageEvent`.
*/
origin: string;
};
/**
* The override handler that throws an error, defaulting to "Handled by outer

@@ -128,2 +142,2 @@ * wallet."

export { 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 OverrideHandler, type OverrideHandlerCall, type OverrideHandlerError, type OverrideHandlerSuccess, type Overrides, type ParentMetadata, type RequestMethodCallMessage, type RequestMethodCallMessageNoId, type SignerType };

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

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

@@ -15,3 +15,3 @@ import '@cosmjs/proto-signing';

*/
declare const callParentMethod: <T = any>(message: RequestMethodCallMessageNoId, origins: string[], timeout?: number) => Promise<T>;
declare const callParentMethod: <T = any>(message: RequestMethodCallMessageNoId, origins: string[], timeout?: number) => Promise<CalledParentMethodResult<T>>;
/**

@@ -18,0 +18,0 @@ * Convert override handler into a method call result message. If the override

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

"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});
"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});
//# sourceMappingURL=utils.js.map
{
"name": "@dao-dao/cosmiframe",
"version": "0.1.0",
"version": "1.0.0-rc.0",
"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