import{g as $,s as c,o as It}from"./chunk-CwBz3wv4.js";import{D as Y,m as pt,p as Bt,b as xt,n as kt,d as Lt,a as Rt,g as Nt,i as St}from"./chunk-CMnPkCrZ.js";import{D as Pt,d as At}from"./chunk-Ba02fv6T.js";const F="https://eth-beacon-chain.drpc.org",Mt=["https://eth-beacon-chain.drpc.org","https://ethereum-beacon-api.publicnode.com","https://lodestar-mainnet.chainsafe.io"],Tt=document.getElementById("rpc-form"),f=document.getElementById("rpc-input"),T=document.getElementById("rpc-apply"),u=document.getElementById("rpc-status"),L=document.getElementById("rpc-reveal"),y=document.getElementById("helios-live"),at=document.getElementById("helios-dot"),h=document.getElementById("helios-restart"),R=document.getElementById("trust-rpc-directly"),K=document.getElementById("trust-rpc-directly-status"),Dt=document.getElementById("consensus-form"),Z=document.getElementById("consensus-input"),ot=document.getElementById("beacon-endpoints"),l=document.getElementById("consensus-status"),V=document.getElementById("consensus-apply"),D=document.getElementById("intercept-ethlimo"),G=document.getElementById("intercept-w3eth"),H=document.getElementById("intercept-gweidomains"),m=document.getElementById("auto-pin-ipfs"),B=document.getElementById("auto-pin-ipfs-status"),Gt=document.getElementById("ipfs-gateway-form"),x=document.getElementById("ipfs-gateway-host"),k=document.getElementById("ipfs-gateway-port"),mt=document.getElementById("ipfs-gateway-apply"),J=document.getElementById("ipfs-gateway-reset"),Ht=document.getElementById("ipfs-gateway-preview"),r=document.getElementById("ipfs-gateway-status"),q={host:Y,port:pt};let U=q;const Ut=document.getElementById("verifier-form"),j=document.getElementById("verifier-input"),O=document.getElementById("verifier-add"),o=document.getElementById("verifier-status"),it=document.getElementById("verifier-list"),$t=document.getElementById("checkpoint-form"),Q=document.getElementById("checkpoint-input"),rt=document.getElementById("checkpoint-apply"),w=document.getElementById("checkpoint-status"),Ft=`
  <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>`,_t=`
  <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 v=!1,ht=!1,ft=null;function Wt(t){try{const e=new URL(t);return e.pathname&&e.pathname!=="/"?`${e.origin}/•••`:e.origin}catch{return t}}function _(t){const e=t??"",n=v||!e;f.dataset.real=e,f.value=n?e:Wt(e),f.type=n?"url":"text",f.readOnly=!n,T.disabled=!n,L.innerHTML=v?_t:Ft,L.title=v?"Cancel edit":"Edit URL",L.setAttribute("aria-label",L.title),u.textContent="",u.className="hint"}L.addEventListener("click",()=>{v=!v;const t=f.dataset.real??"";_(t),v&&f.focus()});Tt.addEventListener("submit",async t=>{t.preventDefault();const e=f.value.trim();if(!e)return;let n;try{n=new URL(e)}catch{u.textContent="That URL isn't valid.",u.className="hint bad";return}if(n.protocol!=="http:"&&n.protocol!=="https:"){u.textContent="Only http:// or https:// URLs are accepted.",u.className="hint bad";return}T.disabled=!0,u.className="hint",u.textContent="Requesting permission…";const s=n.origin+"/*";if(!await chrome.permissions.contains({origins:[s]})&&!await chrome.permissions.request({origins:[s]})){u.textContent="Permission denied — Helios can't reach that host.",u.className="hint bad",T.disabled=!1;return}const p=(await $()).rpcUrl;if(await c({rpcUrl:e}),p===e){try{await chrome.runtime.sendMessage({type:"shutdown-helios"})}catch{}try{await chrome.runtime.sendMessage({type:"boot-helios"})}catch{}}E({state:"booting"}),v=!1,_(e),u.textContent="Saved. Rebooting Helios…",T.disabled=!1});function Vt(){return Z.value.trim()||F}function Ot(){ot.innerHTML="";for(const t of Mt){const e=document.createElement("option");e.value=t,ot.appendChild(e)}}function yt(t){Z.value=t||F,l.textContent=""}Dt.addEventListener("submit",async t=>{t.preventDefault();const e=Vt();let n;try{n=new URL(e)}catch{l.textContent="That URL isn't valid.",l.className="hint bad";return}if(n.protocol!=="http:"&&n.protocol!=="https:"){l.textContent="Only http:// or https:// URLs are accepted.",l.className="hint bad";return}V.disabled=!0,l.className="hint",l.textContent="Requesting permission…";const s=n.origin+"/*";if(!await chrome.permissions.contains({origins:[s]})&&!await chrome.permissions.request({origins:[s]})){l.textContent="Permission denied — Helios can't reach that host.",l.className="hint bad",V.disabled=!1;return}await c({consensusRpc:e===F?void 0:e}),l.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{}l.textContent="Applied. Watching sync status above.",V.disabled=!1});async function X(){try{await chrome.runtime.sendMessage({type:"shutdown-helios"})}catch{}E({state:"booting"});try{await chrome.runtime.sendMessage({type:"boot-helios"})}catch{}}const zt=`
  <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 W(t){it.innerHTML="";for(const e of t){const n=document.createElement("li");n.className="verifier-row";const s=document.createElement("span");s.className="verifier-url",s.textContent=e,s.title=e;const a=document.createElement("button");a.type="button",a.className="icon danger",a.title="Remove verifier",a.setAttribute("aria-label","Remove verifier"),a.innerHTML=zt,a.addEventListener("click",async()=>{a.disabled=!0;const d=((await $()).consensusVerifiers??[]).filter(C=>C!==e);await c({consensusVerifiers:d}),W(d),o.className="hint",o.textContent="Removed. Rebooting Helios…",await X(),o.textContent="Removed. Watching sync status above."}),n.append(s,a),it.append(n)}}Ut.addEventListener("submit",async t=>{t.preventDefault();const e=j.value.trim();if(!e)return;let n;try{n=new URL(e)}catch{o.textContent="That URL isn't valid.",o.className="hint bad";return}if(n.protocol!=="http:"&&n.protocol!=="https:"){o.textContent="Only http:// or https:// URLs are accepted.",o.className="hint bad";return}const s=await $(),a=s.consensusVerifiers??[],p=(s.consensusRpc||F).replace(/\/$/,"").toLowerCase(),d=e.replace(/\/$/,"").toLowerCase();if(d===p){o.textContent="Verifier must differ from the primary consensus RPC.",o.className="hint bad";return}if(a.some(i=>i.replace(/\/$/,"").toLowerCase()===d)){o.textContent="That verifier is already in the list.",o.className="hint bad";return}O.disabled=!0,o.className="hint",o.textContent="Requesting permission…";const C=n.origin+"/*";if(!await chrome.permissions.contains({origins:[C]})&&!await chrome.permissions.request({origins:[C]})){o.textContent="Permission denied — Helios can't reach that host.",o.className="hint bad",O.disabled=!1;return}const I=[...a,e];await c({consensusVerifiers:I}),W(I),j.value="",o.textContent="Added. Rebooting Helios with the new verifier…",await X(),o.textContent="Added. Watching sync status above.",O.disabled=!1});function tt(t){Q.value=t??"",w.textContent="",w.className="hint"}function Kt(){return`ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["chrome-extension://${chrome.runtime.id}"]' && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["POST"]'`}function S(t){Ht.textContent=`http://<cid>.ipfs.${t.host}:${t.port}/`}function z(t,e){return t.host===e.host&&t.port===e.port}function N(t){mt.disabled=!t||z(t,U),J.disabled=z(U,q)&&!!t&&z(t,q)}async function qt(t){if(t.host===Y)return!0;const e=St(t);try{return await chrome.permissions.contains({origins:e})?!0:await chrome.permissions.request({origins:e})}catch{return!1}}function gt(t){const e=Nt(t);U=e,x.value=e.host,k.value=String(e.port),S(e),N(e)}function bt(t={}){const e=t.report!==!1,n=xt(x.value),s=n?.port??kt(k.value);return n?s?{host:n.host,port:s}:(e&&(r.textContent="Enter a port from 1 to 65535.",r.className="hint bad"),null):(e&&(r.textContent="Enter a gateway host, or an http:// gateway URL without a path.",r.className="hint bad"),null)}async function wt(t){if(mt.disabled=!0,J.disabled=!0,r.className="hint",r.textContent="Requesting gateway permission…",!await qt(t)){r.className="hint bad",r.textContent="Permission denied — dapp3 can't reach that gateway host.",N(t);return}r.textContent="Saving and checking gateway…",await c({ipfsGatewayHost:t.host,ipfsGatewayPort:t.port}),x.value=t.host,k.value=String(t.port),U=t,Lt();const n=await Rt(t,{force:!0});r.className=n?"hint":"hint bad",r.textContent=n?`Saved. Kubo gateway is reachable at ${t.host}:${t.port}.`:`Saved, but the gateway did not answer at ${t.host}:${t.port}.`,S(t),N(t)}function vt(){const t=bt({report:!1});if(!t){N(null);return}r.textContent="",r.className="hint",S(t),N(t)}x.addEventListener("input",vt);k.addEventListener("input",vt);Gt.addEventListener("submit",async t=>{t.preventDefault();const e=bt();e&&(S(e),await wt(e))});J.addEventListener("click",async()=>{const t={host:Y,port:pt};x.value=t.host,k.value=String(t.port),S(t),await wt(t)});function jt(t){const e=t.trim();if(!e)return"";const n=e.startsWith("0x")?e:`0x${e}`;return/^0x[0-9a-fA-F]{64}$/.test(n)?n.toLowerCase():null}$t.addEventListener("submit",async t=>{t.preventDefault();const e=jt(Q.value);if(e===null){w.textContent="Expected a 32-byte hex root (0x followed by 64 hex chars).",w.className="hint bad";return}rt.disabled=!0,w.className="hint",w.textContent=e?"Saving and rebooting Helios with the new checkpoint…":"Clearing pin and rebooting Helios with a fresh checkpoint…",await c({checkpoint:e||void 0}),tt(e||void 0),await X(),w.textContent=e?"Pinned. Watching sync status above.":"Cleared. Watching sync status above.",rt.disabled=!1});function g(t){at.classList.remove("ok","bad","syncing","caution"),t!=="idle"&&at.classList.add(t)}function E(t){if(ft=t,ht){y.textContent="Skipped · trusting execution RPC directly",g("caution"),b("Skipped",!0);return}if(!t){y.textContent="Unknown",g("idle"),b("Start",!1);return}switch(t.state){case"idle":y.textContent="Idle",g("idle"),b("Restart",!1);break;case"booting":y.textContent="Booting…",g("syncing"),b("Booting…",!0);break;case"syncing":y.textContent="Syncing with consensus…",g("syncing"),b("Restart",!1);break;case"synced":y.textContent="Synced · verifying onchain reads locally",g("ok"),b("Restart",!1);break;case"error":y.textContent=`Error: ${t.error??"unknown"}`,g("bad"),b("Restart",!1);break}}function et(t){ht=t,R.checked=t,K.textContent=t?"Enabled. New resolutions will be marked RPC-trusted.":"",E(ft)}function b(t,e){h.dataset.busy!=="1"&&(h.textContent=t,h.disabled=e)}h.addEventListener("click",async()=>{h.dataset.busy="1",h.disabled=!0,h.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 h.dataset.busy}});async function Yt(){for(;;){try{const t=await chrome.runtime.sendMessage({type:"get-helios-status"});E(t?.status??null)}catch{E(null)}await new Promise(t=>setTimeout(t,1500))}}It(t=>{document.activeElement!==f&&_(t.rpcUrl),document.activeElement!==Z&&yt(t.consensusRpc),document.activeElement!==j&&W(t.consensusVerifiers??[]),document.activeElement!==Q&&tt(t.checkpoint),document.activeElement!==x&&document.activeElement!==k&&gt(t),D.checked=t.interceptEthLimo,G.checked=t.interceptW3Eth,H.checked=t.interceptGweiDomains,m.checked=t.autoPinIpfsContent,et(t.trustRpcDirectly),document.activeElement!==nt&&document.activeElement!==st&&Et(t)});D.addEventListener("change",async()=>{await c({interceptEthLimo:D.checked})});G.addEventListener("change",async()=>{await c({interceptW3Eth:G.checked})});H.addEventListener("change",async()=>{await c({interceptGweiDomains:H.checked})});R.addEventListener("change",async()=>{R.disabled=!0;const t=R.checked;K.className="hint",et(t),await c({trustRpcDirectly:t}),K.textContent=t?"Enabled. New resolutions will be marked RPC-trusted.":"Disabled. Helios will verify onchain reads again.",R.disabled=!1});m.addEventListener("change",async()=>{if(m.disabled=!0,B.className="hint",!m.checked){await c({autoPinIpfsContent:!1}),B.textContent="Disabled. IPFS contenthashes will only be gateway-cached by Kubo.",m.disabled=!1;return}B.textContent="Checking Kubo API access…";const t=await Bt();if(!t.ok){m.checked=!1,B.className="hint bad",B.textContent=t.kind.kind==="cors"?`Kubo is rejecting this extension. Run once, restart Kubo, then enable again: ${Kt()}`:`Kubo API is not reachable at 127.0.0.1:5001: ${t.kind.kind==="unreachable"?t.kind.cause:t.kind.body}`,m.disabled=!1;return}await c({autoPinIpfsContent:!0}),B.textContent="Enabled. New IPFS contenthash CIDs will be pinned in the background.",m.disabled=!1});const nt=document.getElementById("web3-size-cap"),st=document.getElementById("web3-entry-budget"),Zt=document.getElementById("web3-budgets"),ct=document.getElementById("web3-budgets-apply"),M=document.getElementById("web3-budgets-status"),dt=document.getElementById("web3-totals"),lt=document.getElementById("web3-list"),Jt=`
  <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 ut(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(2)} MB`:t>=1024?`${(t/1024).toFixed(1)} KB`:`${t} B`}function Qt(t){const e=Date.now()-t;return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}function Et(t){const e=t.web3SizeCapBytes??Pt,n=t.web3EntryBudget??At;nt.value=String(Math.round(e/(1024*1024))),st.value=String(n)}Zt.addEventListener("submit",async t=>{t.preventDefault();const e=Number(nt.value),n=Number(st.value);if(!Number.isFinite(e)||e<1||!Number.isFinite(n)||n<1){M.textContent="Pick numbers >= 1.",M.className="hint bad";return}ct.disabled=!0,await c({web3SizeCapBytes:Math.round(e*1024*1024),web3EntryBudget:Math.round(n)}),M.className="hint",M.textContent="Saved. Eviction uses the new budget on next pin.",ct.disabled=!1});async function Ct(){let t=[];try{const e=await chrome.runtime.sendMessage({type:"web3-list"});e?.ok&&(t=e.entries)}catch{}Xt(t)}function Xt(t){if(lt.innerHTML="",t.length===0){dt.textContent="No web3 dapps cached.";return}const e=t.reduce((n,s)=>n+s.bodyLen,0);dt.textContent=`${t.length} dapp${t.length===1?"":"s"} · ${ut(e)} pinned`;for(const n of t){const s=document.createElement("li");s.className="web3-item";const a=document.createElement("div");a.className="web3-item-main";const p=document.createElement("div");p.className="web3-name",p.textContent=n.ensName??n.contractAddress;const d=document.createElement("div");d.className="web3-meta";const C=n.trustedDirectly?" · RPC-trusted":"";d.textContent=`${n.contractAddress.slice(0,10)}… · ${ut(n.bodyLen)} · ${Qt(n.lastAccess)}${C}`;const P=document.createElement("div");P.className="web3-cid",P.textContent=n.cid,a.append(p,d,P);const I=document.createElement("div");I.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=Jt,i.addEventListener("click",async()=>{i.disabled=!0;try{const A=await chrome.runtime.sendMessage({type:"web3-evict",contractAddress:n.contractAddress});if(!A?.ok){console.warn("[dapp3] evict failed",A?.error),i.disabled=!1;return}await Ct()}catch(A){console.warn("[dapp3] evict threw",A),i.disabled=!1}}),I.append(i),s.append(a,I),lt.append(s)}}(async()=>{const t=await $();if(!t.onboardingComplete&&!t.rpcUrl){location.replace(chrome.runtime.getURL("onboarding.html"));return}Ot(),_(t.rpcUrl),yt(t.consensusRpc),W(t.consensusVerifiers??[]),tt(t.checkpoint),gt(t),D.checked=t.interceptEthLimo,G.checked=t.interceptW3Eth,H.checked=t.interceptGweiDomains,m.checked=t.autoPinIpfsContent,et(t.trustRpcDirectly),Et(t),Ct(),Yt()})();
//# sourceMappingURL=chunk-C7J0RjNf.js.map
