import{g as R,s as p,o as Q}from"./chunk-DQIhPnbi.js";import{D as X,d as ee}from"./chunk-Cw1i3Jo-.js";const N="https://eth-beacon-chain.drpc.org",te=["https://eth-beacon-chain.drpc.org","https://ethereum-beacon-api.publicnode.com","https://lodestar-mainnet.chainsafe.io"],ne=document.getElementById("rpc-form"),h=document.getElementById("rpc-input"),L=document.getElementById("rpc-apply"),d=document.getElementById("rpc-status"),C=document.getElementById("rpc-reveal"),y=document.getElementById("helios-live"),_=document.getElementById("helios-dot"),m=document.getElementById("helios-restart"),se=document.getElementById("consensus-form"),T=document.getElementById("consensus-input"),W=document.getElementById("beacon-endpoints"),r=document.getElementById("consensus-status"),U=document.getElementById("consensus-apply"),k=document.getElementById("intercept-ethlimo"),I=document.getElementById("intercept-w3eth"),oe=document.getElementById("verifier-form"),H=document.getElementById("verifier-input"),A=document.getElementById("verifier-add"),a=document.getElementById("verifier-status"),z=document.getElementById("verifier-list"),ae=document.getElementById("checkpoint-form"),$=document.getElementById("checkpoint-input"),O=document.getElementById("checkpoint-apply"),b=document.getElementById("checkpoint-status"),ie=`
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4"
       stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
    <path d="M11.5 2.5 13.5 4.5 5 13H3v-2z"/>
    <path d="M10 4l2 2"/>
  </svg>`,ce=`
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4"
       stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
    <path d="M11.5 2.5 13.5 4.5 5 13H3v-2z"/>
    <path d="M10 4l2 2"/>
    <path d="M2.5 2.5 13.5 13.5"/>
  </svg>`;let f=!1;function re(e){try{const t=new URL(e);return t.pathname&&t.pathname!=="/"?`${t.origin}/•••`:t.origin}catch{return e}}function M(e){const t=e??"",n=f||!t;h.dataset.real=t,h.value=n?t:re(t),h.type=n?"url":"text",h.readOnly=!n,L.disabled=!n,C.innerHTML=f?ce:ie,C.title=f?"Cancel edit":"Edit URL",C.setAttribute("aria-label",C.title),d.textContent="",d.className="hint"}C.addEventListener("click",()=>{f=!f;const e=h.dataset.real??"";M(e),f&&h.focus()});ne.addEventListener("submit",async e=>{e.preventDefault();const t=h.value.trim();if(!t)return;let n;try{n=new URL(t)}catch{d.textContent="That URL isn't valid.",d.className="hint bad";return}if(n.protocol!=="http:"&&n.protocol!=="https:"){d.textContent="Only http:// or https:// URLs are accepted.",d.className="hint bad";return}L.disabled=!0,d.className="hint",d.textContent="Requesting permission…";const s=n.origin+"/*";if(!await chrome.permissions.contains({origins:[s]})&&!await chrome.permissions.request({origins:[s]})){d.textContent="Permission denied — Helios can't reach that host.",d.className="hint bad",L.disabled=!1;return}const l=(await R()).rpcUrl;if(await p({rpcUrl:t}),l===t){try{await chrome.runtime.sendMessage({type:"shutdown-helios"})}catch{}try{await chrome.runtime.sendMessage({type:"boot-helios"})}catch{}}E({state:"booting"}),f=!1,M(t),d.textContent="Saved. Rebooting Helios…",L.disabled=!1});function de(){return T.value.trim()||N}function le(){W.innerHTML="";for(const e of te){const t=document.createElement("option");t.value=e,W.appendChild(t)}}function K(e){T.value=e||N,r.textContent=""}se.addEventListener("submit",async e=>{e.preventDefault();const t=de();let n;try{n=new URL(t)}catch{r.textContent="That URL isn't valid.",r.className="hint bad";return}if(n.protocol!=="http:"&&n.protocol!=="https:"){r.textContent="Only http:// or https:// URLs are accepted.",r.className="hint bad";return}U.disabled=!0,r.className="hint",r.textContent="Requesting permission…";const s=n.origin+"/*";if(!await chrome.permissions.contains({origins:[s]})&&!await chrome.permissions.request({origins:[s]})){r.textContent="Permission denied — Helios can't reach that host.",r.className="hint bad",U.disabled=!1;return}await p({consensusRpc:t===N?void 0:t}),r.textContent="Rebooting Helios with the new consensus RPC…";try{await chrome.runtime.sendMessage({type:"shutdown-helios"})}catch{}E({state:"booting"});try{await chrome.runtime.sendMessage({type:"boot-helios"})}catch{}r.textContent="Applied. Watching sync status above.",U.disabled=!1});async function F(){try{await chrome.runtime.sendMessage({type:"shutdown-helios"})}catch{}E({state:"booting"});try{await chrome.runtime.sendMessage({type:"boot-helios"})}catch{}}const ue=`
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"
       stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
    <path d="M2.5 4h11"/>
    <path d="M5.5 4V2.5h5V4"/>
    <path d="M4 4l1 9.5h6L12 4"/>
    <path d="M6.5 7v4"/>
    <path d="M9.5 7v4"/>
  </svg>`;function S(e){z.innerHTML="";for(const t of e){const n=document.createElement("li");n.className="verifier-row";const s=document.createElement("span");s.className="verifier-url",s.textContent=t,s.title=t;const o=document.createElement("button");o.type="button",o.className="icon danger",o.title="Remove verifier",o.setAttribute("aria-label","Remove verifier"),o.innerHTML=ue,o.addEventListener("click",async()=>{o.disabled=!0;const c=((await R()).consensusVerifiers??[]).filter(u=>u!==t);await p({consensusVerifiers:c}),S(c),a.className="hint",a.textContent="Removed. Rebooting Helios…",await F(),a.textContent="Removed. Watching sync status above."}),n.append(s,o),z.append(n)}}oe.addEventListener("submit",async e=>{e.preventDefault();const t=H.value.trim();if(!t)return;let n;try{n=new URL(t)}catch{a.textContent="That URL isn't valid.",a.className="hint bad";return}if(n.protocol!=="http:"&&n.protocol!=="https:"){a.textContent="Only http:// or https:// URLs are accepted.",a.className="hint bad";return}const s=await R(),o=s.consensusVerifiers??[],l=(s.consensusRpc||N).replace(/\/$/,"").toLowerCase(),c=t.replace(/\/$/,"").toLowerCase();if(c===l){a.textContent="Verifier must differ from the primary consensus RPC.",a.className="hint bad";return}if(o.some(g=>g.replace(/\/$/,"").toLowerCase()===c)){a.textContent="That verifier is already in the list.",a.className="hint bad";return}A.disabled=!0,a.className="hint",a.textContent="Requesting permission…";const u=n.origin+"/*";if(!await chrome.permissions.contains({origins:[u]})&&!await chrome.permissions.request({origins:[u]})){a.textContent="Permission denied — Helios can't reach that host.",a.className="hint bad",A.disabled=!1;return}const i=[...o,t];await p({consensusVerifiers:i}),S(i),H.value="",a.textContent="Added. Rebooting Helios with the new verifier…",await F(),a.textContent="Added. Watching sync status above.",A.disabled=!1});function V(e){$.value=e??"",b.textContent="",b.className="hint"}function me(e){const t=e.trim();if(!t)return"";const n=t.startsWith("0x")?t:`0x${t}`;return/^0x[0-9a-fA-F]{64}$/.test(n)?n.toLowerCase():null}ae.addEventListener("submit",async e=>{e.preventDefault();const t=me($.value);if(t===null){b.textContent="Expected a 32-byte hex root (0x followed by 64 hex chars).",b.className="hint bad";return}O.disabled=!0,b.className="hint",b.textContent=t?"Saving and rebooting Helios with the new checkpoint…":"Clearing pin and rebooting Helios with a fresh checkpoint…",await p({checkpoint:t||void 0}),V(t||void 0),await F(),b.textContent=t?"Pinned. Watching sync status above.":"Cleared. Watching sync status above.",O.disabled=!1});function v(e){_.classList.remove("ok","bad","syncing"),e!=="idle"&&_.classList.add(e)}function E(e){if(!e){y.textContent="Unknown",v("idle"),w("Start",!1);return}switch(e.state){case"idle":y.textContent="Idle",v("idle"),w("Restart",!1);break;case"booting":y.textContent="Booting…",v("syncing"),w("Booting…",!0);break;case"syncing":y.textContent="Syncing with consensus…",v("syncing"),w("Restart",!1);break;case"synced":y.textContent="Synced · verifying onchain reads locally",v("ok"),w("Restart",!1);break;case"error":y.textContent=`Error: ${e.error??"unknown"}`,v("bad"),w("Restart",!1);break}}function w(e,t){m.dataset.busy!=="1"&&(m.textContent=e,m.disabled=t)}m.addEventListener("click",async()=>{m.dataset.busy="1",m.disabled=!0,m.textContent="Restarting…";try{try{await chrome.runtime.sendMessage({type:"shutdown-helios"})}catch{}E({state:"booting"});try{await chrome.runtime.sendMessage({type:"boot-helios"})}catch{}}finally{delete m.dataset.busy}});async function he(){for(;;){try{const e=await chrome.runtime.sendMessage({type:"get-helios-status"});E(e?.status??null)}catch{E(null)}await new Promise(e=>setTimeout(e,1500))}}Q(e=>{document.activeElement!==h&&M(e.rpcUrl),document.activeElement!==T&&K(e.consensusRpc),document.activeElement!==H&&S(e.consensusVerifiers??[]),document.activeElement!==$&&V(e.checkpoint),k.checked=e.interceptEthLimo,I.checked=e.interceptW3Eth,document.activeElement!==D&&document.activeElement!==P&&Z(e)});k.addEventListener("change",async()=>{await p({interceptEthLimo:k.checked})});I.addEventListener("change",async()=>{await p({interceptW3Eth:I.checked})});const D=document.getElementById("web3-size-cap"),P=document.getElementById("web3-entry-budget"),pe=document.getElementById("web3-budgets"),q=document.getElementById("web3-budgets-apply"),x=document.getElementById("web3-budgets-status"),j=document.getElementById("web3-totals"),G=document.getElementById("web3-list"),ge=`
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"
       stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
    <path d="M2.5 4h11"/>
    <path d="M5.5 4V2.5h5V4"/>
    <path d="M4 4l1 9.5h6L12 4"/>
    <path d="M6.5 7v4"/>
    <path d="M9.5 7v4"/>
  </svg>`;function Y(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(2)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function be(e){const t=Date.now()-e;return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function Z(e){const t=e.web3SizeCapBytes??X,n=e.web3EntryBudget??ee;D.value=String(Math.round(t/(1024*1024))),P.value=String(n)}pe.addEventListener("submit",async e=>{e.preventDefault();const t=Number(D.value),n=Number(P.value);if(!Number.isFinite(t)||t<1||!Number.isFinite(n)||n<1){x.textContent="Pick numbers >= 1.",x.className="hint bad";return}q.disabled=!0,await p({web3SizeCapBytes:Math.round(t*1024*1024),web3EntryBudget:Math.round(n)}),x.className="hint",x.textContent="Saved. Eviction uses the new budget on next pin.",q.disabled=!1});async function J(){let e=[];try{const t=await chrome.runtime.sendMessage({type:"web3-list"});t?.ok&&(e=t.entries)}catch{}fe(e)}function fe(e){if(G.innerHTML="",e.length===0){j.textContent="No web3 dapps cached.";return}const t=e.reduce((n,s)=>n+s.bodyLen,0);j.textContent=`${e.length} dapp${e.length===1?"":"s"} · ${Y(t)} pinned`;for(const n of e){const s=document.createElement("li");s.className="web3-item";const o=document.createElement("div");o.className="web3-item-main";const l=document.createElement("div");l.className="web3-name",l.textContent=n.ensName??n.contractAddress;const c=document.createElement("div");c.className="web3-meta",c.textContent=`${n.contractAddress.slice(0,10)}… · ${Y(n.bodyLen)} · ${be(n.lastAccess)}`;const u=document.createElement("div");u.className="web3-cid",u.textContent=n.cid,o.append(l,c,u);const B=document.createElement("div");B.className="web3-actions";const i=document.createElement("button");i.type="button",i.className="icon danger",i.title="Evict from cache and unpin",i.setAttribute("aria-label","Evict"),i.innerHTML=ge,i.addEventListener("click",async()=>{i.disabled=!0;try{const g=await chrome.runtime.sendMessage({type:"web3-evict",contractAddress:n.contractAddress});if(!g?.ok){console.warn("[dapp3] evict failed",g?.error),i.disabled=!1;return}await J()}catch(g){console.warn("[dapp3] evict threw",g),i.disabled=!1}}),B.append(i),s.append(o,B),G.append(s)}}(async()=>{const e=await R();if(!e.onboardingComplete&&!e.rpcUrl){location.replace(chrome.runtime.getURL("onboarding.html"));return}le(),M(e.rpcUrl),K(e.consensusRpc),S(e.consensusVerifiers??[]),V(e.checkpoint),k.checked=e.interceptEthLimo,I.checked=e.interceptW3Eth,Z(e),J(),he()})();
//# sourceMappingURL=chunk-DfF5H004.js.map
