@cashie/ethereum-provider 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var A=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var Z=(r,e)=>{for(var t in e)A(r,t,{get:e[t],enumerable:!0})},ee=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of X(e))!$.call(r,s)&&s!==t&&A(r,s,{get:()=>e[s],enumerable:!(n=G(e,s))||n.enumerable});return r};var te=r=>ee(A({},"__esModule",{value:!0}),r);var ie={};Z(ie,{ProviderEvent:()=>C,ProviderRpcError:()=>y,TranseptorEthereumProvider:()=>v,announceProvider:()=>H,createEip1193Provider:()=>I});module.exports=te(ie);var y=class extends Error{code;data;constructor({message:e,code:t,data:n}){super(e),this.code=t,this.data=n}};var T=class{ALGO={name:"ECDH",namedCurve:"P-256"};#n=!1;#r={keyPair:null,pubJwk:null,nonce:null};#s={role:null,ok:!1};#a=0;#e=null;constructor(){}#t(){if(!this.#n)throw new Error("ECDH not initialized")}#o(){if(!this.#s.ok)throw new Error("Secure connection not established")}#i(){try{if(typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.getRandomValues<"u"&&typeof crypto.subtle.generateKey<"u"&&typeof crypto.subtle.encrypt<"u"&&typeof crypto.subtle.decrypt<"u")return;throw new Error("Web Crypto API not available")}catch(e){throw new Error("Web Crypto API not available",{cause:e})}}get isSecureConnectionEstablished(){return this.#s.ok}async initializeEcdh(){this.#i();let e=await crypto.subtle.generateKey(this.ALGO,!0,["deriveBits"]),t=await crypto.subtle.exportKey("jwk",e.publicKey),n=crypto.getRandomValues(new Uint8Array(16));this.#r={keyPair:e,pubJwk:t,nonce:n},this.#n=!0}async parseKeyExchangeMessage(e){if(this.#t(),!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");let{pub:t,nonce:n}=e.payload,s=await crypto.subtle.importKey("jwk",t,this.ALGO,!1,[]),i=await crypto.subtle.deriveBits({name:this.ALGO.name,public:s},this.#r.keyPair.privateKey,256),o=await crypto.subtle.importKey("raw",i,"HKDF",!1,["deriveKey"]),d=new Uint8Array([...this.#r.nonce,...new Uint8Array(n)]);this.#e=await crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:d,info:new TextEncoder().encode("transeptor-pay-v1")},o,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async generateKeyExchangeMessage(){if(this.#t(),!this.#r.pubJwk)throw new Error("Ephemeral public key not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");if(!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");return{type:"kex-init",payload:{pub:this.#r.pubJwk,nonce:Array.from(this.#r.nonce)}}}async prepareSecureMessage(e){if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");this.#a++;let t=crypto.getRandomValues(new Uint8Array(12)),n=new TextEncoder().encode(`seq:${this.#a}`),s=new TextEncoder().encode(JSON.stringify(e)),i=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:t,additionalData:n},this.#e,s));return{type:"enc",payload:{iv:Array.from(t),cipherText:Array.from(i),additionalData:Array.from(n)}}}async decryptSecureMessage(e){try{if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");let{iv:t,cipherText:n,additionalData:s}=e.payload;if(!t||!n||!s)throw new Error("Invalid message payload: missing required fields");if(!Array.isArray(t)||!Array.isArray(n)||!Array.isArray(s))throw new Error("Invalid message payload: fields must be arrays");let i=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(t),additionalData:new Uint8Array(s)},this.#e,new Uint8Array(n));return{decryptedMessage:JSON.parse(new TextDecoder().decode(i)),passedDecryption:!0}}catch(t){return console.error("Error decrypting secure message from iframe",t),{decryptedMessage:null,passedDecryption:!1}}}parseKeyExchangeDoneMessage(e){this.#t();let{ok:t,role:n}=e.payload;t&&(this.#s={role:n,ok:t})}generateKeyExchangeDoneMessage(){return{type:"kex-done",payload:{ok:!0,role:"parent"}}}closeSecureConnection(){this.#s={role:null,ok:!1},this.#e=null}};var q=r=>{if(typeof r!="object"||r===null)return{isValid:!1,response:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,response:null}:e.id===null||e.id===void 0?{isValid:!1,response:null}:e&&("result"in e||"error"in e)?{isValid:!0,response:e}:{isValid:!0,response:e}},k=r=>{if(typeof r!="object"||r===null)return{isValid:!1,eventRequest:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,eventRequest:null}:e.method?"params"in e?{isValid:!0,eventRequest:e}:{isValid:!1,eventRequest:null}:{isValid:!1,eventRequest:null}},V=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeResponse:null};let e=r;return e.type!=="kex-response"?{isValid:!1,keyExchangeResponse:null}:e.payload.pub?e.payload.nonce?{isValid:!0,keyExchangeResponse:e}:{isValid:!1,keyExchangeResponse:null}:{isValid:!1,keyExchangeResponse:null}},O=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeDone:null};let e=r;return e.type!=="kex-done"?{isValid:!1,keyExchangeDone:null}:e.payload.ok?e.payload.role?{isValid:!0,keyExchangeDone:e}:{isValid:!1,keyExchangeDone:null}:{isValid:!1,keyExchangeDone:null}},J=r=>{if(typeof r!="object"||r===null)return{isValid:!1,encryptedRequest:null};let e=r;return e.type!=="enc"?{isValid:!1,encryptedRequest:null}:e.payload.iv?e.payload.cipherText?e.payload.additionalData?{isValid:!0,encryptedRequest:e}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}},U=r=>{if(typeof r!="object"||r===null)return{isValid:!1,fatalError:null};let e=r;return e.code?e.message?{isValid:!0,fatalError:e}:{isValid:!1,fatalError:null}:{isValid:!1,fatalError:null}};var f=()=>window.innerWidth<768,D=(r,e,t)=>{let n=document.getElementById(r);n&&(n.style.width=e,n.style.height=t)},ne=(r,e)=>{r.style.opacity="1",r.style.pointerEvents="auto",e.style.opacity="1",e.style.transform="scale(1)"},se=(r,e)=>{r.style.opacity="0",r.style.pointerEvents="none",e.style.opacity="0",e.style.transform="scale(0.8)"},S=(r,e,t)=>{let n=document.getElementById(r),s=document.getElementById(e);!n||!s||(document.body.style.overflow=t?"hidden":"auto",t?ne(s,n):se(s,n))},K=(r,e,t,n,s)=>{let i=document.createElement("div");i.id=e,Object.assign(i.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:"9999",opacity:"1",pointerEvents:"none",cursor:"default",transition:"opacity 0.3s ease-in-out"});let o=document.createElement("iframe");o.id=r,o.src=t,o.allow="publickey-credentials-get *; publickey-credentials-create *",Object.assign(o.style,{height:s,width:n,position:"relative",borderRadius:"0.75rem",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",overflowY:"auto",zIndex:"1000",opacity:"1",transform:"scale(0.8)",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out"}),i.appendChild(o),document.body.appendChild(i),setTimeout(()=>{i.style.opacity="1",i.style.pointerEvents="auto",o.style.opacity="1",o.style.transform="scale(1)"},100),document.body.style.overflow="hidden"},_=(r,e)=>{let t=document.getElementById(e);t&&(t.parentNode?.removeChild(t),document.body.style.overflow="auto");let n=document.getElementById(r);n&&n.parentNode&&n.parentNode.removeChild(n)};var F=r=>{let e=new T,{devWalletUrl:t}=r,n=t||"https://pay.transeptorlabs.io",s=new URLSearchParams({embedded:"true"}).toString(),i=t?`${t}?${s}`:`https://pay.transeptorlabs.io/?${s}`,o="dapp:iframe-embedded-payment",d="dapp:iframe-container",g="412px",R="640px",m=!1,N=a=>{let c=document.getElementById(d);c&&a.target===c&&S(o,d,!1)},b=()=>{let a=document.getElementById(o);if(!a)throw new Error("Iframe not found");return"contentWindow"in a?a.contentWindow:null},z=async(a=600)=>{let c=b();if(!c)throw new Error("Iframe not found");let l=!1,E=u=>{if(!u.isTrusted||u.origin!==n)return;if(u.data==="pong"){l=!0;return}};return window.addEventListener("message",E.bind(void 0)),new Promise((u,w)=>{let h=0,p=setInterval(()=>{h++,h>=a&&(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),w(new Error("Max ping attempts reached to establish connection with the iframe"))),l?(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),console.log("Iframe is ready to receive messages"),u(!0)):(console.log("Sending ping to the iframe to check if it is ready"),c.postMessage("ping",n))},500)})},B=async(a=600)=>{console.log("Establishing secure connection with the iframe");let c=b();if(!c)throw new Error("Iframe not found");let l=await e.generateKeyExchangeMessage(),E=null,u=null,w=h=>{if(!h.isTrusted||h.origin!==n)return;let p=h.data,{isValid:x,keyExchangeResponse:M}=V(p);if(x&&M){c.postMessage(e.generateKeyExchangeDoneMessage(),n),E=p;return}let{isValid:Y,keyExchangeDone:Q}=O(p);if(Y&&Q){u=p;return}};return window.addEventListener("message",w.bind(void 0)),c.postMessage(l,n),new Promise((h,p)=>{let x=0,M=setInterval(()=>{x++,x>=a&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),p(new Error("Max secure connection attempts reached to establish secure connection with the iframe"))),E&&u&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),e.parseKeyExchangeDoneMessage(u),h(E))},200)})};return{getIframeOrigin:()=>n,prepareIframe:async()=>{if(!m){console.log("Appending iframe to the DOM"),g=f()?"100%":"412px",R=f()?"100%":"640px",K(o,d,i,g,R);let a=document.getElementById(d);a&&a.addEventListener("click",N),m=!0}if(!e.isSecureConnectionEstablished){let a=await z();if(!b()&&!a)throw new Error("Iframe content window not found, cannot start key exchange");await e.initializeEcdh();let l=await B();await e.parseKeyExchangeMessage(l)}},disconnectIframe:()=>{if(!m||!e.isSecureConnectionEstablished)return;e.closeSecureConnection(),_(o,d);let a=document.getElementById(d);a&&a.removeEventListener("click",N),m=!1,console.log("Secure connection closed with the iframe removed from the DOM",{isSecureConnectionEstablished:e.isSecureConnectionEstablished,isIframeCreated:m})},toggleFrameVisibility:a=>{m&&(S(o,d,a),g=f()?"100%":"412px",R=f()?"100%":"640px",D(o,g,R))},resizeIframe:a=>{m&&(g=f()?"100%":a||"412px",R=f()?"100%":"640px",D(o,g,R))},sendMessageToIframe:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let c=b();if(c){let l=await e.prepareSecureMessage(a);c.postMessage(l,n)}else throw new Error("Iframe content window not found")},decryptSecureMessage:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let{decryptedMessage:c,passedDecryption:l}=await e.decryptSecureMessage(a);if(!l||!c)throw new Error("Failed to decrypt secure message");return c}}};var W=r=>{let e=Math.random,t=e();return Math.floor(t*r)};var v=class r{static#n;#r;#s;FATAL_ERROR_MESSAGE="fatal: internal error";#a=["wallet_requestExecutionPermissions","wallet_revokeExecutionPermission"];#e;#t=new Map;constructor(e){this.#r=window,this.#e=e,this.#s=this.#l.bind(this),this.#r.addEventListener("message",this.#s)}#o(){let e=W(1e10)+Date.now();return this.#t.has(e)?this.#o():e}#i(){this.#e.toggleFrameVisibility(!1)}#c(e){this.#e.resizeIframe(e)}async#l(e){if(!e.isTrusted||e.origin!==this.#e.getIframeOrigin())return;let t=e.data;if(typeof t!="object")return;let{isValid:n,fatalError:s}=U(t);if(n&&s){this.#h(s);return}let{isValid:i,encryptedRequest:o}=J(t);if(i&&o){await this.#y(o);return}}#u(e){let{id:t}=e;this.#t.has(Number(t))&&this.#t.set(Number(t),{status:"fulfilled",response:e})}#p(e){let{method:t}=e;switch(t){case"wallet_paymentEvent":break;case"wallet_closeFrame":this.#i();break;case"wallet_disconnect":this.#d();break;case"wallet_resizeFrameFull":this.#c("100%");break;case"wallet_resizeFrameDefault":this.#c("412px");break}}async#y(e){let t=await this.#e.decryptSecureMessage(e),{isValid:n,response:s}=q(t);if(n&&s){this.#u(s);return}let{isValid:i,eventRequest:o}=k(t);if(i&&o){this.#p(o);return}}#h(e){this.#t.size&&this.#t.forEach(t=>{t.status==="pending"&&(t.status="failed",t.fatalError=e)})}async#m(e,t){try{await this.#e.prepareIframe(),t&&this.#e.toggleFrameVisibility(!0);let{id:n}=e;return this.#t.set(Number(n),{status:"pending",response:void 0}),await this.#e.sendMessageToIframe(e),await this.#E(Number(n))}catch(n){return n.message===this.FATAL_ERROR_MESSAGE&&this.#i(),{jsonrpc:"2.0",id:e.id,error:{message:n.message,code:-32e3}}}}#E(e,t=300){return new Promise((n,s)=>{let i=0,o=setInterval(()=>{i++,i>=t&&(clearInterval(o),s(new Error("Max attempts reached waiting for response")));let d=this.#t.get(e);d&&(d.status==="failed"&&d.fatalError&&(clearInterval(o),this.#t.delete(e),s(new Error(d.fatalError.message))),d.status==="fulfilled"&&(clearInterval(o),this.#t.delete(e),n(d.response)))},1e3)})}#d(){return this.#e.toggleFrameVisibility(!1),this.#e.disconnectIframe(),this.#t=new Map,!0}async sendRequest(e){let t=this.#o(),n=this.#a.includes(e.method);switch(e.method){case"wallet_disconnect":return this.#d(),!0;case"wallet_openHomePage":return await this.#e.prepareIframe(),this.#e.toggleFrameVisibility(!0),await this.#e.sendMessageToIframe({jsonrpc:"2.0",method:"wallet_navigateToDashboardEvent",params:[]}),!0;default:{let s=await this.#m({jsonrpc:"2.0",id:t,method:e.method,params:e.params||[]},n);if("error"in s)throw new y({message:s.error.message,code:s.error.code,data:s.error.data});return s.result}}}static Create(e){if(!r.#n){let t=F({parentOrigin:window.location.origin,devWalletUrl:e.devWalletUrl});r.#n=new r(t)}return r.#n}};var ae={4001:{code:4001,message:"User rejected the request."},4100:{code:4100,message:"The requested method and/or account has not been authorized by the user."},4200:{code:4200,message:"The Provider does not support the requested method."},4900:{code:4900,message:"The Provider is disconnected from all chains."},4901:{code:4901,message:"The Provider is not connected to the requested chain."},4101:{code:4101,message:"The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method."},5700:{code:5700,message:"This wallet does not support a capability that was not marked as optional."},5710:{code:5710,message:"This wallet does not support the specified chain id."},5720:{code:5720,message:"There is already a bundle submitted with this id."},5730:{code:5730,message:"This bundle id is unknown / has not been submitted."},5740:{code:5740,message:"The call bundle is too large for the wallet to process."},5750:{code:5750,message:"The wallet can support atomicity after an upgrade, but the user rejected the upgrade."},5760:{code:5760,message:"The wallet does not support atomic execution but the request requires it."},[-32001]:{code:-32001,message:"fatal: internal error"},[-32602]:{code:4002,message:"Invalid parameters."}},L=r=>{let e=ae[r];return e||{code:r,message:`Unknown error code: ${r}`}};var P=class{#n;constructor(e){this.#n=v.Create(e)}async request(e){try{return await this.#n.sendRequest(e)}catch(t){if(t instanceof y){let n=L(t.code);if(n)throw new y(n)}throw new y({code:-32e3,message:"Unknown internal error",data:t})}}};function I(r){return new P(r)}var C=(t=>(t.AnnounceProvider="eip6963:announceProvider",t.RequestProvider="eip6963:requestProvider",t))(C||{});var j="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg==";var H=r=>{let e=I(r),t=Object.freeze({info:Object.freeze({uuid:"2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1",name:"Transeptor",icon:j,rdns:"io.transeptor.pay"}),provider:e}),n=new CustomEvent("eip6963:announceProvider",{detail:t});window.addEventListener("eip6963:requestProvider",()=>{window.dispatchEvent(n)}),window.dispatchEvent(n)};
1
+ "use strict";var T=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var Z=(r,e)=>{for(var t in e)T(r,t,{get:e[t],enumerable:!0})},ee=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of X(e))!$.call(r,s)&&s!==t&&T(r,s,{get:()=>e[s],enumerable:!(n=G(e,s))||n.enumerable});return r};var te=r=>ee(T({},"__esModule",{value:!0}),r);var ie={};Z(ie,{CashieEthereumProvider:()=>b,ProviderEvent:()=>P,ProviderRpcError:()=>h,announceProvider:()=>j,createEip1193Provider:()=>A});module.exports=te(ie);var h=class extends Error{code;data;constructor({message:e,code:t,data:n}){super(e),this.code=t,this.data=n}};var I=class{ALGO={name:"ECDH",namedCurve:"P-256"};#n=!1;#r={keyPair:null,pubJwk:null,nonce:null};#s={role:null,ok:!1};#a=0;#e=null;constructor(){}#t(){if(!this.#n)throw new Error("ECDH not initialized")}#o(){if(!this.#s.ok)throw new Error("Secure connection not established")}#i(){try{if(typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.getRandomValues<"u"&&typeof crypto.subtle.generateKey<"u"&&typeof crypto.subtle.encrypt<"u"&&typeof crypto.subtle.decrypt<"u")return;throw new Error("Web Crypto API not available")}catch(e){throw new Error("Web Crypto API not available",{cause:e})}}get isSecureConnectionEstablished(){return this.#s.ok}async initializeEcdh(){this.#i();let e=await crypto.subtle.generateKey(this.ALGO,!0,["deriveBits"]),t=await crypto.subtle.exportKey("jwk",e.publicKey),n=crypto.getRandomValues(new Uint8Array(16));this.#r={keyPair:e,pubJwk:t,nonce:n},this.#n=!0}async parseKeyExchangeMessage(e){if(this.#t(),!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");let{pub:t,nonce:n}=e.payload,s=await crypto.subtle.importKey("jwk",t,this.ALGO,!1,[]),i=await crypto.subtle.deriveBits({name:this.ALGO.name,public:s},this.#r.keyPair.privateKey,256),o=await crypto.subtle.importKey("raw",i,"HKDF",!1,["deriveKey"]),d=new Uint8Array([...this.#r.nonce,...new Uint8Array(n)]);this.#e=await crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:d,info:new TextEncoder().encode("cashie-connect")},o,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async generateKeyExchangeMessage(){if(this.#t(),!this.#r.pubJwk)throw new Error("Ephemeral public key not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");if(!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");return{type:"kex-init",payload:{pub:this.#r.pubJwk,nonce:Array.from(this.#r.nonce)}}}async prepareSecureMessage(e){if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");this.#a++;let t=crypto.getRandomValues(new Uint8Array(12)),n=new TextEncoder().encode(`seq:${this.#a}`),s=new TextEncoder().encode(JSON.stringify(e)),i=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:t,additionalData:n},this.#e,s));return{type:"enc",payload:{iv:Array.from(t),cipherText:Array.from(i),additionalData:Array.from(n)}}}async decryptSecureMessage(e){try{if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");let{iv:t,cipherText:n,additionalData:s}=e.payload;if(!t||!n||!s)throw new Error("Invalid message payload: missing required fields");if(!Array.isArray(t)||!Array.isArray(n)||!Array.isArray(s))throw new Error("Invalid message payload: fields must be arrays");let i=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(t),additionalData:new Uint8Array(s)},this.#e,new Uint8Array(n));return{decryptedMessage:JSON.parse(new TextDecoder().decode(i)),passedDecryption:!0}}catch(t){return console.error("Error decrypting secure message from iframe",t),{decryptedMessage:null,passedDecryption:!1}}}parseKeyExchangeDoneMessage(e){this.#t();let{ok:t,role:n}=e.payload;t&&(this.#s={role:n,ok:t})}generateKeyExchangeDoneMessage(){return{type:"kex-done",payload:{ok:!0,role:"parent"}}}closeSecureConnection(){this.#s={role:null,ok:!1},this.#e=null}};var N=r=>{if(typeof r!="object"||r===null)return{isValid:!1,response:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,response:null}:e.id===null||e.id===void 0?{isValid:!1,response:null}:e&&("result"in e||"error"in e)?{isValid:!0,response:e}:{isValid:!0,response:e}},k=r=>{if(typeof r!="object"||r===null)return{isValid:!1,eventRequest:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,eventRequest:null}:e.method?"params"in e?{isValid:!0,eventRequest:e}:{isValid:!1,eventRequest:null}:{isValid:!1,eventRequest:null}},V=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeResponse:null};let e=r;return e.type!=="kex-response"?{isValid:!1,keyExchangeResponse:null}:e.payload.pub?e.payload.nonce?{isValid:!0,keyExchangeResponse:e}:{isValid:!1,keyExchangeResponse:null}:{isValid:!1,keyExchangeResponse:null}},O=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeDone:null};let e=r;return e.type!=="kex-done"?{isValid:!1,keyExchangeDone:null}:e.payload.ok?e.payload.role?{isValid:!0,keyExchangeDone:e}:{isValid:!1,keyExchangeDone:null}:{isValid:!1,keyExchangeDone:null}},J=r=>{if(typeof r!="object"||r===null)return{isValid:!1,encryptedRequest:null};let e=r;return e.type!=="enc"?{isValid:!1,encryptedRequest:null}:e.payload.iv?e.payload.cipherText?e.payload.additionalData?{isValid:!0,encryptedRequest:e}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}},U=r=>{if(typeof r!="object"||r===null)return{isValid:!1,fatalError:null};let e=r;return e.code?e.message?{isValid:!0,fatalError:e}:{isValid:!1,fatalError:null}:{isValid:!1,fatalError:null}};var f=()=>window.innerWidth<768,D=(r,e,t)=>{let n=document.getElementById(r);n&&(n.style.width=e,n.style.height=t)},ne=(r,e)=>{r.style.opacity="1",r.style.pointerEvents="auto",e.style.opacity="1",e.style.transform="scale(1)"},se=(r,e)=>{r.style.opacity="0",r.style.pointerEvents="none",e.style.opacity="0",e.style.transform="scale(0.8)"},S=(r,e,t)=>{let n=document.getElementById(r),s=document.getElementById(e);!n||!s||(document.body.style.overflow=t?"hidden":"auto",t?ne(s,n):se(s,n))},K=(r,e,t,n,s)=>{let i=document.createElement("div");i.id=e,Object.assign(i.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:"9999",opacity:"1",pointerEvents:"none",cursor:"default",transition:"opacity 0.3s ease-in-out"});let o=document.createElement("iframe");o.id=r,o.src=t,o.allow="publickey-credentials-get *; publickey-credentials-create *",Object.assign(o.style,{height:s,width:n,position:"relative",borderRadius:"0.75rem",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",overflowY:"auto",zIndex:"1000",opacity:"1",transform:"scale(0.8)",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out"}),i.appendChild(o),document.body.appendChild(i),setTimeout(()=>{i.style.opacity="1",i.style.pointerEvents="auto",o.style.opacity="1",o.style.transform="scale(1)"},100),document.body.style.overflow="hidden"},_=(r,e)=>{let t=document.getElementById(e);t&&(t.parentNode?.removeChild(t),document.body.style.overflow="auto");let n=document.getElementById(r);n&&n.parentNode&&n.parentNode.removeChild(n)};var F=r=>{let e=new I,{devWalletUrl:t}=r,n=t||"https://pay.transeptorlabs.io",s=new URLSearchParams({embedded:"true"}).toString(),i=t?`${t}?${s}`:`https://pay.transeptorlabs.io/?${s}`,o="dapp:iframe-embedded-payment",d="dapp:iframe-container",g="412px",R="640px",m=!1,q=a=>{let c=document.getElementById(d);c&&a.target===c&&S(o,d,!1)},v=()=>{let a=document.getElementById(o);if(!a)throw new Error("Iframe not found");return"contentWindow"in a?a.contentWindow:null},z=async(a=600)=>{let c=v();if(!c)throw new Error("Iframe not found");let l=!1,E=u=>{if(!u.isTrusted||u.origin!==n)return;if(u.data==="pong"){l=!0;return}};return window.addEventListener("message",E.bind(void 0)),new Promise((u,w)=>{let y=0,p=setInterval(()=>{y++,y>=a&&(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),w(new Error("Max ping attempts reached to establish connection with the iframe"))),l?(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),console.log("Iframe is ready to receive messages"),u(!0)):(console.log("Sending ping to the iframe to check if it is ready"),c.postMessage("ping",n))},500)})},B=async(a=600)=>{console.log("Establishing secure connection with the iframe");let c=v();if(!c)throw new Error("Iframe not found");let l=await e.generateKeyExchangeMessage(),E=null,u=null,w=y=>{if(!y.isTrusted||y.origin!==n)return;let p=y.data,{isValid:x,keyExchangeResponse:M}=V(p);if(x&&M){c.postMessage(e.generateKeyExchangeDoneMessage(),n),E=p;return}let{isValid:Y,keyExchangeDone:Q}=O(p);if(Y&&Q){u=p;return}};return window.addEventListener("message",w.bind(void 0)),c.postMessage(l,n),new Promise((y,p)=>{let x=0,M=setInterval(()=>{x++,x>=a&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),p(new Error("Max secure connection attempts reached to establish secure connection with the iframe"))),E&&u&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),e.parseKeyExchangeDoneMessage(u),y(E))},200)})};return{getIframeOrigin:()=>n,prepareIframe:async()=>{if(!m){console.log("Appending iframe to the DOM"),g=f()?"100%":"412px",R=f()?"100%":"640px",K(o,d,i,g,R);let a=document.getElementById(d);a&&a.addEventListener("click",q),m=!0}if(!e.isSecureConnectionEstablished){let a=await z();if(!v()&&!a)throw new Error("Iframe content window not found, cannot start key exchange");await e.initializeEcdh();let l=await B();await e.parseKeyExchangeMessage(l)}},disconnectIframe:()=>{if(!m||!e.isSecureConnectionEstablished)return;e.closeSecureConnection(),_(o,d);let a=document.getElementById(d);a&&a.removeEventListener("click",q),m=!1,console.log("Secure connection closed with the iframe removed from the DOM",{isSecureConnectionEstablished:e.isSecureConnectionEstablished,isIframeCreated:m})},toggleFrameVisibility:a=>{m&&(S(o,d,a),g=f()?"100%":"412px",R=f()?"100%":"640px",D(o,g,R))},resizeIframe:a=>{m&&(g=f()?"100%":a||"412px",R=f()?"100%":"640px",D(o,g,R))},sendMessageToIframe:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let c=v();if(c){let l=await e.prepareSecureMessage(a);c.postMessage(l,n)}else throw new Error("Iframe content window not found")},decryptSecureMessage:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let{decryptedMessage:c,passedDecryption:l}=await e.decryptSecureMessage(a);if(!l||!c)throw new Error("Failed to decrypt secure message");return c}}};var W=r=>{let e=Math.random,t=e();return Math.floor(t*r)};var b=class r{static#n;#r;#s;FATAL_ERROR_MESSAGE="fatal: internal error";#a=["wallet_requestExecutionPermissions","wallet_revokeExecutionPermission"];#e;#t=new Map;constructor(e){this.#r=window,this.#e=e,this.#s=this.#l.bind(this),this.#r.addEventListener("message",this.#s)}#o(){let e=W(1e10)+Date.now();return this.#t.has(e)?this.#o():e}#i(){this.#e.toggleFrameVisibility(!1)}#c(e){this.#e.resizeIframe(e)}async#l(e){if(!e.isTrusted||e.origin!==this.#e.getIframeOrigin())return;let t=e.data;if(typeof t!="object")return;let{isValid:n,fatalError:s}=U(t);if(n&&s){this.#y(s);return}let{isValid:i,encryptedRequest:o}=J(t);if(i&&o){await this.#h(o);return}}#u(e){let{id:t}=e;this.#t.has(Number(t))&&this.#t.set(Number(t),{status:"fulfilled",response:e})}#p(e){let{method:t}=e;switch(t){case"wallet_paymentEvent":break;case"wallet_closeFrame":this.#i();break;case"wallet_disconnect":this.#d();break;case"wallet_resizeFrameFull":this.#c("100%");break;case"wallet_resizeFrameDefault":this.#c("412px");break}}async#h(e){let t=await this.#e.decryptSecureMessage(e),{isValid:n,response:s}=N(t);if(n&&s){this.#u(s);return}let{isValid:i,eventRequest:o}=k(t);if(i&&o){this.#p(o);return}}#y(e){this.#t.size&&this.#t.forEach(t=>{t.status==="pending"&&(t.status="failed",t.fatalError=e)})}async#m(e,t){try{await this.#e.prepareIframe(),t&&this.#e.toggleFrameVisibility(!0);let{id:n}=e;return this.#t.set(Number(n),{status:"pending",response:void 0}),await this.#e.sendMessageToIframe(e),await this.#E(Number(n))}catch(n){return n.message===this.FATAL_ERROR_MESSAGE&&this.#i(),{jsonrpc:"2.0",id:e.id,error:{message:n.message,code:-32e3}}}}#E(e,t=300){return new Promise((n,s)=>{let i=0,o=setInterval(()=>{i++,i>=t&&(clearInterval(o),s(new Error("Max attempts reached waiting for response")));let d=this.#t.get(e);d&&(d.status==="failed"&&d.fatalError&&(clearInterval(o),this.#t.delete(e),s(new Error(d.fatalError.message))),d.status==="fulfilled"&&(clearInterval(o),this.#t.delete(e),n(d.response)))},1e3)})}#d(){return this.#e.toggleFrameVisibility(!1),this.#e.disconnectIframe(),this.#t=new Map,!0}async sendRequest(e){let t=this.#o(),n=this.#a.includes(e.method);switch(e.method){case"wallet_disconnect":return this.#d(),!0;case"wallet_openHomePage":return await this.#e.prepareIframe(),this.#e.toggleFrameVisibility(!0),await this.#e.sendMessageToIframe({jsonrpc:"2.0",method:"wallet_navigateToDashboardEvent",params:[]}),!0;default:{let s=await this.#m({jsonrpc:"2.0",id:t,method:e.method,params:e.params||[]},n);if("error"in s)throw new h({message:s.error.message,code:s.error.code,data:s.error.data});return s.result}}}static Create(e){if(!r.#n){let t=F({parentOrigin:window.location.origin,devWalletUrl:e.devWalletUrl});r.#n=new r(t)}return r.#n}};var ae={4001:{code:4001,message:"User rejected the request."},4100:{code:4100,message:"The requested method and/or account has not been authorized by the user."},4200:{code:4200,message:"The Provider does not support the requested method."},4900:{code:4900,message:"The Provider is disconnected from all chains."},4901:{code:4901,message:"The Provider is not connected to the requested chain."},4101:{code:4101,message:"The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method."},5700:{code:5700,message:"This wallet does not support a capability that was not marked as optional."},5710:{code:5710,message:"This wallet does not support the specified chain id."},5720:{code:5720,message:"There is already a bundle submitted with this id."},5730:{code:5730,message:"This bundle id is unknown / has not been submitted."},5740:{code:5740,message:"The call bundle is too large for the wallet to process."},5750:{code:5750,message:"The wallet can support atomicity after an upgrade, but the user rejected the upgrade."},5760:{code:5760,message:"The wallet does not support atomic execution but the request requires it."},[-32001]:{code:-32001,message:"fatal: internal error"},[-32602]:{code:4002,message:"Invalid parameters."}},L=r=>{let e=ae[r];return e||{code:r,message:`Unknown error code: ${r}`}};var C=class{#n;constructor(e){this.#n=b.Create(e)}async request(e){try{return await this.#n.sendRequest(e)}catch(t){if(t instanceof h){let n=L(t.code);if(n)throw new h(n)}throw new h({code:-32e3,message:"Unknown internal error",data:t})}}};function A(r){return new C(r)}var P=(t=>(t.AnnounceProvider="eip6963:announceProvider",t.RequestProvider="eip6963:requestProvider",t))(P||{});var H="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg==";var j=r=>{let e=A(r),t=Object.freeze({info:Object.freeze({uuid:"2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1",name:"Cashie",icon:H,rdns:"org.cashie.app"}),provider:e}),n=new CustomEvent("eip6963:announceProvider",{detail:t});window.addEventListener("eip6963:requestProvider",()=>{window.dispatchEvent(n)}),window.dispatchEvent(n)};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts", "../src/provider/types.ts", "../src/ecdh/ecdh-manager.ts", "../src/utils/validate.ts", "../src/iframe/iframe.ts", "../src/iframe/iframe-handler.ts", "../src/utils/random.ts", "../src/provider/transeptor-ethereum-provider.ts", "../src/provider/errors.ts", "../src/provider/eip-1193-bridge.ts", "../src/provider/eip-6963/types.ts", "../src/provider/eip-6963/icon.ts", "../src/provider/eip-6963/announce-provider.ts"],
4
- "sourcesContent": ["export * from './provider/index.js'\nexport * from './types/index.js'\n", "export class ProviderRpcError extends Error {\n /**\n * MUST be an integer number\n * SHOULD adhere to the specifications in the Error Standards section below\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#error-standards\n */\n code: number\n\n /**\n * SHOULD contain any other useful information about the error\n */\n data?: unknown\n\n constructor({\n message,\n code,\n data,\n }: {\n message: string\n code: number\n data?: unknown\n }) {\n super(message)\n this.code = code\n this.data = data\n }\n}\n\n/**\n * The Eip1193 error types\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#rpc-errors\n */\nexport type Eip1193Error =\n | 'userRejectedRequest'\n | 'unauthorized'\n | 'unsupportedMethod'\n | 'disconnected'\n | 'chainDisconnected'\n\nexport type Eip1193RequestArguments = {\n method: string\n params?: readonly unknown[] | object\n}\n\nexport interface Eip1193Provider {\n /**\n * Request a method from the Eip1193 provider\n *\n * @param request - the request to be sent to the Eip1193 provider\n * @returns the response from the Eip1193 provider\n *\n * @throws {Error} If the returned Promise rejects, it MUST reject with a ProviderRpcError as specified in the [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193#rpc-errors) section below.\n */\n request: (request: Eip1193RequestArguments) => Promise<unknown>\n}\n\n/**\n * The message event is intended for arbitrary notifications not covered by other events.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#message-event\n */\nexport type Eip1193ProviderMessage = {\n readonly type: string\n readonly data: unknown\n}\n\n/**\n * Specify the integer ID of the connected chain as a hexadecimal string, per the eth_chainId Ethereum RPC method.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider_connect\n */\nexport type Eip1193ProviderConnectInfo = {\n readonly chainId: `0x${string}`\n}\n", "/* eslint-disable no-console */\nimport { SecureMessageType, SecureMessage } from './ecdh.types.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n JsonRpcErrorResponse,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n} from '../types/index.js'\n\n/**\n * Ephemeral ECDH key pair(private key, public key), public key(public key in jwk format), and nonce\n */\nexport type EphemeralEcdh = {\n keyPair: CryptoKeyPair | null\n pubJwk: JsonWebKey | null\n nonce: Uint8Array | null\n}\n\n/**\n * Create a new ephemeral ECDH manager\n * The ECDH(Elliptic Curve Diffie\u2013Hellman) key exchange manager is used to generate a shared secret key to encrypt and decrypt secure messages between the two parties on an untrusted channel.\n */\nexport class EphemeralEcdhManager {\n private readonly ALGO = { name: 'ECDH', namedCurve: 'P-256' }\n #isInitialized = false\n #ephemeralEcdh: EphemeralEcdh = {\n keyPair: null,\n pubJwk: null,\n nonce: null,\n }\n #isKeyExchangeDone: {\n role: 'parent' | 'iframe' | null\n ok: boolean\n } = {\n role: null,\n ok: false,\n }\n #sequence = 0\n #aeadKey: CryptoKey | null = null\n\n constructor() {\n // empty constructor\n }\n\n /**\n * Assert that the ECDH is initialized\n *\n * @throws {Error} if the ECDH is not initialized\n */\n #assertInitialized(): void {\n if (!this.#isInitialized) {\n throw new Error('ECDH not initialized')\n }\n }\n\n /**\n * Assert that the secure connection is established\n *\n * @throws {Error} if the secure connection is not established\n */\n #assertSecureConnectionEstablished(): void {\n if (!this.#isKeyExchangeDone.ok) {\n throw new Error('Secure connection not established')\n }\n }\n\n /**\n * Check if Web Crypto API is available and properly configured\n *\n * @throws {Error} if Web Crypto API is not available\n */\n #assertWebCryptoAvailable(): void {\n try {\n if (\n typeof crypto !== 'undefined' &&\n typeof crypto.subtle !== 'undefined' &&\n typeof crypto.getRandomValues !== 'undefined' &&\n typeof crypto.subtle.generateKey !== 'undefined' &&\n typeof crypto.subtle.encrypt !== 'undefined' &&\n typeof crypto.subtle.decrypt !== 'undefined'\n ) {\n return\n }\n throw new Error('Web Crypto API not available')\n } catch (error) {\n throw new Error('Web Crypto API not available', { cause: error })\n }\n }\n\n /**\n * Check if the secure connection is established\n *\n * @returns true if the secure connection is established, false otherwise\n */\n get isSecureConnectionEstablished(): boolean {\n return this.#isKeyExchangeDone.ok\n }\n\n /**\n * Initialize the ECDH\n *\n * @returns void\n */\n async initializeEcdh(): Promise<void> {\n this.#assertWebCryptoAvailable()\n const keyPair = await crypto.subtle.generateKey(this.ALGO, true, [\n 'deriveBits',\n ])\n const pubJwk = await crypto.subtle.exportKey('jwk', keyPair.publicKey)\n const nonce = crypto.getRandomValues(new Uint8Array(16))\n\n this.#ephemeralEcdh = {\n keyPair,\n pubJwk,\n nonce,\n } as EphemeralEcdh\n this.#isInitialized = true\n }\n\n /**\n * Parse a key exchange message to generate a shared secret\n *\n * @param message - the key exchange response message\n * @returns void\n */\n async parseKeyExchangeMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeResponse>,\n ): Promise<void> {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n\n // Extract the public key and nonce from the message\n const { pub, nonce } = message.payload\n const recipientPub = await crypto.subtle.importKey(\n 'jwk',\n pub,\n this.ALGO,\n false,\n [],\n )\n\n // Compute a shared secret using the recipient's public key and the ephemeral private key pair\n const bits = await crypto.subtle.deriveBits(\n { name: this.ALGO.name, public: recipientPub },\n this.#ephemeralEcdh.keyPair.privateKey,\n 256,\n )\n const baseKey = await crypto.subtle.importKey('raw', bits, 'HKDF', false, [\n 'deriveKey',\n ])\n\n // Derive the salt with format <parent-nonce,child-nonce>\n // Note: This must match the iframe's salt ordering for consistent key derivation\n const salt = new Uint8Array([\n ...this.#ephemeralEcdh.nonce,\n ...new Uint8Array(nonce),\n ])\n\n // Derive the AEAD key from the base key and the salt that will be used to encrypt/decrypt the messages between the both parties\n this.#aeadKey = await crypto.subtle.deriveKey(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n salt,\n info: new TextEncoder().encode('transeptor-pay-v1'),\n },\n baseKey,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt'],\n )\n }\n\n /**\n * Generate a key exchange message\n *\n * @returns the key exchange message\n */\n async generateKeyExchangeMessage(): Promise<\n SecureMessage<SecureMessageType.KeyExchangeInit>\n > {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.pubJwk) {\n throw new Error('Ephemeral public key not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n\n return {\n type: SecureMessageType.KeyExchangeInit,\n payload: {\n pub: this.#ephemeralEcdh.pubJwk,\n nonce: Array.from<number>(this.#ephemeralEcdh.nonce),\n },\n }\n }\n\n /**\n * Prepare a secure message\n *\n * @param data - the data to be prepared\n * @returns the secure message\n */\n async prepareSecureMessage(\n data:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ): Promise<SecureMessage<SecureMessageType.Encrypted>> {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n // Increment the sequence number\n this.#sequence++\n\n // Encrypt the data with the AEAD key given by the child iframe to ensure only the child iframe can decrypt the message\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const additionalData = new TextEncoder().encode(`seq:${this.#sequence}`)\n const dataBytes = new TextEncoder().encode(JSON.stringify(data))\n const cipherText = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv, additionalData },\n this.#aeadKey,\n dataBytes,\n ),\n )\n\n return {\n type: SecureMessageType.Encrypted,\n payload: {\n iv: Array.from<number>(iv),\n cipherText: Array.from<number>(cipherText),\n additionalData: Array.from<number>(additionalData),\n },\n }\n }\n\n /**\n * Decrypt a secure message sent by the child iframe\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted data\n */\n async decryptSecureMessage(\n message: SecureMessage<SecureMessageType.Encrypted>,\n ): Promise<{\n decryptedMessage:\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n | null\n passedDecryption: boolean\n }> {\n try {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n\n const { iv, cipherText, additionalData } = message.payload\n\n if (!iv || !cipherText || !additionalData) {\n throw new Error('Invalid message payload: missing required fields')\n }\n\n if (\n !Array.isArray(iv) ||\n !Array.isArray(cipherText) ||\n !Array.isArray(additionalData)\n ) {\n throw new Error('Invalid message payload: fields must be arrays')\n }\n\n const dataBytes = await crypto.subtle.decrypt(\n {\n name: 'AES-GCM',\n iv: new Uint8Array(iv),\n additionalData: new Uint8Array(additionalData),\n },\n this.#aeadKey,\n new Uint8Array(cipherText),\n )\n const decryptedMessage = JSON.parse(new TextDecoder().decode(dataBytes))\n return {\n decryptedMessage,\n passedDecryption: true,\n }\n } catch (error) {\n console.error('Error decrypting secure message from iframe', error)\n return {\n decryptedMessage: null,\n passedDecryption: false,\n }\n }\n }\n\n /**\n * Parse a key exchange done message\n *\n * @param message - the key exchange done message\n */\n parseKeyExchangeDoneMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeDone>,\n ): void {\n this.#assertInitialized()\n const { ok, role } = message.payload\n if (ok) {\n this.#isKeyExchangeDone = {\n role,\n ok,\n }\n }\n }\n\n /**\n * Generate a key exchange done message\n *\n * @returns the key exchange done message\n */\n generateKeyExchangeDoneMessage(): SecureMessage<SecureMessageType.KeyExchangeDone> {\n return {\n type: SecureMessageType.KeyExchangeDone,\n payload: {\n ok: true,\n role: 'parent',\n },\n }\n }\n\n /**\n * Close the secure connection\n *\n */\n closeSecureConnection(): void {\n this.#isKeyExchangeDone = {\n role: null,\n ok: false,\n }\n this.#aeadKey = null\n }\n}\n", "import {\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n FatalError,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/ecdh.types.js'\n\ntype JsonRpcResponseValidator = {\n isValid: boolean\n response: JsonRpcResponse | null\n}\n\ntype JsonRpcEventRequestValidator = {\n isValid: boolean\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames> | null\n}\n\ntype JsonRpcKeyExchangeResponseValidator = {\n isValid: boolean\n keyExchangeResponse: SecureMessage<SecureMessageType.KeyExchangeResponse> | null\n}\n\ntype JsonRpcKeyExchangeDoneValidator = {\n isValid: boolean\n keyExchangeDone: SecureMessage<SecureMessageType.KeyExchangeDone> | null\n}\n\ntype EncryptedRequestValidator = {\n isValid: boolean\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted> | null\n}\n\ntype FatalErrorValidator = {\n isValid: boolean\n fatalError: FatalError | null\n}\n\n/**\n * Validate a JSON-RPC response\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcResponseValidator = (\n message: unknown,\n): JsonRpcResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, response: null }\n }\n const response = message as JsonRpcResponse\n if (response.jsonrpc !== '2.0') {\n return { isValid: false, response: null }\n }\n\n if (response.id === null || response.id === undefined) {\n return { isValid: false, response: null }\n }\n\n if (response && ('result' in response || 'error' in response)) {\n return { isValid: true, response: response as JsonRpcResponse }\n }\n\n return {\n isValid: true,\n response: response as JsonRpcResponse,\n }\n}\n\n/**\n * Validate a JSON-RPC event request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const inboundJsonRpcEventRequestValidator = (\n message: unknown,\n): JsonRpcEventRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, eventRequest: null }\n }\n const eventRequest =\n message as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n if (eventRequest.jsonrpc !== '2.0') {\n return { isValid: false, eventRequest: null }\n }\n if (!eventRequest.method) {\n return { isValid: false, eventRequest: null }\n }\n\n if (!('params' in eventRequest)) {\n return {\n isValid: false,\n eventRequest: null,\n }\n }\n\n return {\n isValid: true,\n eventRequest:\n eventRequest as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange response request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeResponseValidator = (\n message: unknown,\n): JsonRpcKeyExchangeResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeResponse: null }\n }\n const keyExchangeResponse =\n message as SecureMessage<SecureMessageType.KeyExchangeResponse>\n if (keyExchangeResponse.type !== SecureMessageType.KeyExchangeResponse) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.pub) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.nonce) {\n return { isValid: false, keyExchangeResponse: null }\n }\n return {\n isValid: true,\n keyExchangeResponse:\n keyExchangeResponse as SecureMessage<SecureMessageType.KeyExchangeResponse>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange done request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeDoneValidator = (\n message: unknown,\n): JsonRpcKeyExchangeDoneValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeDone: null }\n }\n const keyExchangeDone =\n message as SecureMessage<SecureMessageType.KeyExchangeDone>\n if (keyExchangeDone.type !== SecureMessageType.KeyExchangeDone) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.ok) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.role) {\n return { isValid: false, keyExchangeDone: null }\n }\n\n return {\n isValid: true,\n keyExchangeDone:\n keyExchangeDone as SecureMessage<SecureMessageType.KeyExchangeDone>,\n }\n}\n\n/**\n * Validate a JSON-RPC encrypted message\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const encryptedMessageValidator = (\n message: unknown,\n): EncryptedRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, encryptedRequest: null }\n }\n const encryptedRequest = message as SecureMessage<SecureMessageType.Encrypted>\n if (encryptedRequest.type !== SecureMessageType.Encrypted) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.iv) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.cipherText) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.additionalData) {\n return { isValid: false, encryptedRequest: null }\n }\n return {\n isValid: true,\n encryptedRequest:\n encryptedRequest as SecureMessage<SecureMessageType.Encrypted>,\n }\n}\n\n/**\n * Validate a fatal error\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const fatalErrorValidator = (message: unknown): FatalErrorValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, fatalError: null }\n }\n const fatalError = message as FatalError\n if (!fatalError.code) {\n return { isValid: false, fatalError: null }\n }\n if (!fatalError.message) {\n return { isValid: false, fatalError: null }\n }\n return { isValid: true, fatalError: fatalError as FatalError }\n}\n", "/**\n * Frame width enum\n */\nexport enum FrameWidth {\n Default = '412px',\n Full = '100%',\n}\n\nexport enum FrameHeight {\n Default = '640px',\n Full = '100%',\n}\n\n/**\n * Check if the device is mobile\n *\n * @returns true if the device is mobile, false otherwise\n */\nexport const isMobile = () => {\n return window.innerWidth < 768\n}\n\n/**\n * Resize the iframe container and iframe element width\n *\n * @param iframeId - the id of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const resizeFrameWidth = (\n iframeId: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n const iframe = document.getElementById(iframeId)\n\n if (iframe) {\n iframe.style.width = frameWidth\n iframe.style.height = frameHeight\n }\n}\n\n/**\n * Show the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst showIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)' // Scale in\n}\n\n/**\n * Hide the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst hideIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '0'\n overlay.style.pointerEvents = 'none'\n iframe.style.opacity = '0'\n iframe.style.transform = 'scale(0.8)' // Scale out\n}\n\n/**\n * Toggle the visibility of the iframe\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param isVisible - the visibility of the iframe\n */\nexport const doToggleIframeVisibility = (\n iframeId: string,\n overlayId: string,\n isVisible: boolean,\n) => {\n const iframe = document.getElementById(iframeId)\n const overlay = document.getElementById(overlayId)\n if (!iframe || !overlay) {\n return\n }\n\n document.body.style.overflow = isVisible ? 'hidden' : 'auto'\n if (isVisible) {\n showIframe(overlay, iframe)\n } else {\n hideIframe(overlay, iframe)\n }\n}\n\n/**\n * Append the iframe to the container div\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param url - the url of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const appendIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n url: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n // Create overlay container\n const overlay = document.createElement('div')\n overlay.id = overlayId\n Object.assign(overlay.style, {\n position: 'fixed',\n top: '0',\n left: '0',\n width: '100%',\n height: '100%',\n background: 'rgba(0, 0, 0, 0.4)',\n backdropFilter: 'blur(4px)',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n zIndex: '9999',\n opacity: '1',\n pointerEvents: 'none', // Disable interactions when hidden\n cursor: 'default', // Default cursor for overlay background\n transition: 'opacity 0.3s ease-in-out',\n })\n\n const iframe = document.createElement('iframe')\n iframe.id = iframeId\n iframe.src = url\n iframe.allow = 'publickey-credentials-get *; publickey-credentials-create *'\n Object.assign(iframe.style, {\n height: frameHeight,\n width: frameWidth,\n position: 'relative',\n borderRadius: '0.75rem',\n boxShadow:\n '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)',\n overflowY: 'auto',\n zIndex: '1000',\n opacity: '1',\n transform: 'scale(0.8)',\n transition: 'opacity 0.3s ease-in-out, transform 0.3s ease-in-out',\n })\n\n overlay.appendChild(iframe)\n document.body.appendChild(overlay)\n\n // Ensure styles are applied after DOM insertion\n setTimeout(() => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)'\n }, 100) // Small delay to trigger transition\n\n // Prevent scrolling while overlay is open\n document.body.style.overflow = 'hidden'\n}\n\n/**\n * Destroy the iframe element and remove it from the DOM\n *\n * @param iframeId - the id of the iframe to be destroyed\n * @param overlayId - the id of the overlay container\n */\nexport const destroyIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n) => {\n const overlay = document.getElementById(overlayId)\n if (overlay) {\n overlay.parentNode?.removeChild(overlay)\n document.body.style.overflow = 'auto' // Restore scrolling\n }\n const iframe = document.getElementById(iframeId)\n if (iframe) {\n if (iframe.parentNode) {\n iframe.parentNode.removeChild(iframe)\n }\n }\n}\n", "/* eslint-disable no-console */\nimport {\n EphemeralEcdhManager,\n SecureMessage,\n SecureMessageType,\n} from '../ecdh/index.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcErrorResponse,\n JsonRpcResponse,\n} from '../types/index.js'\nimport {\n jsonRpcKeyExchangeResponseValidator,\n jsonRpcKeyExchangeDoneValidator,\n} from '../utils/validate.js'\nimport {\n appendIframeWithContainer,\n destroyIframeWithContainer,\n doToggleIframeVisibility,\n FrameHeight,\n FrameWidth,\n isMobile,\n resizeFrameWidth,\n} from './iframe.js'\n\n/**\n * Iframe handler interface\n */\nexport type IframeHandler = {\n /**\n * Create a new iframe element and append it to the container div if it is not already created\n * Establish a secure connection with the iframe\n *\n * @returns void\n */\n prepareIframe: () => Promise<void>\n\n /**\n * Disconnect the iframe by closing the secure connection and destroying the iframe container and iframe element\n *\n */\n disconnectIframe: () => void\n\n /**\n * Toggle the visibility of the iframe\n *\n * @param isVisible - the visibility of the iframe\n * @returns void\n */\n toggleFrameVisibility: (isVisible: boolean) => void\n\n /**\n * Send a message to the iframe\n *\n * @param request - the request to be sent to the iframe\n */\n sendMessageToIframe: (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => Promise<void>\n\n /**\n * Resize the iframe\n *\n * @param size - the size of the iframe\n * @returns void\n */\n resizeIframe: (size?: FrameWidth) => void\n\n /**\n * Get the origin of the iframe\n *\n * @returns the origin of the iframe\n */\n getIframeOrigin: () => string\n\n /**\n * Decrypt a secure message\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted message\n */\n decryptSecureMessage: (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => Promise<\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n >\n}\n\ntype IframeHandlerConfig = {\n /**\n * The origin of the parent window\n */\n parentOrigin: string\n\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string | undefined\n}\n\n/**\n * Create a new iframe handler\n *\n * @param config - the iframe handler config\n * @returns the iframe handler\n */\nexport const createIframeHandler = (\n config: IframeHandlerConfig,\n): IframeHandler => {\n const ecdhManager = new EphemeralEcdhManager()\n const { devWalletUrl } = config\n const IFRAME_ORIGIN = devWalletUrl || 'https://pay.transeptorlabs.io'\n const params = new URLSearchParams({ embedded: 'true' }).toString()\n const walletUrl = devWalletUrl\n ? `${devWalletUrl}?${params}`\n : `https://pay.transeptorlabs.io/?${params}`\n const DAPP_IFRAME_ID = 'dapp:iframe-embedded-payment'\n const OVERLAY_CONTAINER_ID = 'dapp:iframe-container'\n\n let activeFrameWidth = FrameWidth.Default\n let activeFrameHeight = FrameHeight.Default\n let isIframeCreated = false\n\n /**\n * Handle the overlay click event\n *\n * @param event - the mouse event\n */\n const handleOverlayClick = (event: MouseEvent) => {\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n if (event.target === overlay) {\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, false)\n }\n }\n }\n\n /**\n * Get the content window of the iframe\n *\n * @returns the content window of the iframe\n */\n const getIframeContentWindow = (): Window | null => {\n const iframe = document.getElementById(DAPP_IFRAME_ID)\n if (!iframe) {\n throw new Error('Iframe not found')\n }\n const hasContentWindow = 'contentWindow' in iframe\n if (hasContentWindow) {\n const childWindow = iframe.contentWindow as Window\n return childWindow\n }\n return null\n }\n\n /**\n * Send a post message to the IFrame window to check if it is ready and to inform the iframe of the parent origin extracted from message event\n * Waits for the frame to be ready before sending the message.\n * max attempts is 600\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns true if the frame is ready, false otherwise will reject with an error\n */\n const checkIframeReady = async (attempts = 600) => {\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n let isFrameReady = false\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n if (message === 'pong') {\n isFrameReady = true\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n return new Promise<boolean>((_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max ping attempts reached to establish connection with the iframe',\n ),\n )\n }\n\n // resolve if the frame is ready\n if (isFrameReady) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n console.log('Iframe is ready to receive messages')\n _resolve(true)\n } else {\n console.log('Sending ping to the iframe to check if it is ready')\n childWindow.postMessage('ping', IFRAME_ORIGIN)\n }\n }, 500) // 500ms\n })\n }\n\n /**\n * Establish a secure connection with the iframe\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns the key exchange response message if the secure connection is established, null otherwise will reject with an error\n */\n const establishSecureConnectionWithIframe = async (attempts = 600) => {\n console.log('Establishing secure connection with the iframe')\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n // Generate key exchange messages\n const keyExchangeMessage = await ecdhManager.generateKeyExchangeMessage()\n let keyExchangeResponseMessage: SecureMessage<SecureMessageType.KeyExchangeResponse> | null =\n null\n let keyExchangeDoneMessage: SecureMessage<SecureMessageType.KeyExchangeDone> | null =\n null\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n const { isValid: isValidKeyExchangeResponse, keyExchangeResponse } =\n jsonRpcKeyExchangeResponseValidator(message)\n if (isValidKeyExchangeResponse && keyExchangeResponse) {\n childWindow.postMessage(\n ecdhManager.generateKeyExchangeDoneMessage(),\n IFRAME_ORIGIN,\n )\n keyExchangeResponseMessage = message\n return\n }\n\n const { isValid: isValidKeyExchangeDone, keyExchangeDone } =\n jsonRpcKeyExchangeDoneValidator(message)\n if (isValidKeyExchangeDone && keyExchangeDone) {\n keyExchangeDoneMessage = message\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n childWindow.postMessage(keyExchangeMessage, IFRAME_ORIGIN)\n\n return new Promise<SecureMessage<SecureMessageType.KeyExchangeResponse>>(\n (_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max secure connection attempts reached to establish secure connection with the iframe',\n ),\n )\n }\n\n // resolve if the secure connection is established\n if (keyExchangeResponseMessage && keyExchangeDoneMessage) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n ecdhManager.parseKeyExchangeDoneMessage(keyExchangeDoneMessage)\n _resolve(keyExchangeResponseMessage)\n }\n }, 200) // 200ms\n },\n )\n }\n\n return {\n getIframeOrigin: () => IFRAME_ORIGIN,\n\n prepareIframe: async () => {\n // Append the iframe to the DOM and add event listener to close overlay when clicking outside the iframe\n if (!isIframeCreated) {\n console.log('Appending iframe to the DOM')\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n appendIframeWithContainer(\n DAPP_IFRAME_ID,\n OVERLAY_CONTAINER_ID,\n walletUrl,\n activeFrameWidth,\n activeFrameHeight,\n )\n\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.addEventListener('click', handleOverlayClick)\n }\n isIframeCreated = true\n }\n\n // Establish connection and start key exchange\n if (!ecdhManager.isSecureConnectionEstablished) {\n const isIframeReady = await checkIframeReady()\n const childWindow = getIframeContentWindow()\n if (!childWindow && !isIframeReady) {\n throw new Error(\n 'Iframe content window not found, cannot start key exchange',\n )\n }\n // Initialize the ECDH manager\n await ecdhManager.initializeEcdh()\n\n // Establish secure connection with the iframe\n const keyExchangeResponseMessage =\n await establishSecureConnectionWithIframe()\n\n // Parse the key exchange response message from the iframe\n await ecdhManager.parseKeyExchangeMessage(keyExchangeResponseMessage)\n }\n },\n\n disconnectIframe: () => {\n if (!isIframeCreated) {\n return\n }\n\n if (!ecdhManager.isSecureConnectionEstablished) {\n return\n }\n\n ecdhManager.closeSecureConnection()\n destroyIframeWithContainer(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID)\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.removeEventListener('click', handleOverlayClick)\n }\n isIframeCreated = false\n\n console.log(\n 'Secure connection closed with the iframe removed from the DOM',\n {\n isSecureConnectionEstablished:\n ecdhManager.isSecureConnectionEstablished,\n isIframeCreated: isIframeCreated,\n },\n )\n },\n\n toggleFrameVisibility: (isVisible) => {\n if (!isIframeCreated) {\n return\n }\n\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, isVisible)\n\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n resizeIframe: (size?: FrameWidth) => {\n if (!isIframeCreated) {\n return\n }\n\n activeFrameWidth = isMobile()\n ? FrameWidth.Full\n : size || FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n sendMessageToIframe: async (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n\n const childWindow = getIframeContentWindow()\n if (childWindow) {\n const encryptedRequest = await ecdhManager.prepareSecureMessage(request)\n childWindow.postMessage(encryptedRequest, IFRAME_ORIGIN)\n } else {\n throw new Error('Iframe content window not found')\n }\n },\n\n decryptSecureMessage: async (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n const { decryptedMessage, passedDecryption } =\n await ecdhManager.decryptSecureMessage(message)\n if (!passedDecryption || !decryptedMessage) {\n throw new Error('Failed to decrypt secure message')\n }\n return decryptedMessage\n },\n }\n}\n", "/**\n * Returns a random number between 0 and maxRange\n *\n * @param maxRange - the maximum range for the random number\n * @returns a random number between 0 and maxRange\n */\nexport const getRandomNum = (maxRange: number) => {\n const rand: () => number = Math.random\n const rn = rand()\n return Math.floor(rn * maxRange)\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n createIframeHandler,\n FrameWidth,\n IframeHandler,\n} from '../iframe/index.js'\n\nimport {\n getRandomNum,\n inboundJsonRpcEventRequestValidator,\n jsonRpcResponseValidator,\n encryptedMessageValidator,\n fatalErrorValidator,\n} from '../utils/index.js'\n\nimport {\n InboundJsonRpcEventRequest,\n JsonRpcResponse,\n InboundRpcRequestEventsMethodNames,\n FatalError,\n JsonRpcRequest,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/index.js'\nimport { Eip1193RequestArguments, ProviderRpcError } from './types.js'\n\n// JSON-RPC types\nexport type Message = unknown\n\nexport type AcceptedChainConfig = {\n /**\n * The chain ID of the blockchain network to be used\n * It should be a valid Ethereum chain ID in hex format\n */\n chainId: `0x${string}`\n\n /**\n * The treasury address to receive the payments\n * It should be a valid Ethereum address in hex format\n */\n treasuryAddress: `0x${string}`\n}\n\n/**\n * The configuration for the EmbeddedPayment\n */\nexport type TranseptorEthereumProviderConfig = {\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string\n\n /**\n * The accepted chain configurations to be used to accept payments\n */\n // acceptedChainConfig: AcceptedChainConfig[]\n\n /**\n * Callback function to handle incoming payment events that emit when the user completes a payment\n */\n // onPaymentEvent: (checkoutResponse: CheckoutResponse) => void\n}\n\n/**\n * We use a singleton class maintains a single instance across a web application, and to ensure\n * the post message listener is only added once, allowing that web application to access wallet globally.\n *\n * The TranseptorEthereumProvider target environment is the browser, and it is designed to be used in web applications.\n */\nexport class TranseptorEthereumProvider {\n static #instance: TranseptorEthereumProvider\n readonly #localWindow: Window\n readonly #boundMessageHandler: (event: MessageEvent<Message>) => void\n readonly FATAL_ERROR_MESSAGE = 'fatal: internal error'\n\n readonly #rpcMethodsThatRequireUserConsent: string[] = [\n 'wallet_requestExecutionPermissions',\n 'wallet_revokeExecutionPermission',\n ]\n\n #iframeHandler: IframeHandler\n #responseQueue: Map<\n number,\n {\n status: 'pending' | 'fulfilled' | 'failed'\n response: JsonRpcResponse | undefined\n fatalError?: FatalError\n }\n > = new Map()\n\n private constructor(iframeHandler: IframeHandler) {\n this.#localWindow = window\n this.#iframeHandler = iframeHandler\n\n this.#boundMessageHandler = this.#handleIncomingMessage.bind(this)\n this.#localWindow.addEventListener('message', this.#boundMessageHandler)\n }\n\n /**\n * Create a messageId to be used in a JSONRPC message and ensure it is unique.\n *\n * @returns A JsonRpcId\n */\n #getJsonRpcId(): number {\n const potentialId = getRandomNum(10000000000) + Date.now()\n\n // Ensure the id is unique and not already in the responseQueue or activeRequestId\n if (this.#responseQueue.has(potentialId)) {\n return this.#getJsonRpcId()\n }\n return potentialId\n }\n\n /**\n * close the TranseptorEthereumProvider\n */\n #close() {\n this.#iframeHandler.toggleFrameVisibility(false)\n }\n\n /**\n * resize the TranseptorEthereumProvider\n *\n * @param size - the size of the frame\n */\n #resize(size: FrameWidth) {\n this.#iframeHandler.resizeIframe(size)\n }\n\n /**\n * Handle incoming Post messages\n * Since the iframe is create locally, it will have the same origin as the dapp\n *\n * @param event - the PostMessageEvent sent from the iframe\n */\n async #handleIncomingMessage(event: MessageEvent<Message>) {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== this.#iframeHandler.getIframeOrigin()) {\n return\n }\n\n const message = event.data\n if (typeof message !== 'object') {\n return\n }\n\n const { isValid: isValidFatalError, fatalError } =\n fatalErrorValidator(message)\n if (isValidFatalError && fatalError) {\n this.#handleFatalError(fatalError)\n return\n }\n\n const { isValid: isValidEncryptedRequest, encryptedRequest } =\n encryptedMessageValidator(message)\n if (isValidEncryptedRequest && encryptedRequest) {\n await this.#handleIncomingEncryptedMessage(encryptedRequest)\n return\n }\n }\n\n /**\n * Handle a JsonRpcResponse and store it in the responseQueue\n *\n * @param response - the JsonRpcResponse to be handled\n */\n #handleJsonRpcResponse(response: JsonRpcResponse) {\n const { id } = response\n if (this.#responseQueue.has(Number(id))) {\n this.#responseQueue.set(Number(id), {\n status: 'fulfilled',\n response,\n })\n }\n }\n\n /**\n * Handle a InboundJsonRpcEventRequest and handle the event\n *\n * @param eventRequest - the JsonRpcEventRequest to be handled\n */\n #handleJsonRpcEvent(\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n ) {\n const { method } = eventRequest\n switch (method) {\n case 'wallet_paymentEvent':\n break\n case 'wallet_closeFrame':\n this.#close()\n break\n case 'wallet_disconnect':\n this.#disconnect()\n break\n case 'wallet_resizeFrameFull':\n this.#resize(FrameWidth.Full)\n break\n case 'wallet_resizeFrameDefault':\n this.#resize(FrameWidth.Default)\n break\n }\n }\n\n /**\n * Handle a SecureMessage and handle the message\n *\n * @param encryptedRequest - the SecureMessage to be handled\n */\n async #handleIncomingEncryptedMessage(\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted>,\n ) {\n const decryptedMessage =\n await this.#iframeHandler.decryptSecureMessage(encryptedRequest)\n\n const { isValid: isValidResponse, response } =\n jsonRpcResponseValidator(decryptedMessage)\n if (isValidResponse && response) {\n this.#handleJsonRpcResponse(response)\n return\n }\n\n const { isValid: isValidEventRequest, eventRequest } =\n inboundJsonRpcEventRequestValidator(decryptedMessage)\n if (isValidEventRequest && eventRequest) {\n this.#handleJsonRpcEvent(eventRequest)\n return\n }\n }\n\n /**\n * Handle a fatal error\n *\n * @param fatalError - the fatal error to be handled\n */\n #handleFatalError(fatalError: FatalError) {\n if (this.#responseQueue.size) {\n // loop through the responseQueue and set the status to failed\n this.#responseQueue.forEach((response) => {\n if (response.status === 'pending') {\n response.status = 'failed'\n response.fatalError = fatalError\n }\n })\n }\n }\n\n /**\n * Handles a JsonRpcRequest coming from the dapp\n * Request are handled synchronously(blocking) and requires immediate response from the user\n *\n * @param request - the JsonRpcRequest to be handled\n * @param requiresUserConsent - whether the user consent is required to show the iframe\n * @returns the response from the blobUrl IFrame\n */\n async #sendRequestToIframe(\n request: JsonRpcRequest,\n requiresUserConsent: boolean,\n ): Promise<JsonRpcResponse> {\n try {\n await this.#iframeHandler.prepareIframe()\n\n // show the iframe if the user consent is required otherwise the iframe will be hidden but can still response to requests\n if (requiresUserConsent) {\n this.#iframeHandler.toggleFrameVisibility(true)\n }\n\n const { id } = request\n this.#responseQueue.set(Number(id), {\n status: 'pending',\n response: undefined,\n })\n await this.#iframeHandler.sendMessageToIframe(request)\n\n // Wait for the user to respond from the IFrame\n return await this.#waitForResponse(Number(id))\n } catch (error: any) {\n if (error.message === this.FATAL_ERROR_MESSAGE) {\n this.#close()\n }\n return {\n jsonrpc: '2.0',\n id: request.id,\n error: {\n message: error.message,\n code: -32000,\n },\n }\n }\n }\n\n /**\n * Wait for a response from the user to be added to the responseQueue every second\n * max attempts is 300 or 5 minutes\n *\n * @param requestId - the id of the request\n * @param attempts - the number of attempts to wait for a response\n * @returns the response from the blobUrl IFrame\n */\n #waitForResponse(requestId: number, attempts = 300) {\n return new Promise<JsonRpcResponse>((_resolve, _reject) => {\n let counter = 0\n\n const intervalId = setInterval(() => {\n counter++\n\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n _reject(new Error('Max attempts reached waiting for response'))\n }\n\n // remove the response from the queue and resolve the promise\n const result = this.#responseQueue.get(requestId)\n if (result) {\n if (result.status === 'failed' && result.fatalError) {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _reject(new Error(result.fatalError.message))\n }\n\n if (result.status === 'fulfilled') {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _resolve(result.response as JsonRpcResponse)\n }\n }\n }, 1000) // 1 second\n })\n }\n\n /**\n * Disconnect the TranseptorEthereumProvider\n *\n * @returns true if the TranseptorEthereumProvider is disconnected successfully, false otherwise\n */\n #disconnect() {\n this.#iframeHandler.toggleFrameVisibility(false)\n this.#iframeHandler.disconnectIframe()\n this.#responseQueue = new Map()\n return true\n }\n\n /**\n * Generic request to the TranseptorEthereumProvider\n *\n * @param request - the request to be sent to the TranseptorEthereumProvider\n * @returns the response from the TranseptorEthereumProvider\n */\n async sendRequest(request: Eip1193RequestArguments): Promise<unknown> {\n const requestId = this.#getJsonRpcId()\n const requiresUserConsent = this.#rpcMethodsThatRequireUserConsent.includes(\n request.method,\n )\n\n switch (request.method) {\n case 'wallet_disconnect':\n this.#disconnect()\n return true\n case 'wallet_openHomePage':\n await this.#iframeHandler.prepareIframe()\n this.#iframeHandler.toggleFrameVisibility(true)\n await this.#iframeHandler.sendMessageToIframe({\n jsonrpc: '2.0',\n method: 'wallet_navigateToDashboardEvent',\n params: [],\n })\n return true\n default: {\n const result = await this.#sendRequestToIframe(\n {\n jsonrpc: '2.0',\n id: requestId,\n method: request.method,\n params: request.params || [],\n },\n requiresUserConsent,\n )\n if ('error' in result) {\n throw new ProviderRpcError({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data,\n })\n }\n return result.result\n }\n }\n }\n\n /**\n * Create a new instance of the TranseptorEthereumProvider\n *\n * @param config - the configuration for the TranseptorEthereumProvider\n * @returns the TranseptorEthereumProvider instance\n */\n static Create(\n config: TranseptorEthereumProviderConfig,\n ): TranseptorEthereumProvider {\n if (!TranseptorEthereumProvider.#instance) {\n const iframeHandler = createIframeHandler({\n parentOrigin: window.location.origin,\n devWalletUrl: config.devWalletUrl,\n })\n TranseptorEthereumProvider.#instance = new TranseptorEthereumProvider(\n iframeHandler,\n )\n }\n return TranseptorEthereumProvider.#instance\n }\n}\n", "export type ErrorDetails = {\n code: number\n message: string\n}\n\n/**\n * The EIP1193 error code enum\n */\nexport enum EIP1193_ERROR_CODES {\n /**\n * The user rejected the request.\n */\n USER_REJECTED_REQUEST = 4001,\n\n /**\n * The specified address is not connected or not in the wallet\n */\n UNAUTHORIZED = 4100,\n\n /**\n * The Provider does not support the requested method.\n */\n UNSUPPORTED_METHOD = 4200,\n\n /**\n * The Provider is disconnected from all chains.\n */\n DISCONNECTED = 4900,\n\n /**\n * The Provider is not connected to the requested chain.\n */\n CHAIN_DISCONNECTED = 4901,\n}\n\n/**\n * The ERC-7715 error code enum\n */\nexport enum ERC7715_ERROR_CODES {\n /**\n * The specified method is not authorized for the given origin\n * Related RPCs: wallet_requestConnection\n */\n UNAUTHORIZED_ACCESS_RESTRICTED_METHOD = 4101,\n}\n\n/**\n * The EIP5792 error code enum\n */\nexport enum EIP5792_ERROR_CODES {\n /**\n * This wallet does not support a capability that was not marked as optional\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_NON_OPTIONAL_CAPABILITY = 5700,\n\n /**\n * This wallet does not support the specified chain id\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_CHAIN_ID = 5710,\n\n /**\n * There is already a bundle submitted with this id\n * Related RPCs: wallet_sendCalls\n */\n DUPLICATE_BUNDLE_ID = 5720,\n\n /**\n * This bundle id is unknown / has not been submitted\n * Related RPCs: wallet_getCallsStatus, wallet_showCallsStatus\n */\n UNKNOWN_BUNDLE_ID = 5730,\n\n /**\n * The call bundle is too large for the wallet to process\n * Related RPCs: wallet_sendCalls\n */\n BUNDLE_TOO_LARGE = 5740,\n\n /**\n * The wallet can support atomicity after an upgrade, but the user rejected the upgrade\n * Related RPCs: wallet_sendCalls\n */\n ATOMIC_READY_WALLET_REJECTED_UPGRADE = 5750,\n\n /**\n * The wallet does not support atomic execution but the request requires it\n * Related RPCs: wallet_sendCalls\n */\n ATOMICITY_NOT_SUPPORTED = 5760,\n}\n\n/**\n * The fatal error code enum\n */\nexport enum FATAL_ERROR_CODES {\n INTERNAL_ERROR = -32001,\n}\n\nexport enum COMMON_ERROR_CODES {\n INVALID_PARAMS = -32602,\n}\n\n/**\n * The error code map\n */\nexport const ERROR_CODES_MAP: Record<\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n ErrorDetails\n> = {\n // EIP1193 errors\n [EIP1193_ERROR_CODES.USER_REJECTED_REQUEST]: {\n code: 4001,\n message: 'User rejected the request.',\n },\n [EIP1193_ERROR_CODES.UNAUTHORIZED]: {\n code: 4100,\n message:\n 'The requested method and/or account has not been authorized by the user.',\n },\n [EIP1193_ERROR_CODES.UNSUPPORTED_METHOD]: {\n code: 4200,\n message: 'The Provider does not support the requested method.',\n },\n [EIP1193_ERROR_CODES.DISCONNECTED]: {\n code: 4900,\n message: 'The Provider is disconnected from all chains.',\n },\n [EIP1193_ERROR_CODES.CHAIN_DISCONNECTED]: {\n code: 4901,\n message: 'The Provider is not connected to the requested chain.',\n },\n\n //ERC-7715 errors\n [ERC7715_ERROR_CODES.UNAUTHORIZED_ACCESS_RESTRICTED_METHOD]: {\n code: 4101,\n message:\n 'The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method.',\n },\n\n // EIP5792 errors\n [EIP5792_ERROR_CODES.UNSUPPORTED_NON_OPTIONAL_CAPABILITY]: {\n code: 5700,\n message:\n 'This wallet does not support a capability that was not marked as optional.',\n },\n [EIP5792_ERROR_CODES.UNSUPPORTED_CHAIN_ID]: {\n code: 5710,\n message: 'This wallet does not support the specified chain id.',\n },\n [EIP5792_ERROR_CODES.DUPLICATE_BUNDLE_ID]: {\n code: 5720,\n message: 'There is already a bundle submitted with this id.',\n },\n [EIP5792_ERROR_CODES.UNKNOWN_BUNDLE_ID]: {\n code: 5730,\n message: 'This bundle id is unknown / has not been submitted.',\n },\n [EIP5792_ERROR_CODES.BUNDLE_TOO_LARGE]: {\n code: 5740,\n message: 'The call bundle is too large for the wallet to process.',\n },\n [EIP5792_ERROR_CODES.ATOMIC_READY_WALLET_REJECTED_UPGRADE]: {\n code: 5750,\n message:\n 'The wallet can support atomicity after an upgrade, but the user rejected the upgrade.',\n },\n [EIP5792_ERROR_CODES.ATOMICITY_NOT_SUPPORTED]: {\n code: 5760,\n message:\n 'The wallet does not support atomic execution but the request requires it.',\n },\n\n // Fatal/Common errors\n [FATAL_ERROR_CODES.INTERNAL_ERROR]: {\n code: -32001,\n message: 'fatal: internal error',\n },\n [COMMON_ERROR_CODES.INVALID_PARAMS]: {\n code: 4002,\n message: 'Invalid parameters.',\n },\n}\n\n/**\n * Get the error message for a given error code\n *\n * @param code - The error code\n * @returns The error message\n * @throws {Error} if the error code is not found\n */\nexport const getErrorMessage = (\n code:\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n): ErrorDetails => {\n const details = ERROR_CODES_MAP[code]\n if (!details) {\n return {\n code,\n message: `Unknown error code: ${code}`,\n }\n }\n return details\n}\n", "import {\n Eip1193RequestArguments,\n Eip1193Provider,\n ProviderRpcError,\n} from './types.js'\nimport {\n TranseptorEthereumProvider,\n TranseptorEthereumProviderConfig,\n} from './transeptor-ethereum-provider.js'\nimport { getErrorMessage } from './errors.js'\n\nexport class Eip1193Bridge implements Eip1193Provider {\n #transeptorEthereumProvider: TranseptorEthereumProvider\n constructor(config: TranseptorEthereumProviderConfig) {\n this.#transeptorEthereumProvider = TranseptorEthereumProvider.Create(config)\n }\n\n async request(request: Eip1193RequestArguments) {\n try {\n return await this.#transeptorEthereumProvider.sendRequest(request)\n } catch (error: unknown) {\n if (error instanceof ProviderRpcError) {\n const errorDetails = getErrorMessage(error.code)\n if (errorDetails) {\n throw new ProviderRpcError(errorDetails)\n }\n }\n throw new ProviderRpcError({\n code: -32000,\n message: 'Unknown internal error',\n data: error,\n })\n }\n }\n}\n\n/**\n * Create a new Eip1193 provider\n *\n * @param config - the configuration for the TranseptorEthereumProvider\n * @returns the Eip1193 provider\n */\nexport function createEip1193Provider(\n config: TranseptorEthereumProviderConfig,\n): Eip1193Provider {\n return new Eip1193Bridge(config)\n}\n", "import { Eip1193Provider } from '../index.js'\n\nexport const enum ProviderEvent {\n AnnounceProvider = 'eip6963:announceProvider',\n RequestProvider = 'eip6963:requestProvider',\n}\n\n/**\n * Provider Detail defined by eip-6963\n */\nexport type EIP6963ProviderDetail = {\n info: {\n uuid: string\n name: string\n icon: string\n rdns: string\n }\n provider: Eip1193Provider\n}\n\n/**\n * Announce Event dispatched by a Wallet\n */\nexport interface EIP6963AnnounceProviderEvent extends CustomEvent {\n type: ProviderEvent.AnnounceProvider\n detail: EIP6963ProviderDetail\n}\n\n/**\n * Request Event dispatched by a DApp\n */\nexport interface EIP6963RequestProviderEvent extends Event {\n type: ProviderEvent.RequestProvider\n}\n", "/**\n * The icon of the Transeptor Pay wallet\n */\nexport const TRANSEPTOR_WALLET_ICON =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg=='\n", "import { TranseptorEthereumProviderConfig } from '../transeptor-ethereum-provider.js'\nimport { createEip1193Provider } from '../eip-1193-bridge.js'\nimport { EIP6963ProviderDetail, ProviderEvent } from './types.js'\nimport { TRANSEPTOR_WALLET_ICON } from './icon.js'\n\n/**\n * Announce the Transeptor Pay provider to the dapp\n *\n * @param config - the configuration for the TranseptorEthereumProvider\n */\nexport const announceProvider = (config: TranseptorEthereumProviderConfig) => {\n const provider = createEip1193Provider(config)\n const detail = Object.freeze({\n info: Object.freeze({\n uuid: '2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1',\n name: 'Transeptor',\n icon: TRANSEPTOR_WALLET_ICON,\n rdns: 'io.transeptor.pay',\n }),\n provider,\n } as EIP6963ProviderDetail)\n const announceEvent = new CustomEvent(ProviderEvent.AnnounceProvider, {\n detail,\n })\n\n // The Wallet dispatches an announce event which is heard by\n // the DApp code that had run earlier\n window.addEventListener(ProviderEvent.RequestProvider, () => {\n window.dispatchEvent(announceEvent)\n })\n\n // The Wallet listens to the request events which may be\n // dispatched later and re-dispatches the `EIP6963AnnounceProviderEvent`\n window.dispatchEvent(announceEvent)\n}\n"],
5
- "mappings": "4aAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,mBAAAE,EAAA,qBAAAC,EAAA,+BAAAC,EAAA,qBAAAC,EAAA,0BAAAC,IAAA,eAAAC,GAAAP,ICAO,IAAMQ,EAAN,cAA+B,KAAM,CAO1C,KAKA,KAEA,YAAY,CACV,QAAAC,EACA,KAAAC,EACA,KAAAC,CACF,EAIG,CACD,MAAMF,CAAO,EACb,KAAK,KAAOC,EACZ,KAAK,KAAOC,CACd,CACF,ECFO,IAAMC,EAAN,KAA2B,CACf,KAAO,CAAE,KAAM,OAAQ,WAAY,OAAQ,EAC5DC,GAAiB,GACjBC,GAAgC,CAC9B,QAAS,KACT,OAAQ,KACR,MAAO,IACT,EACAC,GAGI,CACF,KAAM,KACN,GAAI,EACN,EACAC,GAAY,EACZC,GAA6B,KAE7B,aAAc,CAEd,CAOAC,IAA2B,CACzB,GAAI,CAAC,KAAKL,GACR,MAAM,IAAI,MAAM,sBAAsB,CAE1C,CAOAM,IAA2C,CACzC,GAAI,CAAC,KAAKJ,GAAmB,GAC3B,MAAM,IAAI,MAAM,mCAAmC,CAEvD,CAOAK,IAAkC,CAChC,GAAI,CACF,GACE,OAAO,OAAW,KAClB,OAAO,OAAO,OAAW,KACzB,OAAO,OAAO,gBAAoB,KAClC,OAAO,OAAO,OAAO,YAAgB,KACrC,OAAO,OAAO,OAAO,QAAY,KACjC,OAAO,OAAO,OAAO,QAAY,IAEjC,OAEF,MAAM,IAAI,MAAM,8BAA8B,CAChD,OAASC,EAAO,CACd,MAAM,IAAI,MAAM,+BAAgC,CAAE,MAAOA,CAAM,CAAC,CAClE,CAC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X,EACA,CAAC,MAAiC,EAAG,CACnC,KAAM,KACN,QAAS,qBACX,CACF,EASaC,EACXC,GAMiB,CACjB,IAAMC,EAAUH,GAAgBE,CAAI,EACpC,OAAKC,GACI,CACL,KAAAD,EACA,QAAS,uBAAuBA,CAAI,EACtC,CAGJ,ECzMO,IAAME,EAAN,KAA+C,CACpDC,GACA,YAAYC,EAA0C,CACpD,KAAKD,GAA8BE,EAA2B,OAAOD,CAAM,CAC7E,CAEA,MAAM,QAAQE,EAAkC,CAC9C,GAAI,CACF,OAAO,MAAM,KAAKH,GAA4B,YAAYG,CAAO,CACnE,OAASC,EAAgB,CACvB,GAAIA,aAAiBC,EAAkB,CACrC,IAAMC,EAAeC,EAAgBH,EAAM,IAAI,EAC/C,GAAIE,EACF,MAAM,IAAID,EAAiBC,CAAY,CAE3C,CACA,MAAM,IAAID,EAAiB,CACzB,KAAM,MACN,QAAS,yBACT,KAAMD,CACR,CAAC,CACH,CACF,CACF,EAQO,SAASI,EACdP,EACiB,CACjB,OAAO,IAAIF,EAAcE,CAAM,CACjC,CC5CO,IAAWQ,OAChBA,EAAA,iBAAmB,2BACnBA,EAAA,gBAAkB,0BAFFA,OAAA,ICCX,IAAMC,EACX,i+BCMK,IAAMC,EAAoBC,GAA6C,CAC5E,IAAMC,EAAWC,EAAsBF,CAAM,EACvCG,EAAS,OAAO,OAAO,CAC3B,KAAM,OAAO,OAAO,CAClB,KAAM,uCACN,KAAM,aACN,KAAMC,EACN,KAAM,mBACR,CAAC,EACD,SAAAH,CACF,CAA0B,EACpBI,EAAgB,IAAI,uCAA4C,CACpE,OAAAF,CACF,CAAC,EAID,OAAO,2CAAgD,IAAM,CAC3D,OAAO,cAAcE,CAAa,CACpC,CAAC,EAID,OAAO,cAAcA,CAAa,CACpC",
6
- "names": ["index_exports", "__export", "ProviderEvent", "ProviderRpcError", "TranseptorEthereumProvider", "announceProvider", "createEip1193Provider", "__toCommonJS", "ProviderRpcError", "message", "code", "data", "EphemeralEcdhManager", "#isInitialized", "#ephemeralEcdh", "#isKeyExchangeDone", "#sequence", "#aeadKey", "#assertInitialized", "#assertSecureConnectionEstablished", "#assertWebCryptoAvailable", "error", "keyPair", "pubJwk", "nonce", "message", "pub", "recipientPub", "bits", "baseKey", "salt", "data", "iv", "additionalData", "dataBytes", "cipherText", "ok", "role", "jsonRpcResponseValidator", "message", "response", "inboundJsonRpcEventRequestValidator", "eventRequest", "jsonRpcKeyExchangeResponseValidator", "keyExchangeResponse", "jsonRpcKeyExchangeDoneValidator", "keyExchangeDone", "encryptedMessageValidator", "encryptedRequest", "fatalErrorValidator", "fatalError", "isMobile", "resizeFrameWidth", "iframeId", "frameWidth", "frameHeight", "iframe", "showIframe", "overlay", "hideIframe", "doToggleIframeVisibility", "overlayId", "isVisible", "appendIframeWithContainer", "url", "destroyIframeWithContainer", "createIframeHandler", "config", "ecdhManager", "EphemeralEcdhManager", "devWalletUrl", "IFRAME_ORIGIN", "params", "walletUrl", "DAPP_IFRAME_ID", "OVERLAY_CONTAINER_ID", "activeFrameWidth", "activeFrameHeight", "isIframeCreated", "handleOverlayClick", "event", "overlay", "doToggleIframeVisibility", "getIframeContentWindow", "iframe", "checkIframeReady", "attempts", "childWindow", "isFrameReady", "handleReady", "_resolve", "_reject", "counter", "intervalId", "establishSecureConnectionWithIframe", "keyExchangeMessage", "keyExchangeResponseMessage", "keyExchangeDoneMessage", "message", "isValidKeyExchangeResponse", "keyExchangeResponse", "jsonRpcKeyExchangeResponseValidator", "isValidKeyExchangeDone", "keyExchangeDone", "jsonRpcKeyExchangeDoneValidator", "isMobile", "appendIframeWithContainer", "isIframeReady", "destroyIframeWithContainer", "isVisible", "resizeFrameWidth", "size", "request", "encryptedRequest", "decryptedMessage", "passedDecryption", "getRandomNum", "maxRange", "rand", "rn", "TranseptorEthereumProvider", "_TranseptorEthereumProvider", "#instance", "#localWindow", "#boundMessageHandler", "#rpcMethodsThatRequireUserConsent", "#iframeHandler", "#responseQueue", "iframeHandler", "#handleIncomingMessage", "#getJsonRpcId", "potentialId", "getRandomNum", "#close", "#resize", "size", "event", "message", "isValidFatalError", "fatalError", "fatalErrorValidator", "#handleFatalError", "isValidEncryptedRequest", "encryptedRequest", "encryptedMessageValidator", "#handleIncomingEncryptedMessage", "#handleJsonRpcResponse", "response", "id", "#handleJsonRpcEvent", "eventRequest", "method", "#disconnect", "decryptedMessage", "isValidResponse", "jsonRpcResponseValidator", "isValidEventRequest", "inboundJsonRpcEventRequestValidator", "#sendRequestToIframe", "request", "requiresUserConsent", "#waitForResponse", "error", "requestId", "attempts", "_resolve", "_reject", "counter", "intervalId", "result", "ProviderRpcError", "config", "createIframeHandler", "ERROR_CODES_MAP", "getErrorMessage", "code", "details", "Eip1193Bridge", "#transeptorEthereumProvider", "config", "TranseptorEthereumProvider", "request", "error", "ProviderRpcError", "errorDetails", "getErrorMessage", "createEip1193Provider", "ProviderEvent", "TRANSEPTOR_WALLET_ICON", "announceProvider", "config", "provider", "createEip1193Provider", "detail", "TRANSEPTOR_WALLET_ICON", "announceEvent"]
3
+ "sources": ["../src/index.ts", "../src/provider/types.ts", "../src/ecdh/ecdh-manager.ts", "../src/utils/validate.ts", "../src/iframe/iframe.ts", "../src/iframe/iframe-handler.ts", "../src/utils/random.ts", "../src/provider/cashie-ethereum-provider.ts", "../src/provider/errors.ts", "../src/provider/eip-1193-bridge.ts", "../src/provider/eip-6963/types.ts", "../src/provider/eip-6963/icon.ts", "../src/provider/eip-6963/announce-provider.ts"],
4
+ "sourcesContent": ["export * from './provider/index.js'\nexport * from './types/index.js'\n", "export class ProviderRpcError extends Error {\n /**\n * MUST be an integer number\n * SHOULD adhere to the specifications in the Error Standards section below\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#error-standards\n */\n code: number\n\n /**\n * SHOULD contain any other useful information about the error\n */\n data?: unknown\n\n constructor({\n message,\n code,\n data,\n }: {\n message: string\n code: number\n data?: unknown\n }) {\n super(message)\n this.code = code\n this.data = data\n }\n}\n\n/**\n * The Eip1193 error types\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#rpc-errors\n */\nexport type Eip1193Error =\n | 'userRejectedRequest'\n | 'unauthorized'\n | 'unsupportedMethod'\n | 'disconnected'\n | 'chainDisconnected'\n\nexport type Eip1193RequestArguments = {\n method: string\n params?: readonly unknown[] | object\n}\n\nexport interface Eip1193Provider {\n /**\n * Request a method from the Eip1193 provider\n *\n * @param request - the request to be sent to the Eip1193 provider\n * @returns the response from the Eip1193 provider\n *\n * @throws {Error} If the returned Promise rejects, it MUST reject with a ProviderRpcError as specified in the [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193#rpc-errors) section below.\n */\n request: (request: Eip1193RequestArguments) => Promise<unknown>\n}\n\n/**\n * The message event is intended for arbitrary notifications not covered by other events.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#message-event\n */\nexport type Eip1193ProviderMessage = {\n readonly type: string\n readonly data: unknown\n}\n\n/**\n * Specify the integer ID of the connected chain as a hexadecimal string, per the eth_chainId Ethereum RPC method.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider_connect\n */\nexport type Eip1193ProviderConnectInfo = {\n readonly chainId: `0x${string}`\n}\n", "/* eslint-disable no-console */\nimport { SecureMessageType, SecureMessage } from './ecdh.types.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n JsonRpcErrorResponse,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n} from '../types/index.js'\n\n/**\n * Ephemeral ECDH key pair(private key, public key), public key(public key in jwk format), and nonce\n */\nexport type EphemeralEcdh = {\n keyPair: CryptoKeyPair | null\n pubJwk: JsonWebKey | null\n nonce: Uint8Array | null\n}\n\n/**\n * Create a new ephemeral ECDH manager\n * The ECDH(Elliptic Curve Diffie\u2013Hellman) key exchange manager is used to generate a shared secret key to encrypt and decrypt secure messages between the two parties on an untrusted channel.\n */\nexport class EphemeralEcdhManager {\n private readonly ALGO = { name: 'ECDH', namedCurve: 'P-256' }\n #isInitialized = false\n #ephemeralEcdh: EphemeralEcdh = {\n keyPair: null,\n pubJwk: null,\n nonce: null,\n }\n #isKeyExchangeDone: {\n role: 'parent' | 'iframe' | null\n ok: boolean\n } = {\n role: null,\n ok: false,\n }\n #sequence = 0\n #aeadKey: CryptoKey | null = null\n\n constructor() {\n // empty constructor\n }\n\n /**\n * Assert that the ECDH is initialized\n *\n * @throws {Error} if the ECDH is not initialized\n */\n #assertInitialized(): void {\n if (!this.#isInitialized) {\n throw new Error('ECDH not initialized')\n }\n }\n\n /**\n * Assert that the secure connection is established\n *\n * @throws {Error} if the secure connection is not established\n */\n #assertSecureConnectionEstablished(): void {\n if (!this.#isKeyExchangeDone.ok) {\n throw new Error('Secure connection not established')\n }\n }\n\n /**\n * Check if Web Crypto API is available and properly configured\n *\n * @throws {Error} if Web Crypto API is not available\n */\n #assertWebCryptoAvailable(): void {\n try {\n if (\n typeof crypto !== 'undefined' &&\n typeof crypto.subtle !== 'undefined' &&\n typeof crypto.getRandomValues !== 'undefined' &&\n typeof crypto.subtle.generateKey !== 'undefined' &&\n typeof crypto.subtle.encrypt !== 'undefined' &&\n typeof crypto.subtle.decrypt !== 'undefined'\n ) {\n return\n }\n throw new Error('Web Crypto API not available')\n } catch (error) {\n throw new Error('Web Crypto API not available', { cause: error })\n }\n }\n\n /**\n * Check if the secure connection is established\n *\n * @returns true if the secure connection is established, false otherwise\n */\n get isSecureConnectionEstablished(): boolean {\n return this.#isKeyExchangeDone.ok\n }\n\n /**\n * Initialize the ECDH\n *\n * @returns void\n */\n async initializeEcdh(): Promise<void> {\n this.#assertWebCryptoAvailable()\n const keyPair = await crypto.subtle.generateKey(this.ALGO, true, [\n 'deriveBits',\n ])\n const pubJwk = await crypto.subtle.exportKey('jwk', keyPair.publicKey)\n const nonce = crypto.getRandomValues(new Uint8Array(16))\n\n this.#ephemeralEcdh = {\n keyPair,\n pubJwk,\n nonce,\n } as EphemeralEcdh\n this.#isInitialized = true\n }\n\n /**\n * Parse a key exchange message to generate a shared secret\n *\n * @param message - the key exchange response message\n * @returns void\n */\n async parseKeyExchangeMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeResponse>,\n ): Promise<void> {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n\n // Extract the public key and nonce from the message\n const { pub, nonce } = message.payload\n const recipientPub = await crypto.subtle.importKey(\n 'jwk',\n pub,\n this.ALGO,\n false,\n [],\n )\n\n // Compute a shared secret using the recipient's public key and the ephemeral private key pair\n const bits = await crypto.subtle.deriveBits(\n { name: this.ALGO.name, public: recipientPub },\n this.#ephemeralEcdh.keyPair.privateKey,\n 256,\n )\n const baseKey = await crypto.subtle.importKey('raw', bits, 'HKDF', false, [\n 'deriveKey',\n ])\n\n // Derive the salt with format <parent-nonce,child-nonce>\n // Note: This must match the iframe's salt ordering for consistent key derivation\n const salt = new Uint8Array([\n ...this.#ephemeralEcdh.nonce,\n ...new Uint8Array(nonce),\n ])\n\n // Derive the AEAD key from the base key and the salt that will be used to encrypt/decrypt the messages between the both parties\n this.#aeadKey = await crypto.subtle.deriveKey(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n salt,\n info: new TextEncoder().encode('cashie-connect'),\n },\n baseKey,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt'],\n )\n }\n\n /**\n * Generate a key exchange message\n *\n * @returns the key exchange message\n */\n async generateKeyExchangeMessage(): Promise<\n SecureMessage<SecureMessageType.KeyExchangeInit>\n > {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.pubJwk) {\n throw new Error('Ephemeral public key not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n\n return {\n type: SecureMessageType.KeyExchangeInit,\n payload: {\n pub: this.#ephemeralEcdh.pubJwk,\n nonce: Array.from<number>(this.#ephemeralEcdh.nonce),\n },\n }\n }\n\n /**\n * Prepare a secure message\n *\n * @param data - the data to be prepared\n * @returns the secure message\n */\n async prepareSecureMessage(\n data:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ): Promise<SecureMessage<SecureMessageType.Encrypted>> {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n // Increment the sequence number\n this.#sequence++\n\n // Encrypt the data with the AEAD key given by the child iframe to ensure only the child iframe can decrypt the message\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const additionalData = new TextEncoder().encode(`seq:${this.#sequence}`)\n const dataBytes = new TextEncoder().encode(JSON.stringify(data))\n const cipherText = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv, additionalData },\n this.#aeadKey,\n dataBytes,\n ),\n )\n\n return {\n type: SecureMessageType.Encrypted,\n payload: {\n iv: Array.from<number>(iv),\n cipherText: Array.from<number>(cipherText),\n additionalData: Array.from<number>(additionalData),\n },\n }\n }\n\n /**\n * Decrypt a secure message sent by the child iframe\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted data\n */\n async decryptSecureMessage(\n message: SecureMessage<SecureMessageType.Encrypted>,\n ): Promise<{\n decryptedMessage:\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n | null\n passedDecryption: boolean\n }> {\n try {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n\n const { iv, cipherText, additionalData } = message.payload\n\n if (!iv || !cipherText || !additionalData) {\n throw new Error('Invalid message payload: missing required fields')\n }\n\n if (\n !Array.isArray(iv) ||\n !Array.isArray(cipherText) ||\n !Array.isArray(additionalData)\n ) {\n throw new Error('Invalid message payload: fields must be arrays')\n }\n\n const dataBytes = await crypto.subtle.decrypt(\n {\n name: 'AES-GCM',\n iv: new Uint8Array(iv),\n additionalData: new Uint8Array(additionalData),\n },\n this.#aeadKey,\n new Uint8Array(cipherText),\n )\n const decryptedMessage = JSON.parse(new TextDecoder().decode(dataBytes))\n return {\n decryptedMessage,\n passedDecryption: true,\n }\n } catch (error) {\n console.error('Error decrypting secure message from iframe', error)\n return {\n decryptedMessage: null,\n passedDecryption: false,\n }\n }\n }\n\n /**\n * Parse a key exchange done message\n *\n * @param message - the key exchange done message\n */\n parseKeyExchangeDoneMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeDone>,\n ): void {\n this.#assertInitialized()\n const { ok, role } = message.payload\n if (ok) {\n this.#isKeyExchangeDone = {\n role,\n ok,\n }\n }\n }\n\n /**\n * Generate a key exchange done message\n *\n * @returns the key exchange done message\n */\n generateKeyExchangeDoneMessage(): SecureMessage<SecureMessageType.KeyExchangeDone> {\n return {\n type: SecureMessageType.KeyExchangeDone,\n payload: {\n ok: true,\n role: 'parent',\n },\n }\n }\n\n /**\n * Close the secure connection\n *\n */\n closeSecureConnection(): void {\n this.#isKeyExchangeDone = {\n role: null,\n ok: false,\n }\n this.#aeadKey = null\n }\n}\n", "import {\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n FatalError,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/ecdh.types.js'\n\ntype JsonRpcResponseValidator = {\n isValid: boolean\n response: JsonRpcResponse | null\n}\n\ntype JsonRpcEventRequestValidator = {\n isValid: boolean\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames> | null\n}\n\ntype JsonRpcKeyExchangeResponseValidator = {\n isValid: boolean\n keyExchangeResponse: SecureMessage<SecureMessageType.KeyExchangeResponse> | null\n}\n\ntype JsonRpcKeyExchangeDoneValidator = {\n isValid: boolean\n keyExchangeDone: SecureMessage<SecureMessageType.KeyExchangeDone> | null\n}\n\ntype EncryptedRequestValidator = {\n isValid: boolean\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted> | null\n}\n\ntype FatalErrorValidator = {\n isValid: boolean\n fatalError: FatalError | null\n}\n\n/**\n * Validate a JSON-RPC response\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcResponseValidator = (\n message: unknown,\n): JsonRpcResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, response: null }\n }\n const response = message as JsonRpcResponse\n if (response.jsonrpc !== '2.0') {\n return { isValid: false, response: null }\n }\n\n if (response.id === null || response.id === undefined) {\n return { isValid: false, response: null }\n }\n\n if (response && ('result' in response || 'error' in response)) {\n return { isValid: true, response: response as JsonRpcResponse }\n }\n\n return {\n isValid: true,\n response: response as JsonRpcResponse,\n }\n}\n\n/**\n * Validate a JSON-RPC event request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const inboundJsonRpcEventRequestValidator = (\n message: unknown,\n): JsonRpcEventRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, eventRequest: null }\n }\n const eventRequest =\n message as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n if (eventRequest.jsonrpc !== '2.0') {\n return { isValid: false, eventRequest: null }\n }\n if (!eventRequest.method) {\n return { isValid: false, eventRequest: null }\n }\n\n if (!('params' in eventRequest)) {\n return {\n isValid: false,\n eventRequest: null,\n }\n }\n\n return {\n isValid: true,\n eventRequest:\n eventRequest as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange response request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeResponseValidator = (\n message: unknown,\n): JsonRpcKeyExchangeResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeResponse: null }\n }\n const keyExchangeResponse =\n message as SecureMessage<SecureMessageType.KeyExchangeResponse>\n if (keyExchangeResponse.type !== SecureMessageType.KeyExchangeResponse) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.pub) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.nonce) {\n return { isValid: false, keyExchangeResponse: null }\n }\n return {\n isValid: true,\n keyExchangeResponse:\n keyExchangeResponse as SecureMessage<SecureMessageType.KeyExchangeResponse>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange done request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeDoneValidator = (\n message: unknown,\n): JsonRpcKeyExchangeDoneValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeDone: null }\n }\n const keyExchangeDone =\n message as SecureMessage<SecureMessageType.KeyExchangeDone>\n if (keyExchangeDone.type !== SecureMessageType.KeyExchangeDone) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.ok) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.role) {\n return { isValid: false, keyExchangeDone: null }\n }\n\n return {\n isValid: true,\n keyExchangeDone:\n keyExchangeDone as SecureMessage<SecureMessageType.KeyExchangeDone>,\n }\n}\n\n/**\n * Validate a JSON-RPC encrypted message\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const encryptedMessageValidator = (\n message: unknown,\n): EncryptedRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, encryptedRequest: null }\n }\n const encryptedRequest = message as SecureMessage<SecureMessageType.Encrypted>\n if (encryptedRequest.type !== SecureMessageType.Encrypted) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.iv) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.cipherText) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.additionalData) {\n return { isValid: false, encryptedRequest: null }\n }\n return {\n isValid: true,\n encryptedRequest:\n encryptedRequest as SecureMessage<SecureMessageType.Encrypted>,\n }\n}\n\n/**\n * Validate a fatal error\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const fatalErrorValidator = (message: unknown): FatalErrorValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, fatalError: null }\n }\n const fatalError = message as FatalError\n if (!fatalError.code) {\n return { isValid: false, fatalError: null }\n }\n if (!fatalError.message) {\n return { isValid: false, fatalError: null }\n }\n return { isValid: true, fatalError: fatalError as FatalError }\n}\n", "/**\n * Frame width enum\n */\nexport enum FrameWidth {\n Default = '412px',\n Full = '100%',\n}\n\nexport enum FrameHeight {\n Default = '640px',\n Full = '100%',\n}\n\n/**\n * Check if the device is mobile\n *\n * @returns true if the device is mobile, false otherwise\n */\nexport const isMobile = () => {\n return window.innerWidth < 768\n}\n\n/**\n * Resize the iframe container and iframe element width\n *\n * @param iframeId - the id of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const resizeFrameWidth = (\n iframeId: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n const iframe = document.getElementById(iframeId)\n\n if (iframe) {\n iframe.style.width = frameWidth\n iframe.style.height = frameHeight\n }\n}\n\n/**\n * Show the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst showIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)' // Scale in\n}\n\n/**\n * Hide the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst hideIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '0'\n overlay.style.pointerEvents = 'none'\n iframe.style.opacity = '0'\n iframe.style.transform = 'scale(0.8)' // Scale out\n}\n\n/**\n * Toggle the visibility of the iframe\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param isVisible - the visibility of the iframe\n */\nexport const doToggleIframeVisibility = (\n iframeId: string,\n overlayId: string,\n isVisible: boolean,\n) => {\n const iframe = document.getElementById(iframeId)\n const overlay = document.getElementById(overlayId)\n if (!iframe || !overlay) {\n return\n }\n\n document.body.style.overflow = isVisible ? 'hidden' : 'auto'\n if (isVisible) {\n showIframe(overlay, iframe)\n } else {\n hideIframe(overlay, iframe)\n }\n}\n\n/**\n * Append the iframe to the container div\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param url - the url of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const appendIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n url: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n // Create overlay container\n const overlay = document.createElement('div')\n overlay.id = overlayId\n Object.assign(overlay.style, {\n position: 'fixed',\n top: '0',\n left: '0',\n width: '100%',\n height: '100%',\n background: 'rgba(0, 0, 0, 0.4)',\n backdropFilter: 'blur(4px)',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n zIndex: '9999',\n opacity: '1',\n pointerEvents: 'none', // Disable interactions when hidden\n cursor: 'default', // Default cursor for overlay background\n transition: 'opacity 0.3s ease-in-out',\n })\n\n const iframe = document.createElement('iframe')\n iframe.id = iframeId\n iframe.src = url\n iframe.allow = 'publickey-credentials-get *; publickey-credentials-create *'\n Object.assign(iframe.style, {\n height: frameHeight,\n width: frameWidth,\n position: 'relative',\n borderRadius: '0.75rem',\n boxShadow:\n '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)',\n overflowY: 'auto',\n zIndex: '1000',\n opacity: '1',\n transform: 'scale(0.8)',\n transition: 'opacity 0.3s ease-in-out, transform 0.3s ease-in-out',\n })\n\n overlay.appendChild(iframe)\n document.body.appendChild(overlay)\n\n // Ensure styles are applied after DOM insertion\n setTimeout(() => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)'\n }, 100) // Small delay to trigger transition\n\n // Prevent scrolling while overlay is open\n document.body.style.overflow = 'hidden'\n}\n\n/**\n * Destroy the iframe element and remove it from the DOM\n *\n * @param iframeId - the id of the iframe to be destroyed\n * @param overlayId - the id of the overlay container\n */\nexport const destroyIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n) => {\n const overlay = document.getElementById(overlayId)\n if (overlay) {\n overlay.parentNode?.removeChild(overlay)\n document.body.style.overflow = 'auto' // Restore scrolling\n }\n const iframe = document.getElementById(iframeId)\n if (iframe) {\n if (iframe.parentNode) {\n iframe.parentNode.removeChild(iframe)\n }\n }\n}\n", "/* eslint-disable no-console */\nimport {\n EphemeralEcdhManager,\n SecureMessage,\n SecureMessageType,\n} from '../ecdh/index.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcErrorResponse,\n JsonRpcResponse,\n} from '../types/index.js'\nimport {\n jsonRpcKeyExchangeResponseValidator,\n jsonRpcKeyExchangeDoneValidator,\n} from '../utils/validate.js'\nimport {\n appendIframeWithContainer,\n destroyIframeWithContainer,\n doToggleIframeVisibility,\n FrameHeight,\n FrameWidth,\n isMobile,\n resizeFrameWidth,\n} from './iframe.js'\n\n/**\n * Iframe handler interface\n */\nexport type IframeHandler = {\n /**\n * Create a new iframe element and append it to the container div if it is not already created\n * Establish a secure connection with the iframe\n *\n * @returns void\n */\n prepareIframe: () => Promise<void>\n\n /**\n * Disconnect the iframe by closing the secure connection and destroying the iframe container and iframe element\n *\n */\n disconnectIframe: () => void\n\n /**\n * Toggle the visibility of the iframe\n *\n * @param isVisible - the visibility of the iframe\n * @returns void\n */\n toggleFrameVisibility: (isVisible: boolean) => void\n\n /**\n * Send a message to the iframe\n *\n * @param request - the request to be sent to the iframe\n */\n sendMessageToIframe: (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => Promise<void>\n\n /**\n * Resize the iframe\n *\n * @param size - the size of the iframe\n * @returns void\n */\n resizeIframe: (size?: FrameWidth) => void\n\n /**\n * Get the origin of the iframe\n *\n * @returns the origin of the iframe\n */\n getIframeOrigin: () => string\n\n /**\n * Decrypt a secure message\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted message\n */\n decryptSecureMessage: (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => Promise<\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n >\n}\n\ntype IframeHandlerConfig = {\n /**\n * The origin of the parent window\n */\n parentOrigin: string\n\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string | undefined\n}\n\n/**\n * Create a new iframe handler\n *\n * @param config - the iframe handler config\n * @returns the iframe handler\n */\nexport const createIframeHandler = (\n config: IframeHandlerConfig,\n): IframeHandler => {\n const ecdhManager = new EphemeralEcdhManager()\n const { devWalletUrl } = config\n const IFRAME_ORIGIN = devWalletUrl || 'https://pay.transeptorlabs.io'\n const params = new URLSearchParams({ embedded: 'true' }).toString()\n const walletUrl = devWalletUrl\n ? `${devWalletUrl}?${params}`\n : `https://pay.transeptorlabs.io/?${params}`\n const DAPP_IFRAME_ID = 'dapp:iframe-embedded-payment'\n const OVERLAY_CONTAINER_ID = 'dapp:iframe-container'\n\n let activeFrameWidth = FrameWidth.Default\n let activeFrameHeight = FrameHeight.Default\n let isIframeCreated = false\n\n /**\n * Handle the overlay click event\n *\n * @param event - the mouse event\n */\n const handleOverlayClick = (event: MouseEvent) => {\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n if (event.target === overlay) {\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, false)\n }\n }\n }\n\n /**\n * Get the content window of the iframe\n *\n * @returns the content window of the iframe\n */\n const getIframeContentWindow = (): Window | null => {\n const iframe = document.getElementById(DAPP_IFRAME_ID)\n if (!iframe) {\n throw new Error('Iframe not found')\n }\n const hasContentWindow = 'contentWindow' in iframe\n if (hasContentWindow) {\n const childWindow = iframe.contentWindow as Window\n return childWindow\n }\n return null\n }\n\n /**\n * Send a post message to the IFrame window to check if it is ready and to inform the iframe of the parent origin extracted from message event\n * Waits for the frame to be ready before sending the message.\n * max attempts is 600\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns true if the frame is ready, false otherwise will reject with an error\n */\n const checkIframeReady = async (attempts = 600) => {\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n let isFrameReady = false\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n if (message === 'pong') {\n isFrameReady = true\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n return new Promise<boolean>((_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max ping attempts reached to establish connection with the iframe',\n ),\n )\n }\n\n // resolve if the frame is ready\n if (isFrameReady) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n console.log('Iframe is ready to receive messages')\n _resolve(true)\n } else {\n console.log('Sending ping to the iframe to check if it is ready')\n childWindow.postMessage('ping', IFRAME_ORIGIN)\n }\n }, 500) // 500ms\n })\n }\n\n /**\n * Establish a secure connection with the iframe\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns the key exchange response message if the secure connection is established, null otherwise will reject with an error\n */\n const establishSecureConnectionWithIframe = async (attempts = 600) => {\n console.log('Establishing secure connection with the iframe')\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n // Generate key exchange messages\n const keyExchangeMessage = await ecdhManager.generateKeyExchangeMessage()\n let keyExchangeResponseMessage: SecureMessage<SecureMessageType.KeyExchangeResponse> | null =\n null\n let keyExchangeDoneMessage: SecureMessage<SecureMessageType.KeyExchangeDone> | null =\n null\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n const { isValid: isValidKeyExchangeResponse, keyExchangeResponse } =\n jsonRpcKeyExchangeResponseValidator(message)\n if (isValidKeyExchangeResponse && keyExchangeResponse) {\n childWindow.postMessage(\n ecdhManager.generateKeyExchangeDoneMessage(),\n IFRAME_ORIGIN,\n )\n keyExchangeResponseMessage = message\n return\n }\n\n const { isValid: isValidKeyExchangeDone, keyExchangeDone } =\n jsonRpcKeyExchangeDoneValidator(message)\n if (isValidKeyExchangeDone && keyExchangeDone) {\n keyExchangeDoneMessage = message\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n childWindow.postMessage(keyExchangeMessage, IFRAME_ORIGIN)\n\n return new Promise<SecureMessage<SecureMessageType.KeyExchangeResponse>>(\n (_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max secure connection attempts reached to establish secure connection with the iframe',\n ),\n )\n }\n\n // resolve if the secure connection is established\n if (keyExchangeResponseMessage && keyExchangeDoneMessage) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n ecdhManager.parseKeyExchangeDoneMessage(keyExchangeDoneMessage)\n _resolve(keyExchangeResponseMessage)\n }\n }, 200) // 200ms\n },\n )\n }\n\n return {\n getIframeOrigin: () => IFRAME_ORIGIN,\n\n prepareIframe: async () => {\n // Append the iframe to the DOM and add event listener to close overlay when clicking outside the iframe\n if (!isIframeCreated) {\n console.log('Appending iframe to the DOM')\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n appendIframeWithContainer(\n DAPP_IFRAME_ID,\n OVERLAY_CONTAINER_ID,\n walletUrl,\n activeFrameWidth,\n activeFrameHeight,\n )\n\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.addEventListener('click', handleOverlayClick)\n }\n isIframeCreated = true\n }\n\n // Establish connection and start key exchange\n if (!ecdhManager.isSecureConnectionEstablished) {\n const isIframeReady = await checkIframeReady()\n const childWindow = getIframeContentWindow()\n if (!childWindow && !isIframeReady) {\n throw new Error(\n 'Iframe content window not found, cannot start key exchange',\n )\n }\n // Initialize the ECDH manager\n await ecdhManager.initializeEcdh()\n\n // Establish secure connection with the iframe\n const keyExchangeResponseMessage =\n await establishSecureConnectionWithIframe()\n\n // Parse the key exchange response message from the iframe\n await ecdhManager.parseKeyExchangeMessage(keyExchangeResponseMessage)\n }\n },\n\n disconnectIframe: () => {\n if (!isIframeCreated) {\n return\n }\n\n if (!ecdhManager.isSecureConnectionEstablished) {\n return\n }\n\n ecdhManager.closeSecureConnection()\n destroyIframeWithContainer(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID)\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.removeEventListener('click', handleOverlayClick)\n }\n isIframeCreated = false\n\n console.log(\n 'Secure connection closed with the iframe removed from the DOM',\n {\n isSecureConnectionEstablished:\n ecdhManager.isSecureConnectionEstablished,\n isIframeCreated: isIframeCreated,\n },\n )\n },\n\n toggleFrameVisibility: (isVisible) => {\n if (!isIframeCreated) {\n return\n }\n\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, isVisible)\n\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n resizeIframe: (size?: FrameWidth) => {\n if (!isIframeCreated) {\n return\n }\n\n activeFrameWidth = isMobile()\n ? FrameWidth.Full\n : size || FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n sendMessageToIframe: async (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n\n const childWindow = getIframeContentWindow()\n if (childWindow) {\n const encryptedRequest = await ecdhManager.prepareSecureMessage(request)\n childWindow.postMessage(encryptedRequest, IFRAME_ORIGIN)\n } else {\n throw new Error('Iframe content window not found')\n }\n },\n\n decryptSecureMessage: async (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n const { decryptedMessage, passedDecryption } =\n await ecdhManager.decryptSecureMessage(message)\n if (!passedDecryption || !decryptedMessage) {\n throw new Error('Failed to decrypt secure message')\n }\n return decryptedMessage\n },\n }\n}\n", "/**\n * Returns a random number between 0 and maxRange\n *\n * @param maxRange - the maximum range for the random number\n * @returns a random number between 0 and maxRange\n */\nexport const getRandomNum = (maxRange: number) => {\n const rand: () => number = Math.random\n const rn = rand()\n return Math.floor(rn * maxRange)\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n createIframeHandler,\n FrameWidth,\n IframeHandler,\n} from '../iframe/index.js'\n\nimport {\n getRandomNum,\n inboundJsonRpcEventRequestValidator,\n jsonRpcResponseValidator,\n encryptedMessageValidator,\n fatalErrorValidator,\n} from '../utils/index.js'\n\nimport {\n InboundJsonRpcEventRequest,\n JsonRpcResponse,\n InboundRpcRequestEventsMethodNames,\n FatalError,\n JsonRpcRequest,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/index.js'\nimport { Eip1193RequestArguments, ProviderRpcError } from './types.js'\n\n// JSON-RPC types\nexport type Message = unknown\n\nexport type AcceptedChainConfig = {\n /**\n * The chain ID of the blockchain network to be used\n * It should be a valid Ethereum chain ID in hex format\n */\n chainId: `0x${string}`\n\n /**\n * The treasury address to receive the payments\n * It should be a valid Ethereum address in hex format\n */\n treasuryAddress: `0x${string}`\n}\n\n/**\n * The configuration for the EmbeddedPayment\n */\nexport type CashieEthereumProviderConfig = {\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string\n\n /**\n * The accepted chain configurations to be used to accept payments\n */\n // acceptedChainConfig: AcceptedChainConfig[]\n\n /**\n * Callback function to handle incoming payment events that emit when the user completes a payment\n */\n // onPaymentEvent: (checkoutResponse: CheckoutResponse) => void\n}\n\n/**\n * We use a singleton class maintains a single instance across a web application, and to ensure\n * the post message listener is only added once, allowing that web application to access wallet globally.\n *\n * The CashieEthereumProvider target environment is the browser, and it is designed to be used in web applications.\n */\nexport class CashieEthereumProvider {\n static #instance: CashieEthereumProvider\n readonly #localWindow: Window\n readonly #boundMessageHandler: (event: MessageEvent<Message>) => void\n readonly FATAL_ERROR_MESSAGE = 'fatal: internal error'\n\n readonly #rpcMethodsThatRequireUserConsent: string[] = [\n 'wallet_requestExecutionPermissions',\n 'wallet_revokeExecutionPermission',\n ]\n\n #iframeHandler: IframeHandler\n #responseQueue: Map<\n number,\n {\n status: 'pending' | 'fulfilled' | 'failed'\n response: JsonRpcResponse | undefined\n fatalError?: FatalError\n }\n > = new Map()\n\n private constructor(iframeHandler: IframeHandler) {\n this.#localWindow = window\n this.#iframeHandler = iframeHandler\n\n this.#boundMessageHandler = this.#handleIncomingMessage.bind(this)\n this.#localWindow.addEventListener('message', this.#boundMessageHandler)\n }\n\n /**\n * Create a messageId to be used in a JSONRPC message and ensure it is unique.\n *\n * @returns A JsonRpcId\n */\n #getJsonRpcId(): number {\n const potentialId = getRandomNum(10000000000) + Date.now()\n\n // Ensure the id is unique and not already in the responseQueue or activeRequestId\n if (this.#responseQueue.has(potentialId)) {\n return this.#getJsonRpcId()\n }\n return potentialId\n }\n\n /**\n * close the CashieEthereumProvider\n */\n #close() {\n this.#iframeHandler.toggleFrameVisibility(false)\n }\n\n /**\n * resize the CashieEthereumProvider\n *\n * @param size - the size of the frame\n */\n #resize(size: FrameWidth) {\n this.#iframeHandler.resizeIframe(size)\n }\n\n /**\n * Handle incoming Post messages\n * Since the iframe is create locally, it will have the same origin as the dapp\n *\n * @param event - the PostMessageEvent sent from the iframe\n */\n async #handleIncomingMessage(event: MessageEvent<Message>) {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== this.#iframeHandler.getIframeOrigin()) {\n return\n }\n\n const message = event.data\n if (typeof message !== 'object') {\n return\n }\n\n const { isValid: isValidFatalError, fatalError } =\n fatalErrorValidator(message)\n if (isValidFatalError && fatalError) {\n this.#handleFatalError(fatalError)\n return\n }\n\n const { isValid: isValidEncryptedRequest, encryptedRequest } =\n encryptedMessageValidator(message)\n if (isValidEncryptedRequest && encryptedRequest) {\n await this.#handleIncomingEncryptedMessage(encryptedRequest)\n return\n }\n }\n\n /**\n * Handle a JsonRpcResponse and store it in the responseQueue\n *\n * @param response - the JsonRpcResponse to be handled\n */\n #handleJsonRpcResponse(response: JsonRpcResponse) {\n const { id } = response\n if (this.#responseQueue.has(Number(id))) {\n this.#responseQueue.set(Number(id), {\n status: 'fulfilled',\n response,\n })\n }\n }\n\n /**\n * Handle a InboundJsonRpcEventRequest and handle the event\n *\n * @param eventRequest - the JsonRpcEventRequest to be handled\n */\n #handleJsonRpcEvent(\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n ) {\n const { method } = eventRequest\n switch (method) {\n case 'wallet_paymentEvent':\n break\n case 'wallet_closeFrame':\n this.#close()\n break\n case 'wallet_disconnect':\n this.#disconnect()\n break\n case 'wallet_resizeFrameFull':\n this.#resize(FrameWidth.Full)\n break\n case 'wallet_resizeFrameDefault':\n this.#resize(FrameWidth.Default)\n break\n }\n }\n\n /**\n * Handle a SecureMessage and handle the message\n *\n * @param encryptedRequest - the SecureMessage to be handled\n */\n async #handleIncomingEncryptedMessage(\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted>,\n ) {\n const decryptedMessage =\n await this.#iframeHandler.decryptSecureMessage(encryptedRequest)\n\n const { isValid: isValidResponse, response } =\n jsonRpcResponseValidator(decryptedMessage)\n if (isValidResponse && response) {\n this.#handleJsonRpcResponse(response)\n return\n }\n\n const { isValid: isValidEventRequest, eventRequest } =\n inboundJsonRpcEventRequestValidator(decryptedMessage)\n if (isValidEventRequest && eventRequest) {\n this.#handleJsonRpcEvent(eventRequest)\n return\n }\n }\n\n /**\n * Handle a fatal error\n *\n * @param fatalError - the fatal error to be handled\n */\n #handleFatalError(fatalError: FatalError) {\n if (this.#responseQueue.size) {\n // loop through the responseQueue and set the status to failed\n this.#responseQueue.forEach((response) => {\n if (response.status === 'pending') {\n response.status = 'failed'\n response.fatalError = fatalError\n }\n })\n }\n }\n\n /**\n * Handles a JsonRpcRequest coming from the dapp\n * Request are handled synchronously(blocking) and requires immediate response from the user\n *\n * @param request - the JsonRpcRequest to be handled\n * @param requiresUserConsent - whether the user consent is required to show the iframe\n * @returns the response from the blobUrl IFrame\n */\n async #sendRequestToIframe(\n request: JsonRpcRequest,\n requiresUserConsent: boolean,\n ): Promise<JsonRpcResponse> {\n try {\n await this.#iframeHandler.prepareIframe()\n\n // show the iframe if the user consent is required otherwise the iframe will be hidden but can still response to requests\n if (requiresUserConsent) {\n this.#iframeHandler.toggleFrameVisibility(true)\n }\n\n const { id } = request\n this.#responseQueue.set(Number(id), {\n status: 'pending',\n response: undefined,\n })\n await this.#iframeHandler.sendMessageToIframe(request)\n\n // Wait for the user to respond from the IFrame\n return await this.#waitForResponse(Number(id))\n } catch (error: any) {\n if (error.message === this.FATAL_ERROR_MESSAGE) {\n this.#close()\n }\n return {\n jsonrpc: '2.0',\n id: request.id,\n error: {\n message: error.message,\n code: -32000,\n },\n }\n }\n }\n\n /**\n * Wait for a response from the user to be added to the responseQueue every second\n * max attempts is 300 or 5 minutes\n *\n * @param requestId - the id of the request\n * @param attempts - the number of attempts to wait for a response\n * @returns the response from the blobUrl IFrame\n */\n #waitForResponse(requestId: number, attempts = 300) {\n return new Promise<JsonRpcResponse>((_resolve, _reject) => {\n let counter = 0\n\n const intervalId = setInterval(() => {\n counter++\n\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n _reject(new Error('Max attempts reached waiting for response'))\n }\n\n // remove the response from the queue and resolve the promise\n const result = this.#responseQueue.get(requestId)\n if (result) {\n if (result.status === 'failed' && result.fatalError) {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _reject(new Error(result.fatalError.message))\n }\n\n if (result.status === 'fulfilled') {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _resolve(result.response as JsonRpcResponse)\n }\n }\n }, 1000) // 1 second\n })\n }\n\n /**\n * Disconnect the CashieEthereumProvider\n *\n * @returns true if the CashieEthereumProvider is disconnected successfully, false otherwise\n */\n #disconnect() {\n this.#iframeHandler.toggleFrameVisibility(false)\n this.#iframeHandler.disconnectIframe()\n this.#responseQueue = new Map()\n return true\n }\n\n /**\n * Generic request to the CashieEthereumProvider\n *\n * @param request - the request to be sent to the CashieEthereumProvider\n * @returns the response from the CashieEthereumProvider\n */\n async sendRequest(request: Eip1193RequestArguments): Promise<unknown> {\n const requestId = this.#getJsonRpcId()\n const requiresUserConsent = this.#rpcMethodsThatRequireUserConsent.includes(\n request.method,\n )\n\n switch (request.method) {\n case 'wallet_disconnect':\n this.#disconnect()\n return true\n case 'wallet_openHomePage':\n await this.#iframeHandler.prepareIframe()\n this.#iframeHandler.toggleFrameVisibility(true)\n await this.#iframeHandler.sendMessageToIframe({\n jsonrpc: '2.0',\n method: 'wallet_navigateToDashboardEvent',\n params: [],\n })\n return true\n default: {\n const result = await this.#sendRequestToIframe(\n {\n jsonrpc: '2.0',\n id: requestId,\n method: request.method,\n params: request.params || [],\n },\n requiresUserConsent,\n )\n if ('error' in result) {\n throw new ProviderRpcError({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data,\n })\n }\n return result.result\n }\n }\n }\n\n /**\n * Create a new instance of the CashieEthereumProvider\n *\n * @param config - the configuration for the CashieEthereumProvider\n * @returns the CashieEthereumProvider instance\n */\n static Create(config: CashieEthereumProviderConfig): CashieEthereumProvider {\n if (!CashieEthereumProvider.#instance) {\n const iframeHandler = createIframeHandler({\n parentOrigin: window.location.origin,\n devWalletUrl: config.devWalletUrl,\n })\n CashieEthereumProvider.#instance = new CashieEthereumProvider(\n iframeHandler,\n )\n }\n return CashieEthereumProvider.#instance\n }\n}\n", "export type ErrorDetails = {\n code: number\n message: string\n}\n\n/**\n * The EIP1193 error code enum\n */\nexport enum EIP1193_ERROR_CODES {\n /**\n * The user rejected the request.\n */\n USER_REJECTED_REQUEST = 4001,\n\n /**\n * The specified address is not connected or not in the wallet\n */\n UNAUTHORIZED = 4100,\n\n /**\n * The Provider does not support the requested method.\n */\n UNSUPPORTED_METHOD = 4200,\n\n /**\n * The Provider is disconnected from all chains.\n */\n DISCONNECTED = 4900,\n\n /**\n * The Provider is not connected to the requested chain.\n */\n CHAIN_DISCONNECTED = 4901,\n}\n\n/**\n * The ERC-7715 error code enum\n */\nexport enum ERC7715_ERROR_CODES {\n /**\n * The specified method is not authorized for the given origin\n * Related RPCs: wallet_requestConnection\n */\n UNAUTHORIZED_ACCESS_RESTRICTED_METHOD = 4101,\n}\n\n/**\n * The EIP5792 error code enum\n */\nexport enum EIP5792_ERROR_CODES {\n /**\n * This wallet does not support a capability that was not marked as optional\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_NON_OPTIONAL_CAPABILITY = 5700,\n\n /**\n * This wallet does not support the specified chain id\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_CHAIN_ID = 5710,\n\n /**\n * There is already a bundle submitted with this id\n * Related RPCs: wallet_sendCalls\n */\n DUPLICATE_BUNDLE_ID = 5720,\n\n /**\n * This bundle id is unknown / has not been submitted\n * Related RPCs: wallet_getCallsStatus, wallet_showCallsStatus\n */\n UNKNOWN_BUNDLE_ID = 5730,\n\n /**\n * The call bundle is too large for the wallet to process\n * Related RPCs: wallet_sendCalls\n */\n BUNDLE_TOO_LARGE = 5740,\n\n /**\n * The wallet can support atomicity after an upgrade, but the user rejected the upgrade\n * Related RPCs: wallet_sendCalls\n */\n ATOMIC_READY_WALLET_REJECTED_UPGRADE = 5750,\n\n /**\n * The wallet does not support atomic execution but the request requires it\n * Related RPCs: wallet_sendCalls\n */\n ATOMICITY_NOT_SUPPORTED = 5760,\n}\n\n/**\n * The fatal error code enum\n */\nexport enum FATAL_ERROR_CODES {\n INTERNAL_ERROR = -32001,\n}\n\nexport enum COMMON_ERROR_CODES {\n INVALID_PARAMS = -32602,\n}\n\n/**\n * The error code map\n */\nexport const ERROR_CODES_MAP: Record<\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n ErrorDetails\n> = {\n // EIP1193 errors\n [EIP1193_ERROR_CODES.USER_REJECTED_REQUEST]: {\n code: 4001,\n message: 'User rejected the request.',\n },\n [EIP1193_ERROR_CODES.UNAUTHORIZED]: {\n code: 4100,\n message:\n 'The requested method and/or account has not been authorized by the user.',\n },\n [EIP1193_ERROR_CODES.UNSUPPORTED_METHOD]: {\n code: 4200,\n message: 'The Provider does not support the requested method.',\n },\n [EIP1193_ERROR_CODES.DISCONNECTED]: {\n code: 4900,\n message: 'The Provider is disconnected from all chains.',\n },\n [EIP1193_ERROR_CODES.CHAIN_DISCONNECTED]: {\n code: 4901,\n message: 'The Provider is not connected to the requested chain.',\n },\n\n //ERC-7715 errors\n [ERC7715_ERROR_CODES.UNAUTHORIZED_ACCESS_RESTRICTED_METHOD]: {\n code: 4101,\n message:\n 'The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method.',\n },\n\n // EIP5792 errors\n [EIP5792_ERROR_CODES.UNSUPPORTED_NON_OPTIONAL_CAPABILITY]: {\n code: 5700,\n message:\n 'This wallet does not support a capability that was not marked as optional.',\n },\n [EIP5792_ERROR_CODES.UNSUPPORTED_CHAIN_ID]: {\n code: 5710,\n message: 'This wallet does not support the specified chain id.',\n },\n [EIP5792_ERROR_CODES.DUPLICATE_BUNDLE_ID]: {\n code: 5720,\n message: 'There is already a bundle submitted with this id.',\n },\n [EIP5792_ERROR_CODES.UNKNOWN_BUNDLE_ID]: {\n code: 5730,\n message: 'This bundle id is unknown / has not been submitted.',\n },\n [EIP5792_ERROR_CODES.BUNDLE_TOO_LARGE]: {\n code: 5740,\n message: 'The call bundle is too large for the wallet to process.',\n },\n [EIP5792_ERROR_CODES.ATOMIC_READY_WALLET_REJECTED_UPGRADE]: {\n code: 5750,\n message:\n 'The wallet can support atomicity after an upgrade, but the user rejected the upgrade.',\n },\n [EIP5792_ERROR_CODES.ATOMICITY_NOT_SUPPORTED]: {\n code: 5760,\n message:\n 'The wallet does not support atomic execution but the request requires it.',\n },\n\n // Fatal/Common errors\n [FATAL_ERROR_CODES.INTERNAL_ERROR]: {\n code: -32001,\n message: 'fatal: internal error',\n },\n [COMMON_ERROR_CODES.INVALID_PARAMS]: {\n code: 4002,\n message: 'Invalid parameters.',\n },\n}\n\n/**\n * Get the error message for a given error code\n *\n * @param code - The error code\n * @returns The error message\n * @throws {Error} if the error code is not found\n */\nexport const getErrorMessage = (\n code:\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n): ErrorDetails => {\n const details = ERROR_CODES_MAP[code]\n if (!details) {\n return {\n code,\n message: `Unknown error code: ${code}`,\n }\n }\n return details\n}\n", "import {\n Eip1193RequestArguments,\n Eip1193Provider,\n ProviderRpcError,\n} from './types.js'\nimport {\n CashieEthereumProvider,\n CashieEthereumProviderConfig,\n} from './cashie-ethereum-provider.js'\nimport { getErrorMessage } from './errors.js'\n\nexport class Eip1193Bridge implements Eip1193Provider {\n #transeptorEthereumProvider: CashieEthereumProvider\n constructor(config: CashieEthereumProviderConfig) {\n this.#transeptorEthereumProvider = CashieEthereumProvider.Create(config)\n }\n\n async request(request: Eip1193RequestArguments) {\n try {\n return await this.#transeptorEthereumProvider.sendRequest(request)\n } catch (error: unknown) {\n if (error instanceof ProviderRpcError) {\n const errorDetails = getErrorMessage(error.code)\n if (errorDetails) {\n throw new ProviderRpcError(errorDetails)\n }\n }\n throw new ProviderRpcError({\n code: -32000,\n message: 'Unknown internal error',\n data: error,\n })\n }\n }\n}\n\n/**\n * Create a new Eip1193 provider\n *\n * @param config - the configuration for the CashieEthereumProvider\n * @returns the Eip1193 provider\n */\nexport function createEip1193Provider(\n config: CashieEthereumProviderConfig,\n): Eip1193Provider {\n return new Eip1193Bridge(config)\n}\n", "import { Eip1193Provider } from '../index.js'\n\nexport const enum ProviderEvent {\n AnnounceProvider = 'eip6963:announceProvider',\n RequestProvider = 'eip6963:requestProvider',\n}\n\n/**\n * Provider Detail defined by eip-6963\n */\nexport type EIP6963ProviderDetail = {\n info: {\n uuid: string\n name: string\n icon: string\n rdns: string\n }\n provider: Eip1193Provider\n}\n\n/**\n * Announce Event dispatched by a Wallet\n */\nexport interface EIP6963AnnounceProviderEvent extends CustomEvent {\n type: ProviderEvent.AnnounceProvider\n detail: EIP6963ProviderDetail\n}\n\n/**\n * Request Event dispatched by a DApp\n */\nexport interface EIP6963RequestProviderEvent extends Event {\n type: ProviderEvent.RequestProvider\n}\n", "/**\n * The icon of the Cashie wallet\n */\nexport const CASHIE_WALLET_ICON =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg=='\n", "import { CashieEthereumProviderConfig } from '../cashie-ethereum-provider.js'\nimport { createEip1193Provider } from '../eip-1193-bridge.js'\nimport { EIP6963ProviderDetail, ProviderEvent } from './types.js'\nimport { CASHIE_WALLET_ICON } from './icon.js'\n\n/**\n * Announce the Cashie provider to the dapp\n *\n * @param config - the configuration for the CashieEthereumProvider\n */\nexport const announceProvider = (config: CashieEthereumProviderConfig) => {\n const provider = createEip1193Provider(config)\n const detail = Object.freeze({\n info: Object.freeze({\n uuid: '2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1',\n name: 'Cashie',\n icon: CASHIE_WALLET_ICON,\n rdns: 'org.cashie.app',\n }),\n provider,\n } as EIP6963ProviderDetail)\n const announceEvent = new CustomEvent(ProviderEvent.AnnounceProvider, {\n detail,\n })\n\n // The Wallet dispatches an announce event which is heard by\n // the DApp code that had run earlier\n window.addEventListener(ProviderEvent.RequestProvider, () => {\n window.dispatchEvent(announceEvent)\n })\n\n // The Wallet listens to the request events which may be\n // dispatched later and re-dispatches the `EIP6963AnnounceProviderEvent`\n window.dispatchEvent(announceEvent)\n}\n"],
5
+ "mappings": "4aAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,4BAAAE,EAAA,kBAAAC,EAAA,qBAAAC,EAAA,qBAAAC,EAAA,0BAAAC,IAAA,eAAAC,GAAAP,ICAO,IAAMQ,EAAN,cAA+B,KAAM,CAO1C,KAKA,KAEA,YAAY,CACV,QAAAC,EACA,KAAAC,EACA,KAAAC,CACF,EAIG,CACD,MAAMF,CAAO,EACb,KAAK,KAAOC,EACZ,KAAK,KAAOC,CACd,CACF,ECFO,IAAMC,EAAN,KAA2B,CACf,KAAO,CAAE,KAAM,OAAQ,WAAY,OAAQ,EAC5DC,GAAiB,GACjBC,GAAgC,CAC9B,QAAS,KACT,OAAQ,KACR,MAAO,IACT,EACAC,GAGI,CACF,KAAM,KACN,GAAI,EACN,EACAC,GAAY,EACZC,GAA6B,KAE7B,aAAc,CAEd,CAOAC,IAA2B,CACzB,GAAI,CAAC,KAAKL,GACR,MAAM,IAAI,MAAM,sBAAsB,CAE1C,CAOAM,IAA2C,CACzC,GAAI,CAAC,KAAKJ,GAAmB,GAC3B,MAAM,IAAI,MAAM,mCAAmC,CAEvD,CAOAK,IAAkC,CAChC,GAAI,CACF,GACE,OAAO,OAAW,KA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AAI,uCAA4C,CACpE,OAAAF,CACF,CAAC,EAID,OAAO,2CAAgD,IAAM,CAC3D,OAAO,cAAcE,CAAa,CACpC,CAAC,EAID,OAAO,cAAcA,CAAa,CACpC",
6
+ "names": ["index_exports", "__export", "CashieEthereumProvider", "ProviderEvent", "ProviderRpcError", "announceProvider", "createEip1193Provider", "__toCommonJS", "ProviderRpcError", "message", "code", "data", "EphemeralEcdhManager", "#isInitialized", "#ephemeralEcdh", "#isKeyExchangeDone", "#sequence", "#aeadKey", "#assertInitialized", "#assertSecureConnectionEstablished", "#assertWebCryptoAvailable", "error", "keyPair", "pubJwk", "nonce", "message", "pub", "recipientPub", "bits", "baseKey", "salt", "data", "iv", "additionalData", "dataBytes", "cipherText", "ok", "role", "jsonRpcResponseValidator", "message", "response", "inboundJsonRpcEventRequestValidator", "eventRequest", "jsonRpcKeyExchangeResponseValidator", "keyExchangeResponse", "jsonRpcKeyExchangeDoneValidator", "keyExchangeDone", "encryptedMessageValidator", "encryptedRequest", "fatalErrorValidator", "fatalError", "isMobile", "resizeFrameWidth", "iframeId", "frameWidth", "frameHeight", "iframe", "showIframe", "overlay", "hideIframe", "doToggleIframeVisibility", "overlayId", "isVisible", "appendIframeWithContainer", "url", "destroyIframeWithContainer", "createIframeHandler", "config", "ecdhManager", "EphemeralEcdhManager", "devWalletUrl", "IFRAME_ORIGIN", "params", "walletUrl", "DAPP_IFRAME_ID", "OVERLAY_CONTAINER_ID", "activeFrameWidth", "activeFrameHeight", "isIframeCreated", "handleOverlayClick", "event", "overlay", "doToggleIframeVisibility", "getIframeContentWindow", "iframe", "checkIframeReady", "attempts", "childWindow", "isFrameReady", "handleReady", "_resolve", "_reject", "counter", "intervalId", "establishSecureConnectionWithIframe", "keyExchangeMessage", "keyExchangeResponseMessage", "keyExchangeDoneMessage", "message", "isValidKeyExchangeResponse", "keyExchangeResponse", "jsonRpcKeyExchangeResponseValidator", "isValidKeyExchangeDone", "keyExchangeDone", "jsonRpcKeyExchangeDoneValidator", "isMobile", "appendIframeWithContainer", "isIframeReady", "destroyIframeWithContainer", "isVisible", "resizeFrameWidth", "size", "request", "encryptedRequest", "decryptedMessage", "passedDecryption", "getRandomNum", "maxRange", "rand", "rn", "CashieEthereumProvider", "_CashieEthereumProvider", "#instance", "#localWindow", "#boundMessageHandler", "#rpcMethodsThatRequireUserConsent", "#iframeHandler", "#responseQueue", "iframeHandler", "#handleIncomingMessage", "#getJsonRpcId", "potentialId", "getRandomNum", "#close", "#resize", "size", "event", "message", "isValidFatalError", "fatalError", "fatalErrorValidator", "#handleFatalError", "isValidEncryptedRequest", "encryptedRequest", "encryptedMessageValidator", "#handleIncomingEncryptedMessage", "#handleJsonRpcResponse", "response", "id", "#handleJsonRpcEvent", "eventRequest", "method", "#disconnect", "decryptedMessage", "isValidResponse", "jsonRpcResponseValidator", "isValidEventRequest", "inboundJsonRpcEventRequestValidator", "#sendRequestToIframe", "request", "requiresUserConsent", "#waitForResponse", "error", "requestId", "attempts", "_resolve", "_reject", "counter", "intervalId", "result", "ProviderRpcError", "config", "createIframeHandler", "ERROR_CODES_MAP", "getErrorMessage", "code", "details", "Eip1193Bridge", "#transeptorEthereumProvider", "config", "CashieEthereumProvider", "request", "error", "ProviderRpcError", "errorDetails", "getErrorMessage", "createEip1193Provider", "ProviderEvent", "CASHIE_WALLET_ICON", "announceProvider", "config", "provider", "createEip1193Provider", "detail", "CASHIE_WALLET_ICON", "announceEvent"]
7
7
  }
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var h=class extends Error{code;data;constructor({message:e,code:t,data:n}){super(e),this.code=t,this.data=n}};var T=class{ALGO={name:"ECDH",namedCurve:"P-256"};#n=!1;#r={keyPair:null,pubJwk:null,nonce:null};#s={role:null,ok:!1};#a=0;#e=null;constructor(){}#t(){if(!this.#n)throw new Error("ECDH not initialized")}#o(){if(!this.#s.ok)throw new Error("Secure connection not established")}#i(){try{if(typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.getRandomValues<"u"&&typeof crypto.subtle.generateKey<"u"&&typeof crypto.subtle.encrypt<"u"&&typeof crypto.subtle.decrypt<"u")return;throw new Error("Web Crypto API not available")}catch(e){throw new Error("Web Crypto API not available",{cause:e})}}get isSecureConnectionEstablished(){return this.#s.ok}async initializeEcdh(){this.#i();let e=await crypto.subtle.generateKey(this.ALGO,!0,["deriveBits"]),t=await crypto.subtle.exportKey("jwk",e.publicKey),n=crypto.getRandomValues(new Uint8Array(16));this.#r={keyPair:e,pubJwk:t,nonce:n},this.#n=!0}async parseKeyExchangeMessage(e){if(this.#t(),!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");let{pub:t,nonce:n}=e.payload,s=await crypto.subtle.importKey("jwk",t,this.ALGO,!1,[]),i=await crypto.subtle.deriveBits({name:this.ALGO.name,public:s},this.#r.keyPair.privateKey,256),o=await crypto.subtle.importKey("raw",i,"HKDF",!1,["deriveKey"]),d=new Uint8Array([...this.#r.nonce,...new Uint8Array(n)]);this.#e=await crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:d,info:new TextEncoder().encode("transeptor-pay-v1")},o,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async generateKeyExchangeMessage(){if(this.#t(),!this.#r.pubJwk)throw new Error("Ephemeral public key not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");if(!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");return{type:"kex-init",payload:{pub:this.#r.pubJwk,nonce:Array.from(this.#r.nonce)}}}async prepareSecureMessage(e){if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");this.#a++;let t=crypto.getRandomValues(new Uint8Array(12)),n=new TextEncoder().encode(`seq:${this.#a}`),s=new TextEncoder().encode(JSON.stringify(e)),i=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:t,additionalData:n},this.#e,s));return{type:"enc",payload:{iv:Array.from(t),cipherText:Array.from(i),additionalData:Array.from(n)}}}async decryptSecureMessage(e){try{if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");let{iv:t,cipherText:n,additionalData:s}=e.payload;if(!t||!n||!s)throw new Error("Invalid message payload: missing required fields");if(!Array.isArray(t)||!Array.isArray(n)||!Array.isArray(s))throw new Error("Invalid message payload: fields must be arrays");let i=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(t),additionalData:new Uint8Array(s)},this.#e,new Uint8Array(n));return{decryptedMessage:JSON.parse(new TextDecoder().decode(i)),passedDecryption:!0}}catch(t){return console.error("Error decrypting secure message from iframe",t),{decryptedMessage:null,passedDecryption:!1}}}parseKeyExchangeDoneMessage(e){this.#t();let{ok:t,role:n}=e.payload;t&&(this.#s={role:n,ok:t})}generateKeyExchangeDoneMessage(){return{type:"kex-done",payload:{ok:!0,role:"parent"}}}closeSecureConnection(){this.#s={role:null,ok:!1},this.#e=null}};var C=r=>{if(typeof r!="object"||r===null)return{isValid:!1,response:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,response:null}:e.id===null||e.id===void 0?{isValid:!1,response:null}:e&&("result"in e||"error"in e)?{isValid:!0,response:e}:{isValid:!0,response:e}},N=r=>{if(typeof r!="object"||r===null)return{isValid:!1,eventRequest:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,eventRequest:null}:e.method?"params"in e?{isValid:!0,eventRequest:e}:{isValid:!1,eventRequest:null}:{isValid:!1,eventRequest:null}},q=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeResponse:null};let e=r;return e.type!=="kex-response"?{isValid:!1,keyExchangeResponse:null}:e.payload.pub?e.payload.nonce?{isValid:!0,keyExchangeResponse:e}:{isValid:!1,keyExchangeResponse:null}:{isValid:!1,keyExchangeResponse:null}},k=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeDone:null};let e=r;return e.type!=="kex-done"?{isValid:!1,keyExchangeDone:null}:e.payload.ok?e.payload.role?{isValid:!0,keyExchangeDone:e}:{isValid:!1,keyExchangeDone:null}:{isValid:!1,keyExchangeDone:null}},V=r=>{if(typeof r!="object"||r===null)return{isValid:!1,encryptedRequest:null};let e=r;return e.type!=="enc"?{isValid:!1,encryptedRequest:null}:e.payload.iv?e.payload.cipherText?e.payload.additionalData?{isValid:!0,encryptedRequest:e}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}},O=r=>{if(typeof r!="object"||r===null)return{isValid:!1,fatalError:null};let e=r;return e.code?e.message?{isValid:!0,fatalError:e}:{isValid:!1,fatalError:null}:{isValid:!1,fatalError:null}};var f=()=>window.innerWidth<768,I=(r,e,t)=>{let n=document.getElementById(r);n&&(n.style.width=e,n.style.height=t)},Q=(r,e)=>{r.style.opacity="1",r.style.pointerEvents="auto",e.style.opacity="1",e.style.transform="scale(1)"},G=(r,e)=>{r.style.opacity="0",r.style.pointerEvents="none",e.style.opacity="0",e.style.transform="scale(0.8)"},A=(r,e,t)=>{let n=document.getElementById(r),s=document.getElementById(e);!n||!s||(document.body.style.overflow=t?"hidden":"auto",t?Q(s,n):G(s,n))},J=(r,e,t,n,s)=>{let i=document.createElement("div");i.id=e,Object.assign(i.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:"9999",opacity:"1",pointerEvents:"none",cursor:"default",transition:"opacity 0.3s ease-in-out"});let o=document.createElement("iframe");o.id=r,o.src=t,o.allow="publickey-credentials-get *; publickey-credentials-create *",Object.assign(o.style,{height:s,width:n,position:"relative",borderRadius:"0.75rem",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",overflowY:"auto",zIndex:"1000",opacity:"1",transform:"scale(0.8)",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out"}),i.appendChild(o),document.body.appendChild(i),setTimeout(()=>{i.style.opacity="1",i.style.pointerEvents="auto",o.style.opacity="1",o.style.transform="scale(1)"},100),document.body.style.overflow="hidden"},U=(r,e)=>{let t=document.getElementById(e);t&&(t.parentNode?.removeChild(t),document.body.style.overflow="auto");let n=document.getElementById(r);n&&n.parentNode&&n.parentNode.removeChild(n)};var K=r=>{let e=new T,{devWalletUrl:t}=r,n=t||"https://pay.transeptorlabs.io",s=new URLSearchParams({embedded:"true"}).toString(),i=t?`${t}?${s}`:`https://pay.transeptorlabs.io/?${s}`,o="dapp:iframe-embedded-payment",d="dapp:iframe-container",g="412px",R="640px",m=!1,P=a=>{let c=document.getElementById(d);c&&a.target===c&&A(o,d,!1)},b=()=>{let a=document.getElementById(o);if(!a)throw new Error("Iframe not found");return"contentWindow"in a?a.contentWindow:null},j=async(a=600)=>{let c=b();if(!c)throw new Error("Iframe not found");let l=!1,E=u=>{if(!u.isTrusted||u.origin!==n)return;if(u.data==="pong"){l=!0;return}};return window.addEventListener("message",E.bind(void 0)),new Promise((u,w)=>{let y=0,p=setInterval(()=>{y++,y>=a&&(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),w(new Error("Max ping attempts reached to establish connection with the iframe"))),l?(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),console.log("Iframe is ready to receive messages"),u(!0)):(console.log("Sending ping to the iframe to check if it is ready"),c.postMessage("ping",n))},500)})},H=async(a=600)=>{console.log("Establishing secure connection with the iframe");let c=b();if(!c)throw new Error("Iframe not found");let l=await e.generateKeyExchangeMessage(),E=null,u=null,w=y=>{if(!y.isTrusted||y.origin!==n)return;let p=y.data,{isValid:x,keyExchangeResponse:M}=q(p);if(x&&M){c.postMessage(e.generateKeyExchangeDoneMessage(),n),E=p;return}let{isValid:z,keyExchangeDone:B}=k(p);if(z&&B){u=p;return}};return window.addEventListener("message",w.bind(void 0)),c.postMessage(l,n),new Promise((y,p)=>{let x=0,M=setInterval(()=>{x++,x>=a&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),p(new Error("Max secure connection attempts reached to establish secure connection with the iframe"))),E&&u&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),e.parseKeyExchangeDoneMessage(u),y(E))},200)})};return{getIframeOrigin:()=>n,prepareIframe:async()=>{if(!m){console.log("Appending iframe to the DOM"),g=f()?"100%":"412px",R=f()?"100%":"640px",J(o,d,i,g,R);let a=document.getElementById(d);a&&a.addEventListener("click",P),m=!0}if(!e.isSecureConnectionEstablished){let a=await j();if(!b()&&!a)throw new Error("Iframe content window not found, cannot start key exchange");await e.initializeEcdh();let l=await H();await e.parseKeyExchangeMessage(l)}},disconnectIframe:()=>{if(!m||!e.isSecureConnectionEstablished)return;e.closeSecureConnection(),U(o,d);let a=document.getElementById(d);a&&a.removeEventListener("click",P),m=!1,console.log("Secure connection closed with the iframe removed from the DOM",{isSecureConnectionEstablished:e.isSecureConnectionEstablished,isIframeCreated:m})},toggleFrameVisibility:a=>{m&&(A(o,d,a),g=f()?"100%":"412px",R=f()?"100%":"640px",I(o,g,R))},resizeIframe:a=>{m&&(g=f()?"100%":a||"412px",R=f()?"100%":"640px",I(o,g,R))},sendMessageToIframe:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let c=b();if(c){let l=await e.prepareSecureMessage(a);c.postMessage(l,n)}else throw new Error("Iframe content window not found")},decryptSecureMessage:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let{decryptedMessage:c,passedDecryption:l}=await e.decryptSecureMessage(a);if(!l||!c)throw new Error("Failed to decrypt secure message");return c}}};var _=r=>{let e=Math.random,t=e();return Math.floor(t*r)};var v=class r{static#n;#r;#s;FATAL_ERROR_MESSAGE="fatal: internal error";#a=["wallet_requestExecutionPermissions","wallet_revokeExecutionPermission"];#e;#t=new Map;constructor(e){this.#r=window,this.#e=e,this.#s=this.#l.bind(this),this.#r.addEventListener("message",this.#s)}#o(){let e=_(1e10)+Date.now();return this.#t.has(e)?this.#o():e}#i(){this.#e.toggleFrameVisibility(!1)}#c(e){this.#e.resizeIframe(e)}async#l(e){if(!e.isTrusted||e.origin!==this.#e.getIframeOrigin())return;let t=e.data;if(typeof t!="object")return;let{isValid:n,fatalError:s}=O(t);if(n&&s){this.#h(s);return}let{isValid:i,encryptedRequest:o}=V(t);if(i&&o){await this.#y(o);return}}#u(e){let{id:t}=e;this.#t.has(Number(t))&&this.#t.set(Number(t),{status:"fulfilled",response:e})}#p(e){let{method:t}=e;switch(t){case"wallet_paymentEvent":break;case"wallet_closeFrame":this.#i();break;case"wallet_disconnect":this.#d();break;case"wallet_resizeFrameFull":this.#c("100%");break;case"wallet_resizeFrameDefault":this.#c("412px");break}}async#y(e){let t=await this.#e.decryptSecureMessage(e),{isValid:n,response:s}=C(t);if(n&&s){this.#u(s);return}let{isValid:i,eventRequest:o}=N(t);if(i&&o){this.#p(o);return}}#h(e){this.#t.size&&this.#t.forEach(t=>{t.status==="pending"&&(t.status="failed",t.fatalError=e)})}async#m(e,t){try{await this.#e.prepareIframe(),t&&this.#e.toggleFrameVisibility(!0);let{id:n}=e;return this.#t.set(Number(n),{status:"pending",response:void 0}),await this.#e.sendMessageToIframe(e),await this.#E(Number(n))}catch(n){return n.message===this.FATAL_ERROR_MESSAGE&&this.#i(),{jsonrpc:"2.0",id:e.id,error:{message:n.message,code:-32e3}}}}#E(e,t=300){return new Promise((n,s)=>{let i=0,o=setInterval(()=>{i++,i>=t&&(clearInterval(o),s(new Error("Max attempts reached waiting for response")));let d=this.#t.get(e);d&&(d.status==="failed"&&d.fatalError&&(clearInterval(o),this.#t.delete(e),s(new Error(d.fatalError.message))),d.status==="fulfilled"&&(clearInterval(o),this.#t.delete(e),n(d.response)))},1e3)})}#d(){return this.#e.toggleFrameVisibility(!1),this.#e.disconnectIframe(),this.#t=new Map,!0}async sendRequest(e){let t=this.#o(),n=this.#a.includes(e.method);switch(e.method){case"wallet_disconnect":return this.#d(),!0;case"wallet_openHomePage":return await this.#e.prepareIframe(),this.#e.toggleFrameVisibility(!0),await this.#e.sendMessageToIframe({jsonrpc:"2.0",method:"wallet_navigateToDashboardEvent",params:[]}),!0;default:{let s=await this.#m({jsonrpc:"2.0",id:t,method:e.method,params:e.params||[]},n);if("error"in s)throw new h({message:s.error.message,code:s.error.code,data:s.error.data});return s.result}}}static Create(e){if(!r.#n){let t=K({parentOrigin:window.location.origin,devWalletUrl:e.devWalletUrl});r.#n=new r(t)}return r.#n}};var $={4001:{code:4001,message:"User rejected the request."},4100:{code:4100,message:"The requested method and/or account has not been authorized by the user."},4200:{code:4200,message:"The Provider does not support the requested method."},4900:{code:4900,message:"The Provider is disconnected from all chains."},4901:{code:4901,message:"The Provider is not connected to the requested chain."},4101:{code:4101,message:"The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method."},5700:{code:5700,message:"This wallet does not support a capability that was not marked as optional."},5710:{code:5710,message:"This wallet does not support the specified chain id."},5720:{code:5720,message:"There is already a bundle submitted with this id."},5730:{code:5730,message:"This bundle id is unknown / has not been submitted."},5740:{code:5740,message:"The call bundle is too large for the wallet to process."},5750:{code:5750,message:"The wallet can support atomicity after an upgrade, but the user rejected the upgrade."},5760:{code:5760,message:"The wallet does not support atomic execution but the request requires it."},[-32001]:{code:-32001,message:"fatal: internal error"},[-32602]:{code:4002,message:"Invalid parameters."}},F=r=>{let e=$[r];return e||{code:r,message:`Unknown error code: ${r}`}};var D=class{#n;constructor(e){this.#n=v.Create(e)}async request(e){try{return await this.#n.sendRequest(e)}catch(t){if(t instanceof h){let n=F(t.code);if(n)throw new h(n)}throw new h({code:-32e3,message:"Unknown internal error",data:t})}}};function S(r){return new D(r)}var W=(t=>(t.AnnounceProvider="eip6963:announceProvider",t.RequestProvider="eip6963:requestProvider",t))(W||{});var L="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg==";var Z=r=>{let e=S(r),t=Object.freeze({info:Object.freeze({uuid:"2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1",name:"Transeptor",icon:L,rdns:"io.transeptor.pay"}),provider:e}),n=new CustomEvent("eip6963:announceProvider",{detail:t});window.addEventListener("eip6963:requestProvider",()=>{window.dispatchEvent(n)}),window.dispatchEvent(n)};export{W as ProviderEvent,h as ProviderRpcError,v as TranseptorEthereumProvider,Z as announceProvider,S as createEip1193Provider};
1
+ var y=class extends Error{code;data;constructor({message:e,code:t,data:n}){super(e),this.code=t,this.data=n}};var I=class{ALGO={name:"ECDH",namedCurve:"P-256"};#n=!1;#r={keyPair:null,pubJwk:null,nonce:null};#s={role:null,ok:!1};#a=0;#e=null;constructor(){}#t(){if(!this.#n)throw new Error("ECDH not initialized")}#o(){if(!this.#s.ok)throw new Error("Secure connection not established")}#i(){try{if(typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.getRandomValues<"u"&&typeof crypto.subtle.generateKey<"u"&&typeof crypto.subtle.encrypt<"u"&&typeof crypto.subtle.decrypt<"u")return;throw new Error("Web Crypto API not available")}catch(e){throw new Error("Web Crypto API not available",{cause:e})}}get isSecureConnectionEstablished(){return this.#s.ok}async initializeEcdh(){this.#i();let e=await crypto.subtle.generateKey(this.ALGO,!0,["deriveBits"]),t=await crypto.subtle.exportKey("jwk",e.publicKey),n=crypto.getRandomValues(new Uint8Array(16));this.#r={keyPair:e,pubJwk:t,nonce:n},this.#n=!0}async parseKeyExchangeMessage(e){if(this.#t(),!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");let{pub:t,nonce:n}=e.payload,s=await crypto.subtle.importKey("jwk",t,this.ALGO,!1,[]),i=await crypto.subtle.deriveBits({name:this.ALGO.name,public:s},this.#r.keyPair.privateKey,256),o=await crypto.subtle.importKey("raw",i,"HKDF",!1,["deriveKey"]),d=new Uint8Array([...this.#r.nonce,...new Uint8Array(n)]);this.#e=await crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:d,info:new TextEncoder().encode("cashie-connect")},o,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async generateKeyExchangeMessage(){if(this.#t(),!this.#r.pubJwk)throw new Error("Ephemeral public key not initialized");if(!this.#r.nonce)throw new Error("Ephemeral nonce not initialized");if(!this.#r.keyPair)throw new Error("Ephemeral keys not initialized");return{type:"kex-init",payload:{pub:this.#r.pubJwk,nonce:Array.from(this.#r.nonce)}}}async prepareSecureMessage(e){if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");this.#a++;let t=crypto.getRandomValues(new Uint8Array(12)),n=new TextEncoder().encode(`seq:${this.#a}`),s=new TextEncoder().encode(JSON.stringify(e)),i=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:t,additionalData:n},this.#e,s));return{type:"enc",payload:{iv:Array.from(t),cipherText:Array.from(i),additionalData:Array.from(n)}}}async decryptSecureMessage(e){try{if(this.#t(),this.#o(),!this.#e)throw new Error("AEAD key not initialized");let{iv:t,cipherText:n,additionalData:s}=e.payload;if(!t||!n||!s)throw new Error("Invalid message payload: missing required fields");if(!Array.isArray(t)||!Array.isArray(n)||!Array.isArray(s))throw new Error("Invalid message payload: fields must be arrays");let i=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(t),additionalData:new Uint8Array(s)},this.#e,new Uint8Array(n));return{decryptedMessage:JSON.parse(new TextDecoder().decode(i)),passedDecryption:!0}}catch(t){return console.error("Error decrypting secure message from iframe",t),{decryptedMessage:null,passedDecryption:!1}}}parseKeyExchangeDoneMessage(e){this.#t();let{ok:t,role:n}=e.payload;t&&(this.#s={role:n,ok:t})}generateKeyExchangeDoneMessage(){return{type:"kex-done",payload:{ok:!0,role:"parent"}}}closeSecureConnection(){this.#s={role:null,ok:!1},this.#e=null}};var P=r=>{if(typeof r!="object"||r===null)return{isValid:!1,response:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,response:null}:e.id===null||e.id===void 0?{isValid:!1,response:null}:e&&("result"in e||"error"in e)?{isValid:!0,response:e}:{isValid:!0,response:e}},q=r=>{if(typeof r!="object"||r===null)return{isValid:!1,eventRequest:null};let e=r;return e.jsonrpc!=="2.0"?{isValid:!1,eventRequest:null}:e.method?"params"in e?{isValid:!0,eventRequest:e}:{isValid:!1,eventRequest:null}:{isValid:!1,eventRequest:null}},N=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeResponse:null};let e=r;return e.type!=="kex-response"?{isValid:!1,keyExchangeResponse:null}:e.payload.pub?e.payload.nonce?{isValid:!0,keyExchangeResponse:e}:{isValid:!1,keyExchangeResponse:null}:{isValid:!1,keyExchangeResponse:null}},k=r=>{if(typeof r!="object"||r===null)return{isValid:!1,keyExchangeDone:null};let e=r;return e.type!=="kex-done"?{isValid:!1,keyExchangeDone:null}:e.payload.ok?e.payload.role?{isValid:!0,keyExchangeDone:e}:{isValid:!1,keyExchangeDone:null}:{isValid:!1,keyExchangeDone:null}},V=r=>{if(typeof r!="object"||r===null)return{isValid:!1,encryptedRequest:null};let e=r;return e.type!=="enc"?{isValid:!1,encryptedRequest:null}:e.payload.iv?e.payload.cipherText?e.payload.additionalData?{isValid:!0,encryptedRequest:e}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}:{isValid:!1,encryptedRequest:null}},O=r=>{if(typeof r!="object"||r===null)return{isValid:!1,fatalError:null};let e=r;return e.code?e.message?{isValid:!0,fatalError:e}:{isValid:!1,fatalError:null}:{isValid:!1,fatalError:null}};var f=()=>window.innerWidth<768,A=(r,e,t)=>{let n=document.getElementById(r);n&&(n.style.width=e,n.style.height=t)},Q=(r,e)=>{r.style.opacity="1",r.style.pointerEvents="auto",e.style.opacity="1",e.style.transform="scale(1)"},G=(r,e)=>{r.style.opacity="0",r.style.pointerEvents="none",e.style.opacity="0",e.style.transform="scale(0.8)"},T=(r,e,t)=>{let n=document.getElementById(r),s=document.getElementById(e);!n||!s||(document.body.style.overflow=t?"hidden":"auto",t?Q(s,n):G(s,n))},J=(r,e,t,n,s)=>{let i=document.createElement("div");i.id=e,Object.assign(i.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",display:"flex",justifyContent:"center",alignItems:"center",zIndex:"9999",opacity:"1",pointerEvents:"none",cursor:"default",transition:"opacity 0.3s ease-in-out"});let o=document.createElement("iframe");o.id=r,o.src=t,o.allow="publickey-credentials-get *; publickey-credentials-create *",Object.assign(o.style,{height:s,width:n,position:"relative",borderRadius:"0.75rem",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",overflowY:"auto",zIndex:"1000",opacity:"1",transform:"scale(0.8)",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out"}),i.appendChild(o),document.body.appendChild(i),setTimeout(()=>{i.style.opacity="1",i.style.pointerEvents="auto",o.style.opacity="1",o.style.transform="scale(1)"},100),document.body.style.overflow="hidden"},U=(r,e)=>{let t=document.getElementById(e);t&&(t.parentNode?.removeChild(t),document.body.style.overflow="auto");let n=document.getElementById(r);n&&n.parentNode&&n.parentNode.removeChild(n)};var K=r=>{let e=new I,{devWalletUrl:t}=r,n=t||"https://pay.transeptorlabs.io",s=new URLSearchParams({embedded:"true"}).toString(),i=t?`${t}?${s}`:`https://pay.transeptorlabs.io/?${s}`,o="dapp:iframe-embedded-payment",d="dapp:iframe-container",g="412px",R="640px",m=!1,C=a=>{let c=document.getElementById(d);c&&a.target===c&&T(o,d,!1)},v=()=>{let a=document.getElementById(o);if(!a)throw new Error("Iframe not found");return"contentWindow"in a?a.contentWindow:null},H=async(a=600)=>{let c=v();if(!c)throw new Error("Iframe not found");let l=!1,E=u=>{if(!u.isTrusted||u.origin!==n)return;if(u.data==="pong"){l=!0;return}};return window.addEventListener("message",E.bind(void 0)),new Promise((u,w)=>{let h=0,p=setInterval(()=>{h++,h>=a&&(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),w(new Error("Max ping attempts reached to establish connection with the iframe"))),l?(clearInterval(p),window.removeEventListener("message",E.bind(void 0)),console.log("Iframe is ready to receive messages"),u(!0)):(console.log("Sending ping to the iframe to check if it is ready"),c.postMessage("ping",n))},500)})},j=async(a=600)=>{console.log("Establishing secure connection with the iframe");let c=v();if(!c)throw new Error("Iframe not found");let l=await e.generateKeyExchangeMessage(),E=null,u=null,w=h=>{if(!h.isTrusted||h.origin!==n)return;let p=h.data,{isValid:x,keyExchangeResponse:M}=N(p);if(x&&M){c.postMessage(e.generateKeyExchangeDoneMessage(),n),E=p;return}let{isValid:z,keyExchangeDone:B}=k(p);if(z&&B){u=p;return}};return window.addEventListener("message",w.bind(void 0)),c.postMessage(l,n),new Promise((h,p)=>{let x=0,M=setInterval(()=>{x++,x>=a&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),p(new Error("Max secure connection attempts reached to establish secure connection with the iframe"))),E&&u&&(clearInterval(M),window.removeEventListener("message",w.bind(void 0)),e.parseKeyExchangeDoneMessage(u),h(E))},200)})};return{getIframeOrigin:()=>n,prepareIframe:async()=>{if(!m){console.log("Appending iframe to the DOM"),g=f()?"100%":"412px",R=f()?"100%":"640px",J(o,d,i,g,R);let a=document.getElementById(d);a&&a.addEventListener("click",C),m=!0}if(!e.isSecureConnectionEstablished){let a=await H();if(!v()&&!a)throw new Error("Iframe content window not found, cannot start key exchange");await e.initializeEcdh();let l=await j();await e.parseKeyExchangeMessage(l)}},disconnectIframe:()=>{if(!m||!e.isSecureConnectionEstablished)return;e.closeSecureConnection(),U(o,d);let a=document.getElementById(d);a&&a.removeEventListener("click",C),m=!1,console.log("Secure connection closed with the iframe removed from the DOM",{isSecureConnectionEstablished:e.isSecureConnectionEstablished,isIframeCreated:m})},toggleFrameVisibility:a=>{m&&(T(o,d,a),g=f()?"100%":"412px",R=f()?"100%":"640px",A(o,g,R))},resizeIframe:a=>{m&&(g=f()?"100%":a||"412px",R=f()?"100%":"640px",A(o,g,R))},sendMessageToIframe:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let c=v();if(c){let l=await e.prepareSecureMessage(a);c.postMessage(l,n)}else throw new Error("Iframe content window not found")},decryptSecureMessage:async a=>{if(!e.isSecureConnectionEstablished)throw new Error("Secure channel not established with the iframe");let{decryptedMessage:c,passedDecryption:l}=await e.decryptSecureMessage(a);if(!l||!c)throw new Error("Failed to decrypt secure message");return c}}};var _=r=>{let e=Math.random,t=e();return Math.floor(t*r)};var b=class r{static#n;#r;#s;FATAL_ERROR_MESSAGE="fatal: internal error";#a=["wallet_requestExecutionPermissions","wallet_revokeExecutionPermission"];#e;#t=new Map;constructor(e){this.#r=window,this.#e=e,this.#s=this.#l.bind(this),this.#r.addEventListener("message",this.#s)}#o(){let e=_(1e10)+Date.now();return this.#t.has(e)?this.#o():e}#i(){this.#e.toggleFrameVisibility(!1)}#c(e){this.#e.resizeIframe(e)}async#l(e){if(!e.isTrusted||e.origin!==this.#e.getIframeOrigin())return;let t=e.data;if(typeof t!="object")return;let{isValid:n,fatalError:s}=O(t);if(n&&s){this.#y(s);return}let{isValid:i,encryptedRequest:o}=V(t);if(i&&o){await this.#h(o);return}}#u(e){let{id:t}=e;this.#t.has(Number(t))&&this.#t.set(Number(t),{status:"fulfilled",response:e})}#p(e){let{method:t}=e;switch(t){case"wallet_paymentEvent":break;case"wallet_closeFrame":this.#i();break;case"wallet_disconnect":this.#d();break;case"wallet_resizeFrameFull":this.#c("100%");break;case"wallet_resizeFrameDefault":this.#c("412px");break}}async#h(e){let t=await this.#e.decryptSecureMessage(e),{isValid:n,response:s}=P(t);if(n&&s){this.#u(s);return}let{isValid:i,eventRequest:o}=q(t);if(i&&o){this.#p(o);return}}#y(e){this.#t.size&&this.#t.forEach(t=>{t.status==="pending"&&(t.status="failed",t.fatalError=e)})}async#m(e,t){try{await this.#e.prepareIframe(),t&&this.#e.toggleFrameVisibility(!0);let{id:n}=e;return this.#t.set(Number(n),{status:"pending",response:void 0}),await this.#e.sendMessageToIframe(e),await this.#E(Number(n))}catch(n){return n.message===this.FATAL_ERROR_MESSAGE&&this.#i(),{jsonrpc:"2.0",id:e.id,error:{message:n.message,code:-32e3}}}}#E(e,t=300){return new Promise((n,s)=>{let i=0,o=setInterval(()=>{i++,i>=t&&(clearInterval(o),s(new Error("Max attempts reached waiting for response")));let d=this.#t.get(e);d&&(d.status==="failed"&&d.fatalError&&(clearInterval(o),this.#t.delete(e),s(new Error(d.fatalError.message))),d.status==="fulfilled"&&(clearInterval(o),this.#t.delete(e),n(d.response)))},1e3)})}#d(){return this.#e.toggleFrameVisibility(!1),this.#e.disconnectIframe(),this.#t=new Map,!0}async sendRequest(e){let t=this.#o(),n=this.#a.includes(e.method);switch(e.method){case"wallet_disconnect":return this.#d(),!0;case"wallet_openHomePage":return await this.#e.prepareIframe(),this.#e.toggleFrameVisibility(!0),await this.#e.sendMessageToIframe({jsonrpc:"2.0",method:"wallet_navigateToDashboardEvent",params:[]}),!0;default:{let s=await this.#m({jsonrpc:"2.0",id:t,method:e.method,params:e.params||[]},n);if("error"in s)throw new y({message:s.error.message,code:s.error.code,data:s.error.data});return s.result}}}static Create(e){if(!r.#n){let t=K({parentOrigin:window.location.origin,devWalletUrl:e.devWalletUrl});r.#n=new r(t)}return r.#n}};var $={4001:{code:4001,message:"User rejected the request."},4100:{code:4100,message:"The requested method and/or account has not been authorized by the user."},4200:{code:4200,message:"The Provider does not support the requested method."},4900:{code:4900,message:"The Provider is disconnected from all chains."},4901:{code:4901,message:"The Provider is not connected to the requested chain."},4101:{code:4101,message:"The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method."},5700:{code:5700,message:"This wallet does not support a capability that was not marked as optional."},5710:{code:5710,message:"This wallet does not support the specified chain id."},5720:{code:5720,message:"There is already a bundle submitted with this id."},5730:{code:5730,message:"This bundle id is unknown / has not been submitted."},5740:{code:5740,message:"The call bundle is too large for the wallet to process."},5750:{code:5750,message:"The wallet can support atomicity after an upgrade, but the user rejected the upgrade."},5760:{code:5760,message:"The wallet does not support atomic execution but the request requires it."},[-32001]:{code:-32001,message:"fatal: internal error"},[-32602]:{code:4002,message:"Invalid parameters."}},F=r=>{let e=$[r];return e||{code:r,message:`Unknown error code: ${r}`}};var D=class{#n;constructor(e){this.#n=b.Create(e)}async request(e){try{return await this.#n.sendRequest(e)}catch(t){if(t instanceof y){let n=F(t.code);if(n)throw new y(n)}throw new y({code:-32e3,message:"Unknown internal error",data:t})}}};function S(r){return new D(r)}var W=(t=>(t.AnnounceProvider="eip6963:announceProvider",t.RequestProvider="eip6963:requestProvider",t))(W||{});var L="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg==";var Z=r=>{let e=S(r),t=Object.freeze({info:Object.freeze({uuid:"2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1",name:"Cashie",icon:L,rdns:"org.cashie.app"}),provider:e}),n=new CustomEvent("eip6963:announceProvider",{detail:t});window.addEventListener("eip6963:requestProvider",()=>{window.dispatchEvent(n)}),window.dispatchEvent(n)};export{b as CashieEthereumProvider,W as ProviderEvent,y as ProviderRpcError,Z as announceProvider,S as createEip1193Provider};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/provider/types.ts", "../src/ecdh/ecdh-manager.ts", "../src/utils/validate.ts", "../src/iframe/iframe.ts", "../src/iframe/iframe-handler.ts", "../src/utils/random.ts", "../src/provider/transeptor-ethereum-provider.ts", "../src/provider/errors.ts", "../src/provider/eip-1193-bridge.ts", "../src/provider/eip-6963/types.ts", "../src/provider/eip-6963/icon.ts", "../src/provider/eip-6963/announce-provider.ts"],
4
- "sourcesContent": ["export class ProviderRpcError extends Error {\n /**\n * MUST be an integer number\n * SHOULD adhere to the specifications in the Error Standards section below\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#error-standards\n */\n code: number\n\n /**\n * SHOULD contain any other useful information about the error\n */\n data?: unknown\n\n constructor({\n message,\n code,\n data,\n }: {\n message: string\n code: number\n data?: unknown\n }) {\n super(message)\n this.code = code\n this.data = data\n }\n}\n\n/**\n * The Eip1193 error types\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#rpc-errors\n */\nexport type Eip1193Error =\n | 'userRejectedRequest'\n | 'unauthorized'\n | 'unsupportedMethod'\n | 'disconnected'\n | 'chainDisconnected'\n\nexport type Eip1193RequestArguments = {\n method: string\n params?: readonly unknown[] | object\n}\n\nexport interface Eip1193Provider {\n /**\n * Request a method from the Eip1193 provider\n *\n * @param request - the request to be sent to the Eip1193 provider\n * @returns the response from the Eip1193 provider\n *\n * @throws {Error} If the returned Promise rejects, it MUST reject with a ProviderRpcError as specified in the [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193#rpc-errors) section below.\n */\n request: (request: Eip1193RequestArguments) => Promise<unknown>\n}\n\n/**\n * The message event is intended for arbitrary notifications not covered by other events.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#message-event\n */\nexport type Eip1193ProviderMessage = {\n readonly type: string\n readonly data: unknown\n}\n\n/**\n * Specify the integer ID of the connected chain as a hexadecimal string, per the eth_chainId Ethereum RPC method.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider_connect\n */\nexport type Eip1193ProviderConnectInfo = {\n readonly chainId: `0x${string}`\n}\n", "/* eslint-disable no-console */\nimport { SecureMessageType, SecureMessage } from './ecdh.types.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n JsonRpcErrorResponse,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n} from '../types/index.js'\n\n/**\n * Ephemeral ECDH key pair(private key, public key), public key(public key in jwk format), and nonce\n */\nexport type EphemeralEcdh = {\n keyPair: CryptoKeyPair | null\n pubJwk: JsonWebKey | null\n nonce: Uint8Array | null\n}\n\n/**\n * Create a new ephemeral ECDH manager\n * The ECDH(Elliptic Curve Diffie\u2013Hellman) key exchange manager is used to generate a shared secret key to encrypt and decrypt secure messages between the two parties on an untrusted channel.\n */\nexport class EphemeralEcdhManager {\n private readonly ALGO = { name: 'ECDH', namedCurve: 'P-256' }\n #isInitialized = false\n #ephemeralEcdh: EphemeralEcdh = {\n keyPair: null,\n pubJwk: null,\n nonce: null,\n }\n #isKeyExchangeDone: {\n role: 'parent' | 'iframe' | null\n ok: boolean\n } = {\n role: null,\n ok: false,\n }\n #sequence = 0\n #aeadKey: CryptoKey | null = null\n\n constructor() {\n // empty constructor\n }\n\n /**\n * Assert that the ECDH is initialized\n *\n * @throws {Error} if the ECDH is not initialized\n */\n #assertInitialized(): void {\n if (!this.#isInitialized) {\n throw new Error('ECDH not initialized')\n }\n }\n\n /**\n * Assert that the secure connection is established\n *\n * @throws {Error} if the secure connection is not established\n */\n #assertSecureConnectionEstablished(): void {\n if (!this.#isKeyExchangeDone.ok) {\n throw new Error('Secure connection not established')\n }\n }\n\n /**\n * Check if Web Crypto API is available and properly configured\n *\n * @throws {Error} if Web Crypto API is not available\n */\n #assertWebCryptoAvailable(): void {\n try {\n if (\n typeof crypto !== 'undefined' &&\n typeof crypto.subtle !== 'undefined' &&\n typeof crypto.getRandomValues !== 'undefined' &&\n typeof crypto.subtle.generateKey !== 'undefined' &&\n typeof crypto.subtle.encrypt !== 'undefined' &&\n typeof crypto.subtle.decrypt !== 'undefined'\n ) {\n return\n }\n throw new Error('Web Crypto API not available')\n } catch (error) {\n throw new Error('Web Crypto API not available', { cause: error })\n }\n }\n\n /**\n * Check if the secure connection is established\n *\n * @returns true if the secure connection is established, false otherwise\n */\n get isSecureConnectionEstablished(): boolean {\n return this.#isKeyExchangeDone.ok\n }\n\n /**\n * Initialize the ECDH\n *\n * @returns void\n */\n async initializeEcdh(): Promise<void> {\n this.#assertWebCryptoAvailable()\n const keyPair = await crypto.subtle.generateKey(this.ALGO, true, [\n 'deriveBits',\n ])\n const pubJwk = await crypto.subtle.exportKey('jwk', keyPair.publicKey)\n const nonce = crypto.getRandomValues(new Uint8Array(16))\n\n this.#ephemeralEcdh = {\n keyPair,\n pubJwk,\n nonce,\n } as EphemeralEcdh\n this.#isInitialized = true\n }\n\n /**\n * Parse a key exchange message to generate a shared secret\n *\n * @param message - the key exchange response message\n * @returns void\n */\n async parseKeyExchangeMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeResponse>,\n ): Promise<void> {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n\n // Extract the public key and nonce from the message\n const { pub, nonce } = message.payload\n const recipientPub = await crypto.subtle.importKey(\n 'jwk',\n pub,\n this.ALGO,\n false,\n [],\n )\n\n // Compute a shared secret using the recipient's public key and the ephemeral private key pair\n const bits = await crypto.subtle.deriveBits(\n { name: this.ALGO.name, public: recipientPub },\n this.#ephemeralEcdh.keyPair.privateKey,\n 256,\n )\n const baseKey = await crypto.subtle.importKey('raw', bits, 'HKDF', false, [\n 'deriveKey',\n ])\n\n // Derive the salt with format <parent-nonce,child-nonce>\n // Note: This must match the iframe's salt ordering for consistent key derivation\n const salt = new Uint8Array([\n ...this.#ephemeralEcdh.nonce,\n ...new Uint8Array(nonce),\n ])\n\n // Derive the AEAD key from the base key and the salt that will be used to encrypt/decrypt the messages between the both parties\n this.#aeadKey = await crypto.subtle.deriveKey(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n salt,\n info: new TextEncoder().encode('transeptor-pay-v1'),\n },\n baseKey,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt'],\n )\n }\n\n /**\n * Generate a key exchange message\n *\n * @returns the key exchange message\n */\n async generateKeyExchangeMessage(): Promise<\n SecureMessage<SecureMessageType.KeyExchangeInit>\n > {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.pubJwk) {\n throw new Error('Ephemeral public key not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n\n return {\n type: SecureMessageType.KeyExchangeInit,\n payload: {\n pub: this.#ephemeralEcdh.pubJwk,\n nonce: Array.from<number>(this.#ephemeralEcdh.nonce),\n },\n }\n }\n\n /**\n * Prepare a secure message\n *\n * @param data - the data to be prepared\n * @returns the secure message\n */\n async prepareSecureMessage(\n data:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ): Promise<SecureMessage<SecureMessageType.Encrypted>> {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n // Increment the sequence number\n this.#sequence++\n\n // Encrypt the data with the AEAD key given by the child iframe to ensure only the child iframe can decrypt the message\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const additionalData = new TextEncoder().encode(`seq:${this.#sequence}`)\n const dataBytes = new TextEncoder().encode(JSON.stringify(data))\n const cipherText = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv, additionalData },\n this.#aeadKey,\n dataBytes,\n ),\n )\n\n return {\n type: SecureMessageType.Encrypted,\n payload: {\n iv: Array.from<number>(iv),\n cipherText: Array.from<number>(cipherText),\n additionalData: Array.from<number>(additionalData),\n },\n }\n }\n\n /**\n * Decrypt a secure message sent by the child iframe\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted data\n */\n async decryptSecureMessage(\n message: SecureMessage<SecureMessageType.Encrypted>,\n ): Promise<{\n decryptedMessage:\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n | null\n passedDecryption: boolean\n }> {\n try {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n\n const { iv, cipherText, additionalData } = message.payload\n\n if (!iv || !cipherText || !additionalData) {\n throw new Error('Invalid message payload: missing required fields')\n }\n\n if (\n !Array.isArray(iv) ||\n !Array.isArray(cipherText) ||\n !Array.isArray(additionalData)\n ) {\n throw new Error('Invalid message payload: fields must be arrays')\n }\n\n const dataBytes = await crypto.subtle.decrypt(\n {\n name: 'AES-GCM',\n iv: new Uint8Array(iv),\n additionalData: new Uint8Array(additionalData),\n },\n this.#aeadKey,\n new Uint8Array(cipherText),\n )\n const decryptedMessage = JSON.parse(new TextDecoder().decode(dataBytes))\n return {\n decryptedMessage,\n passedDecryption: true,\n }\n } catch (error) {\n console.error('Error decrypting secure message from iframe', error)\n return {\n decryptedMessage: null,\n passedDecryption: false,\n }\n }\n }\n\n /**\n * Parse a key exchange done message\n *\n * @param message - the key exchange done message\n */\n parseKeyExchangeDoneMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeDone>,\n ): void {\n this.#assertInitialized()\n const { ok, role } = message.payload\n if (ok) {\n this.#isKeyExchangeDone = {\n role,\n ok,\n }\n }\n }\n\n /**\n * Generate a key exchange done message\n *\n * @returns the key exchange done message\n */\n generateKeyExchangeDoneMessage(): SecureMessage<SecureMessageType.KeyExchangeDone> {\n return {\n type: SecureMessageType.KeyExchangeDone,\n payload: {\n ok: true,\n role: 'parent',\n },\n }\n }\n\n /**\n * Close the secure connection\n *\n */\n closeSecureConnection(): void {\n this.#isKeyExchangeDone = {\n role: null,\n ok: false,\n }\n this.#aeadKey = null\n }\n}\n", "import {\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n FatalError,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/ecdh.types.js'\n\ntype JsonRpcResponseValidator = {\n isValid: boolean\n response: JsonRpcResponse | null\n}\n\ntype JsonRpcEventRequestValidator = {\n isValid: boolean\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames> | null\n}\n\ntype JsonRpcKeyExchangeResponseValidator = {\n isValid: boolean\n keyExchangeResponse: SecureMessage<SecureMessageType.KeyExchangeResponse> | null\n}\n\ntype JsonRpcKeyExchangeDoneValidator = {\n isValid: boolean\n keyExchangeDone: SecureMessage<SecureMessageType.KeyExchangeDone> | null\n}\n\ntype EncryptedRequestValidator = {\n isValid: boolean\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted> | null\n}\n\ntype FatalErrorValidator = {\n isValid: boolean\n fatalError: FatalError | null\n}\n\n/**\n * Validate a JSON-RPC response\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcResponseValidator = (\n message: unknown,\n): JsonRpcResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, response: null }\n }\n const response = message as JsonRpcResponse\n if (response.jsonrpc !== '2.0') {\n return { isValid: false, response: null }\n }\n\n if (response.id === null || response.id === undefined) {\n return { isValid: false, response: null }\n }\n\n if (response && ('result' in response || 'error' in response)) {\n return { isValid: true, response: response as JsonRpcResponse }\n }\n\n return {\n isValid: true,\n response: response as JsonRpcResponse,\n }\n}\n\n/**\n * Validate a JSON-RPC event request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const inboundJsonRpcEventRequestValidator = (\n message: unknown,\n): JsonRpcEventRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, eventRequest: null }\n }\n const eventRequest =\n message as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n if (eventRequest.jsonrpc !== '2.0') {\n return { isValid: false, eventRequest: null }\n }\n if (!eventRequest.method) {\n return { isValid: false, eventRequest: null }\n }\n\n if (!('params' in eventRequest)) {\n return {\n isValid: false,\n eventRequest: null,\n }\n }\n\n return {\n isValid: true,\n eventRequest:\n eventRequest as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange response request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeResponseValidator = (\n message: unknown,\n): JsonRpcKeyExchangeResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeResponse: null }\n }\n const keyExchangeResponse =\n message as SecureMessage<SecureMessageType.KeyExchangeResponse>\n if (keyExchangeResponse.type !== SecureMessageType.KeyExchangeResponse) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.pub) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.nonce) {\n return { isValid: false, keyExchangeResponse: null }\n }\n return {\n isValid: true,\n keyExchangeResponse:\n keyExchangeResponse as SecureMessage<SecureMessageType.KeyExchangeResponse>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange done request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeDoneValidator = (\n message: unknown,\n): JsonRpcKeyExchangeDoneValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeDone: null }\n }\n const keyExchangeDone =\n message as SecureMessage<SecureMessageType.KeyExchangeDone>\n if (keyExchangeDone.type !== SecureMessageType.KeyExchangeDone) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.ok) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.role) {\n return { isValid: false, keyExchangeDone: null }\n }\n\n return {\n isValid: true,\n keyExchangeDone:\n keyExchangeDone as SecureMessage<SecureMessageType.KeyExchangeDone>,\n }\n}\n\n/**\n * Validate a JSON-RPC encrypted message\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const encryptedMessageValidator = (\n message: unknown,\n): EncryptedRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, encryptedRequest: null }\n }\n const encryptedRequest = message as SecureMessage<SecureMessageType.Encrypted>\n if (encryptedRequest.type !== SecureMessageType.Encrypted) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.iv) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.cipherText) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.additionalData) {\n return { isValid: false, encryptedRequest: null }\n }\n return {\n isValid: true,\n encryptedRequest:\n encryptedRequest as SecureMessage<SecureMessageType.Encrypted>,\n }\n}\n\n/**\n * Validate a fatal error\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const fatalErrorValidator = (message: unknown): FatalErrorValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, fatalError: null }\n }\n const fatalError = message as FatalError\n if (!fatalError.code) {\n return { isValid: false, fatalError: null }\n }\n if (!fatalError.message) {\n return { isValid: false, fatalError: null }\n }\n return { isValid: true, fatalError: fatalError as FatalError }\n}\n", "/**\n * Frame width enum\n */\nexport enum FrameWidth {\n Default = '412px',\n Full = '100%',\n}\n\nexport enum FrameHeight {\n Default = '640px',\n Full = '100%',\n}\n\n/**\n * Check if the device is mobile\n *\n * @returns true if the device is mobile, false otherwise\n */\nexport const isMobile = () => {\n return window.innerWidth < 768\n}\n\n/**\n * Resize the iframe container and iframe element width\n *\n * @param iframeId - the id of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const resizeFrameWidth = (\n iframeId: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n const iframe = document.getElementById(iframeId)\n\n if (iframe) {\n iframe.style.width = frameWidth\n iframe.style.height = frameHeight\n }\n}\n\n/**\n * Show the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst showIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)' // Scale in\n}\n\n/**\n * Hide the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst hideIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '0'\n overlay.style.pointerEvents = 'none'\n iframe.style.opacity = '0'\n iframe.style.transform = 'scale(0.8)' // Scale out\n}\n\n/**\n * Toggle the visibility of the iframe\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param isVisible - the visibility of the iframe\n */\nexport const doToggleIframeVisibility = (\n iframeId: string,\n overlayId: string,\n isVisible: boolean,\n) => {\n const iframe = document.getElementById(iframeId)\n const overlay = document.getElementById(overlayId)\n if (!iframe || !overlay) {\n return\n }\n\n document.body.style.overflow = isVisible ? 'hidden' : 'auto'\n if (isVisible) {\n showIframe(overlay, iframe)\n } else {\n hideIframe(overlay, iframe)\n }\n}\n\n/**\n * Append the iframe to the container div\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param url - the url of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const appendIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n url: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n // Create overlay container\n const overlay = document.createElement('div')\n overlay.id = overlayId\n Object.assign(overlay.style, {\n position: 'fixed',\n top: '0',\n left: '0',\n width: '100%',\n height: '100%',\n background: 'rgba(0, 0, 0, 0.4)',\n backdropFilter: 'blur(4px)',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n zIndex: '9999',\n opacity: '1',\n pointerEvents: 'none', // Disable interactions when hidden\n cursor: 'default', // Default cursor for overlay background\n transition: 'opacity 0.3s ease-in-out',\n })\n\n const iframe = document.createElement('iframe')\n iframe.id = iframeId\n iframe.src = url\n iframe.allow = 'publickey-credentials-get *; publickey-credentials-create *'\n Object.assign(iframe.style, {\n height: frameHeight,\n width: frameWidth,\n position: 'relative',\n borderRadius: '0.75rem',\n boxShadow:\n '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)',\n overflowY: 'auto',\n zIndex: '1000',\n opacity: '1',\n transform: 'scale(0.8)',\n transition: 'opacity 0.3s ease-in-out, transform 0.3s ease-in-out',\n })\n\n overlay.appendChild(iframe)\n document.body.appendChild(overlay)\n\n // Ensure styles are applied after DOM insertion\n setTimeout(() => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)'\n }, 100) // Small delay to trigger transition\n\n // Prevent scrolling while overlay is open\n document.body.style.overflow = 'hidden'\n}\n\n/**\n * Destroy the iframe element and remove it from the DOM\n *\n * @param iframeId - the id of the iframe to be destroyed\n * @param overlayId - the id of the overlay container\n */\nexport const destroyIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n) => {\n const overlay = document.getElementById(overlayId)\n if (overlay) {\n overlay.parentNode?.removeChild(overlay)\n document.body.style.overflow = 'auto' // Restore scrolling\n }\n const iframe = document.getElementById(iframeId)\n if (iframe) {\n if (iframe.parentNode) {\n iframe.parentNode.removeChild(iframe)\n }\n }\n}\n", "/* eslint-disable no-console */\nimport {\n EphemeralEcdhManager,\n SecureMessage,\n SecureMessageType,\n} from '../ecdh/index.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcErrorResponse,\n JsonRpcResponse,\n} from '../types/index.js'\nimport {\n jsonRpcKeyExchangeResponseValidator,\n jsonRpcKeyExchangeDoneValidator,\n} from '../utils/validate.js'\nimport {\n appendIframeWithContainer,\n destroyIframeWithContainer,\n doToggleIframeVisibility,\n FrameHeight,\n FrameWidth,\n isMobile,\n resizeFrameWidth,\n} from './iframe.js'\n\n/**\n * Iframe handler interface\n */\nexport type IframeHandler = {\n /**\n * Create a new iframe element and append it to the container div if it is not already created\n * Establish a secure connection with the iframe\n *\n * @returns void\n */\n prepareIframe: () => Promise<void>\n\n /**\n * Disconnect the iframe by closing the secure connection and destroying the iframe container and iframe element\n *\n */\n disconnectIframe: () => void\n\n /**\n * Toggle the visibility of the iframe\n *\n * @param isVisible - the visibility of the iframe\n * @returns void\n */\n toggleFrameVisibility: (isVisible: boolean) => void\n\n /**\n * Send a message to the iframe\n *\n * @param request - the request to be sent to the iframe\n */\n sendMessageToIframe: (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => Promise<void>\n\n /**\n * Resize the iframe\n *\n * @param size - the size of the iframe\n * @returns void\n */\n resizeIframe: (size?: FrameWidth) => void\n\n /**\n * Get the origin of the iframe\n *\n * @returns the origin of the iframe\n */\n getIframeOrigin: () => string\n\n /**\n * Decrypt a secure message\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted message\n */\n decryptSecureMessage: (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => Promise<\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n >\n}\n\ntype IframeHandlerConfig = {\n /**\n * The origin of the parent window\n */\n parentOrigin: string\n\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string | undefined\n}\n\n/**\n * Create a new iframe handler\n *\n * @param config - the iframe handler config\n * @returns the iframe handler\n */\nexport const createIframeHandler = (\n config: IframeHandlerConfig,\n): IframeHandler => {\n const ecdhManager = new EphemeralEcdhManager()\n const { devWalletUrl } = config\n const IFRAME_ORIGIN = devWalletUrl || 'https://pay.transeptorlabs.io'\n const params = new URLSearchParams({ embedded: 'true' }).toString()\n const walletUrl = devWalletUrl\n ? `${devWalletUrl}?${params}`\n : `https://pay.transeptorlabs.io/?${params}`\n const DAPP_IFRAME_ID = 'dapp:iframe-embedded-payment'\n const OVERLAY_CONTAINER_ID = 'dapp:iframe-container'\n\n let activeFrameWidth = FrameWidth.Default\n let activeFrameHeight = FrameHeight.Default\n let isIframeCreated = false\n\n /**\n * Handle the overlay click event\n *\n * @param event - the mouse event\n */\n const handleOverlayClick = (event: MouseEvent) => {\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n if (event.target === overlay) {\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, false)\n }\n }\n }\n\n /**\n * Get the content window of the iframe\n *\n * @returns the content window of the iframe\n */\n const getIframeContentWindow = (): Window | null => {\n const iframe = document.getElementById(DAPP_IFRAME_ID)\n if (!iframe) {\n throw new Error('Iframe not found')\n }\n const hasContentWindow = 'contentWindow' in iframe\n if (hasContentWindow) {\n const childWindow = iframe.contentWindow as Window\n return childWindow\n }\n return null\n }\n\n /**\n * Send a post message to the IFrame window to check if it is ready and to inform the iframe of the parent origin extracted from message event\n * Waits for the frame to be ready before sending the message.\n * max attempts is 600\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns true if the frame is ready, false otherwise will reject with an error\n */\n const checkIframeReady = async (attempts = 600) => {\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n let isFrameReady = false\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n if (message === 'pong') {\n isFrameReady = true\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n return new Promise<boolean>((_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max ping attempts reached to establish connection with the iframe',\n ),\n )\n }\n\n // resolve if the frame is ready\n if (isFrameReady) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n console.log('Iframe is ready to receive messages')\n _resolve(true)\n } else {\n console.log('Sending ping to the iframe to check if it is ready')\n childWindow.postMessage('ping', IFRAME_ORIGIN)\n }\n }, 500) // 500ms\n })\n }\n\n /**\n * Establish a secure connection with the iframe\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns the key exchange response message if the secure connection is established, null otherwise will reject with an error\n */\n const establishSecureConnectionWithIframe = async (attempts = 600) => {\n console.log('Establishing secure connection with the iframe')\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n // Generate key exchange messages\n const keyExchangeMessage = await ecdhManager.generateKeyExchangeMessage()\n let keyExchangeResponseMessage: SecureMessage<SecureMessageType.KeyExchangeResponse> | null =\n null\n let keyExchangeDoneMessage: SecureMessage<SecureMessageType.KeyExchangeDone> | null =\n null\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n const { isValid: isValidKeyExchangeResponse, keyExchangeResponse } =\n jsonRpcKeyExchangeResponseValidator(message)\n if (isValidKeyExchangeResponse && keyExchangeResponse) {\n childWindow.postMessage(\n ecdhManager.generateKeyExchangeDoneMessage(),\n IFRAME_ORIGIN,\n )\n keyExchangeResponseMessage = message\n return\n }\n\n const { isValid: isValidKeyExchangeDone, keyExchangeDone } =\n jsonRpcKeyExchangeDoneValidator(message)\n if (isValidKeyExchangeDone && keyExchangeDone) {\n keyExchangeDoneMessage = message\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n childWindow.postMessage(keyExchangeMessage, IFRAME_ORIGIN)\n\n return new Promise<SecureMessage<SecureMessageType.KeyExchangeResponse>>(\n (_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max secure connection attempts reached to establish secure connection with the iframe',\n ),\n )\n }\n\n // resolve if the secure connection is established\n if (keyExchangeResponseMessage && keyExchangeDoneMessage) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n ecdhManager.parseKeyExchangeDoneMessage(keyExchangeDoneMessage)\n _resolve(keyExchangeResponseMessage)\n }\n }, 200) // 200ms\n },\n )\n }\n\n return {\n getIframeOrigin: () => IFRAME_ORIGIN,\n\n prepareIframe: async () => {\n // Append the iframe to the DOM and add event listener to close overlay when clicking outside the iframe\n if (!isIframeCreated) {\n console.log('Appending iframe to the DOM')\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n appendIframeWithContainer(\n DAPP_IFRAME_ID,\n OVERLAY_CONTAINER_ID,\n walletUrl,\n activeFrameWidth,\n activeFrameHeight,\n )\n\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.addEventListener('click', handleOverlayClick)\n }\n isIframeCreated = true\n }\n\n // Establish connection and start key exchange\n if (!ecdhManager.isSecureConnectionEstablished) {\n const isIframeReady = await checkIframeReady()\n const childWindow = getIframeContentWindow()\n if (!childWindow && !isIframeReady) {\n throw new Error(\n 'Iframe content window not found, cannot start key exchange',\n )\n }\n // Initialize the ECDH manager\n await ecdhManager.initializeEcdh()\n\n // Establish secure connection with the iframe\n const keyExchangeResponseMessage =\n await establishSecureConnectionWithIframe()\n\n // Parse the key exchange response message from the iframe\n await ecdhManager.parseKeyExchangeMessage(keyExchangeResponseMessage)\n }\n },\n\n disconnectIframe: () => {\n if (!isIframeCreated) {\n return\n }\n\n if (!ecdhManager.isSecureConnectionEstablished) {\n return\n }\n\n ecdhManager.closeSecureConnection()\n destroyIframeWithContainer(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID)\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.removeEventListener('click', handleOverlayClick)\n }\n isIframeCreated = false\n\n console.log(\n 'Secure connection closed with the iframe removed from the DOM',\n {\n isSecureConnectionEstablished:\n ecdhManager.isSecureConnectionEstablished,\n isIframeCreated: isIframeCreated,\n },\n )\n },\n\n toggleFrameVisibility: (isVisible) => {\n if (!isIframeCreated) {\n return\n }\n\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, isVisible)\n\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n resizeIframe: (size?: FrameWidth) => {\n if (!isIframeCreated) {\n return\n }\n\n activeFrameWidth = isMobile()\n ? FrameWidth.Full\n : size || FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n sendMessageToIframe: async (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n\n const childWindow = getIframeContentWindow()\n if (childWindow) {\n const encryptedRequest = await ecdhManager.prepareSecureMessage(request)\n childWindow.postMessage(encryptedRequest, IFRAME_ORIGIN)\n } else {\n throw new Error('Iframe content window not found')\n }\n },\n\n decryptSecureMessage: async (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n const { decryptedMessage, passedDecryption } =\n await ecdhManager.decryptSecureMessage(message)\n if (!passedDecryption || !decryptedMessage) {\n throw new Error('Failed to decrypt secure message')\n }\n return decryptedMessage\n },\n }\n}\n", "/**\n * Returns a random number between 0 and maxRange\n *\n * @param maxRange - the maximum range for the random number\n * @returns a random number between 0 and maxRange\n */\nexport const getRandomNum = (maxRange: number) => {\n const rand: () => number = Math.random\n const rn = rand()\n return Math.floor(rn * maxRange)\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n createIframeHandler,\n FrameWidth,\n IframeHandler,\n} from '../iframe/index.js'\n\nimport {\n getRandomNum,\n inboundJsonRpcEventRequestValidator,\n jsonRpcResponseValidator,\n encryptedMessageValidator,\n fatalErrorValidator,\n} from '../utils/index.js'\n\nimport {\n InboundJsonRpcEventRequest,\n JsonRpcResponse,\n InboundRpcRequestEventsMethodNames,\n FatalError,\n JsonRpcRequest,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/index.js'\nimport { Eip1193RequestArguments, ProviderRpcError } from './types.js'\n\n// JSON-RPC types\nexport type Message = unknown\n\nexport type AcceptedChainConfig = {\n /**\n * The chain ID of the blockchain network to be used\n * It should be a valid Ethereum chain ID in hex format\n */\n chainId: `0x${string}`\n\n /**\n * The treasury address to receive the payments\n * It should be a valid Ethereum address in hex format\n */\n treasuryAddress: `0x${string}`\n}\n\n/**\n * The configuration for the EmbeddedPayment\n */\nexport type TranseptorEthereumProviderConfig = {\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string\n\n /**\n * The accepted chain configurations to be used to accept payments\n */\n // acceptedChainConfig: AcceptedChainConfig[]\n\n /**\n * Callback function to handle incoming payment events that emit when the user completes a payment\n */\n // onPaymentEvent: (checkoutResponse: CheckoutResponse) => void\n}\n\n/**\n * We use a singleton class maintains a single instance across a web application, and to ensure\n * the post message listener is only added once, allowing that web application to access wallet globally.\n *\n * The TranseptorEthereumProvider target environment is the browser, and it is designed to be used in web applications.\n */\nexport class TranseptorEthereumProvider {\n static #instance: TranseptorEthereumProvider\n readonly #localWindow: Window\n readonly #boundMessageHandler: (event: MessageEvent<Message>) => void\n readonly FATAL_ERROR_MESSAGE = 'fatal: internal error'\n\n readonly #rpcMethodsThatRequireUserConsent: string[] = [\n 'wallet_requestExecutionPermissions',\n 'wallet_revokeExecutionPermission',\n ]\n\n #iframeHandler: IframeHandler\n #responseQueue: Map<\n number,\n {\n status: 'pending' | 'fulfilled' | 'failed'\n response: JsonRpcResponse | undefined\n fatalError?: FatalError\n }\n > = new Map()\n\n private constructor(iframeHandler: IframeHandler) {\n this.#localWindow = window\n this.#iframeHandler = iframeHandler\n\n this.#boundMessageHandler = this.#handleIncomingMessage.bind(this)\n this.#localWindow.addEventListener('message', this.#boundMessageHandler)\n }\n\n /**\n * Create a messageId to be used in a JSONRPC message and ensure it is unique.\n *\n * @returns A JsonRpcId\n */\n #getJsonRpcId(): number {\n const potentialId = getRandomNum(10000000000) + Date.now()\n\n // Ensure the id is unique and not already in the responseQueue or activeRequestId\n if (this.#responseQueue.has(potentialId)) {\n return this.#getJsonRpcId()\n }\n return potentialId\n }\n\n /**\n * close the TranseptorEthereumProvider\n */\n #close() {\n this.#iframeHandler.toggleFrameVisibility(false)\n }\n\n /**\n * resize the TranseptorEthereumProvider\n *\n * @param size - the size of the frame\n */\n #resize(size: FrameWidth) {\n this.#iframeHandler.resizeIframe(size)\n }\n\n /**\n * Handle incoming Post messages\n * Since the iframe is create locally, it will have the same origin as the dapp\n *\n * @param event - the PostMessageEvent sent from the iframe\n */\n async #handleIncomingMessage(event: MessageEvent<Message>) {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== this.#iframeHandler.getIframeOrigin()) {\n return\n }\n\n const message = event.data\n if (typeof message !== 'object') {\n return\n }\n\n const { isValid: isValidFatalError, fatalError } =\n fatalErrorValidator(message)\n if (isValidFatalError && fatalError) {\n this.#handleFatalError(fatalError)\n return\n }\n\n const { isValid: isValidEncryptedRequest, encryptedRequest } =\n encryptedMessageValidator(message)\n if (isValidEncryptedRequest && encryptedRequest) {\n await this.#handleIncomingEncryptedMessage(encryptedRequest)\n return\n }\n }\n\n /**\n * Handle a JsonRpcResponse and store it in the responseQueue\n *\n * @param response - the JsonRpcResponse to be handled\n */\n #handleJsonRpcResponse(response: JsonRpcResponse) {\n const { id } = response\n if (this.#responseQueue.has(Number(id))) {\n this.#responseQueue.set(Number(id), {\n status: 'fulfilled',\n response,\n })\n }\n }\n\n /**\n * Handle a InboundJsonRpcEventRequest and handle the event\n *\n * @param eventRequest - the JsonRpcEventRequest to be handled\n */\n #handleJsonRpcEvent(\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n ) {\n const { method } = eventRequest\n switch (method) {\n case 'wallet_paymentEvent':\n break\n case 'wallet_closeFrame':\n this.#close()\n break\n case 'wallet_disconnect':\n this.#disconnect()\n break\n case 'wallet_resizeFrameFull':\n this.#resize(FrameWidth.Full)\n break\n case 'wallet_resizeFrameDefault':\n this.#resize(FrameWidth.Default)\n break\n }\n }\n\n /**\n * Handle a SecureMessage and handle the message\n *\n * @param encryptedRequest - the SecureMessage to be handled\n */\n async #handleIncomingEncryptedMessage(\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted>,\n ) {\n const decryptedMessage =\n await this.#iframeHandler.decryptSecureMessage(encryptedRequest)\n\n const { isValid: isValidResponse, response } =\n jsonRpcResponseValidator(decryptedMessage)\n if (isValidResponse && response) {\n this.#handleJsonRpcResponse(response)\n return\n }\n\n const { isValid: isValidEventRequest, eventRequest } =\n inboundJsonRpcEventRequestValidator(decryptedMessage)\n if (isValidEventRequest && eventRequest) {\n this.#handleJsonRpcEvent(eventRequest)\n return\n }\n }\n\n /**\n * Handle a fatal error\n *\n * @param fatalError - the fatal error to be handled\n */\n #handleFatalError(fatalError: FatalError) {\n if (this.#responseQueue.size) {\n // loop through the responseQueue and set the status to failed\n this.#responseQueue.forEach((response) => {\n if (response.status === 'pending') {\n response.status = 'failed'\n response.fatalError = fatalError\n }\n })\n }\n }\n\n /**\n * Handles a JsonRpcRequest coming from the dapp\n * Request are handled synchronously(blocking) and requires immediate response from the user\n *\n * @param request - the JsonRpcRequest to be handled\n * @param requiresUserConsent - whether the user consent is required to show the iframe\n * @returns the response from the blobUrl IFrame\n */\n async #sendRequestToIframe(\n request: JsonRpcRequest,\n requiresUserConsent: boolean,\n ): Promise<JsonRpcResponse> {\n try {\n await this.#iframeHandler.prepareIframe()\n\n // show the iframe if the user consent is required otherwise the iframe will be hidden but can still response to requests\n if (requiresUserConsent) {\n this.#iframeHandler.toggleFrameVisibility(true)\n }\n\n const { id } = request\n this.#responseQueue.set(Number(id), {\n status: 'pending',\n response: undefined,\n })\n await this.#iframeHandler.sendMessageToIframe(request)\n\n // Wait for the user to respond from the IFrame\n return await this.#waitForResponse(Number(id))\n } catch (error: any) {\n if (error.message === this.FATAL_ERROR_MESSAGE) {\n this.#close()\n }\n return {\n jsonrpc: '2.0',\n id: request.id,\n error: {\n message: error.message,\n code: -32000,\n },\n }\n }\n }\n\n /**\n * Wait for a response from the user to be added to the responseQueue every second\n * max attempts is 300 or 5 minutes\n *\n * @param requestId - the id of the request\n * @param attempts - the number of attempts to wait for a response\n * @returns the response from the blobUrl IFrame\n */\n #waitForResponse(requestId: number, attempts = 300) {\n return new Promise<JsonRpcResponse>((_resolve, _reject) => {\n let counter = 0\n\n const intervalId = setInterval(() => {\n counter++\n\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n _reject(new Error('Max attempts reached waiting for response'))\n }\n\n // remove the response from the queue and resolve the promise\n const result = this.#responseQueue.get(requestId)\n if (result) {\n if (result.status === 'failed' && result.fatalError) {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _reject(new Error(result.fatalError.message))\n }\n\n if (result.status === 'fulfilled') {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _resolve(result.response as JsonRpcResponse)\n }\n }\n }, 1000) // 1 second\n })\n }\n\n /**\n * Disconnect the TranseptorEthereumProvider\n *\n * @returns true if the TranseptorEthereumProvider is disconnected successfully, false otherwise\n */\n #disconnect() {\n this.#iframeHandler.toggleFrameVisibility(false)\n this.#iframeHandler.disconnectIframe()\n this.#responseQueue = new Map()\n return true\n }\n\n /**\n * Generic request to the TranseptorEthereumProvider\n *\n * @param request - the request to be sent to the TranseptorEthereumProvider\n * @returns the response from the TranseptorEthereumProvider\n */\n async sendRequest(request: Eip1193RequestArguments): Promise<unknown> {\n const requestId = this.#getJsonRpcId()\n const requiresUserConsent = this.#rpcMethodsThatRequireUserConsent.includes(\n request.method,\n )\n\n switch (request.method) {\n case 'wallet_disconnect':\n this.#disconnect()\n return true\n case 'wallet_openHomePage':\n await this.#iframeHandler.prepareIframe()\n this.#iframeHandler.toggleFrameVisibility(true)\n await this.#iframeHandler.sendMessageToIframe({\n jsonrpc: '2.0',\n method: 'wallet_navigateToDashboardEvent',\n params: [],\n })\n return true\n default: {\n const result = await this.#sendRequestToIframe(\n {\n jsonrpc: '2.0',\n id: requestId,\n method: request.method,\n params: request.params || [],\n },\n requiresUserConsent,\n )\n if ('error' in result) {\n throw new ProviderRpcError({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data,\n })\n }\n return result.result\n }\n }\n }\n\n /**\n * Create a new instance of the TranseptorEthereumProvider\n *\n * @param config - the configuration for the TranseptorEthereumProvider\n * @returns the TranseptorEthereumProvider instance\n */\n static Create(\n config: TranseptorEthereumProviderConfig,\n ): TranseptorEthereumProvider {\n if (!TranseptorEthereumProvider.#instance) {\n const iframeHandler = createIframeHandler({\n parentOrigin: window.location.origin,\n devWalletUrl: config.devWalletUrl,\n })\n TranseptorEthereumProvider.#instance = new TranseptorEthereumProvider(\n iframeHandler,\n )\n }\n return TranseptorEthereumProvider.#instance\n }\n}\n", "export type ErrorDetails = {\n code: number\n message: string\n}\n\n/**\n * The EIP1193 error code enum\n */\nexport enum EIP1193_ERROR_CODES {\n /**\n * The user rejected the request.\n */\n USER_REJECTED_REQUEST = 4001,\n\n /**\n * The specified address is not connected or not in the wallet\n */\n UNAUTHORIZED = 4100,\n\n /**\n * The Provider does not support the requested method.\n */\n UNSUPPORTED_METHOD = 4200,\n\n /**\n * The Provider is disconnected from all chains.\n */\n DISCONNECTED = 4900,\n\n /**\n * The Provider is not connected to the requested chain.\n */\n CHAIN_DISCONNECTED = 4901,\n}\n\n/**\n * The ERC-7715 error code enum\n */\nexport enum ERC7715_ERROR_CODES {\n /**\n * The specified method is not authorized for the given origin\n * Related RPCs: wallet_requestConnection\n */\n UNAUTHORIZED_ACCESS_RESTRICTED_METHOD = 4101,\n}\n\n/**\n * The EIP5792 error code enum\n */\nexport enum EIP5792_ERROR_CODES {\n /**\n * This wallet does not support a capability that was not marked as optional\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_NON_OPTIONAL_CAPABILITY = 5700,\n\n /**\n * This wallet does not support the specified chain id\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_CHAIN_ID = 5710,\n\n /**\n * There is already a bundle submitted with this id\n * Related RPCs: wallet_sendCalls\n */\n DUPLICATE_BUNDLE_ID = 5720,\n\n /**\n * This bundle id is unknown / has not been submitted\n * Related RPCs: wallet_getCallsStatus, wallet_showCallsStatus\n */\n UNKNOWN_BUNDLE_ID = 5730,\n\n /**\n * The call bundle is too large for the wallet to process\n * Related RPCs: wallet_sendCalls\n */\n BUNDLE_TOO_LARGE = 5740,\n\n /**\n * The wallet can support atomicity after an upgrade, but the user rejected the upgrade\n * Related RPCs: wallet_sendCalls\n */\n ATOMIC_READY_WALLET_REJECTED_UPGRADE = 5750,\n\n /**\n * The wallet does not support atomic execution but the request requires it\n * Related RPCs: wallet_sendCalls\n */\n ATOMICITY_NOT_SUPPORTED = 5760,\n}\n\n/**\n * The fatal error code enum\n */\nexport enum FATAL_ERROR_CODES {\n INTERNAL_ERROR = -32001,\n}\n\nexport enum COMMON_ERROR_CODES {\n INVALID_PARAMS = -32602,\n}\n\n/**\n * The error code map\n */\nexport const ERROR_CODES_MAP: Record<\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n ErrorDetails\n> = {\n // EIP1193 errors\n [EIP1193_ERROR_CODES.USER_REJECTED_REQUEST]: {\n code: 4001,\n message: 'User rejected the request.',\n },\n [EIP1193_ERROR_CODES.UNAUTHORIZED]: {\n code: 4100,\n message:\n 'The requested method and/or account has not been authorized by the user.',\n },\n [EIP1193_ERROR_CODES.UNSUPPORTED_METHOD]: {\n code: 4200,\n message: 'The Provider does not support the requested method.',\n },\n [EIP1193_ERROR_CODES.DISCONNECTED]: {\n code: 4900,\n message: 'The Provider is disconnected from all chains.',\n },\n [EIP1193_ERROR_CODES.CHAIN_DISCONNECTED]: {\n code: 4901,\n message: 'The Provider is not connected to the requested chain.',\n },\n\n //ERC-7715 errors\n [ERC7715_ERROR_CODES.UNAUTHORIZED_ACCESS_RESTRICTED_METHOD]: {\n code: 4101,\n message:\n 'The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method.',\n },\n\n // EIP5792 errors\n [EIP5792_ERROR_CODES.UNSUPPORTED_NON_OPTIONAL_CAPABILITY]: {\n code: 5700,\n message:\n 'This wallet does not support a capability that was not marked as optional.',\n },\n [EIP5792_ERROR_CODES.UNSUPPORTED_CHAIN_ID]: {\n code: 5710,\n message: 'This wallet does not support the specified chain id.',\n },\n [EIP5792_ERROR_CODES.DUPLICATE_BUNDLE_ID]: {\n code: 5720,\n message: 'There is already a bundle submitted with this id.',\n },\n [EIP5792_ERROR_CODES.UNKNOWN_BUNDLE_ID]: {\n code: 5730,\n message: 'This bundle id is unknown / has not been submitted.',\n },\n [EIP5792_ERROR_CODES.BUNDLE_TOO_LARGE]: {\n code: 5740,\n message: 'The call bundle is too large for the wallet to process.',\n },\n [EIP5792_ERROR_CODES.ATOMIC_READY_WALLET_REJECTED_UPGRADE]: {\n code: 5750,\n message:\n 'The wallet can support atomicity after an upgrade, but the user rejected the upgrade.',\n },\n [EIP5792_ERROR_CODES.ATOMICITY_NOT_SUPPORTED]: {\n code: 5760,\n message:\n 'The wallet does not support atomic execution but the request requires it.',\n },\n\n // Fatal/Common errors\n [FATAL_ERROR_CODES.INTERNAL_ERROR]: {\n code: -32001,\n message: 'fatal: internal error',\n },\n [COMMON_ERROR_CODES.INVALID_PARAMS]: {\n code: 4002,\n message: 'Invalid parameters.',\n },\n}\n\n/**\n * Get the error message for a given error code\n *\n * @param code - The error code\n * @returns The error message\n * @throws {Error} if the error code is not found\n */\nexport const getErrorMessage = (\n code:\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n): ErrorDetails => {\n const details = ERROR_CODES_MAP[code]\n if (!details) {\n return {\n code,\n message: `Unknown error code: ${code}`,\n }\n }\n return details\n}\n", "import {\n Eip1193RequestArguments,\n Eip1193Provider,\n ProviderRpcError,\n} from './types.js'\nimport {\n TranseptorEthereumProvider,\n TranseptorEthereumProviderConfig,\n} from './transeptor-ethereum-provider.js'\nimport { getErrorMessage } from './errors.js'\n\nexport class Eip1193Bridge implements Eip1193Provider {\n #transeptorEthereumProvider: TranseptorEthereumProvider\n constructor(config: TranseptorEthereumProviderConfig) {\n this.#transeptorEthereumProvider = TranseptorEthereumProvider.Create(config)\n }\n\n async request(request: Eip1193RequestArguments) {\n try {\n return await this.#transeptorEthereumProvider.sendRequest(request)\n } catch (error: unknown) {\n if (error instanceof ProviderRpcError) {\n const errorDetails = getErrorMessage(error.code)\n if (errorDetails) {\n throw new ProviderRpcError(errorDetails)\n }\n }\n throw new ProviderRpcError({\n code: -32000,\n message: 'Unknown internal error',\n data: error,\n })\n }\n }\n}\n\n/**\n * Create a new Eip1193 provider\n *\n * @param config - the configuration for the TranseptorEthereumProvider\n * @returns the Eip1193 provider\n */\nexport function createEip1193Provider(\n config: TranseptorEthereumProviderConfig,\n): Eip1193Provider {\n return new Eip1193Bridge(config)\n}\n", "import { Eip1193Provider } from '../index.js'\n\nexport const enum ProviderEvent {\n AnnounceProvider = 'eip6963:announceProvider',\n RequestProvider = 'eip6963:requestProvider',\n}\n\n/**\n * Provider Detail defined by eip-6963\n */\nexport type EIP6963ProviderDetail = {\n info: {\n uuid: string\n name: string\n icon: string\n rdns: string\n }\n provider: Eip1193Provider\n}\n\n/**\n * Announce Event dispatched by a Wallet\n */\nexport interface EIP6963AnnounceProviderEvent extends CustomEvent {\n type: ProviderEvent.AnnounceProvider\n detail: EIP6963ProviderDetail\n}\n\n/**\n * Request Event dispatched by a DApp\n */\nexport interface EIP6963RequestProviderEvent extends Event {\n type: ProviderEvent.RequestProvider\n}\n", "/**\n * The icon of the Transeptor Pay wallet\n */\nexport const TRANSEPTOR_WALLET_ICON =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg=='\n", "import { TranseptorEthereumProviderConfig } from '../transeptor-ethereum-provider.js'\nimport { createEip1193Provider } from '../eip-1193-bridge.js'\nimport { EIP6963ProviderDetail, ProviderEvent } from './types.js'\nimport { TRANSEPTOR_WALLET_ICON } from './icon.js'\n\n/**\n * Announce the Transeptor Pay provider to the dapp\n *\n * @param config - the configuration for the TranseptorEthereumProvider\n */\nexport const announceProvider = (config: TranseptorEthereumProviderConfig) => {\n const provider = createEip1193Provider(config)\n const detail = Object.freeze({\n info: Object.freeze({\n uuid: '2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1',\n name: 'Transeptor',\n icon: TRANSEPTOR_WALLET_ICON,\n rdns: 'io.transeptor.pay',\n }),\n provider,\n } as EIP6963ProviderDetail)\n const announceEvent = new CustomEvent(ProviderEvent.AnnounceProvider, {\n detail,\n })\n\n // The Wallet dispatches an announce event which is heard by\n // the DApp code that had run earlier\n window.addEventListener(ProviderEvent.RequestProvider, () => {\n window.dispatchEvent(announceEvent)\n })\n\n // The Wallet listens to the request events which may be\n // dispatched later and re-dispatches the `EIP6963AnnounceProviderEvent`\n window.dispatchEvent(announceEvent)\n}\n"],
5
- "mappings": "AAAO,IAAMA,EAAN,cAA+B,KAAM,CAO1C,KAKA,KAEA,YAAY,CACV,QAAAC,EACA,KAAAC,EACA,KAAAC,CACF,EAIG,CACD,MAAMF,CAAO,EACb,KAAK,KAAOC,EACZ,KAAK,KAAOC,CACd,CACF,ECFO,IAAMC,EAAN,KAA2B,CACf,KAAO,CAAE,KAAM,OAAQ,WAAY,OAAQ,EAC5DC,GAAiB,GACjBC,GAAgC,CAC9B,QAAS,KACT,OAAQ,KACR,MAAO,IACT,EACAC,GAGI,CACF,KAAM,KACN,GAAI,EACN,EACAC,GAAY,EACZC,GAA6B,KAE7B,aAAc,CAEd,CAOAC,IAA2B,CACzB,GAAI,CAAC,KAAKL,GACR,MAAM,IAAI,MAAM,sBAAsB,CAE1C,CAOAM,IAA2C,CACzC,GAAI,CAAC,KAAKJ,GAAmB,GAC3B,MAAM,IAAI,MAAM,mCAAmC,CAEvD,CAOAK,IAAkC,CAChC,GAAI,CACF,GACE,OAAO,OAAW,KAClB,OAAO,OAAO,OAAW,KACzB,OAAO,OAAO,gBAAoB,KAClC,OAAO,OAAO,OAAO,YAAgB,KACrC,OAAO,OAAO,OAAO,QAAY,KACjC,OAAO,OAAO,OAAO,QAAY,IAEjC,OAEF,MAAM,IAAI,MAAM,8BAA8B,CAChD,OAASC,EAAO,CACd,MAAM,IAAI,MAAM,+BAAgC,CAAE,MAAOA,CAAM,CAAC,CAClE,CACF,CAOA,IAAI,+BAAyC,CAC3C,OAAO,KAAKN,GAAmB,EACjC,CAOA,MAAM,gBAAgC,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B,CACjB,IAAMC,EAAUH,EAAgBE,CAAI,EACpC,OAAKC,GACI,CACL,KAAAD,EACA,QAAS,uBAAuBA,CAAI,EACtC,CAGJ,ECzMO,IAAME,EAAN,KAA+C,CACpDC,GACA,YAAYC,EAA0C,CACpD,KAAKD,GAA8BE,EAA2B,OAAOD,CAAM,CAC7E,CAEA,MAAM,QAAQE,EAAkC,CAC9C,GAAI,CACF,OAAO,MAAM,KAAKH,GAA4B,YAAYG,CAAO,CACnE,OAASC,EAAgB,CACvB,GAAIA,aAAiBC,EAAkB,CACrC,IAAMC,EAAeC,EAAgBH,EAAM,IAAI,EAC/C,GAAIE,EACF,MAAM,IAAID,EAAiBC,CAAY,CAE3C,CACA,MAAM,IAAID,EAAiB,CACzB,KAAM,MACN,QAAS,yBACT,KAAMD,CACR,CAAC,CACH,CACF,CACF,EAQO,SAASI,EACdP,EACiB,CACjB,OAAO,IAAIF,EAAcE,CAAM,CACjC,CC5CO,IAAWQ,OAChBA,EAAA,iBAAmB,2BACnBA,EAAA,gBAAkB,0BAFFA,OAAA,ICCX,IAAMC,EACX,i+BCMK,IAAMC,EAAoBC,GAA6C,CAC5E,IAAMC,EAAWC,EAAsBF,CAAM,EACvCG,EAAS,OAAO,OAAO,CAC3B,KAAM,OAAO,OAAO,CAClB,KAAM,uCACN,KAAM,aACN,KAAMC,EACN,KAAM,mBACR,CAAC,EACD,SAAAH,CACF,CAA0B,EACpBI,EAAgB,IAAI,uCAA4C,CACpE,OAAAF,CACF,CAAC,EAID,OAAO,2CAAgD,IAAM,CAC3D,OAAO,cAAcE,CAAa,CACpC,CAAC,EAID,OAAO,cAAcA,CAAa,CACpC",
6
- "names": ["ProviderRpcError", "message", "code", "data", "EphemeralEcdhManager", "#isInitialized", "#ephemeralEcdh", "#isKeyExchangeDone", "#sequence", "#aeadKey", "#assertInitialized", "#assertSecureConnectionEstablished", "#assertWebCryptoAvailable", "error", "keyPair", "pubJwk", "nonce", "message", "pub", "recipientPub", "bits", "baseKey", "salt", "data", "iv", "additionalData", "dataBytes", "cipherText", "ok", "role", "jsonRpcResponseValidator", "message", "response", "inboundJsonRpcEventRequestValidator", "eventRequest", "jsonRpcKeyExchangeResponseValidator", "keyExchangeResponse", "jsonRpcKeyExchangeDoneValidator", "keyExchangeDone", "encryptedMessageValidator", "encryptedRequest", "fatalErrorValidator", "fatalError", "isMobile", "resizeFrameWidth", "iframeId", "frameWidth", "frameHeight", "iframe", "showIframe", "overlay", "hideIframe", "doToggleIframeVisibility", "overlayId", "isVisible", "appendIframeWithContainer", "url", "destroyIframeWithContainer", "createIframeHandler", "config", "ecdhManager", "EphemeralEcdhManager", "devWalletUrl", "IFRAME_ORIGIN", "params", "walletUrl", "DAPP_IFRAME_ID", "OVERLAY_CONTAINER_ID", "activeFrameWidth", "activeFrameHeight", "isIframeCreated", "handleOverlayClick", "event", "overlay", "doToggleIframeVisibility", "getIframeContentWindow", "iframe", "checkIframeReady", "attempts", "childWindow", "isFrameReady", "handleReady", "_resolve", "_reject", "counter", "intervalId", "establishSecureConnectionWithIframe", "keyExchangeMessage", "keyExchangeResponseMessage", "keyExchangeDoneMessage", "message", "isValidKeyExchangeResponse", "keyExchangeResponse", "jsonRpcKeyExchangeResponseValidator", "isValidKeyExchangeDone", "keyExchangeDone", "jsonRpcKeyExchangeDoneValidator", "isMobile", "appendIframeWithContainer", "isIframeReady", "destroyIframeWithContainer", "isVisible", "resizeFrameWidth", "size", "request", "encryptedRequest", "decryptedMessage", "passedDecryption", "getRandomNum", "maxRange", "rand", "rn", "TranseptorEthereumProvider", "_TranseptorEthereumProvider", "#instance", "#localWindow", "#boundMessageHandler", "#rpcMethodsThatRequireUserConsent", "#iframeHandler", "#responseQueue", "iframeHandler", "#handleIncomingMessage", "#getJsonRpcId", "potentialId", "getRandomNum", "#close", "#resize", "size", "event", "message", "isValidFatalError", "fatalError", "fatalErrorValidator", "#handleFatalError", "isValidEncryptedRequest", "encryptedRequest", "encryptedMessageValidator", "#handleIncomingEncryptedMessage", "#handleJsonRpcResponse", "response", "id", "#handleJsonRpcEvent", "eventRequest", "method", "#disconnect", "decryptedMessage", "isValidResponse", "jsonRpcResponseValidator", "isValidEventRequest", "inboundJsonRpcEventRequestValidator", "#sendRequestToIframe", "request", "requiresUserConsent", "#waitForResponse", "error", "requestId", "attempts", "_resolve", "_reject", "counter", "intervalId", "result", "ProviderRpcError", "config", "createIframeHandler", "ERROR_CODES_MAP", "getErrorMessage", "code", "details", "Eip1193Bridge", "#transeptorEthereumProvider", "config", "TranseptorEthereumProvider", "request", "error", "ProviderRpcError", "errorDetails", "getErrorMessage", "createEip1193Provider", "ProviderEvent", "TRANSEPTOR_WALLET_ICON", "announceProvider", "config", "provider", "createEip1193Provider", "detail", "TRANSEPTOR_WALLET_ICON", "announceEvent"]
3
+ "sources": ["../src/provider/types.ts", "../src/ecdh/ecdh-manager.ts", "../src/utils/validate.ts", "../src/iframe/iframe.ts", "../src/iframe/iframe-handler.ts", "../src/utils/random.ts", "../src/provider/cashie-ethereum-provider.ts", "../src/provider/errors.ts", "../src/provider/eip-1193-bridge.ts", "../src/provider/eip-6963/types.ts", "../src/provider/eip-6963/icon.ts", "../src/provider/eip-6963/announce-provider.ts"],
4
+ "sourcesContent": ["export class ProviderRpcError extends Error {\n /**\n * MUST be an integer number\n * SHOULD adhere to the specifications in the Error Standards section below\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#error-standards\n */\n code: number\n\n /**\n * SHOULD contain any other useful information about the error\n */\n data?: unknown\n\n constructor({\n message,\n code,\n data,\n }: {\n message: string\n code: number\n data?: unknown\n }) {\n super(message)\n this.code = code\n this.data = data\n }\n}\n\n/**\n * The Eip1193 error types\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#rpc-errors\n */\nexport type Eip1193Error =\n | 'userRejectedRequest'\n | 'unauthorized'\n | 'unsupportedMethod'\n | 'disconnected'\n | 'chainDisconnected'\n\nexport type Eip1193RequestArguments = {\n method: string\n params?: readonly unknown[] | object\n}\n\nexport interface Eip1193Provider {\n /**\n * Request a method from the Eip1193 provider\n *\n * @param request - the request to be sent to the Eip1193 provider\n * @returns the response from the Eip1193 provider\n *\n * @throws {Error} If the returned Promise rejects, it MUST reject with a ProviderRpcError as specified in the [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193#rpc-errors) section below.\n */\n request: (request: Eip1193RequestArguments) => Promise<unknown>\n}\n\n/**\n * The message event is intended for arbitrary notifications not covered by other events.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#message-event\n */\nexport type Eip1193ProviderMessage = {\n readonly type: string\n readonly data: unknown\n}\n\n/**\n * Specify the integer ID of the connected chain as a hexadecimal string, per the eth_chainId Ethereum RPC method.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider_connect\n */\nexport type Eip1193ProviderConnectInfo = {\n readonly chainId: `0x${string}`\n}\n", "/* eslint-disable no-console */\nimport { SecureMessageType, SecureMessage } from './ecdh.types.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n JsonRpcErrorResponse,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n} from '../types/index.js'\n\n/**\n * Ephemeral ECDH key pair(private key, public key), public key(public key in jwk format), and nonce\n */\nexport type EphemeralEcdh = {\n keyPair: CryptoKeyPair | null\n pubJwk: JsonWebKey | null\n nonce: Uint8Array | null\n}\n\n/**\n * Create a new ephemeral ECDH manager\n * The ECDH(Elliptic Curve Diffie\u2013Hellman) key exchange manager is used to generate a shared secret key to encrypt and decrypt secure messages between the two parties on an untrusted channel.\n */\nexport class EphemeralEcdhManager {\n private readonly ALGO = { name: 'ECDH', namedCurve: 'P-256' }\n #isInitialized = false\n #ephemeralEcdh: EphemeralEcdh = {\n keyPair: null,\n pubJwk: null,\n nonce: null,\n }\n #isKeyExchangeDone: {\n role: 'parent' | 'iframe' | null\n ok: boolean\n } = {\n role: null,\n ok: false,\n }\n #sequence = 0\n #aeadKey: CryptoKey | null = null\n\n constructor() {\n // empty constructor\n }\n\n /**\n * Assert that the ECDH is initialized\n *\n * @throws {Error} if the ECDH is not initialized\n */\n #assertInitialized(): void {\n if (!this.#isInitialized) {\n throw new Error('ECDH not initialized')\n }\n }\n\n /**\n * Assert that the secure connection is established\n *\n * @throws {Error} if the secure connection is not established\n */\n #assertSecureConnectionEstablished(): void {\n if (!this.#isKeyExchangeDone.ok) {\n throw new Error('Secure connection not established')\n }\n }\n\n /**\n * Check if Web Crypto API is available and properly configured\n *\n * @throws {Error} if Web Crypto API is not available\n */\n #assertWebCryptoAvailable(): void {\n try {\n if (\n typeof crypto !== 'undefined' &&\n typeof crypto.subtle !== 'undefined' &&\n typeof crypto.getRandomValues !== 'undefined' &&\n typeof crypto.subtle.generateKey !== 'undefined' &&\n typeof crypto.subtle.encrypt !== 'undefined' &&\n typeof crypto.subtle.decrypt !== 'undefined'\n ) {\n return\n }\n throw new Error('Web Crypto API not available')\n } catch (error) {\n throw new Error('Web Crypto API not available', { cause: error })\n }\n }\n\n /**\n * Check if the secure connection is established\n *\n * @returns true if the secure connection is established, false otherwise\n */\n get isSecureConnectionEstablished(): boolean {\n return this.#isKeyExchangeDone.ok\n }\n\n /**\n * Initialize the ECDH\n *\n * @returns void\n */\n async initializeEcdh(): Promise<void> {\n this.#assertWebCryptoAvailable()\n const keyPair = await crypto.subtle.generateKey(this.ALGO, true, [\n 'deriveBits',\n ])\n const pubJwk = await crypto.subtle.exportKey('jwk', keyPair.publicKey)\n const nonce = crypto.getRandomValues(new Uint8Array(16))\n\n this.#ephemeralEcdh = {\n keyPair,\n pubJwk,\n nonce,\n } as EphemeralEcdh\n this.#isInitialized = true\n }\n\n /**\n * Parse a key exchange message to generate a shared secret\n *\n * @param message - the key exchange response message\n * @returns void\n */\n async parseKeyExchangeMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeResponse>,\n ): Promise<void> {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n\n // Extract the public key and nonce from the message\n const { pub, nonce } = message.payload\n const recipientPub = await crypto.subtle.importKey(\n 'jwk',\n pub,\n this.ALGO,\n false,\n [],\n )\n\n // Compute a shared secret using the recipient's public key and the ephemeral private key pair\n const bits = await crypto.subtle.deriveBits(\n { name: this.ALGO.name, public: recipientPub },\n this.#ephemeralEcdh.keyPair.privateKey,\n 256,\n )\n const baseKey = await crypto.subtle.importKey('raw', bits, 'HKDF', false, [\n 'deriveKey',\n ])\n\n // Derive the salt with format <parent-nonce,child-nonce>\n // Note: This must match the iframe's salt ordering for consistent key derivation\n const salt = new Uint8Array([\n ...this.#ephemeralEcdh.nonce,\n ...new Uint8Array(nonce),\n ])\n\n // Derive the AEAD key from the base key and the salt that will be used to encrypt/decrypt the messages between the both parties\n this.#aeadKey = await crypto.subtle.deriveKey(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n salt,\n info: new TextEncoder().encode('cashie-connect'),\n },\n baseKey,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt'],\n )\n }\n\n /**\n * Generate a key exchange message\n *\n * @returns the key exchange message\n */\n async generateKeyExchangeMessage(): Promise<\n SecureMessage<SecureMessageType.KeyExchangeInit>\n > {\n this.#assertInitialized()\n if (!this.#ephemeralEcdh.pubJwk) {\n throw new Error('Ephemeral public key not initialized')\n }\n if (!this.#ephemeralEcdh.nonce) {\n throw new Error('Ephemeral nonce not initialized')\n }\n if (!this.#ephemeralEcdh.keyPair) {\n throw new Error('Ephemeral keys not initialized')\n }\n\n return {\n type: SecureMessageType.KeyExchangeInit,\n payload: {\n pub: this.#ephemeralEcdh.pubJwk,\n nonce: Array.from<number>(this.#ephemeralEcdh.nonce),\n },\n }\n }\n\n /**\n * Prepare a secure message\n *\n * @param data - the data to be prepared\n * @returns the secure message\n */\n async prepareSecureMessage(\n data:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ): Promise<SecureMessage<SecureMessageType.Encrypted>> {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n // Increment the sequence number\n this.#sequence++\n\n // Encrypt the data with the AEAD key given by the child iframe to ensure only the child iframe can decrypt the message\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const additionalData = new TextEncoder().encode(`seq:${this.#sequence}`)\n const dataBytes = new TextEncoder().encode(JSON.stringify(data))\n const cipherText = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv, additionalData },\n this.#aeadKey,\n dataBytes,\n ),\n )\n\n return {\n type: SecureMessageType.Encrypted,\n payload: {\n iv: Array.from<number>(iv),\n cipherText: Array.from<number>(cipherText),\n additionalData: Array.from<number>(additionalData),\n },\n }\n }\n\n /**\n * Decrypt a secure message sent by the child iframe\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted data\n */\n async decryptSecureMessage(\n message: SecureMessage<SecureMessageType.Encrypted>,\n ): Promise<{\n decryptedMessage:\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n | null\n passedDecryption: boolean\n }> {\n try {\n this.#assertInitialized()\n this.#assertSecureConnectionEstablished()\n if (!this.#aeadKey) {\n throw new Error('AEAD key not initialized')\n }\n\n const { iv, cipherText, additionalData } = message.payload\n\n if (!iv || !cipherText || !additionalData) {\n throw new Error('Invalid message payload: missing required fields')\n }\n\n if (\n !Array.isArray(iv) ||\n !Array.isArray(cipherText) ||\n !Array.isArray(additionalData)\n ) {\n throw new Error('Invalid message payload: fields must be arrays')\n }\n\n const dataBytes = await crypto.subtle.decrypt(\n {\n name: 'AES-GCM',\n iv: new Uint8Array(iv),\n additionalData: new Uint8Array(additionalData),\n },\n this.#aeadKey,\n new Uint8Array(cipherText),\n )\n const decryptedMessage = JSON.parse(new TextDecoder().decode(dataBytes))\n return {\n decryptedMessage,\n passedDecryption: true,\n }\n } catch (error) {\n console.error('Error decrypting secure message from iframe', error)\n return {\n decryptedMessage: null,\n passedDecryption: false,\n }\n }\n }\n\n /**\n * Parse a key exchange done message\n *\n * @param message - the key exchange done message\n */\n parseKeyExchangeDoneMessage(\n message: SecureMessage<SecureMessageType.KeyExchangeDone>,\n ): void {\n this.#assertInitialized()\n const { ok, role } = message.payload\n if (ok) {\n this.#isKeyExchangeDone = {\n role,\n ok,\n }\n }\n }\n\n /**\n * Generate a key exchange done message\n *\n * @returns the key exchange done message\n */\n generateKeyExchangeDoneMessage(): SecureMessage<SecureMessageType.KeyExchangeDone> {\n return {\n type: SecureMessageType.KeyExchangeDone,\n payload: {\n ok: true,\n role: 'parent',\n },\n }\n }\n\n /**\n * Close the secure connection\n *\n */\n closeSecureConnection(): void {\n this.#isKeyExchangeDone = {\n role: null,\n ok: false,\n }\n this.#aeadKey = null\n }\n}\n", "import {\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcResponse,\n FatalError,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/ecdh.types.js'\n\ntype JsonRpcResponseValidator = {\n isValid: boolean\n response: JsonRpcResponse | null\n}\n\ntype JsonRpcEventRequestValidator = {\n isValid: boolean\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames> | null\n}\n\ntype JsonRpcKeyExchangeResponseValidator = {\n isValid: boolean\n keyExchangeResponse: SecureMessage<SecureMessageType.KeyExchangeResponse> | null\n}\n\ntype JsonRpcKeyExchangeDoneValidator = {\n isValid: boolean\n keyExchangeDone: SecureMessage<SecureMessageType.KeyExchangeDone> | null\n}\n\ntype EncryptedRequestValidator = {\n isValid: boolean\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted> | null\n}\n\ntype FatalErrorValidator = {\n isValid: boolean\n fatalError: FatalError | null\n}\n\n/**\n * Validate a JSON-RPC response\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcResponseValidator = (\n message: unknown,\n): JsonRpcResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, response: null }\n }\n const response = message as JsonRpcResponse\n if (response.jsonrpc !== '2.0') {\n return { isValid: false, response: null }\n }\n\n if (response.id === null || response.id === undefined) {\n return { isValid: false, response: null }\n }\n\n if (response && ('result' in response || 'error' in response)) {\n return { isValid: true, response: response as JsonRpcResponse }\n }\n\n return {\n isValid: true,\n response: response as JsonRpcResponse,\n }\n}\n\n/**\n * Validate a JSON-RPC event request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const inboundJsonRpcEventRequestValidator = (\n message: unknown,\n): JsonRpcEventRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, eventRequest: null }\n }\n const eventRequest =\n message as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n if (eventRequest.jsonrpc !== '2.0') {\n return { isValid: false, eventRequest: null }\n }\n if (!eventRequest.method) {\n return { isValid: false, eventRequest: null }\n }\n\n if (!('params' in eventRequest)) {\n return {\n isValid: false,\n eventRequest: null,\n }\n }\n\n return {\n isValid: true,\n eventRequest:\n eventRequest as InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange response request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeResponseValidator = (\n message: unknown,\n): JsonRpcKeyExchangeResponseValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeResponse: null }\n }\n const keyExchangeResponse =\n message as SecureMessage<SecureMessageType.KeyExchangeResponse>\n if (keyExchangeResponse.type !== SecureMessageType.KeyExchangeResponse) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.pub) {\n return { isValid: false, keyExchangeResponse: null }\n }\n if (!keyExchangeResponse.payload.nonce) {\n return { isValid: false, keyExchangeResponse: null }\n }\n return {\n isValid: true,\n keyExchangeResponse:\n keyExchangeResponse as SecureMessage<SecureMessageType.KeyExchangeResponse>,\n }\n}\n\n/**\n * Validate a JSON-RPC key exchange done request\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const jsonRpcKeyExchangeDoneValidator = (\n message: unknown,\n): JsonRpcKeyExchangeDoneValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, keyExchangeDone: null }\n }\n const keyExchangeDone =\n message as SecureMessage<SecureMessageType.KeyExchangeDone>\n if (keyExchangeDone.type !== SecureMessageType.KeyExchangeDone) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.ok) {\n return { isValid: false, keyExchangeDone: null }\n }\n if (!keyExchangeDone.payload.role) {\n return { isValid: false, keyExchangeDone: null }\n }\n\n return {\n isValid: true,\n keyExchangeDone:\n keyExchangeDone as SecureMessage<SecureMessageType.KeyExchangeDone>,\n }\n}\n\n/**\n * Validate a JSON-RPC encrypted message\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const encryptedMessageValidator = (\n message: unknown,\n): EncryptedRequestValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, encryptedRequest: null }\n }\n const encryptedRequest = message as SecureMessage<SecureMessageType.Encrypted>\n if (encryptedRequest.type !== SecureMessageType.Encrypted) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.iv) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.cipherText) {\n return { isValid: false, encryptedRequest: null }\n }\n if (!encryptedRequest.payload.additionalData) {\n return { isValid: false, encryptedRequest: null }\n }\n return {\n isValid: true,\n encryptedRequest:\n encryptedRequest as SecureMessage<SecureMessageType.Encrypted>,\n }\n}\n\n/**\n * Validate a fatal error\n *\n * @param message - The message to be validated\n * @returns The validated request\n */\nexport const fatalErrorValidator = (message: unknown): FatalErrorValidator => {\n if (typeof message !== 'object' || message === null) {\n return { isValid: false, fatalError: null }\n }\n const fatalError = message as FatalError\n if (!fatalError.code) {\n return { isValid: false, fatalError: null }\n }\n if (!fatalError.message) {\n return { isValid: false, fatalError: null }\n }\n return { isValid: true, fatalError: fatalError as FatalError }\n}\n", "/**\n * Frame width enum\n */\nexport enum FrameWidth {\n Default = '412px',\n Full = '100%',\n}\n\nexport enum FrameHeight {\n Default = '640px',\n Full = '100%',\n}\n\n/**\n * Check if the device is mobile\n *\n * @returns true if the device is mobile, false otherwise\n */\nexport const isMobile = () => {\n return window.innerWidth < 768\n}\n\n/**\n * Resize the iframe container and iframe element width\n *\n * @param iframeId - the id of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const resizeFrameWidth = (\n iframeId: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n const iframe = document.getElementById(iframeId)\n\n if (iframe) {\n iframe.style.width = frameWidth\n iframe.style.height = frameHeight\n }\n}\n\n/**\n * Show the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst showIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)' // Scale in\n}\n\n/**\n * Hide the iframe\n *\n * @param overlay - the overlay element\n * @param iframe - the iframe element\n */\nconst hideIframe = (overlay: HTMLElement, iframe: HTMLElement) => {\n overlay.style.opacity = '0'\n overlay.style.pointerEvents = 'none'\n iframe.style.opacity = '0'\n iframe.style.transform = 'scale(0.8)' // Scale out\n}\n\n/**\n * Toggle the visibility of the iframe\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param isVisible - the visibility of the iframe\n */\nexport const doToggleIframeVisibility = (\n iframeId: string,\n overlayId: string,\n isVisible: boolean,\n) => {\n const iframe = document.getElementById(iframeId)\n const overlay = document.getElementById(overlayId)\n if (!iframe || !overlay) {\n return\n }\n\n document.body.style.overflow = isVisible ? 'hidden' : 'auto'\n if (isVisible) {\n showIframe(overlay, iframe)\n } else {\n hideIframe(overlay, iframe)\n }\n}\n\n/**\n * Append the iframe to the container div\n *\n * @param iframeId - the id of the iframe\n * @param overlayId - the id of the overlay container\n * @param url - the url of the iframe\n * @param frameWidth - the width of the iframe\n * @param frameHeight - the height of the iframe\n */\nexport const appendIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n url: string,\n frameWidth: FrameWidth,\n frameHeight: FrameHeight,\n) => {\n // Create overlay container\n const overlay = document.createElement('div')\n overlay.id = overlayId\n Object.assign(overlay.style, {\n position: 'fixed',\n top: '0',\n left: '0',\n width: '100%',\n height: '100%',\n background: 'rgba(0, 0, 0, 0.4)',\n backdropFilter: 'blur(4px)',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n zIndex: '9999',\n opacity: '1',\n pointerEvents: 'none', // Disable interactions when hidden\n cursor: 'default', // Default cursor for overlay background\n transition: 'opacity 0.3s ease-in-out',\n })\n\n const iframe = document.createElement('iframe')\n iframe.id = iframeId\n iframe.src = url\n iframe.allow = 'publickey-credentials-get *; publickey-credentials-create *'\n Object.assign(iframe.style, {\n height: frameHeight,\n width: frameWidth,\n position: 'relative',\n borderRadius: '0.75rem',\n boxShadow:\n '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)',\n overflowY: 'auto',\n zIndex: '1000',\n opacity: '1',\n transform: 'scale(0.8)',\n transition: 'opacity 0.3s ease-in-out, transform 0.3s ease-in-out',\n })\n\n overlay.appendChild(iframe)\n document.body.appendChild(overlay)\n\n // Ensure styles are applied after DOM insertion\n setTimeout(() => {\n overlay.style.opacity = '1'\n overlay.style.pointerEvents = 'auto'\n iframe.style.opacity = '1'\n iframe.style.transform = 'scale(1)'\n }, 100) // Small delay to trigger transition\n\n // Prevent scrolling while overlay is open\n document.body.style.overflow = 'hidden'\n}\n\n/**\n * Destroy the iframe element and remove it from the DOM\n *\n * @param iframeId - the id of the iframe to be destroyed\n * @param overlayId - the id of the overlay container\n */\nexport const destroyIframeWithContainer = (\n iframeId: string,\n overlayId: string,\n) => {\n const overlay = document.getElementById(overlayId)\n if (overlay) {\n overlay.parentNode?.removeChild(overlay)\n document.body.style.overflow = 'auto' // Restore scrolling\n }\n const iframe = document.getElementById(iframeId)\n if (iframe) {\n if (iframe.parentNode) {\n iframe.parentNode.removeChild(iframe)\n }\n }\n}\n", "/* eslint-disable no-console */\nimport {\n EphemeralEcdhManager,\n SecureMessage,\n SecureMessageType,\n} from '../ecdh/index.js'\nimport {\n JsonRpcRequest,\n OutboundJsonRpcEventRequest,\n OutboundRpcRequestEventsMethodNames,\n InboundJsonRpcEventRequest,\n InboundRpcRequestEventsMethodNames,\n JsonRpcErrorResponse,\n JsonRpcResponse,\n} from '../types/index.js'\nimport {\n jsonRpcKeyExchangeResponseValidator,\n jsonRpcKeyExchangeDoneValidator,\n} from '../utils/validate.js'\nimport {\n appendIframeWithContainer,\n destroyIframeWithContainer,\n doToggleIframeVisibility,\n FrameHeight,\n FrameWidth,\n isMobile,\n resizeFrameWidth,\n} from './iframe.js'\n\n/**\n * Iframe handler interface\n */\nexport type IframeHandler = {\n /**\n * Create a new iframe element and append it to the container div if it is not already created\n * Establish a secure connection with the iframe\n *\n * @returns void\n */\n prepareIframe: () => Promise<void>\n\n /**\n * Disconnect the iframe by closing the secure connection and destroying the iframe container and iframe element\n *\n */\n disconnectIframe: () => void\n\n /**\n * Toggle the visibility of the iframe\n *\n * @param isVisible - the visibility of the iframe\n * @returns void\n */\n toggleFrameVisibility: (isVisible: boolean) => void\n\n /**\n * Send a message to the iframe\n *\n * @param request - the request to be sent to the iframe\n */\n sendMessageToIframe: (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => Promise<void>\n\n /**\n * Resize the iframe\n *\n * @param size - the size of the iframe\n * @returns void\n */\n resizeIframe: (size?: FrameWidth) => void\n\n /**\n * Get the origin of the iframe\n *\n * @returns the origin of the iframe\n */\n getIframeOrigin: () => string\n\n /**\n * Decrypt a secure message\n *\n * @param message - the secure message to be decrypted\n * @returns the decrypted message\n */\n decryptSecureMessage: (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => Promise<\n | JsonRpcResponse\n | JsonRpcErrorResponse\n | InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>\n >\n}\n\ntype IframeHandlerConfig = {\n /**\n * The origin of the parent window\n */\n parentOrigin: string\n\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string | undefined\n}\n\n/**\n * Create a new iframe handler\n *\n * @param config - the iframe handler config\n * @returns the iframe handler\n */\nexport const createIframeHandler = (\n config: IframeHandlerConfig,\n): IframeHandler => {\n const ecdhManager = new EphemeralEcdhManager()\n const { devWalletUrl } = config\n const IFRAME_ORIGIN = devWalletUrl || 'https://pay.transeptorlabs.io'\n const params = new URLSearchParams({ embedded: 'true' }).toString()\n const walletUrl = devWalletUrl\n ? `${devWalletUrl}?${params}`\n : `https://pay.transeptorlabs.io/?${params}`\n const DAPP_IFRAME_ID = 'dapp:iframe-embedded-payment'\n const OVERLAY_CONTAINER_ID = 'dapp:iframe-container'\n\n let activeFrameWidth = FrameWidth.Default\n let activeFrameHeight = FrameHeight.Default\n let isIframeCreated = false\n\n /**\n * Handle the overlay click event\n *\n * @param event - the mouse event\n */\n const handleOverlayClick = (event: MouseEvent) => {\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n if (event.target === overlay) {\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, false)\n }\n }\n }\n\n /**\n * Get the content window of the iframe\n *\n * @returns the content window of the iframe\n */\n const getIframeContentWindow = (): Window | null => {\n const iframe = document.getElementById(DAPP_IFRAME_ID)\n if (!iframe) {\n throw new Error('Iframe not found')\n }\n const hasContentWindow = 'contentWindow' in iframe\n if (hasContentWindow) {\n const childWindow = iframe.contentWindow as Window\n return childWindow\n }\n return null\n }\n\n /**\n * Send a post message to the IFrame window to check if it is ready and to inform the iframe of the parent origin extracted from message event\n * Waits for the frame to be ready before sending the message.\n * max attempts is 600\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns true if the frame is ready, false otherwise will reject with an error\n */\n const checkIframeReady = async (attempts = 600) => {\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n let isFrameReady = false\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n if (message === 'pong') {\n isFrameReady = true\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n return new Promise<boolean>((_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max ping attempts reached to establish connection with the iframe',\n ),\n )\n }\n\n // resolve if the frame is ready\n if (isFrameReady) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n console.log('Iframe is ready to receive messages')\n _resolve(true)\n } else {\n console.log('Sending ping to the iframe to check if it is ready')\n childWindow.postMessage('ping', IFRAME_ORIGIN)\n }\n }, 500) // 500ms\n })\n }\n\n /**\n * Establish a secure connection with the iframe\n *\n * @param attempts - the number of attempts to wait for a response\n * @returns the key exchange response message if the secure connection is established, null otherwise will reject with an error\n */\n const establishSecureConnectionWithIframe = async (attempts = 600) => {\n console.log('Establishing secure connection with the iframe')\n const childWindow = getIframeContentWindow()\n if (!childWindow) {\n throw new Error('Iframe not found')\n }\n\n // Generate key exchange messages\n const keyExchangeMessage = await ecdhManager.generateKeyExchangeMessage()\n let keyExchangeResponseMessage: SecureMessage<SecureMessageType.KeyExchangeResponse> | null =\n null\n let keyExchangeDoneMessage: SecureMessage<SecureMessageType.KeyExchangeDone> | null =\n null\n\n const handleReady = (event: MessageEvent) => {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== IFRAME_ORIGIN) {\n return\n }\n\n const message = event.data\n const { isValid: isValidKeyExchangeResponse, keyExchangeResponse } =\n jsonRpcKeyExchangeResponseValidator(message)\n if (isValidKeyExchangeResponse && keyExchangeResponse) {\n childWindow.postMessage(\n ecdhManager.generateKeyExchangeDoneMessage(),\n IFRAME_ORIGIN,\n )\n keyExchangeResponseMessage = message\n return\n }\n\n const { isValid: isValidKeyExchangeDone, keyExchangeDone } =\n jsonRpcKeyExchangeDoneValidator(message)\n if (isValidKeyExchangeDone && keyExchangeDone) {\n keyExchangeDoneMessage = message\n return\n }\n }\n\n window.addEventListener('message', handleReady.bind(this))\n\n childWindow.postMessage(keyExchangeMessage, IFRAME_ORIGIN)\n\n return new Promise<SecureMessage<SecureMessageType.KeyExchangeResponse>>(\n (_resolve, _reject) => {\n let counter = 0\n const intervalId = setInterval(() => {\n counter++\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n _reject(\n new Error(\n 'Max secure connection attempts reached to establish secure connection with the iframe',\n ),\n )\n }\n\n // resolve if the secure connection is established\n if (keyExchangeResponseMessage && keyExchangeDoneMessage) {\n clearInterval(intervalId)\n window.removeEventListener('message', handleReady.bind(this))\n ecdhManager.parseKeyExchangeDoneMessage(keyExchangeDoneMessage)\n _resolve(keyExchangeResponseMessage)\n }\n }, 200) // 200ms\n },\n )\n }\n\n return {\n getIframeOrigin: () => IFRAME_ORIGIN,\n\n prepareIframe: async () => {\n // Append the iframe to the DOM and add event listener to close overlay when clicking outside the iframe\n if (!isIframeCreated) {\n console.log('Appending iframe to the DOM')\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n appendIframeWithContainer(\n DAPP_IFRAME_ID,\n OVERLAY_CONTAINER_ID,\n walletUrl,\n activeFrameWidth,\n activeFrameHeight,\n )\n\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.addEventListener('click', handleOverlayClick)\n }\n isIframeCreated = true\n }\n\n // Establish connection and start key exchange\n if (!ecdhManager.isSecureConnectionEstablished) {\n const isIframeReady = await checkIframeReady()\n const childWindow = getIframeContentWindow()\n if (!childWindow && !isIframeReady) {\n throw new Error(\n 'Iframe content window not found, cannot start key exchange',\n )\n }\n // Initialize the ECDH manager\n await ecdhManager.initializeEcdh()\n\n // Establish secure connection with the iframe\n const keyExchangeResponseMessage =\n await establishSecureConnectionWithIframe()\n\n // Parse the key exchange response message from the iframe\n await ecdhManager.parseKeyExchangeMessage(keyExchangeResponseMessage)\n }\n },\n\n disconnectIframe: () => {\n if (!isIframeCreated) {\n return\n }\n\n if (!ecdhManager.isSecureConnectionEstablished) {\n return\n }\n\n ecdhManager.closeSecureConnection()\n destroyIframeWithContainer(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID)\n const overlay = document.getElementById(OVERLAY_CONTAINER_ID)\n if (overlay) {\n overlay.removeEventListener('click', handleOverlayClick)\n }\n isIframeCreated = false\n\n console.log(\n 'Secure connection closed with the iframe removed from the DOM',\n {\n isSecureConnectionEstablished:\n ecdhManager.isSecureConnectionEstablished,\n isIframeCreated: isIframeCreated,\n },\n )\n },\n\n toggleFrameVisibility: (isVisible) => {\n if (!isIframeCreated) {\n return\n }\n\n doToggleIframeVisibility(DAPP_IFRAME_ID, OVERLAY_CONTAINER_ID, isVisible)\n\n activeFrameWidth = isMobile() ? FrameWidth.Full : FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n resizeIframe: (size?: FrameWidth) => {\n if (!isIframeCreated) {\n return\n }\n\n activeFrameWidth = isMobile()\n ? FrameWidth.Full\n : size || FrameWidth.Default\n activeFrameHeight = isMobile() ? FrameHeight.Full : FrameHeight.Default\n resizeFrameWidth(DAPP_IFRAME_ID, activeFrameWidth, activeFrameHeight)\n },\n\n sendMessageToIframe: async (\n request:\n | JsonRpcRequest\n | OutboundJsonRpcEventRequest<OutboundRpcRequestEventsMethodNames>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n\n const childWindow = getIframeContentWindow()\n if (childWindow) {\n const encryptedRequest = await ecdhManager.prepareSecureMessage(request)\n childWindow.postMessage(encryptedRequest, IFRAME_ORIGIN)\n } else {\n throw new Error('Iframe content window not found')\n }\n },\n\n decryptSecureMessage: async (\n message: SecureMessage<SecureMessageType.Encrypted>,\n ) => {\n if (!ecdhManager.isSecureConnectionEstablished) {\n throw new Error('Secure channel not established with the iframe')\n }\n const { decryptedMessage, passedDecryption } =\n await ecdhManager.decryptSecureMessage(message)\n if (!passedDecryption || !decryptedMessage) {\n throw new Error('Failed to decrypt secure message')\n }\n return decryptedMessage\n },\n }\n}\n", "/**\n * Returns a random number between 0 and maxRange\n *\n * @param maxRange - the maximum range for the random number\n * @returns a random number between 0 and maxRange\n */\nexport const getRandomNum = (maxRange: number) => {\n const rand: () => number = Math.random\n const rn = rand()\n return Math.floor(rn * maxRange)\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n createIframeHandler,\n FrameWidth,\n IframeHandler,\n} from '../iframe/index.js'\n\nimport {\n getRandomNum,\n inboundJsonRpcEventRequestValidator,\n jsonRpcResponseValidator,\n encryptedMessageValidator,\n fatalErrorValidator,\n} from '../utils/index.js'\n\nimport {\n InboundJsonRpcEventRequest,\n JsonRpcResponse,\n InboundRpcRequestEventsMethodNames,\n FatalError,\n JsonRpcRequest,\n} from '../types/index.js'\nimport { SecureMessage, SecureMessageType } from '../ecdh/index.js'\nimport { Eip1193RequestArguments, ProviderRpcError } from './types.js'\n\n// JSON-RPC types\nexport type Message = unknown\n\nexport type AcceptedChainConfig = {\n /**\n * The chain ID of the blockchain network to be used\n * It should be a valid Ethereum chain ID in hex format\n */\n chainId: `0x${string}`\n\n /**\n * The treasury address to receive the payments\n * It should be a valid Ethereum address in hex format\n */\n treasuryAddress: `0x${string}`\n}\n\n/**\n * The configuration for the EmbeddedPayment\n */\nexport type CashieEthereumProviderConfig = {\n /**\n * The development wallet url to be used for the iframe when in dev mode\n */\n devWalletUrl?: string\n\n /**\n * The accepted chain configurations to be used to accept payments\n */\n // acceptedChainConfig: AcceptedChainConfig[]\n\n /**\n * Callback function to handle incoming payment events that emit when the user completes a payment\n */\n // onPaymentEvent: (checkoutResponse: CheckoutResponse) => void\n}\n\n/**\n * We use a singleton class maintains a single instance across a web application, and to ensure\n * the post message listener is only added once, allowing that web application to access wallet globally.\n *\n * The CashieEthereumProvider target environment is the browser, and it is designed to be used in web applications.\n */\nexport class CashieEthereumProvider {\n static #instance: CashieEthereumProvider\n readonly #localWindow: Window\n readonly #boundMessageHandler: (event: MessageEvent<Message>) => void\n readonly FATAL_ERROR_MESSAGE = 'fatal: internal error'\n\n readonly #rpcMethodsThatRequireUserConsent: string[] = [\n 'wallet_requestExecutionPermissions',\n 'wallet_revokeExecutionPermission',\n ]\n\n #iframeHandler: IframeHandler\n #responseQueue: Map<\n number,\n {\n status: 'pending' | 'fulfilled' | 'failed'\n response: JsonRpcResponse | undefined\n fatalError?: FatalError\n }\n > = new Map()\n\n private constructor(iframeHandler: IframeHandler) {\n this.#localWindow = window\n this.#iframeHandler = iframeHandler\n\n this.#boundMessageHandler = this.#handleIncomingMessage.bind(this)\n this.#localWindow.addEventListener('message', this.#boundMessageHandler)\n }\n\n /**\n * Create a messageId to be used in a JSONRPC message and ensure it is unique.\n *\n * @returns A JsonRpcId\n */\n #getJsonRpcId(): number {\n const potentialId = getRandomNum(10000000000) + Date.now()\n\n // Ensure the id is unique and not already in the responseQueue or activeRequestId\n if (this.#responseQueue.has(potentialId)) {\n return this.#getJsonRpcId()\n }\n return potentialId\n }\n\n /**\n * close the CashieEthereumProvider\n */\n #close() {\n this.#iframeHandler.toggleFrameVisibility(false)\n }\n\n /**\n * resize the CashieEthereumProvider\n *\n * @param size - the size of the frame\n */\n #resize(size: FrameWidth) {\n this.#iframeHandler.resizeIframe(size)\n }\n\n /**\n * Handle incoming Post messages\n * Since the iframe is create locally, it will have the same origin as the dapp\n *\n * @param event - the PostMessageEvent sent from the iframe\n */\n async #handleIncomingMessage(event: MessageEvent<Message>) {\n if (!event.isTrusted) {\n return\n }\n\n if (event.origin !== this.#iframeHandler.getIframeOrigin()) {\n return\n }\n\n const message = event.data\n if (typeof message !== 'object') {\n return\n }\n\n const { isValid: isValidFatalError, fatalError } =\n fatalErrorValidator(message)\n if (isValidFatalError && fatalError) {\n this.#handleFatalError(fatalError)\n return\n }\n\n const { isValid: isValidEncryptedRequest, encryptedRequest } =\n encryptedMessageValidator(message)\n if (isValidEncryptedRequest && encryptedRequest) {\n await this.#handleIncomingEncryptedMessage(encryptedRequest)\n return\n }\n }\n\n /**\n * Handle a JsonRpcResponse and store it in the responseQueue\n *\n * @param response - the JsonRpcResponse to be handled\n */\n #handleJsonRpcResponse(response: JsonRpcResponse) {\n const { id } = response\n if (this.#responseQueue.has(Number(id))) {\n this.#responseQueue.set(Number(id), {\n status: 'fulfilled',\n response,\n })\n }\n }\n\n /**\n * Handle a InboundJsonRpcEventRequest and handle the event\n *\n * @param eventRequest - the JsonRpcEventRequest to be handled\n */\n #handleJsonRpcEvent(\n eventRequest: InboundJsonRpcEventRequest<InboundRpcRequestEventsMethodNames>,\n ) {\n const { method } = eventRequest\n switch (method) {\n case 'wallet_paymentEvent':\n break\n case 'wallet_closeFrame':\n this.#close()\n break\n case 'wallet_disconnect':\n this.#disconnect()\n break\n case 'wallet_resizeFrameFull':\n this.#resize(FrameWidth.Full)\n break\n case 'wallet_resizeFrameDefault':\n this.#resize(FrameWidth.Default)\n break\n }\n }\n\n /**\n * Handle a SecureMessage and handle the message\n *\n * @param encryptedRequest - the SecureMessage to be handled\n */\n async #handleIncomingEncryptedMessage(\n encryptedRequest: SecureMessage<SecureMessageType.Encrypted>,\n ) {\n const decryptedMessage =\n await this.#iframeHandler.decryptSecureMessage(encryptedRequest)\n\n const { isValid: isValidResponse, response } =\n jsonRpcResponseValidator(decryptedMessage)\n if (isValidResponse && response) {\n this.#handleJsonRpcResponse(response)\n return\n }\n\n const { isValid: isValidEventRequest, eventRequest } =\n inboundJsonRpcEventRequestValidator(decryptedMessage)\n if (isValidEventRequest && eventRequest) {\n this.#handleJsonRpcEvent(eventRequest)\n return\n }\n }\n\n /**\n * Handle a fatal error\n *\n * @param fatalError - the fatal error to be handled\n */\n #handleFatalError(fatalError: FatalError) {\n if (this.#responseQueue.size) {\n // loop through the responseQueue and set the status to failed\n this.#responseQueue.forEach((response) => {\n if (response.status === 'pending') {\n response.status = 'failed'\n response.fatalError = fatalError\n }\n })\n }\n }\n\n /**\n * Handles a JsonRpcRequest coming from the dapp\n * Request are handled synchronously(blocking) and requires immediate response from the user\n *\n * @param request - the JsonRpcRequest to be handled\n * @param requiresUserConsent - whether the user consent is required to show the iframe\n * @returns the response from the blobUrl IFrame\n */\n async #sendRequestToIframe(\n request: JsonRpcRequest,\n requiresUserConsent: boolean,\n ): Promise<JsonRpcResponse> {\n try {\n await this.#iframeHandler.prepareIframe()\n\n // show the iframe if the user consent is required otherwise the iframe will be hidden but can still response to requests\n if (requiresUserConsent) {\n this.#iframeHandler.toggleFrameVisibility(true)\n }\n\n const { id } = request\n this.#responseQueue.set(Number(id), {\n status: 'pending',\n response: undefined,\n })\n await this.#iframeHandler.sendMessageToIframe(request)\n\n // Wait for the user to respond from the IFrame\n return await this.#waitForResponse(Number(id))\n } catch (error: any) {\n if (error.message === this.FATAL_ERROR_MESSAGE) {\n this.#close()\n }\n return {\n jsonrpc: '2.0',\n id: request.id,\n error: {\n message: error.message,\n code: -32000,\n },\n }\n }\n }\n\n /**\n * Wait for a response from the user to be added to the responseQueue every second\n * max attempts is 300 or 5 minutes\n *\n * @param requestId - the id of the request\n * @param attempts - the number of attempts to wait for a response\n * @returns the response from the blobUrl IFrame\n */\n #waitForResponse(requestId: number, attempts = 300) {\n return new Promise<JsonRpcResponse>((_resolve, _reject) => {\n let counter = 0\n\n const intervalId = setInterval(() => {\n counter++\n\n // reject if more than the specified attempts\n if (counter >= attempts) {\n clearInterval(intervalId)\n _reject(new Error('Max attempts reached waiting for response'))\n }\n\n // remove the response from the queue and resolve the promise\n const result = this.#responseQueue.get(requestId)\n if (result) {\n if (result.status === 'failed' && result.fatalError) {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _reject(new Error(result.fatalError.message))\n }\n\n if (result.status === 'fulfilled') {\n clearInterval(intervalId)\n this.#responseQueue.delete(requestId)\n _resolve(result.response as JsonRpcResponse)\n }\n }\n }, 1000) // 1 second\n })\n }\n\n /**\n * Disconnect the CashieEthereumProvider\n *\n * @returns true if the CashieEthereumProvider is disconnected successfully, false otherwise\n */\n #disconnect() {\n this.#iframeHandler.toggleFrameVisibility(false)\n this.#iframeHandler.disconnectIframe()\n this.#responseQueue = new Map()\n return true\n }\n\n /**\n * Generic request to the CashieEthereumProvider\n *\n * @param request - the request to be sent to the CashieEthereumProvider\n * @returns the response from the CashieEthereumProvider\n */\n async sendRequest(request: Eip1193RequestArguments): Promise<unknown> {\n const requestId = this.#getJsonRpcId()\n const requiresUserConsent = this.#rpcMethodsThatRequireUserConsent.includes(\n request.method,\n )\n\n switch (request.method) {\n case 'wallet_disconnect':\n this.#disconnect()\n return true\n case 'wallet_openHomePage':\n await this.#iframeHandler.prepareIframe()\n this.#iframeHandler.toggleFrameVisibility(true)\n await this.#iframeHandler.sendMessageToIframe({\n jsonrpc: '2.0',\n method: 'wallet_navigateToDashboardEvent',\n params: [],\n })\n return true\n default: {\n const result = await this.#sendRequestToIframe(\n {\n jsonrpc: '2.0',\n id: requestId,\n method: request.method,\n params: request.params || [],\n },\n requiresUserConsent,\n )\n if ('error' in result) {\n throw new ProviderRpcError({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data,\n })\n }\n return result.result\n }\n }\n }\n\n /**\n * Create a new instance of the CashieEthereumProvider\n *\n * @param config - the configuration for the CashieEthereumProvider\n * @returns the CashieEthereumProvider instance\n */\n static Create(config: CashieEthereumProviderConfig): CashieEthereumProvider {\n if (!CashieEthereumProvider.#instance) {\n const iframeHandler = createIframeHandler({\n parentOrigin: window.location.origin,\n devWalletUrl: config.devWalletUrl,\n })\n CashieEthereumProvider.#instance = new CashieEthereumProvider(\n iframeHandler,\n )\n }\n return CashieEthereumProvider.#instance\n }\n}\n", "export type ErrorDetails = {\n code: number\n message: string\n}\n\n/**\n * The EIP1193 error code enum\n */\nexport enum EIP1193_ERROR_CODES {\n /**\n * The user rejected the request.\n */\n USER_REJECTED_REQUEST = 4001,\n\n /**\n * The specified address is not connected or not in the wallet\n */\n UNAUTHORIZED = 4100,\n\n /**\n * The Provider does not support the requested method.\n */\n UNSUPPORTED_METHOD = 4200,\n\n /**\n * The Provider is disconnected from all chains.\n */\n DISCONNECTED = 4900,\n\n /**\n * The Provider is not connected to the requested chain.\n */\n CHAIN_DISCONNECTED = 4901,\n}\n\n/**\n * The ERC-7715 error code enum\n */\nexport enum ERC7715_ERROR_CODES {\n /**\n * The specified method is not authorized for the given origin\n * Related RPCs: wallet_requestConnection\n */\n UNAUTHORIZED_ACCESS_RESTRICTED_METHOD = 4101,\n}\n\n/**\n * The EIP5792 error code enum\n */\nexport enum EIP5792_ERROR_CODES {\n /**\n * This wallet does not support a capability that was not marked as optional\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_NON_OPTIONAL_CAPABILITY = 5700,\n\n /**\n * This wallet does not support the specified chain id\n * Related RPCs: wallet_sendCalls\n */\n UNSUPPORTED_CHAIN_ID = 5710,\n\n /**\n * There is already a bundle submitted with this id\n * Related RPCs: wallet_sendCalls\n */\n DUPLICATE_BUNDLE_ID = 5720,\n\n /**\n * This bundle id is unknown / has not been submitted\n * Related RPCs: wallet_getCallsStatus, wallet_showCallsStatus\n */\n UNKNOWN_BUNDLE_ID = 5730,\n\n /**\n * The call bundle is too large for the wallet to process\n * Related RPCs: wallet_sendCalls\n */\n BUNDLE_TOO_LARGE = 5740,\n\n /**\n * The wallet can support atomicity after an upgrade, but the user rejected the upgrade\n * Related RPCs: wallet_sendCalls\n */\n ATOMIC_READY_WALLET_REJECTED_UPGRADE = 5750,\n\n /**\n * The wallet does not support atomic execution but the request requires it\n * Related RPCs: wallet_sendCalls\n */\n ATOMICITY_NOT_SUPPORTED = 5760,\n}\n\n/**\n * The fatal error code enum\n */\nexport enum FATAL_ERROR_CODES {\n INTERNAL_ERROR = -32001,\n}\n\nexport enum COMMON_ERROR_CODES {\n INVALID_PARAMS = -32602,\n}\n\n/**\n * The error code map\n */\nexport const ERROR_CODES_MAP: Record<\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n ErrorDetails\n> = {\n // EIP1193 errors\n [EIP1193_ERROR_CODES.USER_REJECTED_REQUEST]: {\n code: 4001,\n message: 'User rejected the request.',\n },\n [EIP1193_ERROR_CODES.UNAUTHORIZED]: {\n code: 4100,\n message:\n 'The requested method and/or account has not been authorized by the user.',\n },\n [EIP1193_ERROR_CODES.UNSUPPORTED_METHOD]: {\n code: 4200,\n message: 'The Provider does not support the requested method.',\n },\n [EIP1193_ERROR_CODES.DISCONNECTED]: {\n code: 4900,\n message: 'The Provider is disconnected from all chains.',\n },\n [EIP1193_ERROR_CODES.CHAIN_DISCONNECTED]: {\n code: 4901,\n message: 'The Provider is not connected to the requested chain.',\n },\n\n //ERC-7715 errors\n [ERC7715_ERROR_CODES.UNAUTHORIZED_ACCESS_RESTRICTED_METHOD]: {\n code: 4101,\n message:\n 'The specified method is not authorized for the given origin. Please call wallet_requestConnection to authorize the method.',\n },\n\n // EIP5792 errors\n [EIP5792_ERROR_CODES.UNSUPPORTED_NON_OPTIONAL_CAPABILITY]: {\n code: 5700,\n message:\n 'This wallet does not support a capability that was not marked as optional.',\n },\n [EIP5792_ERROR_CODES.UNSUPPORTED_CHAIN_ID]: {\n code: 5710,\n message: 'This wallet does not support the specified chain id.',\n },\n [EIP5792_ERROR_CODES.DUPLICATE_BUNDLE_ID]: {\n code: 5720,\n message: 'There is already a bundle submitted with this id.',\n },\n [EIP5792_ERROR_CODES.UNKNOWN_BUNDLE_ID]: {\n code: 5730,\n message: 'This bundle id is unknown / has not been submitted.',\n },\n [EIP5792_ERROR_CODES.BUNDLE_TOO_LARGE]: {\n code: 5740,\n message: 'The call bundle is too large for the wallet to process.',\n },\n [EIP5792_ERROR_CODES.ATOMIC_READY_WALLET_REJECTED_UPGRADE]: {\n code: 5750,\n message:\n 'The wallet can support atomicity after an upgrade, but the user rejected the upgrade.',\n },\n [EIP5792_ERROR_CODES.ATOMICITY_NOT_SUPPORTED]: {\n code: 5760,\n message:\n 'The wallet does not support atomic execution but the request requires it.',\n },\n\n // Fatal/Common errors\n [FATAL_ERROR_CODES.INTERNAL_ERROR]: {\n code: -32001,\n message: 'fatal: internal error',\n },\n [COMMON_ERROR_CODES.INVALID_PARAMS]: {\n code: 4002,\n message: 'Invalid parameters.',\n },\n}\n\n/**\n * Get the error message for a given error code\n *\n * @param code - The error code\n * @returns The error message\n * @throws {Error} if the error code is not found\n */\nexport const getErrorMessage = (\n code:\n | EIP1193_ERROR_CODES\n | EIP5792_ERROR_CODES\n | ERC7715_ERROR_CODES\n | FATAL_ERROR_CODES\n | COMMON_ERROR_CODES,\n): ErrorDetails => {\n const details = ERROR_CODES_MAP[code]\n if (!details) {\n return {\n code,\n message: `Unknown error code: ${code}`,\n }\n }\n return details\n}\n", "import {\n Eip1193RequestArguments,\n Eip1193Provider,\n ProviderRpcError,\n} from './types.js'\nimport {\n CashieEthereumProvider,\n CashieEthereumProviderConfig,\n} from './cashie-ethereum-provider.js'\nimport { getErrorMessage } from './errors.js'\n\nexport class Eip1193Bridge implements Eip1193Provider {\n #transeptorEthereumProvider: CashieEthereumProvider\n constructor(config: CashieEthereumProviderConfig) {\n this.#transeptorEthereumProvider = CashieEthereumProvider.Create(config)\n }\n\n async request(request: Eip1193RequestArguments) {\n try {\n return await this.#transeptorEthereumProvider.sendRequest(request)\n } catch (error: unknown) {\n if (error instanceof ProviderRpcError) {\n const errorDetails = getErrorMessage(error.code)\n if (errorDetails) {\n throw new ProviderRpcError(errorDetails)\n }\n }\n throw new ProviderRpcError({\n code: -32000,\n message: 'Unknown internal error',\n data: error,\n })\n }\n }\n}\n\n/**\n * Create a new Eip1193 provider\n *\n * @param config - the configuration for the CashieEthereumProvider\n * @returns the Eip1193 provider\n */\nexport function createEip1193Provider(\n config: CashieEthereumProviderConfig,\n): Eip1193Provider {\n return new Eip1193Bridge(config)\n}\n", "import { Eip1193Provider } from '../index.js'\n\nexport const enum ProviderEvent {\n AnnounceProvider = 'eip6963:announceProvider',\n RequestProvider = 'eip6963:requestProvider',\n}\n\n/**\n * Provider Detail defined by eip-6963\n */\nexport type EIP6963ProviderDetail = {\n info: {\n uuid: string\n name: string\n icon: string\n rdns: string\n }\n provider: Eip1193Provider\n}\n\n/**\n * Announce Event dispatched by a Wallet\n */\nexport interface EIP6963AnnounceProviderEvent extends CustomEvent {\n type: ProviderEvent.AnnounceProvider\n detail: EIP6963ProviderDetail\n}\n\n/**\n * Request Event dispatched by a DApp\n */\nexport interface EIP6963RequestProviderEvent extends Event {\n type: ProviderEvent.RequestProvider\n}\n", "/**\n * The icon of the Cashie wallet\n */\nexport const CASHIE_WALLET_ICON =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg=='\n", "import { CashieEthereumProviderConfig } from '../cashie-ethereum-provider.js'\nimport { createEip1193Provider } from '../eip-1193-bridge.js'\nimport { EIP6963ProviderDetail, ProviderEvent } from './types.js'\nimport { CASHIE_WALLET_ICON } from './icon.js'\n\n/**\n * Announce the Cashie provider to the dapp\n *\n * @param config - the configuration for the CashieEthereumProvider\n */\nexport const announceProvider = (config: CashieEthereumProviderConfig) => {\n const provider = createEip1193Provider(config)\n const detail = Object.freeze({\n info: Object.freeze({\n uuid: '2d1e5f4d-8b8a-48bb-8d0a-7d6f8f2fa9a1',\n name: 'Cashie',\n icon: CASHIE_WALLET_ICON,\n rdns: 'org.cashie.app',\n }),\n provider,\n } as EIP6963ProviderDetail)\n const announceEvent = new CustomEvent(ProviderEvent.AnnounceProvider, {\n detail,\n })\n\n // The Wallet dispatches an announce event which is heard by\n // the DApp code that had run earlier\n window.addEventListener(ProviderEvent.RequestProvider, () => {\n window.dispatchEvent(announceEvent)\n })\n\n // The Wallet listens to the request events which may be\n // dispatched later and re-dispatches the `EIP6963AnnounceProviderEvent`\n window.dispatchEvent(announceEvent)\n}\n"],
5
+ "mappings": "AAAO,IAAMA,EAAN,cAA+B,KAAM,CAO1C,KAKA,KAEA,YAAY,CACV,QAAAC,EACA,KAAAC,EACA,KAAAC,CACF,EAIG,CACD,MAAMF,CAAO,EACb,KAAK,KAAOC,EACZ,KAAK,KAAOC,CACd,CACF,ECFO,IAAMC,EAAN,KAA2B,CACf,KAAO,CAAE,KAAM,OAAQ,WAAY,OAAQ,EAC5DC,GAAiB,GACjBC,GAAgC,CAC9B,QAAS,KACT,OAAQ,KACR,MAAO,IACT,EACAC,GAGI,CACF,KAAM,KACN,GAAI,EACN,EACAC,GAAY,EACZC,GAA6B,KAE7B,aAAc,CAEd,CAOAC,IAA2B,CACzB,GAAI,CAAC,KAAKL,GACR,MAAM,IAAI,MAAM,sBAAsB,CAE1C,CAOAM,IAA2C,CACzC,GAAI,CAAC,KAAKJ,GAAmB,GAC3B,MAAM,IAAI,MAAM,mCAAmC,CAEvD,CAOAK,IAAkC,CAChC,GAAI,CACF,GACE,OAAO,OAAW,KAClB,OAAO,OAAO,OAAW,KACzB,OAAO,OAAO,gBAAoB,KAClC,OAAO,OAAO,OAAO,YAAgB,KACrC,OAAO,OAAO,OAAO,QAAY,KACjC,OAAO,OAAO,OAAO,QAAY,IAEjC,OAEF,MAAM,IAAI,MAAM,8BAA8B,CAChD,OAASC,EAAO,CACd,MAAM,IAAI,MAAM,+BAAgC,CAAE,MAAOA,CAAM,CAAC,CAClE,CACF,CAOA,IAAI,+BAAyC,CAC3C,OAAO,KAAKN,GAAmB,EACjC,CAOA,MAAM,gB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XC,GAMiB,CACjB,IAAMC,EAAUH,EAAgBE,CAAI,EACpC,OAAKC,GACI,CACL,KAAAD,EACA,QAAS,uBAAuBA,CAAI,EACtC,CAGJ,ECzMO,IAAME,EAAN,KAA+C,CACpDC,GACA,YAAYC,EAAsC,CAChD,KAAKD,GAA8BE,EAAuB,OAAOD,CAAM,CACzE,CAEA,MAAM,QAAQE,EAAkC,CAC9C,GAAI,CACF,OAAO,MAAM,KAAKH,GAA4B,YAAYG,CAAO,CACnE,OAASC,EAAgB,CACvB,GAAIA,aAAiBC,EAAkB,CACrC,IAAMC,EAAeC,EAAgBH,EAAM,IAAI,EAC/C,GAAIE,EACF,MAAM,IAAID,EAAiBC,CAAY,CAE3C,CACA,MAAM,IAAID,EAAiB,CACzB,KAAM,MACN,QAAS,yBACT,KAAMD,CACR,CAAC,CACH,CACF,CACF,EAQO,SAASI,EACdP,EACiB,CACjB,OAAO,IAAIF,EAAcE,CAAM,CACjC,CC5CO,IAAWQ,OAChBA,EAAA,iBAAmB,2BACnBA,EAAA,gBAAkB,0BAFFA,OAAA,ICCX,IAAMC,EACX,i+BCMK,IAAMC,EAAoBC,GAAyC,CACxE,IAAMC,EAAWC,EAAsBF,CAAM,EACvCG,EAAS,OAAO,OAAO,CAC3B,KAAM,OAAO,OAAO,CAClB,KAAM,uCACN,KAAM,SACN,KAAMC,EACN,KAAM,gBACR,CAAC,EACD,SAAAH,CACF,CAA0B,EACpBI,EAAgB,IAAI,uCAA4C,CACpE,OAAAF,CACF,CAAC,EAID,OAAO,2CAAgD,IAAM,CAC3D,OAAO,cAAcE,CAAa,CACpC,CAAC,EAID,OAAO,cAAcA,CAAa,CACpC",
6
+ "names": ["ProviderRpcError", "message", "code", "data", "EphemeralEcdhManager", "#isInitialized", "#ephemeralEcdh", "#isKeyExchangeDone", "#sequence", "#aeadKey", "#assertInitialized", "#assertSecureConnectionEstablished", "#assertWebCryptoAvailable", "error", "keyPair", "pubJwk", "nonce", "message", "pub", "recipientPub", "bits", "baseKey", "salt", "data", "iv", "additionalData", "dataBytes", "cipherText", "ok", "role", "jsonRpcResponseValidator", "message", "response", "inboundJsonRpcEventRequestValidator", "eventRequest", "jsonRpcKeyExchangeResponseValidator", "keyExchangeResponse", "jsonRpcKeyExchangeDoneValidator", "keyExchangeDone", "encryptedMessageValidator", "encryptedRequest", "fatalErrorValidator", "fatalError", "isMobile", "resizeFrameWidth", "iframeId", "frameWidth", "frameHeight", "iframe", "showIframe", "overlay", "hideIframe", "doToggleIframeVisibility", "overlayId", "isVisible", "appendIframeWithContainer", "url", "destroyIframeWithContainer", "createIframeHandler", "config", "ecdhManager", "EphemeralEcdhManager", "devWalletUrl", "IFRAME_ORIGIN", "params", "walletUrl", "DAPP_IFRAME_ID", "OVERLAY_CONTAINER_ID", "activeFrameWidth", "activeFrameHeight", "isIframeCreated", "handleOverlayClick", "event", "overlay", "doToggleIframeVisibility", "getIframeContentWindow", "iframe", "checkIframeReady", "attempts", "childWindow", "isFrameReady", "handleReady", "_resolve", "_reject", "counter", "intervalId", "establishSecureConnectionWithIframe", "keyExchangeMessage", "keyExchangeResponseMessage", "keyExchangeDoneMessage", "message", "isValidKeyExchangeResponse", "keyExchangeResponse", "jsonRpcKeyExchangeResponseValidator", "isValidKeyExchangeDone", "keyExchangeDone", "jsonRpcKeyExchangeDoneValidator", "isMobile", "appendIframeWithContainer", "isIframeReady", "destroyIframeWithContainer", "isVisible", "resizeFrameWidth", "size", "request", "encryptedRequest", "decryptedMessage", "passedDecryption", "getRandomNum", "maxRange", "rand", "rn", "CashieEthereumProvider", "_CashieEthereumProvider", "#instance", "#localWindow", "#boundMessageHandler", "#rpcMethodsThatRequireUserConsent", "#iframeHandler", "#responseQueue", "iframeHandler", "#handleIncomingMessage", "#getJsonRpcId", "potentialId", "getRandomNum", "#close", "#resize", "size", "event", "message", "isValidFatalError", "fatalError", "fatalErrorValidator", "#handleFatalError", "isValidEncryptedRequest", "encryptedRequest", "encryptedMessageValidator", "#handleIncomingEncryptedMessage", "#handleJsonRpcResponse", "response", "id", "#handleJsonRpcEvent", "eventRequest", "method", "#disconnect", "decryptedMessage", "isValidResponse", "jsonRpcResponseValidator", "isValidEventRequest", "inboundJsonRpcEventRequestValidator", "#sendRequestToIframe", "request", "requiresUserConsent", "#waitForResponse", "error", "requestId", "attempts", "_resolve", "_reject", "counter", "intervalId", "result", "ProviderRpcError", "config", "createIframeHandler", "ERROR_CODES_MAP", "getErrorMessage", "code", "details", "Eip1193Bridge", "#transeptorEthereumProvider", "config", "CashieEthereumProvider", "request", "error", "ProviderRpcError", "errorDetails", "getErrorMessage", "createEip1193Provider", "ProviderEvent", "CASHIE_WALLET_ICON", "announceProvider", "config", "provider", "createEip1193Provider", "detail", "CASHIE_WALLET_ICON", "announceEvent"]
7
7
  }
@@ -15,7 +15,7 @@ export type AcceptedChainConfig = {
15
15
  /**
16
16
  * The configuration for the EmbeddedPayment
17
17
  */
18
- export type TranseptorEthereumProviderConfig = {
18
+ export type CashieEthereumProviderConfig = {
19
19
  /**
20
20
  * The development wallet url to be used for the iframe when in dev mode
21
21
  */
@@ -25,24 +25,24 @@ export type TranseptorEthereumProviderConfig = {
25
25
  * We use a singleton class maintains a single instance across a web application, and to ensure
26
26
  * the post message listener is only added once, allowing that web application to access wallet globally.
27
27
  *
28
- * The TranseptorEthereumProvider target environment is the browser, and it is designed to be used in web applications.
28
+ * The CashieEthereumProvider target environment is the browser, and it is designed to be used in web applications.
29
29
  */
30
- export declare class TranseptorEthereumProvider {
30
+ export declare class CashieEthereumProvider {
31
31
  #private;
32
32
  readonly FATAL_ERROR_MESSAGE = "fatal: internal error";
33
33
  private constructor();
34
34
  /**
35
- * Generic request to the TranseptorEthereumProvider
35
+ * Generic request to the CashieEthereumProvider
36
36
  *
37
- * @param request - the request to be sent to the TranseptorEthereumProvider
38
- * @returns the response from the TranseptorEthereumProvider
37
+ * @param request - the request to be sent to the CashieEthereumProvider
38
+ * @returns the response from the CashieEthereumProvider
39
39
  */
40
40
  sendRequest(request: Eip1193RequestArguments): Promise<unknown>;
41
41
  /**
42
- * Create a new instance of the TranseptorEthereumProvider
42
+ * Create a new instance of the CashieEthereumProvider
43
43
  *
44
- * @param config - the configuration for the TranseptorEthereumProvider
45
- * @returns the TranseptorEthereumProvider instance
44
+ * @param config - the configuration for the CashieEthereumProvider
45
+ * @returns the CashieEthereumProvider instance
46
46
  */
47
- static Create(config: TranseptorEthereumProviderConfig): TranseptorEthereumProvider;
47
+ static Create(config: CashieEthereumProviderConfig): CashieEthereumProvider;
48
48
  }
@@ -1,14 +1,14 @@
1
1
  import { Eip1193RequestArguments, Eip1193Provider } from './types.js';
2
- import { TranseptorEthereumProviderConfig } from './transeptor-ethereum-provider.js';
2
+ import { CashieEthereumProviderConfig } from './cashie-ethereum-provider.js';
3
3
  export declare class Eip1193Bridge implements Eip1193Provider {
4
4
  #private;
5
- constructor(config: TranseptorEthereumProviderConfig);
5
+ constructor(config: CashieEthereumProviderConfig);
6
6
  request(request: Eip1193RequestArguments): Promise<unknown>;
7
7
  }
8
8
  /**
9
9
  * Create a new Eip1193 provider
10
10
  *
11
- * @param config - the configuration for the TranseptorEthereumProvider
11
+ * @param config - the configuration for the CashieEthereumProvider
12
12
  * @returns the Eip1193 provider
13
13
  */
14
- export declare function createEip1193Provider(config: TranseptorEthereumProviderConfig): Eip1193Provider;
14
+ export declare function createEip1193Provider(config: CashieEthereumProviderConfig): Eip1193Provider;
@@ -1,7 +1,7 @@
1
- import { TranseptorEthereumProviderConfig } from '../transeptor-ethereum-provider.js';
1
+ import { CashieEthereumProviderConfig } from '../cashie-ethereum-provider.js';
2
2
  /**
3
- * Announce the Transeptor Pay provider to the dapp
3
+ * Announce the Cashie provider to the dapp
4
4
  *
5
- * @param config - the configuration for the TranseptorEthereumProvider
5
+ * @param config - the configuration for the CashieEthereumProvider
6
6
  */
7
- export declare const announceProvider: (config: TranseptorEthereumProviderConfig) => void;
7
+ export declare const announceProvider: (config: CashieEthereumProviderConfig) => void;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * The icon of the Transeptor Pay wallet
2
+ * The icon of the Cashie wallet
3
3
  */
4
- export declare const TRANSEPTOR_WALLET_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg==";
4
+ export declare const CASHIE_WALLET_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAChklEQVR4nO2YTW/TMBjHs7Jpm4QK34BLJSSkldieugiGwho7y41TvwInPgCX6dEktqKWVSoXhDjssFtL7JTDruPEie9U5KQvaZd2DWVEiZ6f9FSW3+3/300cw0AQBEEQBEEQBEEQBEEQ5J7YuKe6eWAYLoixr1tP7Mudine9vSwMA0oF2gTQizGYG7wnXF4yoU6ICM6oUB/mgwh1ylzVJVy+i7fNvfJ7R8FTItRP4g5atn2z+fyNelzzrsrzwXjvked1twmX3arTJ/E+cgqECppCfqRHiplCnTARHMTLZquP3CK+vyRcncfzcghEizn2KeWyo9Omq14QEbTD4kbjweicz0XUjgj5qeoEeXYBRAvhfpNxeTjOZUK2mStr8TpJ7XSbHLsAwgnvHfvU5P6FTjcaPa24QfnAIq5qLV9YpHiOXQAJ6kNpesaDIrsAbqk/VS8qK7gLIFn9SXGhXQAj9X8kqD9bh3oDi/DCuQBG6qtk9ZNcUC+MC2AF9QvtAlhN/WK6AFKoX0gXQDr1i+UCWPLcX61tGhdQri5Y3afpxsnyuX8Xad8LPHmob5fxtjlVf0z6t8NZF2S6CTA5+9WJ+ouuuUsiuhob+qrMRP9gcT9RPVpXr+jYBdltAIQD7zt9QrjfWu9Mjj+byRoTqhnPW/JEaE+/GmWyCRB97XFlh3Dl6HTFuyo/s3sP/yYq3nVZ90l58Jk56rVOV2q3+9Nj6LH2nYBTV3Wy2oAN/WNZvV0m5Dd9BIiQZ2sFV+dE+KemUF/0x1OdjvIW1m/qsfUc4nP6/8CwpCdh2zc764Zl/dplb39v2fZw864+w4Vn/xRAjNT/+P8+EARBEARBEARBEARBEMRYnT/136hHs8p9dgAAAABJRU5ErkJggg==";
@@ -1,5 +1,5 @@
1
1
  export { createEip1193Provider } from './eip-1193-bridge.js';
2
- export { TranseptorEthereumProvider } from './transeptor-ethereum-provider.js';
3
- export type { TranseptorEthereumProviderConfig } from './transeptor-ethereum-provider.js';
2
+ export { CashieEthereumProvider } from './cashie-ethereum-provider.js';
3
+ export type { CashieEthereumProviderConfig } from './cashie-ethereum-provider.js';
4
4
  export * from './eip-6963/index.js';
5
5
  export * from './types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashie/ethereum-provider",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A EIP-1193 provider for the Cashie Protocol client",
5
5
  "homepage": "https://github.com/transeptorlabs/cashie-core/blob/main/packages/ethereum-provider/README.md",
6
6
  "repository": {
@@ -41,10 +41,13 @@
41
41
  "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies --check",
42
42
  "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:dependencies",
43
43
  "test": "vitest run --config ./vitest.config.ts --coverage",
44
- "test:watch": "vitest --config ./vitest.config.ts"
44
+ "test:watch": "vitest --config ./vitest.config.ts",
45
+ "run:audit:all": "yarn npm audit --recursive",
46
+ "run:audit": "yarn npm audit",
47
+ "run:audit:ci": "yarn npm audit --recursive --no-deprecations"
45
48
  },
46
49
  "engines": {
47
- "node": ">=22.14.0"
50
+ "node": ">=22.23.4"
48
51
  },
49
52
  "packageManager": "yarn@4.7.0",
50
53
  "publishConfig": {