import{C as i,M as s,B as c,a as r,E as a,d as m}from"./index-8U_L1d87.js";import{W as g}from"./secp256k1-CE3CsNCK.js";import{C as h}from"./contentScript-DqM7mNnQ.js";class o{constructor(e){this.connection=void 0,this.onDisconnect=()=>{this.destroy()},this.onMessageFromExtension=t=>{t.target===i&&this.postMessage(t)},this.onMessageFromWindow=t=>{const{data:n,origin:d}=Object.freeze(t);this.shouldAcceptMessage(n,d)&&(this.connection||this.connectAndAttachListeners(),n.type===s.request&&n.request.method==="connectorName"?this.sendConnectorName(n.request.id):(this.connection||this.connectAndAttachListeners(),this.connection?.postMessage({...n,target:c})))},this.connectorName=e,this.onMessageFromWindow=this.onMessageFromWindow.bind(this),this.onMessageFromExtension=this.onMessageFromExtension.bind(this),this.onDisconnect=this.onDisconnect.bind(this),this.connectAndAttachListeners()}onStartEvent(){this.postMessage({type:s.event,target:r,connectorName:this.connectorName,events:[{event:"start",params:[]}]})}connectAndAttachListeners(){const e=chrome.runtime.connect(chrome.runtime.id,{name:c});e.onMessage.addListener(this.onMessageFromExtension),chrome.runtime.onMessage.addListener(this.handlePing),e.onDisconnect.addListener(this.onDisconnect),this.connection=e,window.addEventListener(a,this.onMessageFromWindow),this.onStartEvent()}destroy(e=!0){this.connection?.onMessage.removeListener(this.onMessageFromExtension),chrome.runtime.onMessage.removeListener(this.handlePing),this.connection?.onDisconnect.removeListener(this.onDisconnect),this.connection?.disconnect(),this.connection=void 0,e||window.removeEventListener(a,this.onMessageFromWindow)}static start(e){return new o(e)}shouldAcceptMessage(e,t){return t===window.location.origin&&e.target===i&&e.connectorName===this.connectorName}sendConnectorName(e){this.postMessage({type:s.response,response:m.createJSONRPCSuccessResponse(e,this.connectorName),target:this.connectorName})}handlePing(e,t,n){e?.type===h.PING&&n({type:h.PONG})}postMessage(e){const t={...e,target:r,connectorName:this.connectorName};window.postMessage(t,window.location.origin)}}const M=o.start(g);window.addEventListener("beforeunload",()=>{M.destroy(!1)});
//# sourceMappingURL=contentScript.ts-DFPP1rqr.js.map
