import{r as O,a as U,o as F,i as K,n as j}from"./chunk-Ci5y0mdV.js";import{c as q}from"./chunk-BT7H_Nq3.js";import{p as J}from"./chunk-CMnPkCrZ.js";import{c as W}from"./chunk-YE5gLsn5.js";function _(){const e=location.hash.startsWith("#")?location.hash.slice(1):"";if(e)try{const s=new URL(e),m=s.hostname.replace(/\.$/,"").toLowerCase(),f=m.match(/^(0x[a-f0-9]{40})\.1\.w3link\.io$/i);if(f&&f[1])return{ensName:f[1].toLowerCase(),path:s.pathname||"/",search:s.search,hash:s.hash,mode:"address"};const b=m.match(/^(0x[a-f0-9]{40})\.w3eth\.io$/i);return b&&b[1]?{ensName:b[1].toLowerCase(),path:s.pathname||"/",search:s.search,hash:s.hash,mode:"address"}:{ensName:m,path:s.pathname||"/",search:s.search,hash:s.hash,mode:"ens"}}catch{}const t=new URLSearchParams(location.search),o=(t.get("name")??"").toLowerCase(),r=/^0x[a-f0-9]{40}$/i.test(o)?"address":"ens";return{ensName:o,path:t.get("path")??"/",search:t.get("search")??"",hash:t.get("hash")??"",mode:r}}const{ensName:n,path:i,search:l,hash:d,mode:G}=_(),h=G==="address";document.title=n?`resolving ${h?Q(n):n}…`:"dapp3.eth";function Q(e){return e.length>12?`${e.slice(0,6)}…${e.slice(-4)}`:e}const g=document.getElementById("name"),w=document.getElementById("status"),A=document.getElementById("bar"),E=document.getElementById("loader"),V=document.getElementById("bypass"),a=document.getElementById("star"),$=document.getElementById("statusBadge"),P=document.getElementById("statusDot"),X=document.getElementById("statusLabel"),x=document.getElementById("stageSub"),S=document.getElementById("errorCard"),Y=document.getElementById("errorDetail"),u=document.getElementById("ethlimoFallback"),R=document.getElementById("ensHistory"),I=document.getElementById("setupCard"),Z=document.getElementById("setupCmd"),ee=document.getElementById("setupJson"),L=document.getElementById("setupRecheck"),c=document.getElementById("setupStatus");!h&&n&&/^(?:[a-z0-9-]+\.)+eth$/.test(n)&&(R.href=`https://ens.eth.sh/history/${n}`,R.hidden=!1);function te(){const e=i.startsWith("/")?i:`/${i}`;return h?/^0x[a-f0-9]{40}$/.test(n)?`https://${n}.w3eth.io${e}${l}${d}`:null:/^(?:[a-z0-9-]+\.)+eth$/.test(n)?`https://${n}.limo${e}${l}${d}`:/^(?:[a-z0-9-]+\.)+gwei$/.test(n)?`https://${n}.domains${e}${l}${d}`:null}function ne(e){try{const t=new URL(e).hostname.toLowerCase().replace(/\.$/,"");if(/^(?:[a-z0-9-]+\.)+eth\.(?:limo|link)$/.test(t))return"open-on-eth-limo";if(/^(?:[a-z0-9-]+\.)+gwei\.domains$/.test(t))return"open-on-gwei-domains";if(/^0x[a-f0-9]{40}\.w3eth\.io$/.test(t))return"open-on-w3eth"}catch{}return null}function v(e){Y.textContent=e,S.hidden=!1,x.hidden=!0;const t=te();t&&(u.href=t,u.textContent=h?"Open on w3eth.io →":/^(?:[a-z0-9-]+\.)+gwei$/.test(n)?"Open on gwei.domains gateway →":"Open on eth.limo gateway →",u.hidden=!1)}u.addEventListener("click",e=>{const t=u.href,o=ne(t);o&&(e.preventDefault(),chrome.runtime.sendMessage({type:o,url:t}).catch(()=>{location.assign(t)}))});function T(){S.hidden=!0,x.hidden=!1,u.hidden=!0}const se=`ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["chrome-extension://${chrome.runtime.id}"]' && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["POST"]'`;Z.textContent=se;ee.innerHTML=W(["{","  ...",'  "API": {','    "HTTPHeaders": {',"      ...",'      "Access-Control-Allow-Methods": ["POST"],','      "Access-Control-Allow-Origin": [',"        ...,",`        "chrome-extension://${chrome.runtime.id}"`,"      ]","    }","  },","  ...","}"].join(`
`));function oe(){S.hidden=!0,u.hidden=!0,x.hidden=!0,E.hidden=!0,w.textContent="Kubo needs one-time setup",I.hidden=!1}function D(){I.hidden=!0,E.hidden=!1}function y(e,t){c.hidden=!1,c.classList.remove("ok","warn","bad"),c.classList.add(e),c.textContent=t}function N(){c.hidden=!0,c.textContent="",c.classList.remove("ok","warn","bad")}I.querySelectorAll(".setup-copy").forEach(e=>{const t=e.querySelector(".setup-copy-label");e.addEventListener("click",async()=>{const o=e.dataset.target;if(!o)return;const r=document.getElementById(o),s=r?.textContent??"";if(s){try{await navigator.clipboard.writeText(s)}catch{if(r){const m=document.createRange();m.selectNodeContents(r);const f=window.getSelection();f?.removeAllRanges(),f?.addRange(m)}return}e.classList.add("copied"),t&&(t.textContent="Copied"),setTimeout(()=>{e.classList.remove("copied"),t&&(t.textContent="Copy")},1500)}})});L.addEventListener("click",async()=>{L.disabled=!0,y("warn","Probing Kubo API…");const e=await J();if(!e.ok){L.disabled=!1,e.kind.kind==="cors"?y("bad","Kubo is still rejecting this extension's origin. Did the daemon restart?"):e.kind.kind==="unreachable"?y("bad",`Can't reach Kubo at 127.0.0.1:5001. Is IPFS Desktop running? (${e.kind.cause})`):y("bad",`Kubo returned an unexpected response: ${e.kind.kind}.`);return}y("ok","Kubo allowed the extension. Retrying…"),D(),N(),await C(!1)});function p(e,t,o){$.classList.remove("ok","syncing","warn"),P.classList.remove("ok","syncing","warn"),$.classList.add(e),P.classList.add(e),X.textContent=t,$.title=o}function z(e){if(!e){p("warn","Helios offline","Helios has not started yet.");return}switch(e.state){case"idle":p("warn","Helios offline","Helios has not started yet.");return;case"booting":p("syncing","Helios booting","Helios is starting up against your execution RPC.");return;case"syncing":p("syncing","Helios syncing","Helios is catching up to the chain tip.");return;case"synced":p("ok","Helios online","Helios is in sync with Ethereum consensus and ready to verify.");return;case"error":p("warn","Helios error",`Helios error: ${e.error??"unknown"}`);return}}z(void 0);const B=`${i==="/"?"":i}${l}${d}`;if(n)if(h){g.textContent="";const e=document.createElement("span");if(e.className="u-host",e.textContent=n,e.title=n,g.appendChild(e),B){const t=document.createElement("span");t.className="u-path",t.textContent=B,g.appendChild(t)}}else q(g,`${n}${B}`);else g.textContent="(no name)";let H=!0;async function ae(){if(!n)return!1;try{const e=await chrome.runtime.sendMessage({type:"interstitial-cache-check",name:n,path:i,search:l,hash:d});if(e?.cached&&typeof e.gatewayUrl=="string")return H=!1,location.replace(e.gatewayUrl),!0;if(e?.bypassHelios)return await C(!0),!0}catch{}return!1}function k(e){A.classList.remove("ok","bad"),E.classList.remove("ok","bad"),e!=="loading"&&(A.classList.add(e),E.classList.add(e))}function re(e){switch(e.state){case"idle":return"Helios is not yet running.";case"booting":return"Starting Helios…";case"syncing":return"Syncing with Ethereum consensus…";case"synced":return"Synced. Resolving…";case"error":return"Helios sync failed"}}async function C(e=!1){H=!1,w.textContent=e?"Resolving via RPC (skipping Helios)…":h?"Fetching onchain HTML…":"Fetching contenthash…",k("loading"),D(),N();const t=await chrome.runtime.sendMessage({type:"interstitial-retry",name:n,path:i,search:l,hash:d,bypassHelios:e});if(!t?.ok){if(t?.code==="kubo-cors-blocked"){oe(),k("bad");return}w.textContent="Resolution failed",v(t?.error??"Unknown error"),k("bad")}}async function ie(){for(;H;){try{const t=(await chrome.runtime.sendMessage({type:"get-helios-status"}))?.status;if(t){if(w.textContent=re(t),z(t),t.state==="synced"){T(),await C(!1);return}t.state==="error"?(k("bad"),v(t.error??"Unknown error")):T()}}catch(e){const t=e instanceof Error?e.message:String(e);w.textContent="Status check failed",v(t)}await new Promise(e=>setTimeout(e,750))}}V.addEventListener("click",()=>C(!0));function M(e){const t=a.querySelector("svg");e?(a.classList.add("favorited"),a.setAttribute("title","Remove from favorites"),a.setAttribute("aria-pressed","true"),t?.setAttribute("fill","currentColor")):(a.classList.remove("favorited"),a.setAttribute("title","Favorite this site"),a.setAttribute("aria-pressed","false"),t?.setAttribute("fill","none"))}if(n&&!h){const e=j(`${i}${l}${d}`||"/");(async()=>{M(await K(n,e))})(),a.addEventListener("click",async o=>{if(o.stopPropagation(),a.classList.contains("favorited"))await O(n,e);else{const r={ensName:n,path:e,addedAt:Date.now()};await U(r)}}),F(o=>{const r=o.some(s=>s.ensName===n&&s.path===e);M(r)})}else a.hidden=!0;(async()=>await ae()||ie())();
//# sourceMappingURL=interstitial-B48k46Km.js.map
