@stacknet/userutils 0.5.3 → 0.5.4

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.
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var Ae=react.createContext(null);function at(){let e=react.useContext(Ae);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function it({config:e,callbacks:o,children:r}){return jsxRuntime.jsx(Ae.Provider,{value:{config:e,callbacks:o},children:r})}function ze(){let[e,o]=react.useState({connected:false,address:null,chain:null,provider:null}),[r,i]=react.useState(null),x=react.useCallback(async(f="phantom")=>{i(null);try{let d=typeof window<"u"?window:null,N=f==="phantom"?d?.phantom?.solana||d?.solana:d?.solflare;if(!N)return i(`${f} wallet not found`),null;let u=(await N.connect()).publicKey.toString();return o({connected:!0,address:u,chain:"solana",provider:f}),u}catch(d){return i(d.message||"Failed to connect wallet"),null}},[]),y=react.useCallback(async()=>{i(null);try{let d=(typeof window<"u"?window:null)?.ethereum;if(!d)return i("MetaMask not found"),null;let N=d;d.providers?.length&&(N=d.providers.find(t=>t.isMetaMask)||d);let u=(await N.request({method:"eth_requestAccounts"}))[0];return u?(o({connected:!0,address:u,chain:"ethereum",provider:"metamask"}),u):(i("No account selected"),null)}catch(f){return i(f.message||"Failed to connect wallet"),null}},[]),m=react.useCallback(async(f,d)=>{i(null);let N=d?.chain||e.chain,a=d?.provider||e.provider,u=d?.address||e.address;try{if(N==="solana"){let t=typeof window<"u"?window:null,p=a==="solflare"?t?.solflare:t?.phantom?.solana||t?.solana;if(!p)throw new Error("Wallet not available");let n=new TextEncoder().encode(f),g=await p.signMessage(n,"utf8"),h=new Uint8Array(g.signature||g),k="";for(let P=0;P<h.byteLength;P++)k+=String.fromCharCode(h[P]);return btoa(k)}if(N==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(g=>g.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[f,u]})}throw new Error("No wallet connected")}catch(t){return i(t.message||"Signing failed"),null}},[e]),c=react.useCallback(()=>{o({connected:false,address:null,chain:null,provider:null}),i(null);},[]);return {wallet:e,error:r,connectSolana:x,connectEVM:y,signMessage:m,disconnect:c}}function je(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("stackauth_session="));if(!e)return null;let o=e.slice(18);return JSON.parse(atob(o.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function De(e="__csrf"){if(typeof document>"u")return null;let o=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return o?o.slice(e.length+1):null}function Ee(){let[e,o]=react.useState(null),[r,i]=react.useState(true),x=react.useCallback(()=>{let c=je();c&&c.expiresAt>Date.now()?o({userId:c.userId,address:c.address,chain:c.chain,expiresAt:c.expiresAt,planId:c.planId,authMethod:c.authMethod}):o(null),i(false);},[]);react.useEffect(()=>{x();},[x]);let y=react.useCallback(async(c="")=>{try{let f=await fetch(`${c}/api/auth/session`);if(f.ok){let d=await f.json();if(d.session)return o(d.session),d.session}return o(null),null}catch{return null}},[]),m=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:m,refresh:y,readSession:x}}function Re(e="__csrf",o="x-csrf-token"){let[r,i]=react.useState(null);react.useEffect(()=>{i(De(e));},[e]);let x=r?{[o]:r}:{};return {token:r,headers:x}}var gt="https://stacknet.magma-rpc.com/auth/bridge",ne="stacknet-auth-bridge";function We(e){let o=e?.bridgeUrl||gt,r=e?.disabled||false,i=react.useRef(null),[x,y]=react.useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),m=react.useRef([]),c=react.useRef(false),f=react.useCallback(t=>{let p={...t,protocol:ne};c.current&&i.current?.contentWindow?i.current.contentWindow.postMessage(p,new URL(o).origin):m.current.push(p);},[o]);react.useEffect(()=>{if(r)return;let t=n=>{if(!(!n.data||n.data.protocol!==ne)){try{if(n.origin!==new URL(o).origin)return}catch{return}switch(n.data.type){case "bridge:ready":c.current=true,y(g=>({...g,ready:true}));for(let g of m.current)i.current?.contentWindow?.postMessage(g,n.origin);m.current=[],i.current?.contentWindow?.postMessage({protocol:ne,type:"auth:check"},n.origin),i.current?.contentWindow?.postMessage({protocol:ne,type:"auth:resolve-stack"},n.origin);break;case "auth:status":y(g=>({...g,known:n.data.known,identity:n.data.identity,identityCount:n.data.identityCount||0}));break;case "auth:resolved-stack":y(g=>({...g,resolvedStackId:n.data.stackId||null}));break;}}};window.addEventListener("message",t);let p=document.createElement("iframe");return p.src=o,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),i.current=p,()=>{window.removeEventListener("message",t),p.parentNode&&p.parentNode.removeChild(p),i.current=null,c.current=false;}},[o,r]);let d=react.useCallback(t=>{f({type:"auth:connected",...t});},[f]),N=react.useCallback(t=>{f({type:"auth:disconnected",...t});},[f]),a=react.useCallback(()=>{f({type:"auth:clear"}),y({ready:x.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[f,x.ready]),u=react.useCallback(()=>{f({type:"auth:check"});},[f]);return {...x,reportConnected:d,reportDisconnected:N,clearAll:a,refresh:u}}async function $e(e,o,r,i){let x=e.apiVersion||"v2",y=`${e.baseUrl}/api/${x}${r}`;try{let m=await fetch(y,{method:o,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),c=await m.json();return m.ok?c.success&&c.data!==void 0?{success:!0,data:c.data}:{success:!0,data:c}:{success:!1,error:c.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(m){return {success:false,error:{code:"NETWORK_ERROR",message:m instanceof Error?m.message:"Network error"}}}}function Be(e){return {getNetworkStatus:()=>$e(e,"GET","/network/status"),getWeb3Challenge:(o,r)=>$e(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:o,address:r})}}function Fe(e={apiBaseUrl:""}){let{wallet:o,connectSolana:r,connectEVM:i,signMessage:x,disconnect:y}=ze(),{session:m,isAuthenticated:c,refresh:f,readSession:d}=Ee(),{headers:N}=Re(),a=We({disabled:typeof window>"u"}),[u,t]=react.useState(false),[p,n]=react.useState(null),[g,h]=react.useState(false),k=e.apiBaseUrl||"",P=e.stacknetUrl||"https://stacknet.magma-rpc.com",b=e.stackId||a.resolvedStackId||"",I=Be({baseUrl:P,stackId:b}),R=react.useCallback(async(v,C,D,T)=>{t(true),n(null);try{let S=C;if(!S){let Z=await D();if(!Z)return t(!1),!1;S=Z;}let U=await I.getWeb3Challenge(v,S);if(!U.success||!U.data)return n("Failed to get challenge"),t(!1),!1;let E=await x(U.data.message,{chain:v,provider:T,address:S});if(!E)return t(!1),!1;let B={chain:v,message:U.data.message,signature:E,stackId:b};v==="solana"&&(B.publicKey=S);let Q=await fetch(`${k}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(B)});if(!Q.ok){let Z=await Q.json().catch(()=>({}));return n(Z.error||"Authentication failed"),t(!1),!1}return a.reportConnected({address:S,chain:v,method:T||(v==="solana"?"phantom":"metamask"),stackId:b}),d(),t(!1),!0}catch(S){return n(S.message||"Authentication failed"),t(false),false}},[k,I,x,d,a,b]),W=react.useCallback(async(v="phantom")=>{let C=await r(v);return C?R("solana",C,()=>r(v),v):false},[r,R]),j=react.useCallback(async()=>{let v=await i();return v?R("ethereum",v,i,"metamask"):false},[i,R]),z=react.useCallback(async v=>{t(true),n(null);try{let C=await fetch(`${k}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:v})});if(!C.ok){let D=await C.json().catch(()=>({}));return n(D.error||"Invalid code"),t(!1),!1}return d(),t(!1),!0}catch(C){return n(C.message||"OTP verification failed"),t(false),false}},[k,d]),_=react.useCallback(async(v,C)=>{t(true),n(null);try{let D=C||`${window.location.origin}/api/auth/oauth/callback`,T=new URLSearchParams({provider:v,redirectUri:D,stackId:b}),S=await fetch(`${k}/api/auth/oauth/start?${T}`,{credentials:"include"});if(!S.ok){let E=await S.json().catch(()=>({}));return n(E.error||"Failed to start OAuth flow"),t(!1),!1}let U=await S.json();if(U.redirect_url){let E;try{E=new URL(U.redirect_url);}catch{return n("Invalid OAuth redirect URL"),t(!1),!1}let B=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return E.protocol!=="https:"||!B.some(Q=>Q.test(E.hostname))?(n(`Refusing to redirect to non-OAuth host: ${E.hostname}`),t(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",U.state||""),sessionStorage.setItem("oauth_provider",v)),window.location.href=E.toString(),!0)}return n("No redirect URL returned"),t(!1),!1}catch(D){return n(D.message||"OAuth flow failed"),t(false),false}},[k,b]),L=react.useCallback(async(v,C,D)=>{t(true),n(null);try{if(typeof sessionStorage<"u"){let S=sessionStorage.getItem("oauth_state"),U=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!S||S!==D)return n("OAuth state mismatch \u2014 refusing to complete login"),t(!1),!1;if(U&&U!==v)return n("OAuth provider mismatch \u2014 refusing to complete login"),t(!1),!1}let T=await fetch(`${k}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:v,code:C,state:D,stackId:b})});if(!T.ok){let S=await T.json().catch(()=>({}));return n(S.error||"OAuth authentication failed"),t(!1),!1}return d(),t(!1),!0}catch(T){return n(T.message||"OAuth callback failed"),t(false),false}},[k,b,d]),O=react.useCallback(async()=>{o.address&&o.chain&&a.reportDisconnected({address:o.address,chain:o.chain,stackId:b});try{await fetch(`${k}/api/auth/logout`,{method:"POST",headers:N,credentials:"include"});}catch{}y(),d();},[k,N,y,d,o,a,b]);return react.useEffect(()=>{if(!e.autoConnect||g||c||!a.ready||!a.known||!a.identity)return;h(true);let{chain:v,method:C}=a.identity;v==="solana"&&(C==="phantom"||C==="solflare")?W(C):v==="ethereum"&&j();},[e.autoConnect,g,c,a,W,j]),{session:m,isAuthenticated:c,wallet:o,loading:u,error:p,authenticateSolana:W,authenticateEVM:j,authenticateOTP:z,authenticateOAuth:_,authenticateOAuthCallback:L,logout:O,refresh:()=>f(k),stackId:b,bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount,resolvedStackId:a.resolvedStackId}}}function He(e,o="https://stacknet.magma-rpc.com"){let[r,i]=react.useState(null),[x,y]=react.useState(false),[m,c]=react.useState(null),f=react.useCallback(async N=>{y(true),c(null);try{let a=await fetch(`${o}/api/v2/stacks/${N}`);if(!a.ok)return c("Stack not found"),y(!1),null;let u=await a.json(),t=u.data?.stack||u.stack||u,p={id:t.id,name:t.name,displayName:t.displayName||t.name,description:t.description,logoUrl:t.logoUrl,webPageUrl:t.webPageUrl,allowedChains:t.allowedChains||[],features:t.features,stripeProvider:t.stripeProvider,oauthProviders:t.oauthProviders?.map(n=>({provider:n.provider,clientId:n.clientId,enabled:n.enabled!==!1}))};return i(p),y(!1),p}catch(a){return c(a.message),y(false),null}},[o]);react.useEffect(()=>{e&&f(e);},[e,f]);let d=r?kt(r):[];return {config:r,loading:x,error:m,identityProviders:d,fetchConfig:f}}function kt(e){let o=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(o.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),o.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&o.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&o.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let r of e.oauthProviders)r.enabled&&o.push({type:"oauth",id:r.provider,name:r.provider});return o}function oe(e,o="#"){if(!e||typeof e!="string")return o;let r=e.trim();if(r===""||r==="#")return o;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let i=new URL(r);if(i.protocol==="http:"||i.protocol==="https:")return i.toString()}catch{}return o}function re({length:e=6,onComplete:o,disabled:r=false,error:i,className:x="",inputClassName:y=""}){let [m,c]=react.useState(Array(e).fill("")),f=react.useCallback((a,u)=>{if(u.length>1){let p=u.replace(/\D/g,"").slice(0,e).split(""),n=[...m];p.forEach((h,k)=>{a+k<e&&(n[a+k]=h);}),c(n);let g=Math.min(a+p.length,e-1);document.getElementById(`userutils-otp-${g}`)?.focus(),n.every(h=>h!=="")&&setTimeout(()=>o(n.join("")),100);return}if(!/^\d?$/.test(u))return;let t=[...m];t[a]=u,c(t),u&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),u&&a===e-1&&t.every(p=>p!=="")&&setTimeout(()=>o(t.join("")),100);},[m,e,o]),d=react.useCallback((a,u)=>{if(u.key==="Backspace"&&!m[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let t=[...m];t[a-1]="",c(t);}if(u.key==="Enter"){let t=m.join("");t.length===e&&o(t);}},[m,e,o]);react.useCallback(()=>{c(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:x,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:m.map((a,u)=>jsxRuntime.jsx("input",{id:`userutils-otp-${u}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:t=>f(u,t.target.value),onKeyDown:t=>d(u,t),disabled:r,autoFocus:u===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},u))}),i&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:i})]})}re.displayName="OTPInput";var xt="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function se({className:e}){return jsxRuntime.jsx("img",{src:xt,alt:"Phantom",className:e})}function ae({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function be({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function we({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function xe({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function Mt({config:e,onSuccess:o,title:r="Log in or Sign up",showWallets:i,showOTP:x,hideHeader:y,onOTPSubmit:m,otpLabel:c="Access Code",oauthInline:f,oauthFirst:d,className:N=""}){let a=Fe(e),{isAuthenticated:u,wallet:t,loading:p,error:n,authenticateSolana:g,authenticateEVM:h,authenticateOTP:k,authenticateOAuth:P,bridge:b,stackId:I}=a,R=!e.stackId&&!I,W=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:z,loading:_}=He(I||e.stackId||null,W),[L,O]=react.useState(R?"stack-select":"select"),[v,C]=react.useState(null),[D,T]=react.useState(false),[S,U]=react.useState("idle"),[E,B]=react.useState(""),[Q,Z]=react.useState([]),[Ke,Ce]=react.useState(e.stackId||null),[ue,qe]=react.useState(false),[Xe,et]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let s=()=>{let G=window;qe(!!(G.phantom?.solana?.isPhantom||G.solana?.isPhantom));let J=G.ethereum;et(!!(J?.isMetaMask||J?.providers?.some(K=>K.isMetaMask)));};s(),window.addEventListener("ethereum#initialized",s);let F=setTimeout(s,500);return ()=>{window.removeEventListener("ethereum#initialized",s),clearTimeout(F);}},[]),react.useEffect(()=>{L==="stack-select"&&I&&(Ce(I),O("select"));},[L,I]),react.useEffect(()=>{if(!(!b.ready||!R)&&b.identity){let s=[];b.resolvedStackId&&s.push({stackId:b.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(s.map(async F=>{try{let G=await fetch(`${W}/api/v2/stacks/${F.stackId}`);if(G.ok){let J=await G.json(),K=J.data?.stack||J;F.name=K.displayName||K.name,F.logoUrl=K.logoUrl;}}catch{}return F})).then(Z);}},[b.ready,b.identity,b.resolvedStackId,R,W]),react.useEffect(()=>{u&&L==="success"&&o?.();},[u,L,o]);let Se=i||(z.length>0?z.filter(s=>s.type==="wallet").map(s=>s.id):["phantom","metamask"]),Ie=x!==void 0?x:z.length>0?z.some(s=>s.type==="otp"):true,V=z.filter(s=>s.type==="oauth"),pe=new Set(d||[]),Me=V.filter(s=>pe.has(s.id)),fe=f?V.filter(s=>!pe.has(s.id)):V,Le=async s=>{C(s),O("connecting"),await P(s)||O("error");},tt=async()=>{C("phantom"),O("connecting");let s=await g("phantom");O(s?"success":"error");},nt=async()=>{C("metamask"),O("connecting");let s=await h();O(s?"success":"error");},ot=async s=>{U("verifying"),B(""),await(m||k)(s)?(U("success"),O("success")):(U("error"),B("Invalid or expired code"),setTimeout(()=>U("idle"),2e3));},Ue=()=>{O(R&&!Ke?"stack-select":"select"),C(null),T(false),U("idle"),B("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${N}`,children:[!y&&jsxRuntime.jsxs("div",{className:"mb-6 text-center",children:[j?.logoUrl&&L!=="stack-select"&&jsxRuntime.jsx("img",{src:oe(j.logoUrl),alt:j.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),j?.displayName&&jsxRuntime.jsx("p",{className:"text-sm text-zinc-400 mb-2",children:j.displayName}),jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),L==="stack-select"&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:Q.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),Q.map(s=>jsxRuntime.jsxs("button",{onClick:()=>{Ce(s.stackId),O("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[s.logoUrl?jsxRuntime.jsx("img",{src:oe(s.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsxRuntime.jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:s.name?.[0]?.toUpperCase()||"S"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-white",children:s.name||s.stackId}),jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:s.domain})]}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},s.stackId)),b.ready&&!b.known&&jsxRuntime.jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),L==="select"&&_&&jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),n&&L==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:n}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Ue,children:"Try Again"})]}),L==="success"&&jsxRuntime.jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),L==="connecting"&&p&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxRuntime.jsxs("div",{className:"mx-auto mb-3 h-10 w-10 animate-pulse",children:[v==="phantom"&&jsxRuntime.jsx(se,{className:"h-10 w-10"}),v==="metamask"&&jsxRuntime.jsx(ae,{className:"h-10 w-10"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:t.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:Ue,children:"Cancel"})]}),L==="select"&&!p&&!_&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Me.map(s=>jsxRuntime.jsxs("button",{onClick:()=>Le(s.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx(Ge,{provider:s.id}),jsxRuntime.jsx("span",{className:"font-medium text-white",children:Ye(s.id,s.name)})]},s.id)),Se.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:tt,disabled:!ue,className:`flex w-full items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${ue?"cursor-pointer":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(se,{className:"h-10 w-10 flex-shrink-0 rounded-lg"}),jsxRuntime.jsx("span",{className:"flex-1 text-left font-medium text-white",children:"Phantom"}),!ue&&jsxRuntime.jsx("span",{className:"text-xs text-zinc-500",children:"Not installed"})]}),Se.includes("metamask")&&Xe&&jsxRuntime.jsxs("button",{onClick:nt,className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx(ae,{className:"h-10 w-10 flex-shrink-0"}),jsxRuntime.jsx("span",{className:"flex-1 text-left font-medium text-white",children:"MetaMask"})]}),Ie&&!D&&jsxRuntime.jsxs("button",{onClick:()=>T(true),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e]",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsxRuntime.jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsxRuntime.jsx("span",{className:"flex-1 text-left font-medium text-white",children:c})]}),Ie&&D&&jsxRuntime.jsxs("div",{className:"rounded-xl border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsxRuntime.jsx(re,{onComplete:ot,disabled:S==="verifying",error:E}),S==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),S==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),j?.webPageUrl&&S==="idle"&&(()=>{let s=oe(j.webPageUrl);return s==="#"?null:jsxRuntime.jsx("a",{href:`${s.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})})()]}),(f?fe:V).length>0&&(!f||fe.length>0)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!f&&Me.length===0&&jsxRuntime.jsxs("div",{className:"flex items-center gap-3 py-1",children:[jsxRuntime.jsx("div",{className:"flex-1 border-t border-zinc-800"}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"or continue with"}),jsxRuntime.jsx("div",{className:"flex-1 border-t border-zinc-800"})]}),(f?fe:V.filter(s=>!pe.has(s.id))).map(s=>jsxRuntime.jsxs("button",{onClick:()=>Le(s.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx(Ge,{provider:s.id}),jsxRuntime.jsx("span",{className:"font-medium text-white",children:Ye(s.id,s.name)})]},s.id))]})]})]})}function Ge({provider:e}){switch(e){case "google":return jsxRuntime.jsx(be,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "discord":return jsxRuntime.jsx(we,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "twitter":return jsxRuntime.jsx(xe,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});default:return jsxRuntime.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e] text-sm text-zinc-400 font-mono",children:e[0]?.toUpperCase()})}}function Ye(e,o){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||o||e}function Ut(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith("__csrf="));return e?e.slice(7):null}function Ve(e,o){let[r,i]=react.useState(null),[x,y]=react.useState(true),[m,c]=react.useState(false),[f,d]=react.useState(null),N=o?.apiBaseUrl??"",a=o?.scope===void 0||o?.scope==="global"?"global":`stack:${o.scope.stackId}`,u=react.useCallback(n=>{let g=encodeURIComponent(n);if(a==="global")return `${N}/api/user/profile/${g}`;let h=a.slice(6);return `${N}/api/v2/stacks/${encodeURIComponent(h)}/members/${g}/profile`},[N,a]),t=react.useCallback(async()=>{if(!e){i(null),y(false);return}y(true),d(null);try{let n=await fetch(u(e));if(n.ok){let g=await n.json(),h=g.profile||g.data?.profile||g;i({mid:h.mid||e,username:h.username||"",avatarUrl:h.avatar_url||h.avatarUrl,bio:h.bio,paymentAddress:h.payment_address||h.paymentAddress,createdAt:h.created_at||h.createdAt,updatedAt:h.updated_at||h.updatedAt});}else if(n.status===404)i({mid:e,username:""});else throw new Error(`${n.status}`)}catch(n){d(n instanceof Error?n.message:"Failed to load profile");}finally{y(false);}},[e,u]);react.useEffect(()=>{t();},[t]);let p=react.useCallback(async n=>{if(!e)return false;c(true),d(null);try{let g=Ut(),h={};n.username!==void 0&&(h.username=n.username),n.avatarUrl!==void 0&&(h.avatar_url=n.avatarUrl),n.bio!==void 0&&(h.bio=n.bio),n.paymentAddress!==void 0&&(h.payment_address=n.paymentAddress);let k=await fetch(u(e),{method:"PUT",headers:{"Content-Type":"application/json",...g?{"x-csrf-token":g}:{}},credentials:"same-origin",body:JSON.stringify(h)});if(!k.ok){let I=await k.json().catch(()=>({}));throw new Error(I.error||I.message||`Update failed: ${k.status}`)}let P=await k.json(),b=P.profile||P.data?.profile||P;return i(I=>({mid:I?.mid||e,username:n.username??I?.username??"",avatarUrl:n.avatarUrl??I?.avatarUrl,bio:n.bio??I?.bio,paymentAddress:n.paymentAddress??b.payment_address??b.paymentAddress??I?.paymentAddress,createdAt:I?.createdAt,updatedAt:b.updated_at||b.updatedAt||Date.now()})),!0}catch(g){return d(g instanceof Error?g.message:"Update failed"),false}finally{c(false);}},[e,u]);return {profile:r,loading:x,saving:m,error:f,updateProfile:p,refresh:t}}function zt({mid:e,apiBaseUrl:o="",scope:r,onSave:i,className:x}){let{profile:y,loading:m,saving:c,error:f,updateProfile:d}=Ve(e,{apiBaseUrl:o,scope:r}),[N,a]=react.useState(null),[u,t]=react.useState(null),[p,n]=react.useState(null),g=react.useRef(null),[h,k]=react.useState(false),P=N??y?.username??"",b=u??y?.bio??"",I=p??y?.avatarUrl,R=react.useCallback(z=>{let _=z.target.files?.[0];if(!_)return;let L=new FileReader;L.onload=()=>{n(L.result),k(true);},L.readAsDataURL(_);},[]),W=async()=>{await d({username:P||void 0,avatarUrl:p??y?.avatarUrl,bio:b||void 0})&&(k(false),i?.());};if(m)return jsxRuntime.jsxs("div",{className:x,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let j=r==="global"||!r?"Global profile":`Stack profile (${r.stackId})`;return jsxRuntime.jsxs("div",{className:x,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:j}),jsxRuntime.jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>g.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:I?jsxRuntime.jsx("img",{src:I,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsxRuntime.jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsxRuntime.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsxRuntime.jsx("input",{type:"text",value:P,onChange:z=>{a(z.target.value),k(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsxRuntime.jsx("input",{ref:g,type:"file",accept:"image/*",onChange:R,style:{display:"none"}})]}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsxRuntime.jsx("input",{type:"text",value:b,onChange:z=>{t(z.target.value),k(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),f&&jsxRuntime.jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:f}),h&&jsxRuntime.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsxRuntime.jsx("button",{onClick:W,disabled:c,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:c?"wait":"pointer",opacity:c?.6:1},children:c?"Saving...":"Save"}),jsxRuntime.jsx("button",{onClick:()=>{a(null),t(null),n(null),k(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function jt({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxRuntime.jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsxRuntime.jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsxRuntime.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsxRuntime.jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsxRuntime.jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Dt({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Tt({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
2
- exports.ConnectWidget=Mt;exports.DiscordIcon=we;exports.EthereumIcon=Dt;exports.GoogleIcon=be;exports.MetaMaskIcon=ae;exports.OTPInput=re;exports.PhantomIcon=se;exports.ProfileSettings=zt;exports.SolanaIcon=jt;exports.TelegramIcon=Tt;exports.TwitterIcon=xe;exports.UserUtilsProvider=it;exports.useUserUtilsContext=at;
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var je=react.createContext(null);function lt(){let e=react.useContext(je);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function ct({config:e,callbacks:t,children:r}){return jsxRuntime.jsx(je.Provider,{value:{config:e,callbacks:t},children:r})}function Te(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[r,i]=react.useState(null),v=react.useCallback(async(f="phantom")=>{i(null);try{let d=typeof window<"u"?window:null,C=f==="phantom"?d?.phantom?.solana||d?.solana:d?.solflare;if(!C)return i(`${f} wallet not found`),null;let u=(await C.connect()).publicKey.toString();return t({connected:!0,address:u,chain:"solana",provider:f}),u}catch(d){return i(d.message||"Failed to connect wallet"),null}},[]),y=react.useCallback(async()=>{i(null);try{let d=(typeof window<"u"?window:null)?.ethereum;if(!d)return i("MetaMask not found"),null;let C=d;d.providers?.length&&(C=d.providers.find(n=>n.isMetaMask)||d);let u=(await C.request({method:"eth_requestAccounts"}))[0];return u?(t({connected:!0,address:u,chain:"ethereum",provider:"metamask"}),u):(i("No account selected"),null)}catch(f){return i(f.message||"Failed to connect wallet"),null}},[]),m=react.useCallback(async(f,d)=>{i(null);let C=d?.chain||e.chain,a=d?.provider||e.provider,u=d?.address||e.address;try{if(C==="solana"){let n=typeof window<"u"?window:null,p=a==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!p)throw new Error("Wallet not available");let o=new TextEncoder().encode(f),g=await p.signMessage(o,"utf8"),h=new Uint8Array(g.signature||g),k="";for(let P=0;P<h.byteLength;P++)k+=String.fromCharCode(h[P]);return btoa(k)}if(C==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(g=>g.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[f,u]})}throw new Error("No wallet connected")}catch(n){return i(n.message||"Signing failed"),null}},[e]),c=react.useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),i(null);},[]);return {wallet:e,error:r,connectSolana:v,connectEVM:y,signMessage:m,disconnect:c}}function ze(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function Oe(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function We(){let[e,t]=react.useState(null),[r,i]=react.useState(true),v=react.useCallback(()=>{let c=ze();c&&c.expiresAt>Date.now()?t({userId:c.userId,address:c.address,chain:c.chain,expiresAt:c.expiresAt,planId:c.planId,authMethod:c.authMethod}):t(null),i(false);},[]);react.useEffect(()=>{v();},[v]);let y=react.useCallback(async(c="")=>{try{let f=await fetch(`${c}/api/auth/session`);if(f.ok){let d=await f.json();if(d.session)return t(d.session),d.session}return t(null),null}catch{return null}},[]),m=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:m,refresh:y,readSession:v}}function Be(e="__csrf",t="x-csrf-token"){let[r,i]=react.useState(null);react.useEffect(()=>{i(Oe(e));},[e]);let v=r?{[t]:r}:{};return {token:r,headers:v}}var ht="https://stacknet.magma-rpc.com/auth/bridge",se="stacknet-auth-bridge";function $e(e){let t=e?.bridgeUrl||ht,r=e?.disabled||false,i=react.useRef(null),[v,y]=react.useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),m=react.useRef([]),c=react.useRef(false),f=react.useCallback(n=>{let p={...n,protocol:se};c.current&&i.current?.contentWindow?i.current.contentWindow.postMessage(p,new URL(t).origin):m.current.push(p);},[t]);react.useEffect(()=>{if(r)return;let n=o=>{if(!(!o.data||o.data.protocol!==se)){try{if(o.origin!==new URL(t).origin)return}catch{return}switch(o.data.type){case "bridge:ready":c.current=true,y(g=>({...g,ready:true}));for(let g of m.current)i.current?.contentWindow?.postMessage(g,o.origin);m.current=[],i.current?.contentWindow?.postMessage({protocol:se,type:"auth:check"},o.origin),i.current?.contentWindow?.postMessage({protocol:se,type:"auth:resolve-stack"},o.origin);break;case "auth:status":y(g=>({...g,known:o.data.known,identity:o.data.identity,identityCount:o.data.identityCount||0}));break;case "auth:resolved-stack":y(g=>({...g,resolvedStackId:o.data.stackId||null}));break;}}};window.addEventListener("message",n);let p=document.createElement("iframe");return p.src=t,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),i.current=p,()=>{window.removeEventListener("message",n),p.parentNode&&p.parentNode.removeChild(p),i.current=null,c.current=false;}},[t,r]);let d=react.useCallback(n=>{f({type:"auth:connected",...n});},[f]),C=react.useCallback(n=>{f({type:"auth:disconnected",...n});},[f]),a=react.useCallback(()=>{f({type:"auth:clear"}),y({ready:v.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[f,v.ready]),u=react.useCallback(()=>{f({type:"auth:check"});},[f]);return {...v,reportConnected:d,reportDisconnected:C,clearAll:a,refresh:u}}async function Fe(e,t,r,i){let v=e.apiVersion||"v2",y=`${e.baseUrl}/api/${v}${r}`;try{let m=await fetch(y,{method:t,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),c=await m.json();return m.ok?c.success&&c.data!==void 0?{success:!0,data:c.data}:{success:!0,data:c}:{success:!1,error:c.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(m){return {success:false,error:{code:"NETWORK_ERROR",message:m instanceof Error?m.message:"Network error"}}}}function He(e){return {getNetworkStatus:()=>Fe(e,"GET","/network/status"),getWeb3Challenge:(t,r)=>Fe(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:r})}}function _e(e={apiBaseUrl:""}){let{wallet:t,connectSolana:r,connectEVM:i,signMessage:v,disconnect:y}=Te(),{session:m,isAuthenticated:c,refresh:f,readSession:d}=We(),{headers:C}=Be(),a=$e({disabled:typeof window>"u"}),[u,n]=react.useState(false),[p,o]=react.useState(null),[g,h]=react.useState(false),k=e.apiBaseUrl||"",P=e.stacknetUrl||"https://stacknet.magma-rpc.com",b=e.stackId||a.resolvedStackId||"",I=He({baseUrl:P,stackId:b}),R=react.useCallback(async(x,S,T,O)=>{n(true),o(null);try{let N=S;if(!N){let V=await T();if(!V)return n(!1),!1;N=V;}let A=await I.getWeb3Challenge(x,N);if(!A.success||!A.data)return o("Failed to get challenge"),n(!1),!1;let E=await v(A.data.message,{chain:x,provider:O,address:N});if(!E)return n(!1),!1;let F={chain:x,message:A.data.message,signature:E,stackId:b};x==="solana"&&(F.publicKey=N);let G=await fetch(`${k}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(F)});if(!G.ok){let V=await G.json().catch(()=>({}));return o(V.error||"Authentication failed"),n(!1),!1}return a.reportConnected({address:N,chain:x,method:O||(x==="solana"?"phantom":"metamask"),stackId:b}),d(),n(!1),!0}catch(N){return o(N.message||"Authentication failed"),n(false),false}},[k,I,v,d,a,b]),W=react.useCallback(async(x="phantom")=>{let S=await r(x);return S?R("solana",S,()=>r(x),x):false},[r,R]),D=react.useCallback(async()=>{let x=await i();return x?R("ethereum",x,i,"metamask"):false},[i,R]),j=react.useCallback(async x=>{n(true),o(null);try{let S=await fetch(`${k}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:x})});if(!S.ok){let T=await S.json().catch(()=>({}));return o(T.error||"Invalid code"),n(!1),!1}return d(),n(!1),!0}catch(S){return o(S.message||"OTP verification failed"),n(false),false}},[k,d]),Q=react.useCallback(async(x,S)=>{n(true),o(null);try{let T=S||`${window.location.origin}/api/auth/oauth/callback`,O=new URLSearchParams({provider:x,redirectUri:T,stackId:b}),N=await fetch(`${k}/api/auth/oauth/start?${O}`,{credentials:"include"});if(!N.ok){let E=await N.json().catch(()=>({}));return o(E.error||"Failed to start OAuth flow"),n(!1),!1}let A=await N.json();if(A.redirect_url){let E;try{E=new URL(A.redirect_url);}catch{return o("Invalid OAuth redirect URL"),n(!1),!1}let F=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return E.protocol!=="https:"||!F.some(G=>G.test(E.hostname))?(o(`Refusing to redirect to non-OAuth host: ${E.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",A.state||""),sessionStorage.setItem("oauth_provider",x)),window.location.href=E.toString(),!0)}return o("No redirect URL returned"),n(!1),!1}catch(T){return o(T.message||"OAuth flow failed"),n(false),false}},[k,b]),L=react.useCallback(async(x,S,T)=>{n(true),o(null);try{if(typeof sessionStorage<"u"){let N=sessionStorage.getItem("oauth_state"),A=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!N||N!==T)return o("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(A&&A!==x)return o("OAuth provider mismatch \u2014 refusing to complete login"),n(!1),!1}let O=await fetch(`${k}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:x,code:S,state:T,stackId:b})});if(!O.ok){let N=await O.json().catch(()=>({}));return o(N.error||"OAuth authentication failed"),n(!1),!1}return d(),n(!1),!0}catch(O){return o(O.message||"OAuth callback failed"),n(false),false}},[k,b,d]),z=react.useCallback(async()=>{t.address&&t.chain&&a.reportDisconnected({address:t.address,chain:t.chain,stackId:b});try{await fetch(`${k}/api/auth/logout`,{method:"POST",headers:C,credentials:"include"});}catch{}y(),d();},[k,C,y,d,t,a,b]);return react.useEffect(()=>{if(!e.autoConnect||g||c||!a.ready||!a.known||!a.identity)return;h(true);let{chain:x,method:S}=a.identity;x==="solana"&&(S==="phantom"||S==="solflare")?W(S):x==="ethereum"&&D();},[e.autoConnect,g,c,a,W,D]),{session:m,isAuthenticated:c,wallet:t,loading:u,error:p,authenticateSolana:W,authenticateEVM:D,authenticateOTP:j,authenticateOAuth:Q,authenticateOAuthCallback:L,logout:z,refresh:()=>f(k),stackId:b,bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount,resolvedStackId:a.resolvedStackId}}}function Qe(e,t="https://stacknet.magma-rpc.com"){let[r,i]=react.useState(null),[v,y]=react.useState(false),[m,c]=react.useState(null),f=react.useCallback(async C=>{y(true),c(null);try{let a=await fetch(`${t}/api/v2/stacks/${C}`);if(!a.ok)return c("Stack not found"),y(!1),null;let u=await a.json(),n=u.data?.stack||u.stack||u,p={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(o=>({provider:o.provider,clientId:o.clientId,enabled:o.enabled!==!1}))};return i(p),y(!1),p}catch(a){return c(a.message),y(false),null}},[t]);react.useEffect(()=>{e&&f(e);},[e,f]);let d=r?wt(r):[];return {config:r,loading:v,error:m,identityProviders:d,fetchConfig:f}}function wt(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let r of e.oauthProviders)r.enabled&&t.push({type:"oauth",id:r.provider,name:r.provider});return t}function ae(e,t="#"){if(!e||typeof e!="string")return t;let r=e.trim();if(r===""||r==="#")return t;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let i=new URL(r);if(i.protocol==="http:"||i.protocol==="https:")return i.toString()}catch{}return t}function ie({length:e=6,onComplete:t,disabled:r=false,error:i,className:v="",inputClassName:y=""}){let [m,c]=react.useState(Array(e).fill("")),f=react.useCallback((a,u)=>{if(u.length>1){let p=u.replace(/\D/g,"").slice(0,e).split(""),o=[...m];p.forEach((h,k)=>{a+k<e&&(o[a+k]=h);}),c(o);let g=Math.min(a+p.length,e-1);document.getElementById(`userutils-otp-${g}`)?.focus(),o.every(h=>h!=="")&&setTimeout(()=>t(o.join("")),100);return}if(!/^\d?$/.test(u))return;let n=[...m];n[a]=u,c(n),u&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),u&&a===e-1&&n.every(p=>p!=="")&&setTimeout(()=>t(n.join("")),100);},[m,e,t]),d=react.useCallback((a,u)=>{if(u.key==="Backspace"&&!m[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let n=[...m];n[a-1]="",c(n);}if(u.key==="Enter"){let n=m.join("");n.length===e&&t(n);}},[m,e,t]);react.useCallback(()=>{c(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:v,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:m.map((a,u)=>jsxRuntime.jsx("input",{id:`userutils-otp-${u}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:n=>f(u,n.target.value),onKeyDown:n=>d(u,n),disabled:r,autoFocus:u===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},u))}),i&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:i})]})}ie.displayName="OTPInput";var Ct="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function le({className:e,style:t}){return jsxRuntime.jsx("img",{src:Ct,alt:"Phantom",className:e,style:t})}function ce({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function ve({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function xe({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Ce({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function At({config:e,onSuccess:t,title:r="Log in or Sign up",showWallets:i,showOTP:v,hideHeader:y,onOTPSubmit:m,otpLabel:c="Access Code",oauthInline:f,oauthFirst:d,className:C=""}){let a=_e(e),{isAuthenticated:u,wallet:n,loading:p,error:o,authenticateSolana:g,authenticateEVM:h,authenticateOTP:k,authenticateOAuth:P,bridge:b,stackId:I}=a,R=!e.stackId&&!I,W=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:D,identityProviders:j,loading:Q}=Qe(I||e.stackId||null,W),[L,z]=react.useState(R?"stack-select":"select"),[x,S]=react.useState(null),[T,O]=react.useState(false),[N,A]=react.useState("idle"),[E,F]=react.useState(""),[G,V]=react.useState([]),[Xe,Ie]=react.useState(e.stackId||null),[oe,et]=react.useState(false),[tt,nt]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let s=()=>{let Y=window;et(!!(Y.phantom?.solana?.isPhantom||Y.solana?.isPhantom));let K=Y.ethereum;nt(!!(K?.isMetaMask||K?.providers?.some(q=>q.isMetaMask)));};s(),window.addEventListener("ethereum#initialized",s);let H=setTimeout(s,500);return ()=>{window.removeEventListener("ethereum#initialized",s),clearTimeout(H);}},[]),react.useEffect(()=>{L==="stack-select"&&I&&(Ie(I),z("select"));},[L,I]),react.useEffect(()=>{if(!(!b.ready||!R)&&b.identity){let s=[];b.resolvedStackId&&s.push({stackId:b.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(s.map(async H=>{try{let Y=await fetch(`${W}/api/v2/stacks/${H.stackId}`);if(Y.ok){let K=await Y.json(),q=K.data?.stack||K;H.name=q.displayName||q.name,H.logoUrl=q.logoUrl;}}catch{}return H})).then(V);}},[b.ready,b.identity,b.resolvedStackId,R,W]),react.useEffect(()=>{u&&L==="success"&&t?.();},[u,L,t]);let Me=i||(j.length>0?j.filter(s=>s.type==="wallet").map(s=>s.id):["phantom","metamask"]),Le=v!==void 0?v:j.length>0?j.some(s=>s.type==="otp"):true,J=j.filter(s=>s.type==="oauth"),ge=new Set(d||[]),Ae=J.filter(s=>ge.has(s.id)),me=f?J.filter(s=>!ge.has(s.id)):J,Ue=async s=>{S(s),z("connecting"),await P(s)||z("error");},ot=async()=>{S("phantom"),z("connecting");let s=await g("phantom");z(s?"success":"error");},rt=async()=>{S("metamask"),z("connecting");let s=await h();z(s?"success":"error");},st=async s=>{A("verifying"),F(""),await(m||k)(s)?(A("success"),z("success")):(A("error"),F("Invalid or expired code"),setTimeout(()=>A("idle"),2e3));},Pe=()=>{z(R&&!Xe?"stack-select":"select"),S(null),O(false),A("idle"),F("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${C}`,children:[!y&&jsxRuntime.jsxs("div",{className:"mb-6 text-center",children:[D?.logoUrl&&L!=="stack-select"&&jsxRuntime.jsx("img",{src:ae(D.logoUrl),alt:D.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),D?.displayName&&jsxRuntime.jsx("p",{className:"text-sm text-zinc-400 mb-2",children:D.displayName}),jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),L==="stack-select"&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:G.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),G.map(s=>jsxRuntime.jsxs("button",{onClick:()=>{Ie(s.stackId),z("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[s.logoUrl?jsxRuntime.jsx("img",{src:ae(s.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsxRuntime.jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:s.name?.[0]?.toUpperCase()||"S"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-white",children:s.name||s.stackId}),jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:s.domain})]}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},s.stackId)),b.ready&&!b.known&&jsxRuntime.jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),L==="select"&&Q&&jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),o&&L==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:o}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Pe,children:"Try Again"})]}),L==="success"&&jsxRuntime.jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),L==="connecting"&&p&&jsxRuntime.jsxs("div",{style:{border:"1px solid #27272a",background:"#25252f",padding:24,textAlign:"center"},children:[jsxRuntime.jsxs("div",{style:{width:40,height:40,margin:"0 auto 12px"},children:[x==="phantom"&&jsxRuntime.jsx(le,{style:$}),x==="metamask"&&jsxRuntime.jsx(ce,{style:$})]}),jsxRuntime.jsx("p",{style:{fontWeight:500,fontSize:14,color:"#fff"},children:n.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{style:{marginTop:4,fontSize:12,color:"#71717a"},children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{style:{marginTop:16,fontSize:14,color:"#71717a",background:"none",border:"none",cursor:"pointer"},onClick:Pe,children:"Cancel"})]}),L==="select"&&!p&&!Q&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Ae.map(s=>jsxRuntime.jsxs("button",{onClick:()=>Ue(s.id),style:te,children:[jsxRuntime.jsx(Ze,{provider:s.id}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:"#fff"},children:Ve(s.id,s.name)})]},s.id)),Me.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:ot,disabled:!oe,style:{...te,opacity:oe?1:.5,cursor:oe?"pointer":"not-allowed"},children:[jsxRuntime.jsx(le,{style:{...$,borderRadius:8}}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"Phantom"}),!oe&&jsxRuntime.jsx("span",{style:{fontSize:12,color:"#71717a"},children:"Not installed"})]}),Me.includes("metamask")&&tt&&jsxRuntime.jsxs("button",{onClick:rt,style:te,children:[jsxRuntime.jsx(ce,{style:$}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"MetaMask"})]}),Le&&!T&&jsxRuntime.jsxs("button",{onClick:()=>O(true),style:te,children:[jsxRuntime.jsx("div",{style:{...$,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e"},children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsxRuntime.jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:c})]}),Le&&T&&jsxRuntime.jsxs("div",{style:{borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:24},children:[jsxRuntime.jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginBottom:16},children:"Enter your 6-digit access code"}),jsxRuntime.jsx(ie,{onComplete:st,disabled:N==="verifying",error:E}),N==="verifying"&&jsxRuntime.jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginTop:16},children:"Verifying..."}),N==="success"&&jsxRuntime.jsx("p",{style:{textAlign:"center",fontSize:14,color:"#4ade80",marginTop:16},children:"Verified!"}),D?.webPageUrl&&N==="idle"&&(()=>{let s=ae(D.webPageUrl);return s==="#"?null:jsxRuntime.jsx("a",{href:`${s.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",style:{display:"block",textAlign:"center",fontSize:14,color:"#71717a",marginTop:16},children:"Get code"})})()]}),(f?me:J).length>0&&(!f||me.length>0)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!f&&Ae.length===0&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 0"},children:[jsxRuntime.jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}}),jsxRuntime.jsx("span",{style:{fontSize:12,color:"#52525b"},children:"or continue with"}),jsxRuntime.jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}})]}),(f?me:J.filter(s=>!ge.has(s.id))).map(s=>jsxRuntime.jsxs("button",{onClick:()=>Ue(s.id),style:te,children:[jsxRuntime.jsx(Ze,{provider:s.id}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:"#fff"},children:Ve(s.id,s.name)})]},s.id))]})]})]})}var $={width:40,height:40,flexShrink:0},te={display:"flex",width:"100%",alignItems:"center",gap:12,borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:16,cursor:"pointer",transition:"background 0.15s"};function Ze({provider:e}){switch(e){case "google":return jsxRuntime.jsx(ve,{style:{...$,borderRadius:8}});case "discord":return jsxRuntime.jsx(xe,{style:{...$,borderRadius:8}});case "twitter":return jsxRuntime.jsx(Ce,{style:{...$,borderRadius:8}});default:return jsxRuntime.jsx("div",{style:{...$,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e",fontSize:14,color:"#a1a1aa",fontFamily:"monospace"},children:e[0]?.toUpperCase()})}}function Ve(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||t||e}function Pt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function Ke(e,t){let[r,i]=react.useState(null),[v,y]=react.useState(true),[m,c]=react.useState(false),[f,d]=react.useState(null),C=t?.apiBaseUrl??"",a=t?.scope===void 0||t?.scope==="global"?"global":`stack:${t.scope.stackId}`,u=react.useCallback(o=>{let g=encodeURIComponent(o);if(a==="global")return `${C}/api/user/profile/${g}`;let h=a.slice(6);return `${C}/api/v2/stacks/${encodeURIComponent(h)}/members/${g}/profile`},[C,a]),n=react.useCallback(async()=>{if(!e){i(null),y(false);return}y(true),d(null);try{let o=await fetch(u(e));if(o.ok){let g=await o.json(),h=g.profile||g.data?.profile||g;i({mid:h.mid||e,username:h.username||"",avatarUrl:h.avatar_url||h.avatarUrl,bio:h.bio,paymentAddress:h.payment_address||h.paymentAddress,createdAt:h.created_at||h.createdAt,updatedAt:h.updated_at||h.updatedAt});}else if(o.status===404)i({mid:e,username:""});else throw new Error(`${o.status}`)}catch(o){d(o instanceof Error?o.message:"Failed to load profile");}finally{y(false);}},[e,u]);react.useEffect(()=>{n();},[n]);let p=react.useCallback(async o=>{if(!e)return false;c(true),d(null);try{let g=Pt(),h={};o.username!==void 0&&(h.username=o.username),o.avatarUrl!==void 0&&(h.avatar_url=o.avatarUrl),o.bio!==void 0&&(h.bio=o.bio),o.paymentAddress!==void 0&&(h.payment_address=o.paymentAddress);let k=await fetch(u(e),{method:"PUT",headers:{"Content-Type":"application/json",...g?{"x-csrf-token":g}:{}},credentials:"same-origin",body:JSON.stringify(h)});if(!k.ok){let I=await k.json().catch(()=>({}));throw new Error(I.error||I.message||`Update failed: ${k.status}`)}let P=await k.json(),b=P.profile||P.data?.profile||P;return i(I=>({mid:I?.mid||e,username:o.username??I?.username??"",avatarUrl:o.avatarUrl??I?.avatarUrl,bio:o.bio??I?.bio,paymentAddress:o.paymentAddress??b.payment_address??b.paymentAddress??I?.paymentAddress,createdAt:I?.createdAt,updatedAt:b.updated_at||b.updatedAt||Date.now()})),!0}catch(g){return d(g instanceof Error?g.message:"Update failed"),false}finally{c(false);}},[e,u]);return {profile:r,loading:v,saving:m,error:f,updateProfile:p,refresh:n}}function Tt({mid:e,apiBaseUrl:t="",scope:r,onSave:i,className:v}){let{profile:y,loading:m,saving:c,error:f,updateProfile:d}=Ke(e,{apiBaseUrl:t,scope:r}),[C,a]=react.useState(null),[u,n]=react.useState(null),[p,o]=react.useState(null),g=react.useRef(null),[h,k]=react.useState(false),P=C??y?.username??"",b=u??y?.bio??"",I=p??y?.avatarUrl,R=react.useCallback(j=>{let Q=j.target.files?.[0];if(!Q)return;let L=new FileReader;L.onload=()=>{o(L.result),k(true);},L.readAsDataURL(Q);},[]),W=async()=>{await d({username:P||void 0,avatarUrl:p??y?.avatarUrl,bio:b||void 0})&&(k(false),i?.());};if(m)return jsxRuntime.jsxs("div",{className:v,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let D=r==="global"||!r?"Global profile":`Stack profile (${r.stackId})`;return jsxRuntime.jsxs("div",{className:v,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:D}),jsxRuntime.jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>g.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:I?jsxRuntime.jsx("img",{src:I,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsxRuntime.jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsxRuntime.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsxRuntime.jsx("input",{type:"text",value:P,onChange:j=>{a(j.target.value),k(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsxRuntime.jsx("input",{ref:g,type:"file",accept:"image/*",onChange:R,style:{display:"none"}})]}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsxRuntime.jsx("input",{type:"text",value:b,onChange:j=>{n(j.target.value),k(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),f&&jsxRuntime.jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:f}),h&&jsxRuntime.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsxRuntime.jsx("button",{onClick:W,disabled:c,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:c?"wait":"pointer",opacity:c?.6:1},children:c?"Saving...":"Save"}),jsxRuntime.jsx("button",{onClick:()=>{a(null),n(null),o(null),k(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function zt({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxRuntime.jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsxRuntime.jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsxRuntime.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsxRuntime.jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsxRuntime.jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Ot({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Rt({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
2
+ exports.ConnectWidget=At;exports.DiscordIcon=xe;exports.EthereumIcon=Ot;exports.GoogleIcon=ve;exports.MetaMaskIcon=ce;exports.OTPInput=ie;exports.PhantomIcon=le;exports.ProfileSettings=Tt;exports.SolanaIcon=zt;exports.TelegramIcon=Rt;exports.TwitterIcon=Ce;exports.UserUtilsProvider=ct;exports.useUserUtilsContext=lt;
@@ -65,12 +65,14 @@ interface ProfileSettingsProps {
65
65
  }
66
66
  declare function ProfileSettings({ mid, apiBaseUrl, scope, onSave, className, }: ProfileSettingsProps): react_jsx_runtime.JSX.Element;
67
67
 
68
- declare function PhantomIcon({ className }: {
68
+ declare function PhantomIcon({ className, style }: {
69
69
  className?: string;
70
+ style?: React.CSSProperties;
70
71
  }): react_jsx_runtime.JSX.Element;
71
72
 
72
- declare function MetaMaskIcon({ className }: {
73
+ declare function MetaMaskIcon({ className, style }: {
73
74
  className?: string;
75
+ style?: React.CSSProperties;
74
76
  }): react_jsx_runtime.JSX.Element;
75
77
 
76
78
  declare function SolanaIcon({ className }: {
@@ -81,16 +83,19 @@ declare function EthereumIcon({ className }: {
81
83
  className?: string;
82
84
  }): react_jsx_runtime.JSX.Element;
83
85
 
84
- declare function TwitterIcon({ className }: {
86
+ declare function TwitterIcon({ className, style }: {
85
87
  className?: string;
88
+ style?: React.CSSProperties;
86
89
  }): react_jsx_runtime.JSX.Element;
87
90
 
88
- declare function GoogleIcon({ className }: {
91
+ declare function GoogleIcon({ className, style }: {
89
92
  className?: string;
93
+ style?: React.CSSProperties;
90
94
  }): react_jsx_runtime.JSX.Element;
91
95
 
92
- declare function DiscordIcon({ className }: {
96
+ declare function DiscordIcon({ className, style }: {
93
97
  className?: string;
98
+ style?: React.CSSProperties;
94
99
  }): react_jsx_runtime.JSX.Element;
95
100
 
96
101
  declare function TelegramIcon({ className }: {
@@ -65,12 +65,14 @@ interface ProfileSettingsProps {
65
65
  }
66
66
  declare function ProfileSettings({ mid, apiBaseUrl, scope, onSave, className, }: ProfileSettingsProps): react_jsx_runtime.JSX.Element;
67
67
 
68
- declare function PhantomIcon({ className }: {
68
+ declare function PhantomIcon({ className, style }: {
69
69
  className?: string;
70
+ style?: React.CSSProperties;
70
71
  }): react_jsx_runtime.JSX.Element;
71
72
 
72
- declare function MetaMaskIcon({ className }: {
73
+ declare function MetaMaskIcon({ className, style }: {
73
74
  className?: string;
75
+ style?: React.CSSProperties;
74
76
  }): react_jsx_runtime.JSX.Element;
75
77
 
76
78
  declare function SolanaIcon({ className }: {
@@ -81,16 +83,19 @@ declare function EthereumIcon({ className }: {
81
83
  className?: string;
82
84
  }): react_jsx_runtime.JSX.Element;
83
85
 
84
- declare function TwitterIcon({ className }: {
86
+ declare function TwitterIcon({ className, style }: {
85
87
  className?: string;
88
+ style?: React.CSSProperties;
86
89
  }): react_jsx_runtime.JSX.Element;
87
90
 
88
- declare function GoogleIcon({ className }: {
91
+ declare function GoogleIcon({ className, style }: {
89
92
  className?: string;
93
+ style?: React.CSSProperties;
90
94
  }): react_jsx_runtime.JSX.Element;
91
95
 
92
- declare function DiscordIcon({ className }: {
96
+ declare function DiscordIcon({ className, style }: {
93
97
  className?: string;
98
+ style?: React.CSSProperties;
94
99
  }): react_jsx_runtime.JSX.Element;
95
100
 
96
101
  declare function TelegramIcon({ className }: {
@@ -1,2 +1,2 @@
1
- import {createContext,useContext,useState,useCallback,useEffect,useRef}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Ae=createContext(null);function at(){let e=useContext(Ae);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function it({config:e,callbacks:o,children:r}){return jsx(Ae.Provider,{value:{config:e,callbacks:o},children:r})}function ze(){let[e,o]=useState({connected:false,address:null,chain:null,provider:null}),[r,i]=useState(null),x=useCallback(async(f="phantom")=>{i(null);try{let d=typeof window<"u"?window:null,N=f==="phantom"?d?.phantom?.solana||d?.solana:d?.solflare;if(!N)return i(`${f} wallet not found`),null;let u=(await N.connect()).publicKey.toString();return o({connected:!0,address:u,chain:"solana",provider:f}),u}catch(d){return i(d.message||"Failed to connect wallet"),null}},[]),y=useCallback(async()=>{i(null);try{let d=(typeof window<"u"?window:null)?.ethereum;if(!d)return i("MetaMask not found"),null;let N=d;d.providers?.length&&(N=d.providers.find(t=>t.isMetaMask)||d);let u=(await N.request({method:"eth_requestAccounts"}))[0];return u?(o({connected:!0,address:u,chain:"ethereum",provider:"metamask"}),u):(i("No account selected"),null)}catch(f){return i(f.message||"Failed to connect wallet"),null}},[]),m=useCallback(async(f,d)=>{i(null);let N=d?.chain||e.chain,a=d?.provider||e.provider,u=d?.address||e.address;try{if(N==="solana"){let t=typeof window<"u"?window:null,p=a==="solflare"?t?.solflare:t?.phantom?.solana||t?.solana;if(!p)throw new Error("Wallet not available");let n=new TextEncoder().encode(f),g=await p.signMessage(n,"utf8"),h=new Uint8Array(g.signature||g),k="";for(let P=0;P<h.byteLength;P++)k+=String.fromCharCode(h[P]);return btoa(k)}if(N==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(g=>g.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[f,u]})}throw new Error("No wallet connected")}catch(t){return i(t.message||"Signing failed"),null}},[e]),c=useCallback(()=>{o({connected:false,address:null,chain:null,provider:null}),i(null);},[]);return {wallet:e,error:r,connectSolana:x,connectEVM:y,signMessage:m,disconnect:c}}function je(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("stackauth_session="));if(!e)return null;let o=e.slice(18);return JSON.parse(atob(o.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function De(e="__csrf"){if(typeof document>"u")return null;let o=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return o?o.slice(e.length+1):null}function Ee(){let[e,o]=useState(null),[r,i]=useState(true),x=useCallback(()=>{let c=je();c&&c.expiresAt>Date.now()?o({userId:c.userId,address:c.address,chain:c.chain,expiresAt:c.expiresAt,planId:c.planId,authMethod:c.authMethod}):o(null),i(false);},[]);useEffect(()=>{x();},[x]);let y=useCallback(async(c="")=>{try{let f=await fetch(`${c}/api/auth/session`);if(f.ok){let d=await f.json();if(d.session)return o(d.session),d.session}return o(null),null}catch{return null}},[]),m=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:m,refresh:y,readSession:x}}function Re(e="__csrf",o="x-csrf-token"){let[r,i]=useState(null);useEffect(()=>{i(De(e));},[e]);let x=r?{[o]:r}:{};return {token:r,headers:x}}var gt="https://stacknet.magma-rpc.com/auth/bridge",ne="stacknet-auth-bridge";function We(e){let o=e?.bridgeUrl||gt,r=e?.disabled||false,i=useRef(null),[x,y]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),m=useRef([]),c=useRef(false),f=useCallback(t=>{let p={...t,protocol:ne};c.current&&i.current?.contentWindow?i.current.contentWindow.postMessage(p,new URL(o).origin):m.current.push(p);},[o]);useEffect(()=>{if(r)return;let t=n=>{if(!(!n.data||n.data.protocol!==ne)){try{if(n.origin!==new URL(o).origin)return}catch{return}switch(n.data.type){case "bridge:ready":c.current=true,y(g=>({...g,ready:true}));for(let g of m.current)i.current?.contentWindow?.postMessage(g,n.origin);m.current=[],i.current?.contentWindow?.postMessage({protocol:ne,type:"auth:check"},n.origin),i.current?.contentWindow?.postMessage({protocol:ne,type:"auth:resolve-stack"},n.origin);break;case "auth:status":y(g=>({...g,known:n.data.known,identity:n.data.identity,identityCount:n.data.identityCount||0}));break;case "auth:resolved-stack":y(g=>({...g,resolvedStackId:n.data.stackId||null}));break;}}};window.addEventListener("message",t);let p=document.createElement("iframe");return p.src=o,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),i.current=p,()=>{window.removeEventListener("message",t),p.parentNode&&p.parentNode.removeChild(p),i.current=null,c.current=false;}},[o,r]);let d=useCallback(t=>{f({type:"auth:connected",...t});},[f]),N=useCallback(t=>{f({type:"auth:disconnected",...t});},[f]),a=useCallback(()=>{f({type:"auth:clear"}),y({ready:x.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[f,x.ready]),u=useCallback(()=>{f({type:"auth:check"});},[f]);return {...x,reportConnected:d,reportDisconnected:N,clearAll:a,refresh:u}}async function $e(e,o,r,i){let x=e.apiVersion||"v2",y=`${e.baseUrl}/api/${x}${r}`;try{let m=await fetch(y,{method:o,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),c=await m.json();return m.ok?c.success&&c.data!==void 0?{success:!0,data:c.data}:{success:!0,data:c}:{success:!1,error:c.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(m){return {success:false,error:{code:"NETWORK_ERROR",message:m instanceof Error?m.message:"Network error"}}}}function Be(e){return {getNetworkStatus:()=>$e(e,"GET","/network/status"),getWeb3Challenge:(o,r)=>$e(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:o,address:r})}}function Fe(e={apiBaseUrl:""}){let{wallet:o,connectSolana:r,connectEVM:i,signMessage:x,disconnect:y}=ze(),{session:m,isAuthenticated:c,refresh:f,readSession:d}=Ee(),{headers:N}=Re(),a=We({disabled:typeof window>"u"}),[u,t]=useState(false),[p,n]=useState(null),[g,h]=useState(false),k=e.apiBaseUrl||"",P=e.stacknetUrl||"https://stacknet.magma-rpc.com",b=e.stackId||a.resolvedStackId||"",I=Be({baseUrl:P,stackId:b}),R=useCallback(async(v,C,D,T)=>{t(true),n(null);try{let S=C;if(!S){let Z=await D();if(!Z)return t(!1),!1;S=Z;}let U=await I.getWeb3Challenge(v,S);if(!U.success||!U.data)return n("Failed to get challenge"),t(!1),!1;let E=await x(U.data.message,{chain:v,provider:T,address:S});if(!E)return t(!1),!1;let B={chain:v,message:U.data.message,signature:E,stackId:b};v==="solana"&&(B.publicKey=S);let Q=await fetch(`${k}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(B)});if(!Q.ok){let Z=await Q.json().catch(()=>({}));return n(Z.error||"Authentication failed"),t(!1),!1}return a.reportConnected({address:S,chain:v,method:T||(v==="solana"?"phantom":"metamask"),stackId:b}),d(),t(!1),!0}catch(S){return n(S.message||"Authentication failed"),t(false),false}},[k,I,x,d,a,b]),W=useCallback(async(v="phantom")=>{let C=await r(v);return C?R("solana",C,()=>r(v),v):false},[r,R]),j=useCallback(async()=>{let v=await i();return v?R("ethereum",v,i,"metamask"):false},[i,R]),z=useCallback(async v=>{t(true),n(null);try{let C=await fetch(`${k}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:v})});if(!C.ok){let D=await C.json().catch(()=>({}));return n(D.error||"Invalid code"),t(!1),!1}return d(),t(!1),!0}catch(C){return n(C.message||"OTP verification failed"),t(false),false}},[k,d]),_=useCallback(async(v,C)=>{t(true),n(null);try{let D=C||`${window.location.origin}/api/auth/oauth/callback`,T=new URLSearchParams({provider:v,redirectUri:D,stackId:b}),S=await fetch(`${k}/api/auth/oauth/start?${T}`,{credentials:"include"});if(!S.ok){let E=await S.json().catch(()=>({}));return n(E.error||"Failed to start OAuth flow"),t(!1),!1}let U=await S.json();if(U.redirect_url){let E;try{E=new URL(U.redirect_url);}catch{return n("Invalid OAuth redirect URL"),t(!1),!1}let B=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return E.protocol!=="https:"||!B.some(Q=>Q.test(E.hostname))?(n(`Refusing to redirect to non-OAuth host: ${E.hostname}`),t(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",U.state||""),sessionStorage.setItem("oauth_provider",v)),window.location.href=E.toString(),!0)}return n("No redirect URL returned"),t(!1),!1}catch(D){return n(D.message||"OAuth flow failed"),t(false),false}},[k,b]),L=useCallback(async(v,C,D)=>{t(true),n(null);try{if(typeof sessionStorage<"u"){let S=sessionStorage.getItem("oauth_state"),U=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!S||S!==D)return n("OAuth state mismatch \u2014 refusing to complete login"),t(!1),!1;if(U&&U!==v)return n("OAuth provider mismatch \u2014 refusing to complete login"),t(!1),!1}let T=await fetch(`${k}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:v,code:C,state:D,stackId:b})});if(!T.ok){let S=await T.json().catch(()=>({}));return n(S.error||"OAuth authentication failed"),t(!1),!1}return d(),t(!1),!0}catch(T){return n(T.message||"OAuth callback failed"),t(false),false}},[k,b,d]),O=useCallback(async()=>{o.address&&o.chain&&a.reportDisconnected({address:o.address,chain:o.chain,stackId:b});try{await fetch(`${k}/api/auth/logout`,{method:"POST",headers:N,credentials:"include"});}catch{}y(),d();},[k,N,y,d,o,a,b]);return useEffect(()=>{if(!e.autoConnect||g||c||!a.ready||!a.known||!a.identity)return;h(true);let{chain:v,method:C}=a.identity;v==="solana"&&(C==="phantom"||C==="solflare")?W(C):v==="ethereum"&&j();},[e.autoConnect,g,c,a,W,j]),{session:m,isAuthenticated:c,wallet:o,loading:u,error:p,authenticateSolana:W,authenticateEVM:j,authenticateOTP:z,authenticateOAuth:_,authenticateOAuthCallback:L,logout:O,refresh:()=>f(k),stackId:b,bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount,resolvedStackId:a.resolvedStackId}}}function He(e,o="https://stacknet.magma-rpc.com"){let[r,i]=useState(null),[x,y]=useState(false),[m,c]=useState(null),f=useCallback(async N=>{y(true),c(null);try{let a=await fetch(`${o}/api/v2/stacks/${N}`);if(!a.ok)return c("Stack not found"),y(!1),null;let u=await a.json(),t=u.data?.stack||u.stack||u,p={id:t.id,name:t.name,displayName:t.displayName||t.name,description:t.description,logoUrl:t.logoUrl,webPageUrl:t.webPageUrl,allowedChains:t.allowedChains||[],features:t.features,stripeProvider:t.stripeProvider,oauthProviders:t.oauthProviders?.map(n=>({provider:n.provider,clientId:n.clientId,enabled:n.enabled!==!1}))};return i(p),y(!1),p}catch(a){return c(a.message),y(false),null}},[o]);useEffect(()=>{e&&f(e);},[e,f]);let d=r?kt(r):[];return {config:r,loading:x,error:m,identityProviders:d,fetchConfig:f}}function kt(e){let o=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(o.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),o.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&o.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&o.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let r of e.oauthProviders)r.enabled&&o.push({type:"oauth",id:r.provider,name:r.provider});return o}function oe(e,o="#"){if(!e||typeof e!="string")return o;let r=e.trim();if(r===""||r==="#")return o;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let i=new URL(r);if(i.protocol==="http:"||i.protocol==="https:")return i.toString()}catch{}return o}function re({length:e=6,onComplete:o,disabled:r=false,error:i,className:x="",inputClassName:y=""}){let [m,c]=useState(Array(e).fill("")),f=useCallback((a,u)=>{if(u.length>1){let p=u.replace(/\D/g,"").slice(0,e).split(""),n=[...m];p.forEach((h,k)=>{a+k<e&&(n[a+k]=h);}),c(n);let g=Math.min(a+p.length,e-1);document.getElementById(`userutils-otp-${g}`)?.focus(),n.every(h=>h!=="")&&setTimeout(()=>o(n.join("")),100);return}if(!/^\d?$/.test(u))return;let t=[...m];t[a]=u,c(t),u&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),u&&a===e-1&&t.every(p=>p!=="")&&setTimeout(()=>o(t.join("")),100);},[m,e,o]),d=useCallback((a,u)=>{if(u.key==="Backspace"&&!m[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let t=[...m];t[a-1]="",c(t);}if(u.key==="Enter"){let t=m.join("");t.length===e&&o(t);}},[m,e,o]);useCallback(()=>{c(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:x,children:[jsx("div",{className:"flex gap-2 justify-center",children:m.map((a,u)=>jsx("input",{id:`userutils-otp-${u}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:t=>f(u,t.target.value),onKeyDown:t=>d(u,t),disabled:r,autoFocus:u===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},u))}),i&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:i})]})}re.displayName="OTPInput";var xt="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function se({className:e}){return jsx("img",{src:xt,alt:"Phantom",className:e})}function ae({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function be({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function we({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function xe({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function Mt({config:e,onSuccess:o,title:r="Log in or Sign up",showWallets:i,showOTP:x,hideHeader:y,onOTPSubmit:m,otpLabel:c="Access Code",oauthInline:f,oauthFirst:d,className:N=""}){let a=Fe(e),{isAuthenticated:u,wallet:t,loading:p,error:n,authenticateSolana:g,authenticateEVM:h,authenticateOTP:k,authenticateOAuth:P,bridge:b,stackId:I}=a,R=!e.stackId&&!I,W=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:z,loading:_}=He(I||e.stackId||null,W),[L,O]=useState(R?"stack-select":"select"),[v,C]=useState(null),[D,T]=useState(false),[S,U]=useState("idle"),[E,B]=useState(""),[Q,Z]=useState([]),[Ke,Ce]=useState(e.stackId||null),[ue,qe]=useState(false),[Xe,et]=useState(false);useEffect(()=>{if(typeof window>"u")return;let s=()=>{let G=window;qe(!!(G.phantom?.solana?.isPhantom||G.solana?.isPhantom));let J=G.ethereum;et(!!(J?.isMetaMask||J?.providers?.some(K=>K.isMetaMask)));};s(),window.addEventListener("ethereum#initialized",s);let F=setTimeout(s,500);return ()=>{window.removeEventListener("ethereum#initialized",s),clearTimeout(F);}},[]),useEffect(()=>{L==="stack-select"&&I&&(Ce(I),O("select"));},[L,I]),useEffect(()=>{if(!(!b.ready||!R)&&b.identity){let s=[];b.resolvedStackId&&s.push({stackId:b.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(s.map(async F=>{try{let G=await fetch(`${W}/api/v2/stacks/${F.stackId}`);if(G.ok){let J=await G.json(),K=J.data?.stack||J;F.name=K.displayName||K.name,F.logoUrl=K.logoUrl;}}catch{}return F})).then(Z);}},[b.ready,b.identity,b.resolvedStackId,R,W]),useEffect(()=>{u&&L==="success"&&o?.();},[u,L,o]);let Se=i||(z.length>0?z.filter(s=>s.type==="wallet").map(s=>s.id):["phantom","metamask"]),Ie=x!==void 0?x:z.length>0?z.some(s=>s.type==="otp"):true,V=z.filter(s=>s.type==="oauth"),pe=new Set(d||[]),Me=V.filter(s=>pe.has(s.id)),fe=f?V.filter(s=>!pe.has(s.id)):V,Le=async s=>{C(s),O("connecting"),await P(s)||O("error");},tt=async()=>{C("phantom"),O("connecting");let s=await g("phantom");O(s?"success":"error");},nt=async()=>{C("metamask"),O("connecting");let s=await h();O(s?"success":"error");},ot=async s=>{U("verifying"),B(""),await(m||k)(s)?(U("success"),O("success")):(U("error"),B("Invalid or expired code"),setTimeout(()=>U("idle"),2e3));},Ue=()=>{O(R&&!Ke?"stack-select":"select"),C(null),T(false),U("idle"),B("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${N}`,children:[!y&&jsxs("div",{className:"mb-6 text-center",children:[j?.logoUrl&&L!=="stack-select"&&jsx("img",{src:oe(j.logoUrl),alt:j.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),j?.displayName&&jsx("p",{className:"text-sm text-zinc-400 mb-2",children:j.displayName}),jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),L==="stack-select"&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:Q.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),Q.map(s=>jsxs("button",{onClick:()=>{Ce(s.stackId),O("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[s.logoUrl?jsx("img",{src:oe(s.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:s.name?.[0]?.toUpperCase()||"S"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-white",children:s.name||s.stackId}),jsx("p",{className:"text-xs text-zinc-500",children:s.domain})]}),jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},s.stackId)),b.ready&&!b.known&&jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),L==="select"&&_&&jsx("div",{className:"flex items-center justify-center py-8",children:jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),n&&L==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:n}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Ue,children:"Try Again"})]}),L==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),L==="connecting"&&p&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxs("div",{className:"mx-auto mb-3 h-10 w-10 animate-pulse",children:[v==="phantom"&&jsx(se,{className:"h-10 w-10"}),v==="metamask"&&jsx(ae,{className:"h-10 w-10"})]}),jsx("p",{className:"font-medium text-sm text-white",children:t.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:Ue,children:"Cancel"})]}),L==="select"&&!p&&!_&&jsxs(Fragment,{children:[Me.map(s=>jsxs("button",{onClick:()=>Le(s.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx(Ge,{provider:s.id}),jsx("span",{className:"font-medium text-white",children:Ye(s.id,s.name)})]},s.id)),Se.includes("phantom")&&jsxs("button",{onClick:tt,disabled:!ue,className:`flex w-full items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${ue?"cursor-pointer":"cursor-not-allowed opacity-50"}`,children:[jsx(se,{className:"h-10 w-10 flex-shrink-0 rounded-lg"}),jsx("span",{className:"flex-1 text-left font-medium text-white",children:"Phantom"}),!ue&&jsx("span",{className:"text-xs text-zinc-500",children:"Not installed"})]}),Se.includes("metamask")&&Xe&&jsxs("button",{onClick:nt,className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx(ae,{className:"h-10 w-10 flex-shrink-0"}),jsx("span",{className:"flex-1 text-left font-medium text-white",children:"MetaMask"})]}),Ie&&!D&&jsxs("button",{onClick:()=>T(true),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e]",children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("span",{className:"flex-1 text-left font-medium text-white",children:c})]}),Ie&&D&&jsxs("div",{className:"rounded-xl border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsx(re,{onComplete:ot,disabled:S==="verifying",error:E}),S==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),S==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),j?.webPageUrl&&S==="idle"&&(()=>{let s=oe(j.webPageUrl);return s==="#"?null:jsx("a",{href:`${s.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})})()]}),(f?fe:V).length>0&&(!f||fe.length>0)&&jsxs(Fragment,{children:[!f&&Me.length===0&&jsxs("div",{className:"flex items-center gap-3 py-1",children:[jsx("div",{className:"flex-1 border-t border-zinc-800"}),jsx("span",{className:"text-xs text-zinc-600",children:"or continue with"}),jsx("div",{className:"flex-1 border-t border-zinc-800"})]}),(f?fe:V.filter(s=>!pe.has(s.id))).map(s=>jsxs("button",{onClick:()=>Le(s.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx(Ge,{provider:s.id}),jsx("span",{className:"font-medium text-white",children:Ye(s.id,s.name)})]},s.id))]})]})]})}function Ge({provider:e}){switch(e){case "google":return jsx(be,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "discord":return jsx(we,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "twitter":return jsx(xe,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});default:return jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e] text-sm text-zinc-400 font-mono",children:e[0]?.toUpperCase()})}}function Ye(e,o){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||o||e}function Ut(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith("__csrf="));return e?e.slice(7):null}function Ve(e,o){let[r,i]=useState(null),[x,y]=useState(true),[m,c]=useState(false),[f,d]=useState(null),N=o?.apiBaseUrl??"",a=o?.scope===void 0||o?.scope==="global"?"global":`stack:${o.scope.stackId}`,u=useCallback(n=>{let g=encodeURIComponent(n);if(a==="global")return `${N}/api/user/profile/${g}`;let h=a.slice(6);return `${N}/api/v2/stacks/${encodeURIComponent(h)}/members/${g}/profile`},[N,a]),t=useCallback(async()=>{if(!e){i(null),y(false);return}y(true),d(null);try{let n=await fetch(u(e));if(n.ok){let g=await n.json(),h=g.profile||g.data?.profile||g;i({mid:h.mid||e,username:h.username||"",avatarUrl:h.avatar_url||h.avatarUrl,bio:h.bio,paymentAddress:h.payment_address||h.paymentAddress,createdAt:h.created_at||h.createdAt,updatedAt:h.updated_at||h.updatedAt});}else if(n.status===404)i({mid:e,username:""});else throw new Error(`${n.status}`)}catch(n){d(n instanceof Error?n.message:"Failed to load profile");}finally{y(false);}},[e,u]);useEffect(()=>{t();},[t]);let p=useCallback(async n=>{if(!e)return false;c(true),d(null);try{let g=Ut(),h={};n.username!==void 0&&(h.username=n.username),n.avatarUrl!==void 0&&(h.avatar_url=n.avatarUrl),n.bio!==void 0&&(h.bio=n.bio),n.paymentAddress!==void 0&&(h.payment_address=n.paymentAddress);let k=await fetch(u(e),{method:"PUT",headers:{"Content-Type":"application/json",...g?{"x-csrf-token":g}:{}},credentials:"same-origin",body:JSON.stringify(h)});if(!k.ok){let I=await k.json().catch(()=>({}));throw new Error(I.error||I.message||`Update failed: ${k.status}`)}let P=await k.json(),b=P.profile||P.data?.profile||P;return i(I=>({mid:I?.mid||e,username:n.username??I?.username??"",avatarUrl:n.avatarUrl??I?.avatarUrl,bio:n.bio??I?.bio,paymentAddress:n.paymentAddress??b.payment_address??b.paymentAddress??I?.paymentAddress,createdAt:I?.createdAt,updatedAt:b.updated_at||b.updatedAt||Date.now()})),!0}catch(g){return d(g instanceof Error?g.message:"Update failed"),false}finally{c(false);}},[e,u]);return {profile:r,loading:x,saving:m,error:f,updateProfile:p,refresh:t}}function zt({mid:e,apiBaseUrl:o="",scope:r,onSave:i,className:x}){let{profile:y,loading:m,saving:c,error:f,updateProfile:d}=Ve(e,{apiBaseUrl:o,scope:r}),[N,a]=useState(null),[u,t]=useState(null),[p,n]=useState(null),g=useRef(null),[h,k]=useState(false),P=N??y?.username??"",b=u??y?.bio??"",I=p??y?.avatarUrl,R=useCallback(z=>{let _=z.target.files?.[0];if(!_)return;let L=new FileReader;L.onload=()=>{n(L.result),k(true);},L.readAsDataURL(_);},[]),W=async()=>{await d({username:P||void 0,avatarUrl:p??y?.avatarUrl,bio:b||void 0})&&(k(false),i?.());};if(m)return jsxs("div",{className:x,style:{display:"grid",gap:"1.5rem"},children:[jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let j=r==="global"||!r?"Global profile":`Stack profile (${r.stackId})`;return jsxs("div",{className:x,style:{display:"grid",gap:"1.5rem"},children:[jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:j}),jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsx("button",{type:"button",onClick:()=>g.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:I?jsx("img",{src:I,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsx("input",{type:"text",value:P,onChange:z=>{a(z.target.value),k(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsx("input",{ref:g,type:"file",accept:"image/*",onChange:R,style:{display:"none"}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsx("input",{type:"text",value:b,onChange:z=>{t(z.target.value),k(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),f&&jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:f}),h&&jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsx("button",{onClick:W,disabled:c,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:c?"wait":"pointer",opacity:c?.6:1},children:c?"Saving...":"Save"}),jsx("button",{onClick:()=>{a(null),t(null),n(null),k(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function jt({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Dt({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Tt({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
2
- export{Mt as ConnectWidget,we as DiscordIcon,Dt as EthereumIcon,be as GoogleIcon,ae as MetaMaskIcon,re as OTPInput,se as PhantomIcon,zt as ProfileSettings,jt as SolanaIcon,Tt as TelegramIcon,xe as TwitterIcon,it as UserUtilsProvider,at as useUserUtilsContext};
1
+ import {createContext,useContext,useState,useCallback,useEffect,useRef}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var je=createContext(null);function lt(){let e=useContext(je);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function ct({config:e,callbacks:t,children:r}){return jsx(je.Provider,{value:{config:e,callbacks:t},children:r})}function Te(){let[e,t]=useState({connected:false,address:null,chain:null,provider:null}),[r,i]=useState(null),v=useCallback(async(f="phantom")=>{i(null);try{let d=typeof window<"u"?window:null,C=f==="phantom"?d?.phantom?.solana||d?.solana:d?.solflare;if(!C)return i(`${f} wallet not found`),null;let u=(await C.connect()).publicKey.toString();return t({connected:!0,address:u,chain:"solana",provider:f}),u}catch(d){return i(d.message||"Failed to connect wallet"),null}},[]),y=useCallback(async()=>{i(null);try{let d=(typeof window<"u"?window:null)?.ethereum;if(!d)return i("MetaMask not found"),null;let C=d;d.providers?.length&&(C=d.providers.find(n=>n.isMetaMask)||d);let u=(await C.request({method:"eth_requestAccounts"}))[0];return u?(t({connected:!0,address:u,chain:"ethereum",provider:"metamask"}),u):(i("No account selected"),null)}catch(f){return i(f.message||"Failed to connect wallet"),null}},[]),m=useCallback(async(f,d)=>{i(null);let C=d?.chain||e.chain,a=d?.provider||e.provider,u=d?.address||e.address;try{if(C==="solana"){let n=typeof window<"u"?window:null,p=a==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!p)throw new Error("Wallet not available");let o=new TextEncoder().encode(f),g=await p.signMessage(o,"utf8"),h=new Uint8Array(g.signature||g),k="";for(let P=0;P<h.byteLength;P++)k+=String.fromCharCode(h[P]);return btoa(k)}if(C==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(g=>g.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[f,u]})}throw new Error("No wallet connected")}catch(n){return i(n.message||"Signing failed"),null}},[e]),c=useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),i(null);},[]);return {wallet:e,error:r,connectSolana:v,connectEVM:y,signMessage:m,disconnect:c}}function ze(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function Oe(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function We(){let[e,t]=useState(null),[r,i]=useState(true),v=useCallback(()=>{let c=ze();c&&c.expiresAt>Date.now()?t({userId:c.userId,address:c.address,chain:c.chain,expiresAt:c.expiresAt,planId:c.planId,authMethod:c.authMethod}):t(null),i(false);},[]);useEffect(()=>{v();},[v]);let y=useCallback(async(c="")=>{try{let f=await fetch(`${c}/api/auth/session`);if(f.ok){let d=await f.json();if(d.session)return t(d.session),d.session}return t(null),null}catch{return null}},[]),m=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:m,refresh:y,readSession:v}}function Be(e="__csrf",t="x-csrf-token"){let[r,i]=useState(null);useEffect(()=>{i(Oe(e));},[e]);let v=r?{[t]:r}:{};return {token:r,headers:v}}var ht="https://stacknet.magma-rpc.com/auth/bridge",se="stacknet-auth-bridge";function $e(e){let t=e?.bridgeUrl||ht,r=e?.disabled||false,i=useRef(null),[v,y]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),m=useRef([]),c=useRef(false),f=useCallback(n=>{let p={...n,protocol:se};c.current&&i.current?.contentWindow?i.current.contentWindow.postMessage(p,new URL(t).origin):m.current.push(p);},[t]);useEffect(()=>{if(r)return;let n=o=>{if(!(!o.data||o.data.protocol!==se)){try{if(o.origin!==new URL(t).origin)return}catch{return}switch(o.data.type){case "bridge:ready":c.current=true,y(g=>({...g,ready:true}));for(let g of m.current)i.current?.contentWindow?.postMessage(g,o.origin);m.current=[],i.current?.contentWindow?.postMessage({protocol:se,type:"auth:check"},o.origin),i.current?.contentWindow?.postMessage({protocol:se,type:"auth:resolve-stack"},o.origin);break;case "auth:status":y(g=>({...g,known:o.data.known,identity:o.data.identity,identityCount:o.data.identityCount||0}));break;case "auth:resolved-stack":y(g=>({...g,resolvedStackId:o.data.stackId||null}));break;}}};window.addEventListener("message",n);let p=document.createElement("iframe");return p.src=t,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),i.current=p,()=>{window.removeEventListener("message",n),p.parentNode&&p.parentNode.removeChild(p),i.current=null,c.current=false;}},[t,r]);let d=useCallback(n=>{f({type:"auth:connected",...n});},[f]),C=useCallback(n=>{f({type:"auth:disconnected",...n});},[f]),a=useCallback(()=>{f({type:"auth:clear"}),y({ready:v.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[f,v.ready]),u=useCallback(()=>{f({type:"auth:check"});},[f]);return {...v,reportConnected:d,reportDisconnected:C,clearAll:a,refresh:u}}async function Fe(e,t,r,i){let v=e.apiVersion||"v2",y=`${e.baseUrl}/api/${v}${r}`;try{let m=await fetch(y,{method:t,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),c=await m.json();return m.ok?c.success&&c.data!==void 0?{success:!0,data:c.data}:{success:!0,data:c}:{success:!1,error:c.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(m){return {success:false,error:{code:"NETWORK_ERROR",message:m instanceof Error?m.message:"Network error"}}}}function He(e){return {getNetworkStatus:()=>Fe(e,"GET","/network/status"),getWeb3Challenge:(t,r)=>Fe(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:r})}}function _e(e={apiBaseUrl:""}){let{wallet:t,connectSolana:r,connectEVM:i,signMessage:v,disconnect:y}=Te(),{session:m,isAuthenticated:c,refresh:f,readSession:d}=We(),{headers:C}=Be(),a=$e({disabled:typeof window>"u"}),[u,n]=useState(false),[p,o]=useState(null),[g,h]=useState(false),k=e.apiBaseUrl||"",P=e.stacknetUrl||"https://stacknet.magma-rpc.com",b=e.stackId||a.resolvedStackId||"",I=He({baseUrl:P,stackId:b}),R=useCallback(async(x,S,T,O)=>{n(true),o(null);try{let N=S;if(!N){let V=await T();if(!V)return n(!1),!1;N=V;}let A=await I.getWeb3Challenge(x,N);if(!A.success||!A.data)return o("Failed to get challenge"),n(!1),!1;let E=await v(A.data.message,{chain:x,provider:O,address:N});if(!E)return n(!1),!1;let F={chain:x,message:A.data.message,signature:E,stackId:b};x==="solana"&&(F.publicKey=N);let G=await fetch(`${k}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(F)});if(!G.ok){let V=await G.json().catch(()=>({}));return o(V.error||"Authentication failed"),n(!1),!1}return a.reportConnected({address:N,chain:x,method:O||(x==="solana"?"phantom":"metamask"),stackId:b}),d(),n(!1),!0}catch(N){return o(N.message||"Authentication failed"),n(false),false}},[k,I,v,d,a,b]),W=useCallback(async(x="phantom")=>{let S=await r(x);return S?R("solana",S,()=>r(x),x):false},[r,R]),D=useCallback(async()=>{let x=await i();return x?R("ethereum",x,i,"metamask"):false},[i,R]),j=useCallback(async x=>{n(true),o(null);try{let S=await fetch(`${k}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:x})});if(!S.ok){let T=await S.json().catch(()=>({}));return o(T.error||"Invalid code"),n(!1),!1}return d(),n(!1),!0}catch(S){return o(S.message||"OTP verification failed"),n(false),false}},[k,d]),Q=useCallback(async(x,S)=>{n(true),o(null);try{let T=S||`${window.location.origin}/api/auth/oauth/callback`,O=new URLSearchParams({provider:x,redirectUri:T,stackId:b}),N=await fetch(`${k}/api/auth/oauth/start?${O}`,{credentials:"include"});if(!N.ok){let E=await N.json().catch(()=>({}));return o(E.error||"Failed to start OAuth flow"),n(!1),!1}let A=await N.json();if(A.redirect_url){let E;try{E=new URL(A.redirect_url);}catch{return o("Invalid OAuth redirect URL"),n(!1),!1}let F=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return E.protocol!=="https:"||!F.some(G=>G.test(E.hostname))?(o(`Refusing to redirect to non-OAuth host: ${E.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",A.state||""),sessionStorage.setItem("oauth_provider",x)),window.location.href=E.toString(),!0)}return o("No redirect URL returned"),n(!1),!1}catch(T){return o(T.message||"OAuth flow failed"),n(false),false}},[k,b]),L=useCallback(async(x,S,T)=>{n(true),o(null);try{if(typeof sessionStorage<"u"){let N=sessionStorage.getItem("oauth_state"),A=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!N||N!==T)return o("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(A&&A!==x)return o("OAuth provider mismatch \u2014 refusing to complete login"),n(!1),!1}let O=await fetch(`${k}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:x,code:S,state:T,stackId:b})});if(!O.ok){let N=await O.json().catch(()=>({}));return o(N.error||"OAuth authentication failed"),n(!1),!1}return d(),n(!1),!0}catch(O){return o(O.message||"OAuth callback failed"),n(false),false}},[k,b,d]),z=useCallback(async()=>{t.address&&t.chain&&a.reportDisconnected({address:t.address,chain:t.chain,stackId:b});try{await fetch(`${k}/api/auth/logout`,{method:"POST",headers:C,credentials:"include"});}catch{}y(),d();},[k,C,y,d,t,a,b]);return useEffect(()=>{if(!e.autoConnect||g||c||!a.ready||!a.known||!a.identity)return;h(true);let{chain:x,method:S}=a.identity;x==="solana"&&(S==="phantom"||S==="solflare")?W(S):x==="ethereum"&&D();},[e.autoConnect,g,c,a,W,D]),{session:m,isAuthenticated:c,wallet:t,loading:u,error:p,authenticateSolana:W,authenticateEVM:D,authenticateOTP:j,authenticateOAuth:Q,authenticateOAuthCallback:L,logout:z,refresh:()=>f(k),stackId:b,bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount,resolvedStackId:a.resolvedStackId}}}function Qe(e,t="https://stacknet.magma-rpc.com"){let[r,i]=useState(null),[v,y]=useState(false),[m,c]=useState(null),f=useCallback(async C=>{y(true),c(null);try{let a=await fetch(`${t}/api/v2/stacks/${C}`);if(!a.ok)return c("Stack not found"),y(!1),null;let u=await a.json(),n=u.data?.stack||u.stack||u,p={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(o=>({provider:o.provider,clientId:o.clientId,enabled:o.enabled!==!1}))};return i(p),y(!1),p}catch(a){return c(a.message),y(false),null}},[t]);useEffect(()=>{e&&f(e);},[e,f]);let d=r?wt(r):[];return {config:r,loading:v,error:m,identityProviders:d,fetchConfig:f}}function wt(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let r of e.oauthProviders)r.enabled&&t.push({type:"oauth",id:r.provider,name:r.provider});return t}function ae(e,t="#"){if(!e||typeof e!="string")return t;let r=e.trim();if(r===""||r==="#")return t;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let i=new URL(r);if(i.protocol==="http:"||i.protocol==="https:")return i.toString()}catch{}return t}function ie({length:e=6,onComplete:t,disabled:r=false,error:i,className:v="",inputClassName:y=""}){let [m,c]=useState(Array(e).fill("")),f=useCallback((a,u)=>{if(u.length>1){let p=u.replace(/\D/g,"").slice(0,e).split(""),o=[...m];p.forEach((h,k)=>{a+k<e&&(o[a+k]=h);}),c(o);let g=Math.min(a+p.length,e-1);document.getElementById(`userutils-otp-${g}`)?.focus(),o.every(h=>h!=="")&&setTimeout(()=>t(o.join("")),100);return}if(!/^\d?$/.test(u))return;let n=[...m];n[a]=u,c(n),u&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),u&&a===e-1&&n.every(p=>p!=="")&&setTimeout(()=>t(n.join("")),100);},[m,e,t]),d=useCallback((a,u)=>{if(u.key==="Backspace"&&!m[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let n=[...m];n[a-1]="",c(n);}if(u.key==="Enter"){let n=m.join("");n.length===e&&t(n);}},[m,e,t]);useCallback(()=>{c(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:v,children:[jsx("div",{className:"flex gap-2 justify-center",children:m.map((a,u)=>jsx("input",{id:`userutils-otp-${u}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:n=>f(u,n.target.value),onKeyDown:n=>d(u,n),disabled:r,autoFocus:u===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},u))}),i&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:i})]})}ie.displayName="OTPInput";var Ct="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function le({className:e,style:t}){return jsx("img",{src:Ct,alt:"Phantom",className:e,style:t})}function ce({className:e,style:t}){return jsxs("svg",{className:e,style:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function ve({className:e,style:t}){return jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function xe({className:e,style:t}){return jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Ce({className:e,style:t}){return jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function At({config:e,onSuccess:t,title:r="Log in or Sign up",showWallets:i,showOTP:v,hideHeader:y,onOTPSubmit:m,otpLabel:c="Access Code",oauthInline:f,oauthFirst:d,className:C=""}){let a=_e(e),{isAuthenticated:u,wallet:n,loading:p,error:o,authenticateSolana:g,authenticateEVM:h,authenticateOTP:k,authenticateOAuth:P,bridge:b,stackId:I}=a,R=!e.stackId&&!I,W=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:D,identityProviders:j,loading:Q}=Qe(I||e.stackId||null,W),[L,z]=useState(R?"stack-select":"select"),[x,S]=useState(null),[T,O]=useState(false),[N,A]=useState("idle"),[E,F]=useState(""),[G,V]=useState([]),[Xe,Ie]=useState(e.stackId||null),[oe,et]=useState(false),[tt,nt]=useState(false);useEffect(()=>{if(typeof window>"u")return;let s=()=>{let Y=window;et(!!(Y.phantom?.solana?.isPhantom||Y.solana?.isPhantom));let K=Y.ethereum;nt(!!(K?.isMetaMask||K?.providers?.some(q=>q.isMetaMask)));};s(),window.addEventListener("ethereum#initialized",s);let H=setTimeout(s,500);return ()=>{window.removeEventListener("ethereum#initialized",s),clearTimeout(H);}},[]),useEffect(()=>{L==="stack-select"&&I&&(Ie(I),z("select"));},[L,I]),useEffect(()=>{if(!(!b.ready||!R)&&b.identity){let s=[];b.resolvedStackId&&s.push({stackId:b.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(s.map(async H=>{try{let Y=await fetch(`${W}/api/v2/stacks/${H.stackId}`);if(Y.ok){let K=await Y.json(),q=K.data?.stack||K;H.name=q.displayName||q.name,H.logoUrl=q.logoUrl;}}catch{}return H})).then(V);}},[b.ready,b.identity,b.resolvedStackId,R,W]),useEffect(()=>{u&&L==="success"&&t?.();},[u,L,t]);let Me=i||(j.length>0?j.filter(s=>s.type==="wallet").map(s=>s.id):["phantom","metamask"]),Le=v!==void 0?v:j.length>0?j.some(s=>s.type==="otp"):true,J=j.filter(s=>s.type==="oauth"),ge=new Set(d||[]),Ae=J.filter(s=>ge.has(s.id)),me=f?J.filter(s=>!ge.has(s.id)):J,Ue=async s=>{S(s),z("connecting"),await P(s)||z("error");},ot=async()=>{S("phantom"),z("connecting");let s=await g("phantom");z(s?"success":"error");},rt=async()=>{S("metamask"),z("connecting");let s=await h();z(s?"success":"error");},st=async s=>{A("verifying"),F(""),await(m||k)(s)?(A("success"),z("success")):(A("error"),F("Invalid or expired code"),setTimeout(()=>A("idle"),2e3));},Pe=()=>{z(R&&!Xe?"stack-select":"select"),S(null),O(false),A("idle"),F("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${C}`,children:[!y&&jsxs("div",{className:"mb-6 text-center",children:[D?.logoUrl&&L!=="stack-select"&&jsx("img",{src:ae(D.logoUrl),alt:D.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),D?.displayName&&jsx("p",{className:"text-sm text-zinc-400 mb-2",children:D.displayName}),jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),L==="stack-select"&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:G.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),G.map(s=>jsxs("button",{onClick:()=>{Ie(s.stackId),z("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[s.logoUrl?jsx("img",{src:ae(s.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:s.name?.[0]?.toUpperCase()||"S"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-white",children:s.name||s.stackId}),jsx("p",{className:"text-xs text-zinc-500",children:s.domain})]}),jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},s.stackId)),b.ready&&!b.known&&jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),L==="select"&&Q&&jsx("div",{className:"flex items-center justify-center py-8",children:jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),o&&L==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:o}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Pe,children:"Try Again"})]}),L==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),L==="connecting"&&p&&jsxs("div",{style:{border:"1px solid #27272a",background:"#25252f",padding:24,textAlign:"center"},children:[jsxs("div",{style:{width:40,height:40,margin:"0 auto 12px"},children:[x==="phantom"&&jsx(le,{style:$}),x==="metamask"&&jsx(ce,{style:$})]}),jsx("p",{style:{fontWeight:500,fontSize:14,color:"#fff"},children:n.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{style:{marginTop:4,fontSize:12,color:"#71717a"},children:"Please confirm in your wallet"}),jsx("button",{style:{marginTop:16,fontSize:14,color:"#71717a",background:"none",border:"none",cursor:"pointer"},onClick:Pe,children:"Cancel"})]}),L==="select"&&!p&&!Q&&jsxs(Fragment,{children:[Ae.map(s=>jsxs("button",{onClick:()=>Ue(s.id),style:te,children:[jsx(Ze,{provider:s.id}),jsx("span",{style:{fontWeight:500,color:"#fff"},children:Ve(s.id,s.name)})]},s.id)),Me.includes("phantom")&&jsxs("button",{onClick:ot,disabled:!oe,style:{...te,opacity:oe?1:.5,cursor:oe?"pointer":"not-allowed"},children:[jsx(le,{style:{...$,borderRadius:8}}),jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"Phantom"}),!oe&&jsx("span",{style:{fontSize:12,color:"#71717a"},children:"Not installed"})]}),Me.includes("metamask")&&tt&&jsxs("button",{onClick:rt,style:te,children:[jsx(ce,{style:$}),jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"MetaMask"})]}),Le&&!T&&jsxs("button",{onClick:()=>O(true),style:te,children:[jsx("div",{style:{...$,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e"},children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:c})]}),Le&&T&&jsxs("div",{style:{borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:24},children:[jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginBottom:16},children:"Enter your 6-digit access code"}),jsx(ie,{onComplete:st,disabled:N==="verifying",error:E}),N==="verifying"&&jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginTop:16},children:"Verifying..."}),N==="success"&&jsx("p",{style:{textAlign:"center",fontSize:14,color:"#4ade80",marginTop:16},children:"Verified!"}),D?.webPageUrl&&N==="idle"&&(()=>{let s=ae(D.webPageUrl);return s==="#"?null:jsx("a",{href:`${s.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",style:{display:"block",textAlign:"center",fontSize:14,color:"#71717a",marginTop:16},children:"Get code"})})()]}),(f?me:J).length>0&&(!f||me.length>0)&&jsxs(Fragment,{children:[!f&&Ae.length===0&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 0"},children:[jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}}),jsx("span",{style:{fontSize:12,color:"#52525b"},children:"or continue with"}),jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}})]}),(f?me:J.filter(s=>!ge.has(s.id))).map(s=>jsxs("button",{onClick:()=>Ue(s.id),style:te,children:[jsx(Ze,{provider:s.id}),jsx("span",{style:{fontWeight:500,color:"#fff"},children:Ve(s.id,s.name)})]},s.id))]})]})]})}var $={width:40,height:40,flexShrink:0},te={display:"flex",width:"100%",alignItems:"center",gap:12,borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:16,cursor:"pointer",transition:"background 0.15s"};function Ze({provider:e}){switch(e){case "google":return jsx(ve,{style:{...$,borderRadius:8}});case "discord":return jsx(xe,{style:{...$,borderRadius:8}});case "twitter":return jsx(Ce,{style:{...$,borderRadius:8}});default:return jsx("div",{style:{...$,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e",fontSize:14,color:"#a1a1aa",fontFamily:"monospace"},children:e[0]?.toUpperCase()})}}function Ve(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||t||e}function Pt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function Ke(e,t){let[r,i]=useState(null),[v,y]=useState(true),[m,c]=useState(false),[f,d]=useState(null),C=t?.apiBaseUrl??"",a=t?.scope===void 0||t?.scope==="global"?"global":`stack:${t.scope.stackId}`,u=useCallback(o=>{let g=encodeURIComponent(o);if(a==="global")return `${C}/api/user/profile/${g}`;let h=a.slice(6);return `${C}/api/v2/stacks/${encodeURIComponent(h)}/members/${g}/profile`},[C,a]),n=useCallback(async()=>{if(!e){i(null),y(false);return}y(true),d(null);try{let o=await fetch(u(e));if(o.ok){let g=await o.json(),h=g.profile||g.data?.profile||g;i({mid:h.mid||e,username:h.username||"",avatarUrl:h.avatar_url||h.avatarUrl,bio:h.bio,paymentAddress:h.payment_address||h.paymentAddress,createdAt:h.created_at||h.createdAt,updatedAt:h.updated_at||h.updatedAt});}else if(o.status===404)i({mid:e,username:""});else throw new Error(`${o.status}`)}catch(o){d(o instanceof Error?o.message:"Failed to load profile");}finally{y(false);}},[e,u]);useEffect(()=>{n();},[n]);let p=useCallback(async o=>{if(!e)return false;c(true),d(null);try{let g=Pt(),h={};o.username!==void 0&&(h.username=o.username),o.avatarUrl!==void 0&&(h.avatar_url=o.avatarUrl),o.bio!==void 0&&(h.bio=o.bio),o.paymentAddress!==void 0&&(h.payment_address=o.paymentAddress);let k=await fetch(u(e),{method:"PUT",headers:{"Content-Type":"application/json",...g?{"x-csrf-token":g}:{}},credentials:"same-origin",body:JSON.stringify(h)});if(!k.ok){let I=await k.json().catch(()=>({}));throw new Error(I.error||I.message||`Update failed: ${k.status}`)}let P=await k.json(),b=P.profile||P.data?.profile||P;return i(I=>({mid:I?.mid||e,username:o.username??I?.username??"",avatarUrl:o.avatarUrl??I?.avatarUrl,bio:o.bio??I?.bio,paymentAddress:o.paymentAddress??b.payment_address??b.paymentAddress??I?.paymentAddress,createdAt:I?.createdAt,updatedAt:b.updated_at||b.updatedAt||Date.now()})),!0}catch(g){return d(g instanceof Error?g.message:"Update failed"),false}finally{c(false);}},[e,u]);return {profile:r,loading:v,saving:m,error:f,updateProfile:p,refresh:n}}function Tt({mid:e,apiBaseUrl:t="",scope:r,onSave:i,className:v}){let{profile:y,loading:m,saving:c,error:f,updateProfile:d}=Ke(e,{apiBaseUrl:t,scope:r}),[C,a]=useState(null),[u,n]=useState(null),[p,o]=useState(null),g=useRef(null),[h,k]=useState(false),P=C??y?.username??"",b=u??y?.bio??"",I=p??y?.avatarUrl,R=useCallback(j=>{let Q=j.target.files?.[0];if(!Q)return;let L=new FileReader;L.onload=()=>{o(L.result),k(true);},L.readAsDataURL(Q);},[]),W=async()=>{await d({username:P||void 0,avatarUrl:p??y?.avatarUrl,bio:b||void 0})&&(k(false),i?.());};if(m)return jsxs("div",{className:v,style:{display:"grid",gap:"1.5rem"},children:[jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let D=r==="global"||!r?"Global profile":`Stack profile (${r.stackId})`;return jsxs("div",{className:v,style:{display:"grid",gap:"1.5rem"},children:[jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:D}),jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsx("button",{type:"button",onClick:()=>g.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:I?jsx("img",{src:I,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsx("input",{type:"text",value:P,onChange:j=>{a(j.target.value),k(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsx("input",{ref:g,type:"file",accept:"image/*",onChange:R,style:{display:"none"}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsx("input",{type:"text",value:b,onChange:j=>{n(j.target.value),k(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),f&&jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:f}),h&&jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsx("button",{onClick:W,disabled:c,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:c?"wait":"pointer",opacity:c?.6:1},children:c?"Saving...":"Save"}),jsx("button",{onClick:()=>{a(null),n(null),o(null),k(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function zt({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Ot({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Rt({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
2
+ export{At as ConnectWidget,xe as DiscordIcon,Ot as EthereumIcon,ve as GoogleIcon,ce as MetaMaskIcon,ie as OTPInput,le as PhantomIcon,Tt as ProfileSettings,zt as SolanaIcon,Rt as TelegramIcon,Ce as TwitterIcon,ct as UserUtilsProvider,lt as useUserUtilsContext};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function wt(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function xt(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function Ct(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let s=new URL(e,t);return s.origin!==t?"/":s.pathname+s.search+s.hash}catch{return "/"}}function X(e,t="#"){if(!e||typeof e!="string")return t;let s=e.trim();if(s===""||s==="#")return t;if(s.startsWith("/")||s.startsWith("./")||s.startsWith("../"))return s;try{let d=new URL(s);if(d.protocol==="http:"||d.protocol==="https:")return d.toString()}catch{}return t}function St(e){try{let t=e.split(".");if(t.length!==3)return null;let s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}function ee(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function W(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function te(){let[e,t]=react.useState(null),[s,d]=react.useState(true),u=react.useCallback(()=>{let i=ee();i&&i.expiresAt>Date.now()?t({userId:i.userId,address:i.address,chain:i.chain,expiresAt:i.expiresAt,planId:i.planId,authMethod:i.authMethod}):t(null),d(false);},[]);react.useEffect(()=>{u();},[u]);let h=react.useCallback(async(i="")=>{try{let l=await fetch(`${i}/api/auth/session`);if(l.ok){let c=await l.json();if(c.session)return t(c.session),c.session}return t(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:g,refresh:h,readSession:u}}function ke(e="__csrf",t="x-csrf-token"){let[s,d]=react.useState(null);react.useEffect(()=>{d(W(e));},[e]);let u=s?{[t]:s}:{};return {token:s,headers:u}}function be(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[s,d]=react.useState(null),u=react.useCallback(async(l="phantom")=>{d(null);try{let c=typeof window<"u"?window:null,m=l==="phantom"?c?.phantom?.solana||c?.solana:c?.solflare;if(!m)return d(`${l} wallet not found`),null;let a=(await m.connect()).publicKey.toString();return t({connected:!0,address:a,chain:"solana",provider:l}),a}catch(c){return d(c.message||"Failed to connect wallet"),null}},[]),h=react.useCallback(async()=>{d(null);try{let c=(typeof window<"u"?window:null)?.ethereum;if(!c)return d("MetaMask not found"),null;let m=c;c.providers?.length&&(m=c.providers.find(n=>n.isMetaMask)||c);let a=(await m.request({method:"eth_requestAccounts"}))[0];return a?(t({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(d("No account selected"),null)}catch(l){return d(l.message||"Failed to connect wallet"),null}},[]),g=react.useCallback(async(l,c)=>{d(null);let m=c?.chain||e.chain,o=c?.provider||e.provider,a=c?.address||e.address;try{if(m==="solana"){let n=typeof window<"u"?window:null,p=o==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!p)throw new Error("Wallet not available");let r=new TextEncoder().encode(l),y=await p.signMessage(r,"utf8"),x=new Uint8Array(y.signature||y),w="";for(let L=0;L<x.byteLength;L++)w+=String.fromCharCode(x[L]);return btoa(w)}if(m==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(y=>y.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[l,a]})}throw new Error("No wallet connected")}catch(n){return d(n.message||"Signing failed"),null}},[e]),i=react.useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),d(null);},[]);return {wallet:e,error:s,connectSolana:u,connectEVM:h,signMessage:g,disconnect:i}}var Mt="https://stacknet.magma-rpc.com/auth/bridge",ie="stacknet-auth-bridge";function xe(e){let t=e?.bridgeUrl||Mt,s=e?.disabled||false,d=react.useRef(null),[u,h]=react.useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),g=react.useRef([]),i=react.useRef(false),l=react.useCallback(n=>{let p={...n,protocol:ie};i.current&&d.current?.contentWindow?d.current.contentWindow.postMessage(p,new URL(t).origin):g.current.push(p);},[t]);react.useEffect(()=>{if(s)return;let n=r=>{if(!(!r.data||r.data.protocol!==ie)){try{if(r.origin!==new URL(t).origin)return}catch{return}switch(r.data.type){case "bridge:ready":i.current=true,h(y=>({...y,ready:true}));for(let y of g.current)d.current?.contentWindow?.postMessage(y,r.origin);g.current=[],d.current?.contentWindow?.postMessage({protocol:ie,type:"auth:check"},r.origin),d.current?.contentWindow?.postMessage({protocol:ie,type:"auth:resolve-stack"},r.origin);break;case "auth:status":h(y=>({...y,known:r.data.known,identity:r.data.identity,identityCount:r.data.identityCount||0}));break;case "auth:resolved-stack":h(y=>({...y,resolvedStackId:r.data.stackId||null}));break;}}};window.addEventListener("message",n);let p=document.createElement("iframe");return p.src=t,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),d.current=p,()=>{window.removeEventListener("message",n),p.parentNode&&p.parentNode.removeChild(p),d.current=null,i.current=false;}},[t,s]);let c=react.useCallback(n=>{l({type:"auth:connected",...n});},[l]),m=react.useCallback(n=>{l({type:"auth:disconnected",...n});},[l]),o=react.useCallback(()=>{l({type:"auth:clear"}),h({ready:u.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[l,u.ready]),a=react.useCallback(()=>{l({type:"auth:check"});},[l]);return {...u,reportConnected:c,reportDisconnected:m,clearAll:o,refresh:a}}async function Xe(e,t,s,d){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${s}`;try{let g=await fetch(h,{method:t,headers:{"Content-Type":"application/json"},body:d?JSON.stringify(d):void 0}),i=await g.json();return g.ok?i.success&&i.data!==void 0?{success:!0,data:i.data}:{success:!0,data:i}:{success:!1,error:i.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(g){return {success:false,error:{code:"NETWORK_ERROR",message:g instanceof Error?g.message:"Network error"}}}}function Ce(e){return {getNetworkStatus:()=>Xe(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>Xe(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:s})}}function ve(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:d,signMessage:u,disconnect:h}=be(),{session:g,isAuthenticated:i,refresh:l,readSession:c}=te(),{headers:m}=ke(),o=xe({disabled:typeof window>"u"}),[a,n]=react.useState(false),[p,r]=react.useState(null),[y,x]=react.useState(false),w=e.apiBaseUrl||"",L=e.stacknetUrl||"https://stacknet.magma-rpc.com",S=e.stackId||o.resolvedStackId||"",C=Ce({baseUrl:L,stackId:S}),D=react.useCallback(async(N,I,E,R)=>{n(true),r(null);try{let P=I;if(!P){let J=await E();if(!J)return n(!1),!1;P=J;}let U=await C.getWeb3Challenge(N,P);if(!U.success||!U.data)return r("Failed to get challenge"),n(!1),!1;let _=await u(U.data.message,{chain:N,provider:R,address:P});if(!_)return n(!1),!1;let G={chain:N,message:U.data.message,signature:_,stackId:S};N==="solana"&&(G.publicKey=P);let Q=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(G)});if(!Q.ok){let J=await Q.json().catch(()=>({}));return r(J.error||"Authentication failed"),n(!1),!1}return o.reportConnected({address:P,chain:N,method:R||(N==="solana"?"phantom":"metamask"),stackId:S}),c(),n(!1),!0}catch(P){return r(P.message||"Authentication failed"),n(false),false}},[w,C,u,c,o,S]),$=react.useCallback(async(N="phantom")=>{let I=await s(N);return I?D("solana",I,()=>s(N),N):false},[s,D]),j=react.useCallback(async()=>{let N=await d();return N?D("ethereum",N,d,"metamask"):false},[d,D]),b=react.useCallback(async N=>{n(true),r(null);try{let I=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:N})});if(!I.ok){let E=await I.json().catch(()=>({}));return r(E.error||"Invalid code"),n(!1),!1}return c(),n(!1),!0}catch(I){return r(I.message||"OTP verification failed"),n(false),false}},[w,c]),T=react.useCallback(async(N,I)=>{n(true),r(null);try{let E=I||`${window.location.origin}/api/auth/oauth/callback`,R=new URLSearchParams({provider:N,redirectUri:E,stackId:S}),P=await fetch(`${w}/api/auth/oauth/start?${R}`,{credentials:"include"});if(!P.ok){let _=await P.json().catch(()=>({}));return r(_.error||"Failed to start OAuth flow"),n(!1),!1}let U=await P.json();if(U.redirect_url){let _;try{_=new URL(U.redirect_url);}catch{return r("Invalid OAuth redirect URL"),n(!1),!1}let G=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return _.protocol!=="https:"||!G.some(Q=>Q.test(_.hostname))?(r(`Refusing to redirect to non-OAuth host: ${_.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",U.state||""),sessionStorage.setItem("oauth_provider",N)),window.location.href=_.toString(),!0)}return r("No redirect URL returned"),n(!1),!1}catch(E){return r(E.message||"OAuth flow failed"),n(false),false}},[w,S]),A=react.useCallback(async(N,I,E)=>{n(true),r(null);try{if(typeof sessionStorage<"u"){let P=sessionStorage.getItem("oauth_state"),U=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!P||P!==E)return r("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(U&&U!==N)return r("OAuth provider mismatch \u2014 refusing to complete login"),n(!1),!1}let R=await fetch(`${w}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:N,code:I,state:E,stackId:S})});if(!R.ok){let P=await R.json().catch(()=>({}));return r(P.error||"OAuth authentication failed"),n(!1),!1}return c(),n(!1),!0}catch(R){return r(R.message||"OAuth callback failed"),n(false),false}},[w,S,c]),z=react.useCallback(async()=>{t.address&&t.chain&&o.reportDisconnected({address:t.address,chain:t.chain,stackId:S});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:m,credentials:"include"});}catch{}h(),c();},[w,m,h,c,t,o,S]);return react.useEffect(()=>{if(!e.autoConnect||y||i||!o.ready||!o.known||!o.identity)return;x(true);let{chain:N,method:I}=o.identity;N==="solana"&&(I==="phantom"||I==="solflare")?$(I):N==="ethereum"&&j();},[e.autoConnect,y,i,o,$,j]),{session:g,isAuthenticated:i,wallet:t,loading:a,error:p,authenticateSolana:$,authenticateEVM:j,authenticateOTP:b,authenticateOAuth:T,authenticateOAuthCallback:A,logout:z,refresh:()=>l(w),stackId:S,bridge:{ready:o.ready,known:o.known,identity:o.identity,identityCount:o.identityCount,resolvedStackId:o.resolvedStackId}}}function oe(e,t="https://stacknet.magma-rpc.com"){let[s,d]=react.useState(null),[u,h]=react.useState(false),[g,i]=react.useState(null),l=react.useCallback(async m=>{h(true),i(null);try{let o=await fetch(`${t}/api/v2/stacks/${m}`);if(!o.ok)return i("Stack not found"),h(!1),null;let a=await o.json(),n=a.data?.stack||a.stack||a,p={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(r=>({provider:r.provider,clientId:r.clientId,enabled:r.enabled!==!1}))};return d(p),h(!1),p}catch(o){return i(o.message),h(false),null}},[t]);react.useEffect(()=>{e&&l(e);},[e,l]);let c=s?Ot(s):[];return {config:s,loading:u,error:g,identityProviders:c,fetchConfig:l}}function Ot(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let s of e.oauthProviders)s.enabled&&t.push({type:"oauth",id:s.provider,name:s.provider});return t}function Dt(e=""){let[t,s]=react.useState([]),[d,u]=react.useState(true),[h,g]=react.useState(null),i=react.useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/plans`);if(l.ok){let c=await l.json();s(c.plans||c||[]);}}catch(l){g(l.message);}finally{u(false);}},[e]);return react.useEffect(()=>{i();},[i]),{plans:t,loading:d,error:h,refresh:i}}function Rt(e=""){let[t,s]=react.useState(null),[d,u]=react.useState(true),[h,g]=react.useState(null),i=react.useCallback(async()=>{try{let m=await fetch(`${e}/api/billing/subscription`);if(m.ok){let o=await m.json();s(o.plan?o:null);}}catch(m){g(m.message);}finally{u(false);}},[e]);react.useEffect(()=>{i();},[i]);let l=react.useCallback(async m=>{let o=W(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({planId:m})})).json();return n.url||n.checkoutUrl||null},[e]),c=react.useCallback(async()=>{let m=W();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:m?{"x-csrf-token":m}:{}})).ok?(await i(),true):false},[e,i]);return {subscription:t,loading:d,error:h,refresh:i,subscribe:l,cancel:c}}function Wt(e=""){let[t,s]=react.useState(null),[d,u]=react.useState(true),[h,g]=react.useState(null),i=react.useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/usage`);if(l.ok){let c=await l.json();s(c);}}catch(l){g(l.message);}finally{u(false);}},[e]);return react.useEffect(()=>{i();},[i]),{usage:t,loading:d,error:h,refresh:i}}function Ft(e=""){let[t,s]=react.useState(false),[d,u]=react.useState(null),h=react.useCallback(async i=>{s(true),u(null);try{let l=W(),c=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({amountCents:i})}),m=await c.json();return c.ok?m.url||null:(u(m.error||"Purchase failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]),g=react.useCallback(async i=>{s(true),u(null);try{let l=W(),c=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({sessionId:i})}),m=await c.json();return c.ok?m:(u(m.error||"Verification failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]);return {purchase:h,verifySession:g,loading:t,error:d}}function Ht(e="",t){let[s,d]=react.useState([]),[u,h]=react.useState(true),[g,i]=react.useState(null),l=t?.limit||50,c=t?.offset||0,m=react.useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/history?limit=${l}&offset=${c}`);if(o.ok){let a=await o.json();d(a.records||a.history||(Array.isArray(a)?a:[]));}}catch(o){i(o.message);}finally{h(false);}},[e,l,c]);return react.useEffect(()=>{m();},[m]),{records:s,loading:u,error:g,refresh:m}}function Vt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function Ue(e,t){let[s,d]=react.useState(null),[u,h]=react.useState(true),[g,i]=react.useState(false),[l,c]=react.useState(null),m=t?.apiBaseUrl??"",o=t?.scope===void 0||t?.scope==="global"?"global":`stack:${t.scope.stackId}`,a=react.useCallback(r=>{let y=encodeURIComponent(r);if(o==="global")return `${m}/api/user/profile/${y}`;let x=o.slice(6);return `${m}/api/v2/stacks/${encodeURIComponent(x)}/members/${y}/profile`},[m,o]),n=react.useCallback(async()=>{if(!e){d(null),h(false);return}h(true),c(null);try{let r=await fetch(a(e));if(r.ok){let y=await r.json(),x=y.profile||y.data?.profile||y;d({mid:x.mid||e,username:x.username||"",avatarUrl:x.avatar_url||x.avatarUrl,bio:x.bio,paymentAddress:x.payment_address||x.paymentAddress,createdAt:x.created_at||x.createdAt,updatedAt:x.updated_at||x.updatedAt});}else if(r.status===404)d({mid:e,username:""});else throw new Error(`${r.status}`)}catch(r){c(r instanceof Error?r.message:"Failed to load profile");}finally{h(false);}},[e,a]);react.useEffect(()=>{n();},[n]);let p=react.useCallback(async r=>{if(!e)return false;i(true),c(null);try{let y=Vt(),x={};r.username!==void 0&&(x.username=r.username),r.avatarUrl!==void 0&&(x.avatar_url=r.avatarUrl),r.bio!==void 0&&(x.bio=r.bio),r.paymentAddress!==void 0&&(x.payment_address=r.paymentAddress);let w=await fetch(a(e),{method:"PUT",headers:{"Content-Type":"application/json",...y?{"x-csrf-token":y}:{}},credentials:"same-origin",body:JSON.stringify(x)});if(!w.ok){let C=await w.json().catch(()=>({}));throw new Error(C.error||C.message||`Update failed: ${w.status}`)}let L=await w.json(),S=L.profile||L.data?.profile||L;return d(C=>({mid:C?.mid||e,username:r.username??C?.username??"",avatarUrl:r.avatarUrl??C?.avatarUrl,bio:r.bio??C?.bio,paymentAddress:r.paymentAddress??S.payment_address??S.paymentAddress??C?.paymentAddress,createdAt:C?.createdAt,updatedAt:S.updated_at||S.updatedAt||Date.now()})),!0}catch(y){return c(y instanceof Error?y.message:"Update failed"),false}finally{i(false);}},[e,a]);return {profile:s,loading:u,saving:g,error:l,updateProfile:p,refresh:n}}var ot="google-identity-services",Yt="https://accounts.google.com/gsi/client";function Jt({stackId:e,stacknetUrl:t="https://stacknet.magma-rpc.com",apiBaseUrl:s="",autoPrompt:d=true,cancelOnTapOutside:u=true,onSuccess:h,onError:g,disabled:i=false}){let{config:l}=oe(e,t),{isAuthenticated:c,loading:m,readSession:o}=te(),[a,n]=react.useState(false),[p,r]=react.useState(null),[y,x]=react.useState(false),w=react.useRef(false),L=react.useRef(false),C=l?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;react.useEffect(()=>{if(i||!C||typeof window>"u")return;if(document.getElementById(ot)){x(true);return}let b=document.createElement("script");b.id=ot,b.src=Yt,b.async=true,b.defer=true,b.onload=()=>x(true),b.onerror=()=>{r("Failed to load Google sign-in"),g?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[i,C,g]);let D=react.useCallback(async b=>{n(true),r(null);try{let T=await fetch(`${s}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!T.ok){let z=(await T.json().catch(()=>({}))).error||"Google sign-in failed";r(z),g?.(z),n(!1);return}o(),n(!1),h?.();}catch(T){let A=T.message||"Google sign-in failed";r(A),g?.(A),n(false);}},[s,e,o,h,g]);react.useEffect(()=>{if(i){console.debug("[GoogleOneTap] Disabled");return}if(!y){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",C);return}if(!C){console.debug("[GoogleOneTap] No Google clientId from stack config");return}if(m){console.debug("[GoogleOneTap] Session still loading");return}if(c){console.debug("[GoogleOneTap] User already authenticated, skipping");return}if(!window.google?.accounts?.id){console.debug("[GoogleOneTap] GIS library not available on window");return}w.current||(console.debug("[GoogleOneTap] Initializing with clientId:",C),w.current=true,window.google.accounts.id.initialize({client_id:C,callback:D,auto_select:true,cancel_on_tap_outside:u}),d&&!L.current&&(L.current=true,console.debug("[GoogleOneTap] Showing prompt..."),window.google.accounts.id.prompt(b=>{b.isDisplayed?.()&&console.debug("[GoogleOneTap] Prompt displayed"),b.isNotDisplayed?.()&&console.debug("[GoogleOneTap] Not displayed:",b.getNotDisplayedReason?.()),b.isSkippedMoment?.()&&console.debug("[GoogleOneTap] Skipped:",b.getSkippedReason?.()),b.isDismissedMoment?.()&&console.debug("[GoogleOneTap] Dismissed:",b.getDismissedReason?.());})));},[i,y,C,m,c,D,d,u]),react.useEffect(()=>()=>{window.google?.accounts?.id&&w.current&&window.google.accounts.id.cancel();},[]);let $=react.useCallback(()=>{!window.google?.accounts?.id||!w.current||window.google.accounts.id.prompt();},[]),j=react.useCallback((b,T)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:T?.theme||"filled_black",size:T?.size||"large",text:T?.text||"signin_with",width:T?.width});},[]);return {available:!!C,ready:y&&!!C,loading:a,error:p,prompt:$,renderButton:j,clientId:C}}var rt=react.createContext(null);function qt(){let e=react.useContext(rt);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Xt({config:e,callbacks:t,children:s}){return jsxRuntime.jsx(rt.Provider,{value:{config:e,callbacks:t},children:s})}function ce({length:e=6,onComplete:t,disabled:s=false,error:d,className:u="",inputClassName:h=""}){let [g,i]=react.useState(Array(e).fill("")),l=react.useCallback((o,a)=>{if(a.length>1){let p=a.replace(/\D/g,"").slice(0,e).split(""),r=[...g];p.forEach((x,w)=>{o+w<e&&(r[o+w]=x);}),i(r);let y=Math.min(o+p.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),r.every(x=>x!=="")&&setTimeout(()=>t(r.join("")),100);return}if(!/^\d?$/.test(a))return;let n=[...g];n[o]=a,i(n),a&&o<e-1&&document.getElementById(`userutils-otp-${o+1}`)?.focus(),a&&o===e-1&&n.every(p=>p!=="")&&setTimeout(()=>t(n.join("")),100);},[g,e,t]),c=react.useCallback((o,a)=>{if(a.key==="Backspace"&&!g[o]&&o>0){document.getElementById(`userutils-otp-${o-1}`)?.focus();let n=[...g];n[o-1]="",i(n);}if(a.key==="Enter"){let n=g.join("");n.length===e&&t(n);}},[g,e,t]);react.useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:u,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:g.map((o,a)=>jsxRuntime.jsx("input",{id:`userutils-otp-${a}`,type:"text",inputMode:"numeric",maxLength:e,value:o,onChange:n=>l(a,n.target.value),onKeyDown:n=>c(a,n),disabled:s,autoFocus:a===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${h}`},a))}),d&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:d})]})}ce.displayName="OTPInput";var on="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function de({className:e}){return jsxRuntime.jsx("img",{src:on,alt:"Phantom",className:e})}function ue({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function Re({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function _e({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function $e({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function dn({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:d,showOTP:u,hideHeader:h,onOTPSubmit:g,otpLabel:i="Access Code",oauthInline:l,oauthFirst:c,className:m=""}){let o=ve(e),{isAuthenticated:a,wallet:n,loading:p,error:r,authenticateSolana:y,authenticateEVM:x,authenticateOTP:w,authenticateOAuth:L,bridge:S,stackId:C}=o,D=!e.stackId&&!C,$=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:b,loading:T}=oe(C||e.stackId||null,$),[A,z]=react.useState(D?"stack-select":"select"),[N,I]=react.useState(null),[E,R]=react.useState(false),[P,U]=react.useState("idle"),[_,G]=react.useState(""),[Q,J]=react.useState([]),[ut,Be]=react.useState(e.stackId||null),[me,pt]=react.useState(false),[ft,gt]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let f=()=>{let V=window;pt(!!(V.phantom?.solana?.isPhantom||V.solana?.isPhantom));let K=V.ethereum;gt(!!(K?.isMetaMask||K?.providers?.some(q=>q.isMetaMask)));};f(),window.addEventListener("ethereum#initialized",f);let B=setTimeout(f,500);return ()=>{window.removeEventListener("ethereum#initialized",f),clearTimeout(B);}},[]),react.useEffect(()=>{A==="stack-select"&&C&&(Be(C),z("select"));},[A,C]),react.useEffect(()=>{if(!(!S.ready||!D)&&S.identity){let f=[];S.resolvedStackId&&f.push({stackId:S.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(f.map(async B=>{try{let V=await fetch(`${$}/api/v2/stacks/${B.stackId}`);if(V.ok){let K=await V.json(),q=K.data?.stack||K;B.name=q.displayName||q.name,B.logoUrl=q.logoUrl;}}catch{}return B})).then(J);}},[S.ready,S.identity,S.resolvedStackId,D,$]),react.useEffect(()=>{a&&A==="success"&&t?.();},[a,A,t]);let He=d||(b.length>0?b.filter(f=>f.type==="wallet").map(f=>f.id):["phantom","metamask"]),Qe=u!==void 0?u:b.length>0?b.some(f=>f.type==="otp"):true,Z=b.filter(f=>f.type==="oauth"),he=new Set(c||[]),Ve=Z.filter(f=>he.has(f.id)),ye=l?Z.filter(f=>!he.has(f.id)):Z,Ye=async f=>{I(f),z("connecting"),await L(f)||z("error");},mt=async()=>{I("phantom"),z("connecting");let f=await y("phantom");z(f?"success":"error");},ht=async()=>{I("metamask"),z("connecting");let f=await x();z(f?"success":"error");},yt=async f=>{U("verifying"),G(""),await(g||w)(f)?(U("success"),z("success")):(U("error"),G("Invalid or expired code"),setTimeout(()=>U("idle"),2e3));},Je=()=>{z(D&&!ut?"stack-select":"select"),I(null),R(false),U("idle"),G("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${m}`,children:[!h&&jsxRuntime.jsxs("div",{className:"mb-6 text-center",children:[j?.logoUrl&&A!=="stack-select"&&jsxRuntime.jsx("img",{src:X(j.logoUrl),alt:j.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),j?.displayName&&jsxRuntime.jsx("p",{className:"text-sm text-zinc-400 mb-2",children:j.displayName}),jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),A==="stack-select"&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:Q.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),Q.map(f=>jsxRuntime.jsxs("button",{onClick:()=>{Be(f.stackId),z("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[f.logoUrl?jsxRuntime.jsx("img",{src:X(f.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsxRuntime.jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:f.name?.[0]?.toUpperCase()||"S"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-white",children:f.name||f.stackId}),jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:f.domain})]}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},f.stackId)),S.ready&&!S.known&&jsxRuntime.jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),A==="select"&&T&&jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),r&&A==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:r}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Je,children:"Try Again"})]}),A==="success"&&jsxRuntime.jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),A==="connecting"&&p&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxRuntime.jsxs("div",{className:"mx-auto mb-3 h-10 w-10 animate-pulse",children:[N==="phantom"&&jsxRuntime.jsx(de,{className:"h-10 w-10"}),N==="metamask"&&jsxRuntime.jsx(ue,{className:"h-10 w-10"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:n.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:Je,children:"Cancel"})]}),A==="select"&&!p&&!T&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Ve.map(f=>jsxRuntime.jsxs("button",{onClick:()=>Ye(f.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx(it,{provider:f.id}),jsxRuntime.jsx("span",{className:"font-medium text-white",children:lt(f.id,f.name)})]},f.id)),He.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:mt,disabled:!me,className:`flex w-full items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${me?"cursor-pointer":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(de,{className:"h-10 w-10 flex-shrink-0 rounded-lg"}),jsxRuntime.jsx("span",{className:"flex-1 text-left font-medium text-white",children:"Phantom"}),!me&&jsxRuntime.jsx("span",{className:"text-xs text-zinc-500",children:"Not installed"})]}),He.includes("metamask")&&ft&&jsxRuntime.jsxs("button",{onClick:ht,className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx(ue,{className:"h-10 w-10 flex-shrink-0"}),jsxRuntime.jsx("span",{className:"flex-1 text-left font-medium text-white",children:"MetaMask"})]}),Qe&&!E&&jsxRuntime.jsxs("button",{onClick:()=>R(true),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e]",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsxRuntime.jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsxRuntime.jsx("span",{className:"flex-1 text-left font-medium text-white",children:i})]}),Qe&&E&&jsxRuntime.jsxs("div",{className:"rounded-xl border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsxRuntime.jsx(ce,{onComplete:yt,disabled:P==="verifying",error:_}),P==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),P==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),j?.webPageUrl&&P==="idle"&&(()=>{let f=X(j.webPageUrl);return f==="#"?null:jsxRuntime.jsx("a",{href:`${f.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})})()]}),(l?ye:Z).length>0&&(!l||ye.length>0)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!l&&Ve.length===0&&jsxRuntime.jsxs("div",{className:"flex items-center gap-3 py-1",children:[jsxRuntime.jsx("div",{className:"flex-1 border-t border-zinc-800"}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"or continue with"}),jsxRuntime.jsx("div",{className:"flex-1 border-t border-zinc-800"})]}),(l?ye:Z.filter(f=>!he.has(f.id))).map(f=>jsxRuntime.jsxs("button",{onClick:()=>Ye(f.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx(it,{provider:f.id}),jsxRuntime.jsx("span",{className:"font-medium text-white",children:lt(f.id,f.name)})]},f.id))]})]})]})}function it({provider:e}){switch(e){case "google":return jsxRuntime.jsx(Re,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "discord":return jsxRuntime.jsx(_e,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "twitter":return jsxRuntime.jsx($e,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});default:return jsxRuntime.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e] text-sm text-zinc-400 font-mono",children:e[0]?.toUpperCase()})}}function lt(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||t||e}function fn({mid:e,apiBaseUrl:t="",scope:s,onSave:d,className:u}){let{profile:h,loading:g,saving:i,error:l,updateProfile:c}=Ue(e,{apiBaseUrl:t,scope:s}),[m,o]=react.useState(null),[a,n]=react.useState(null),[p,r]=react.useState(null),y=react.useRef(null),[x,w]=react.useState(false),L=m??h?.username??"",S=a??h?.bio??"",C=p??h?.avatarUrl,D=react.useCallback(b=>{let T=b.target.files?.[0];if(!T)return;let A=new FileReader;A.onload=()=>{r(A.result),w(true);},A.readAsDataURL(T);},[]),$=async()=>{await c({username:L||void 0,avatarUrl:p??h?.avatarUrl,bio:S||void 0})&&(w(false),d?.());};if(g)return jsxRuntime.jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let j=s==="global"||!s?"Global profile":`Stack profile (${s.stackId})`;return jsxRuntime.jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:j}),jsxRuntime.jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>y.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:C?jsxRuntime.jsx("img",{src:C,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsxRuntime.jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsxRuntime.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsxRuntime.jsx("input",{type:"text",value:L,onChange:b=>{o(b.target.value),w(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsxRuntime.jsx("input",{ref:y,type:"file",accept:"image/*",onChange:D,style:{display:"none"}})]}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsxRuntime.jsx("input",{type:"text",value:S,onChange:b=>{n(b.target.value),w(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),l&&jsxRuntime.jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:l}),x&&jsxRuntime.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsxRuntime.jsx("button",{onClick:$,disabled:i,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:i?"wait":"pointer",opacity:i?.6:1},children:i?"Saving...":"Save"}),jsxRuntime.jsx("button",{onClick:()=>{o(null),n(null),r(null),w(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function gn({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxRuntime.jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsxRuntime.jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsxRuntime.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsxRuntime.jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsxRuntime.jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function mn({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function yn({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}function bn(e){let{apiBaseUrl:t,stacknetUrl:s="https://stacknet.magma-rpc.com",stackId:d="",transport:u,serviceKey:h,onAuthSuccess:g,onAuthError:i,onLogout:l}=e;async function c(o){if(!o.ok){let r=await o.json().catch(()=>({})),y=new Error(r.error||`Authentication failed (${o.status})`);throw i?.(y),y}let a=await o.json(),n=a.token||a.jwt,p=a.session||{userId:a.user?.id||a.userId||a.sub||"",address:a.user?.address||a.address,chain:a.user?.chain||a.chain,expiresAt:a.expiresAt||Date.now()+10080*60*1e3,authMethod:a.authMethod||a.method};return n&&await u.storeCredentials(n,p),g?.(p),p}return {async login(o,a){let n=await fetch(`${t}/api/auth/callback/credentials`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o,password:a})});return c(n)},async loginWeb3({chain:o,address:a,message:n,signature:p}){let r={chain:o,message:n,signature:p,stackId:d};o==="solana"&&(r.publicKey=a);let y=await fetch(`${t}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return c(y)},async loginOTP(o){let a=await fetch(`${t}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});return c(a)},async getSession(){let o=await u.getStoredSession();if(o&&o.expiresAt>Date.now())return o;try{let a=await u.getHeaders(),n=await fetch(`${t}/api/auth/session`,{headers:a});if(n.ok){let p=await n.json();if(p.session)return p.session}}catch{if(o)return o}return null},async checkSession(){let o=await u.getToken();if(!o)return false;try{let a=await fetch(`${t}/api/history?limit=1`,{headers:{Authorization:`Bearer ${o}`}});return a.ok?!0:a.status===401?(await u.clear(),!1):!0}catch{return true}},async getChallenge(o,a){let p=`${s}/api/v2/stacks/${encodeURIComponent(d)}/auth/web3/challenge`,r=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:o,address:a})});if(!r.ok)throw new Error("Failed to get challenge");let y=await r.json();return y.data||y},async logout(){try{let o=await u.getHeaders();await fetch(`${t}/api/auth/logout`,{method:"POST",headers:o});}catch{}await u.clear(),l?.();},async getHeaders(){let o=await u.getHeaders();return Object.keys(o).length>0?o:h?{Authorization:`Bearer ${h}`}:{}},async getToken(){return u.getToken()}}}function wn(){return {async storeCredentials(e,t){},async getToken(){return null},async getHeaders(){return {}},async getStoredSession(){let e=ee();return !e||e.expiresAt<=Date.now()?null:{userId:e.userId,address:e.address,chain:e.chain,expiresAt:e.expiresAt,planId:e.planId,authMethod:e.authMethod}},async clear(){}}}var Fe="stackauth_token",Ge="stackauth_session";function xn(e){return {async storeCredentials(t,s){await e.setItemAsync(Fe,t),await e.setItemAsync(Ge,JSON.stringify(s));},async getToken(){try{return await e.getItemAsync(Fe)}catch{return null}},async getHeaders(){let t=await this.getToken();return t?{Authorization:`Bearer ${t}`}:{}},async getStoredSession(){try{let t=await e.getItemAsync(Ge);return t?JSON.parse(t):null}catch{return null}},async clear(){await e.deleteItemAsync(Fe).catch(()=>{}),await e.deleteItemAsync(Ge).catch(()=>{});}}}
2
- exports.ConnectWidget=dn;exports.DiscordIcon=_e;exports.EthereumIcon=mn;exports.GoogleIcon=Re;exports.MetaMaskIcon=ue;exports.OTPInput=ce;exports.PhantomIcon=de;exports.ProfileSettings=fn;exports.SolanaIcon=gn;exports.TelegramIcon=yn;exports.TwitterIcon=$e;exports.UserUtilsProvider=Xt;exports.cn=wt;exports.createAuthClient=bn;exports.createNativeTransport=xn;exports.createStackNetClient=Ce;exports.createWebTransport=wn;exports.decodeJwtPayloadClient=St;exports.formatTokens=xt;exports.readCSRFCookie=W;exports.readSessionCookie=ee;exports.safeUrl=X;exports.useAuthBridge=xe;exports.useBillingHistory=Ht;exports.useCSRFToken=ke;exports.useGoogleOneTap=Jt;exports.usePlans=Dt;exports.usePrepaidCheckout=Ft;exports.useProfile=Ue;exports.useSession=te;exports.useStackAuth=ve;exports.useStackConfig=oe;exports.useSubscription=Rt;exports.useUsage=Wt;exports.useUserUtilsContext=qt;exports.useWeb3Wallet=be;exports.validateRedirectUrl=Ct;
1
+ 'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function xt(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function Ct(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function vt(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let s=new URL(e,t);return s.origin!==t?"/":s.pathname+s.search+s.hash}catch{return "/"}}function ee(e,t="#"){if(!e||typeof e!="string")return t;let s=e.trim();if(s===""||s==="#")return t;if(s.startsWith("/")||s.startsWith("./")||s.startsWith("../"))return s;try{let d=new URL(s);if(d.protocol==="http:"||d.protocol==="https:")return d.toString()}catch{}return t}function Nt(e){try{let t=e.split(".");if(t.length!==3)return null;let s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}function te(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function $(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function ne(){let[e,t]=react.useState(null),[s,d]=react.useState(true),u=react.useCallback(()=>{let i=te();i&&i.expiresAt>Date.now()?t({userId:i.userId,address:i.address,chain:i.chain,expiresAt:i.expiresAt,planId:i.planId,authMethod:i.authMethod}):t(null),d(false);},[]);react.useEffect(()=>{u();},[u]);let h=react.useCallback(async(i="")=>{try{let l=await fetch(`${i}/api/auth/session`);if(l.ok){let c=await l.json();if(c.session)return t(c.session),c.session}return t(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:g,refresh:h,readSession:u}}function we(e="__csrf",t="x-csrf-token"){let[s,d]=react.useState(null);react.useEffect(()=>{d($(e));},[e]);let u=s?{[t]:s}:{};return {token:s,headers:u}}function Se(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[s,d]=react.useState(null),u=react.useCallback(async(l="phantom")=>{d(null);try{let c=typeof window<"u"?window:null,m=l==="phantom"?c?.phantom?.solana||c?.solana:c?.solflare;if(!m)return d(`${l} wallet not found`),null;let a=(await m.connect()).publicKey.toString();return t({connected:!0,address:a,chain:"solana",provider:l}),a}catch(c){return d(c.message||"Failed to connect wallet"),null}},[]),h=react.useCallback(async()=>{d(null);try{let c=(typeof window<"u"?window:null)?.ethereum;if(!c)return d("MetaMask not found"),null;let m=c;c.providers?.length&&(m=c.providers.find(n=>n.isMetaMask)||c);let a=(await m.request({method:"eth_requestAccounts"}))[0];return a?(t({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(d("No account selected"),null)}catch(l){return d(l.message||"Failed to connect wallet"),null}},[]),g=react.useCallback(async(l,c)=>{d(null);let m=c?.chain||e.chain,o=c?.provider||e.provider,a=c?.address||e.address;try{if(m==="solana"){let n=typeof window<"u"?window:null,p=o==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!p)throw new Error("Wallet not available");let r=new TextEncoder().encode(l),y=await p.signMessage(r,"utf8"),S=new Uint8Array(y.signature||y),w="";for(let T=0;T<S.byteLength;T++)w+=String.fromCharCode(S[T]);return btoa(w)}if(m==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(y=>y.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[l,a]})}throw new Error("No wallet connected")}catch(n){return d(n.message||"Signing failed"),null}},[e]),i=react.useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),d(null);},[]);return {wallet:e,error:s,connectSolana:u,connectEVM:h,signMessage:g,disconnect:i}}var Lt="https://stacknet.magma-rpc.com/auth/bridge",de="stacknet-auth-bridge";function Ce(e){let t=e?.bridgeUrl||Lt,s=e?.disabled||false,d=react.useRef(null),[u,h]=react.useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),g=react.useRef([]),i=react.useRef(false),l=react.useCallback(n=>{let p={...n,protocol:de};i.current&&d.current?.contentWindow?d.current.contentWindow.postMessage(p,new URL(t).origin):g.current.push(p);},[t]);react.useEffect(()=>{if(s)return;let n=r=>{if(!(!r.data||r.data.protocol!==de)){try{if(r.origin!==new URL(t).origin)return}catch{return}switch(r.data.type){case "bridge:ready":i.current=true,h(y=>({...y,ready:true}));for(let y of g.current)d.current?.contentWindow?.postMessage(y,r.origin);g.current=[],d.current?.contentWindow?.postMessage({protocol:de,type:"auth:check"},r.origin),d.current?.contentWindow?.postMessage({protocol:de,type:"auth:resolve-stack"},r.origin);break;case "auth:status":h(y=>({...y,known:r.data.known,identity:r.data.identity,identityCount:r.data.identityCount||0}));break;case "auth:resolved-stack":h(y=>({...y,resolvedStackId:r.data.stackId||null}));break;}}};window.addEventListener("message",n);let p=document.createElement("iframe");return p.src=t,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),d.current=p,()=>{window.removeEventListener("message",n),p.parentNode&&p.parentNode.removeChild(p),d.current=null,i.current=false;}},[t,s]);let c=react.useCallback(n=>{l({type:"auth:connected",...n});},[l]),m=react.useCallback(n=>{l({type:"auth:disconnected",...n});},[l]),o=react.useCallback(()=>{l({type:"auth:clear"}),h({ready:u.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[l,u.ready]),a=react.useCallback(()=>{l({type:"auth:check"});},[l]);return {...u,reportConnected:c,reportDisconnected:m,clearAll:o,refresh:a}}async function tt(e,t,s,d){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${s}`;try{let g=await fetch(h,{method:t,headers:{"Content-Type":"application/json"},body:d?JSON.stringify(d):void 0}),i=await g.json();return g.ok?i.success&&i.data!==void 0?{success:!0,data:i.data}:{success:!0,data:i}:{success:!1,error:i.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(g){return {success:false,error:{code:"NETWORK_ERROR",message:g instanceof Error?g.message:"Network error"}}}}function ve(e){return {getNetworkStatus:()=>tt(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>tt(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:s})}}function Pe(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:d,signMessage:u,disconnect:h}=Se(),{session:g,isAuthenticated:i,refresh:l,readSession:c}=ne(),{headers:m}=we(),o=Ce({disabled:typeof window>"u"}),[a,n]=react.useState(false),[p,r]=react.useState(null),[y,S]=react.useState(false),w=e.apiBaseUrl||"",T=e.stacknetUrl||"https://stacknet.magma-rpc.com",C=e.stackId||o.resolvedStackId||"",x=ve({baseUrl:T,stackId:C}),z=react.useCallback(async(N,P,E,R)=>{n(true),r(null);try{let I=P;if(!I){let Z=await E();if(!Z)return n(!1),!1;I=Z;}let U=await x.getWeb3Challenge(N,I);if(!U.success||!U.data)return r("Failed to get challenge"),n(!1),!1;let _=await u(U.data.message,{chain:N,provider:R,address:I});if(!_)return n(!1),!1;let G={chain:N,message:U.data.message,signature:_,stackId:C};N==="solana"&&(G.publicKey=I);let V=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(G)});if(!V.ok){let Z=await V.json().catch(()=>({}));return r(Z.error||"Authentication failed"),n(!1),!1}return o.reportConnected({address:I,chain:N,method:R||(N==="solana"?"phantom":"metamask"),stackId:C}),c(),n(!1),!0}catch(I){return r(I.message||"Authentication failed"),n(false),false}},[w,x,u,c,o,C]),W=react.useCallback(async(N="phantom")=>{let P=await s(N);return P?z("solana",P,()=>s(N),N):false},[s,z]),j=react.useCallback(async()=>{let N=await d();return N?z("ethereum",N,d,"metamask"):false},[d,z]),b=react.useCallback(async N=>{n(true),r(null);try{let P=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:N})});if(!P.ok){let E=await P.json().catch(()=>({}));return r(E.error||"Invalid code"),n(!1),!1}return c(),n(!1),!0}catch(P){return r(P.message||"OTP verification failed"),n(false),false}},[w,c]),L=react.useCallback(async(N,P)=>{n(true),r(null);try{let E=P||`${window.location.origin}/api/auth/oauth/callback`,R=new URLSearchParams({provider:N,redirectUri:E,stackId:C}),I=await fetch(`${w}/api/auth/oauth/start?${R}`,{credentials:"include"});if(!I.ok){let _=await I.json().catch(()=>({}));return r(_.error||"Failed to start OAuth flow"),n(!1),!1}let U=await I.json();if(U.redirect_url){let _;try{_=new URL(U.redirect_url);}catch{return r("Invalid OAuth redirect URL"),n(!1),!1}let G=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return _.protocol!=="https:"||!G.some(V=>V.test(_.hostname))?(r(`Refusing to redirect to non-OAuth host: ${_.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",U.state||""),sessionStorage.setItem("oauth_provider",N)),window.location.href=_.toString(),!0)}return r("No redirect URL returned"),n(!1),!1}catch(E){return r(E.message||"OAuth flow failed"),n(false),false}},[w,C]),A=react.useCallback(async(N,P,E)=>{n(true),r(null);try{if(typeof sessionStorage<"u"){let I=sessionStorage.getItem("oauth_state"),U=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!I||I!==E)return r("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(U&&U!==N)return r("OAuth provider mismatch \u2014 refusing to complete login"),n(!1),!1}let R=await fetch(`${w}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:N,code:P,state:E,stackId:C})});if(!R.ok){let I=await R.json().catch(()=>({}));return r(I.error||"OAuth authentication failed"),n(!1),!1}return c(),n(!1),!0}catch(R){return r(R.message||"OAuth callback failed"),n(false),false}},[w,C,c]),D=react.useCallback(async()=>{t.address&&t.chain&&o.reportDisconnected({address:t.address,chain:t.chain,stackId:C});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:m,credentials:"include"});}catch{}h(),c();},[w,m,h,c,t,o,C]);return react.useEffect(()=>{if(!e.autoConnect||y||i||!o.ready||!o.known||!o.identity)return;S(true);let{chain:N,method:P}=o.identity;N==="solana"&&(P==="phantom"||P==="solflare")?W(P):N==="ethereum"&&j();},[e.autoConnect,y,i,o,W,j]),{session:g,isAuthenticated:i,wallet:t,loading:a,error:p,authenticateSolana:W,authenticateEVM:j,authenticateOTP:b,authenticateOAuth:L,authenticateOAuthCallback:A,logout:D,refresh:()=>l(w),stackId:C,bridge:{ready:o.ready,known:o.known,identity:o.identity,identityCount:o.identityCount,resolvedStackId:o.resolvedStackId}}}function re(e,t="https://stacknet.magma-rpc.com"){let[s,d]=react.useState(null),[u,h]=react.useState(false),[g,i]=react.useState(null),l=react.useCallback(async m=>{h(true),i(null);try{let o=await fetch(`${t}/api/v2/stacks/${m}`);if(!o.ok)return i("Stack not found"),h(!1),null;let a=await o.json(),n=a.data?.stack||a.stack||a,p={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(r=>({provider:r.provider,clientId:r.clientId,enabled:r.enabled!==!1}))};return d(p),h(!1),p}catch(o){return i(o.message),h(false),null}},[t]);react.useEffect(()=>{e&&l(e);},[e,l]);let c=s?Dt(s):[];return {config:s,loading:u,error:g,identityProviders:c,fetchConfig:l}}function Dt(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let s of e.oauthProviders)s.enabled&&t.push({type:"oauth",id:s.provider,name:s.provider});return t}function Rt(e=""){let[t,s]=react.useState([]),[d,u]=react.useState(true),[h,g]=react.useState(null),i=react.useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/plans`);if(l.ok){let c=await l.json();s(c.plans||c||[]);}}catch(l){g(l.message);}finally{u(false);}},[e]);return react.useEffect(()=>{i();},[i]),{plans:t,loading:d,error:h,refresh:i}}function Wt(e=""){let[t,s]=react.useState(null),[d,u]=react.useState(true),[h,g]=react.useState(null),i=react.useCallback(async()=>{try{let m=await fetch(`${e}/api/billing/subscription`);if(m.ok){let o=await m.json();s(o.plan?o:null);}}catch(m){g(m.message);}finally{u(false);}},[e]);react.useEffect(()=>{i();},[i]);let l=react.useCallback(async m=>{let o=$(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({planId:m})})).json();return n.url||n.checkoutUrl||null},[e]),c=react.useCallback(async()=>{let m=$();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:m?{"x-csrf-token":m}:{}})).ok?(await i(),true):false},[e,i]);return {subscription:t,loading:d,error:h,refresh:i,subscribe:l,cancel:c}}function Bt(e=""){let[t,s]=react.useState(null),[d,u]=react.useState(true),[h,g]=react.useState(null),i=react.useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/usage`);if(l.ok){let c=await l.json();s(c);}}catch(l){g(l.message);}finally{u(false);}},[e]);return react.useEffect(()=>{i();},[i]),{usage:t,loading:d,error:h,refresh:i}}function Gt(e=""){let[t,s]=react.useState(false),[d,u]=react.useState(null),h=react.useCallback(async i=>{s(true),u(null);try{let l=$(),c=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({amountCents:i})}),m=await c.json();return c.ok?m.url||null:(u(m.error||"Purchase failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]),g=react.useCallback(async i=>{s(true),u(null);try{let l=$(),c=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({sessionId:i})}),m=await c.json();return c.ok?m:(u(m.error||"Verification failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]);return {purchase:h,verifySession:g,loading:t,error:d}}function Vt(e="",t){let[s,d]=react.useState([]),[u,h]=react.useState(true),[g,i]=react.useState(null),l=t?.limit||50,c=t?.offset||0,m=react.useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/history?limit=${l}&offset=${c}`);if(o.ok){let a=await o.json();d(a.records||a.history||(Array.isArray(a)?a:[]));}}catch(o){i(o.message);}finally{h(false);}},[e,l,c]);return react.useEffect(()=>{m();},[m]),{records:s,loading:u,error:g,refresh:m}}function Jt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function je(e,t){let[s,d]=react.useState(null),[u,h]=react.useState(true),[g,i]=react.useState(false),[l,c]=react.useState(null),m=t?.apiBaseUrl??"",o=t?.scope===void 0||t?.scope==="global"?"global":`stack:${t.scope.stackId}`,a=react.useCallback(r=>{let y=encodeURIComponent(r);if(o==="global")return `${m}/api/user/profile/${y}`;let S=o.slice(6);return `${m}/api/v2/stacks/${encodeURIComponent(S)}/members/${y}/profile`},[m,o]),n=react.useCallback(async()=>{if(!e){d(null),h(false);return}h(true),c(null);try{let r=await fetch(a(e));if(r.ok){let y=await r.json(),S=y.profile||y.data?.profile||y;d({mid:S.mid||e,username:S.username||"",avatarUrl:S.avatar_url||S.avatarUrl,bio:S.bio,paymentAddress:S.payment_address||S.paymentAddress,createdAt:S.created_at||S.createdAt,updatedAt:S.updated_at||S.updatedAt});}else if(r.status===404)d({mid:e,username:""});else throw new Error(`${r.status}`)}catch(r){c(r instanceof Error?r.message:"Failed to load profile");}finally{h(false);}},[e,a]);react.useEffect(()=>{n();},[n]);let p=react.useCallback(async r=>{if(!e)return false;i(true),c(null);try{let y=Jt(),S={};r.username!==void 0&&(S.username=r.username),r.avatarUrl!==void 0&&(S.avatar_url=r.avatarUrl),r.bio!==void 0&&(S.bio=r.bio),r.paymentAddress!==void 0&&(S.payment_address=r.paymentAddress);let w=await fetch(a(e),{method:"PUT",headers:{"Content-Type":"application/json",...y?{"x-csrf-token":y}:{}},credentials:"same-origin",body:JSON.stringify(S)});if(!w.ok){let x=await w.json().catch(()=>({}));throw new Error(x.error||x.message||`Update failed: ${w.status}`)}let T=await w.json(),C=T.profile||T.data?.profile||T;return d(x=>({mid:x?.mid||e,username:r.username??x?.username??"",avatarUrl:r.avatarUrl??x?.avatarUrl,bio:r.bio??x?.bio,paymentAddress:r.paymentAddress??C.payment_address??C.paymentAddress??x?.paymentAddress,createdAt:x?.createdAt,updatedAt:C.updated_at||C.updatedAt||Date.now()})),!0}catch(y){return c(y instanceof Error?y.message:"Update failed"),false}finally{i(false);}},[e,a]);return {profile:s,loading:u,saving:g,error:l,updateProfile:p,refresh:n}}var st="google-identity-services",Zt="https://accounts.google.com/gsi/client";function Kt({stackId:e,stacknetUrl:t="https://stacknet.magma-rpc.com",apiBaseUrl:s="",autoPrompt:d=true,cancelOnTapOutside:u=true,onSuccess:h,onError:g,disabled:i=false}){let{config:l}=re(e,t),{isAuthenticated:c,loading:m,readSession:o}=ne(),[a,n]=react.useState(false),[p,r]=react.useState(null),[y,S]=react.useState(false),w=react.useRef(false),T=react.useRef(false),x=l?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;react.useEffect(()=>{if(i||!x||typeof window>"u")return;if(document.getElementById(st)){S(true);return}let b=document.createElement("script");b.id=st,b.src=Zt,b.async=true,b.defer=true,b.onload=()=>S(true),b.onerror=()=>{r("Failed to load Google sign-in"),g?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[i,x,g]);let z=react.useCallback(async b=>{n(true),r(null);try{let L=await fetch(`${s}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!L.ok){let D=(await L.json().catch(()=>({}))).error||"Google sign-in failed";r(D),g?.(D),n(!1);return}o(),n(!1),h?.();}catch(L){let A=L.message||"Google sign-in failed";r(A),g?.(A),n(false);}},[s,e,o,h,g]);react.useEffect(()=>{if(i){console.debug("[GoogleOneTap] Disabled");return}if(!y){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",x);return}if(!x){console.debug("[GoogleOneTap] No Google clientId from stack config");return}if(m){console.debug("[GoogleOneTap] Session still loading");return}if(c){console.debug("[GoogleOneTap] User already authenticated, skipping");return}if(!window.google?.accounts?.id){console.debug("[GoogleOneTap] GIS library not available on window");return}w.current||(console.debug("[GoogleOneTap] Initializing with clientId:",x),w.current=true,window.google.accounts.id.initialize({client_id:x,callback:z,auto_select:true,cancel_on_tap_outside:u}),d&&!T.current&&(T.current=true,console.debug("[GoogleOneTap] Showing prompt..."),window.google.accounts.id.prompt(b=>{b.isDisplayed?.()&&console.debug("[GoogleOneTap] Prompt displayed"),b.isNotDisplayed?.()&&console.debug("[GoogleOneTap] Not displayed:",b.getNotDisplayedReason?.()),b.isSkippedMoment?.()&&console.debug("[GoogleOneTap] Skipped:",b.getSkippedReason?.()),b.isDismissedMoment?.()&&console.debug("[GoogleOneTap] Dismissed:",b.getDismissedReason?.());})));},[i,y,x,m,c,z,d,u]),react.useEffect(()=>()=>{window.google?.accounts?.id&&w.current&&window.google.accounts.id.cancel();},[]);let W=react.useCallback(()=>{!window.google?.accounts?.id||!w.current||window.google.accounts.id.prompt();},[]),j=react.useCallback((b,L)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:L?.theme||"filled_black",size:L?.size||"large",text:L?.text||"signin_with",width:L?.width});},[]);return {available:!!x,ready:y&&!!x,loading:a,error:p,prompt:W,renderButton:j,clientId:x}}var at=react.createContext(null);function en(){let e=react.useContext(at);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function tn({config:e,callbacks:t,children:s}){return jsxRuntime.jsx(at.Provider,{value:{config:e,callbacks:t},children:s})}function pe({length:e=6,onComplete:t,disabled:s=false,error:d,className:u="",inputClassName:h=""}){let [g,i]=react.useState(Array(e).fill("")),l=react.useCallback((o,a)=>{if(a.length>1){let p=a.replace(/\D/g,"").slice(0,e).split(""),r=[...g];p.forEach((S,w)=>{o+w<e&&(r[o+w]=S);}),i(r);let y=Math.min(o+p.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),r.every(S=>S!=="")&&setTimeout(()=>t(r.join("")),100);return}if(!/^\d?$/.test(a))return;let n=[...g];n[o]=a,i(n),a&&o<e-1&&document.getElementById(`userutils-otp-${o+1}`)?.focus(),a&&o===e-1&&n.every(p=>p!=="")&&setTimeout(()=>t(n.join("")),100);},[g,e,t]),c=react.useCallback((o,a)=>{if(a.key==="Backspace"&&!g[o]&&o>0){document.getElementById(`userutils-otp-${o-1}`)?.focus();let n=[...g];n[o-1]="",i(n);}if(a.key==="Enter"){let n=g.join("");n.length===e&&t(n);}},[g,e,t]);react.useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:u,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:g.map((o,a)=>jsxRuntime.jsx("input",{id:`userutils-otp-${a}`,type:"text",inputMode:"numeric",maxLength:e,value:o,onChange:n=>l(a,n.target.value),onKeyDown:n=>c(a,n),disabled:s,autoFocus:a===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${h}`},a))}),d&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:d})]})}pe.displayName="OTPInput";var sn="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function fe({className:e,style:t}){return jsxRuntime.jsx("img",{src:sn,alt:"Phantom",className:e,style:t})}function ge({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function We({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function $e({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Fe({className:e,style:t}){return jsxRuntime.jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function pn({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:d,showOTP:u,hideHeader:h,onOTPSubmit:g,otpLabel:i="Access Code",oauthInline:l,oauthFirst:c,className:m=""}){let o=Pe(e),{isAuthenticated:a,wallet:n,loading:p,error:r,authenticateSolana:y,authenticateEVM:S,authenticateOTP:w,authenticateOAuth:T,bridge:C,stackId:x}=o,z=!e.stackId&&!x,W=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:b,loading:L}=re(x||e.stackId||null,W),[A,D]=react.useState(z?"stack-select":"select"),[N,P]=react.useState(null),[E,R]=react.useState(false),[I,U]=react.useState("idle"),[_,G]=react.useState(""),[V,Z]=react.useState([]),[ft,Qe]=react.useState(e.stackId||null),[le,gt]=react.useState(false),[mt,ht]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let f=()=>{let Y=window;gt(!!(Y.phantom?.solana?.isPhantom||Y.solana?.isPhantom));let q=Y.ethereum;ht(!!(q?.isMetaMask||q?.providers?.some(X=>X.isMetaMask)));};f(),window.addEventListener("ethereum#initialized",f);let H=setTimeout(f,500);return ()=>{window.removeEventListener("ethereum#initialized",f),clearTimeout(H);}},[]),react.useEffect(()=>{A==="stack-select"&&x&&(Qe(x),D("select"));},[A,x]),react.useEffect(()=>{if(!(!C.ready||!z)&&C.identity){let f=[];C.resolvedStackId&&f.push({stackId:C.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(f.map(async H=>{try{let Y=await fetch(`${W}/api/v2/stacks/${H.stackId}`);if(Y.ok){let q=await Y.json(),X=q.data?.stack||q;H.name=X.displayName||X.name,H.logoUrl=X.logoUrl;}}catch{}return H})).then(Z);}},[C.ready,C.identity,C.resolvedStackId,z,W]),react.useEffect(()=>{a&&A==="success"&&t?.();},[a,A,t]);let Ve=d||(b.length>0?b.filter(f=>f.type==="wallet").map(f=>f.id):["phantom","metamask"]),Ye=u!==void 0?u:b.length>0?b.some(f=>f.type==="otp"):true,K=b.filter(f=>f.type==="oauth"),ke=new Set(c||[]),Je=K.filter(f=>ke.has(f.id)),be=l?K.filter(f=>!ke.has(f.id)):K,Ze=async f=>{P(f),D("connecting"),await T(f)||D("error");},yt=async()=>{P("phantom"),D("connecting");let f=await y("phantom");D(f?"success":"error");},kt=async()=>{P("metamask"),D("connecting");let f=await S();D(f?"success":"error");},bt=async f=>{U("verifying"),G(""),await(g||w)(f)?(U("success"),D("success")):(U("error"),G("Invalid or expired code"),setTimeout(()=>U("idle"),2e3));},Ke=()=>{D(z&&!ft?"stack-select":"select"),P(null),R(false),U("idle"),G("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${m}`,children:[!h&&jsxRuntime.jsxs("div",{className:"mb-6 text-center",children:[j?.logoUrl&&A!=="stack-select"&&jsxRuntime.jsx("img",{src:ee(j.logoUrl),alt:j.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),j?.displayName&&jsxRuntime.jsx("p",{className:"text-sm text-zinc-400 mb-2",children:j.displayName}),jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),A==="stack-select"&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:V.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),V.map(f=>jsxRuntime.jsxs("button",{onClick:()=>{Qe(f.stackId),D("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[f.logoUrl?jsxRuntime.jsx("img",{src:ee(f.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsxRuntime.jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:f.name?.[0]?.toUpperCase()||"S"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-white",children:f.name||f.stackId}),jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:f.domain})]}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},f.stackId)),C.ready&&!C.known&&jsxRuntime.jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),A==="select"&&L&&jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),r&&A==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:r}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Ke,children:"Try Again"})]}),A==="success"&&jsxRuntime.jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),A==="connecting"&&p&&jsxRuntime.jsxs("div",{style:{border:"1px solid #27272a",background:"#25252f",padding:24,textAlign:"center"},children:[jsxRuntime.jsxs("div",{style:{width:40,height:40,margin:"0 auto 12px"},children:[N==="phantom"&&jsxRuntime.jsx(fe,{style:B}),N==="metamask"&&jsxRuntime.jsx(ge,{style:B})]}),jsxRuntime.jsx("p",{style:{fontWeight:500,fontSize:14,color:"#fff"},children:n.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{style:{marginTop:4,fontSize:12,color:"#71717a"},children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{style:{marginTop:16,fontSize:14,color:"#71717a",background:"none",border:"none",cursor:"pointer"},onClick:Ke,children:"Cancel"})]}),A==="select"&&!p&&!L&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Je.map(f=>jsxRuntime.jsxs("button",{onClick:()=>Ze(f.id),style:ae,children:[jsxRuntime.jsx(ct,{provider:f.id}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:"#fff"},children:dt(f.id,f.name)})]},f.id)),Ve.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:yt,disabled:!le,style:{...ae,opacity:le?1:.5,cursor:le?"pointer":"not-allowed"},children:[jsxRuntime.jsx(fe,{style:{...B,borderRadius:8}}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"Phantom"}),!le&&jsxRuntime.jsx("span",{style:{fontSize:12,color:"#71717a"},children:"Not installed"})]}),Ve.includes("metamask")&&mt&&jsxRuntime.jsxs("button",{onClick:kt,style:ae,children:[jsxRuntime.jsx(ge,{style:B}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"MetaMask"})]}),Ye&&!E&&jsxRuntime.jsxs("button",{onClick:()=>R(true),style:ae,children:[jsxRuntime.jsx("div",{style:{...B,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e"},children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsxRuntime.jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:i})]}),Ye&&E&&jsxRuntime.jsxs("div",{style:{borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:24},children:[jsxRuntime.jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginBottom:16},children:"Enter your 6-digit access code"}),jsxRuntime.jsx(pe,{onComplete:bt,disabled:I==="verifying",error:_}),I==="verifying"&&jsxRuntime.jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginTop:16},children:"Verifying..."}),I==="success"&&jsxRuntime.jsx("p",{style:{textAlign:"center",fontSize:14,color:"#4ade80",marginTop:16},children:"Verified!"}),j?.webPageUrl&&I==="idle"&&(()=>{let f=ee(j.webPageUrl);return f==="#"?null:jsxRuntime.jsx("a",{href:`${f.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",style:{display:"block",textAlign:"center",fontSize:14,color:"#71717a",marginTop:16},children:"Get code"})})()]}),(l?be:K).length>0&&(!l||be.length>0)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!l&&Je.length===0&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 0"},children:[jsxRuntime.jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}}),jsxRuntime.jsx("span",{style:{fontSize:12,color:"#52525b"},children:"or continue with"}),jsxRuntime.jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}})]}),(l?be:K.filter(f=>!ke.has(f.id))).map(f=>jsxRuntime.jsxs("button",{onClick:()=>Ze(f.id),style:ae,children:[jsxRuntime.jsx(ct,{provider:f.id}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:"#fff"},children:dt(f.id,f.name)})]},f.id))]})]})]})}var B={width:40,height:40,flexShrink:0},ae={display:"flex",width:"100%",alignItems:"center",gap:12,borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:16,cursor:"pointer",transition:"background 0.15s"};function ct({provider:e}){switch(e){case "google":return jsxRuntime.jsx(We,{style:{...B,borderRadius:8}});case "discord":return jsxRuntime.jsx($e,{style:{...B,borderRadius:8}});case "twitter":return jsxRuntime.jsx(Fe,{style:{...B,borderRadius:8}});default:return jsxRuntime.jsx("div",{style:{...B,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e",fontSize:14,color:"#a1a1aa",fontFamily:"monospace"},children:e[0]?.toUpperCase()})}}function dt(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||t||e}function mn({mid:e,apiBaseUrl:t="",scope:s,onSave:d,className:u}){let{profile:h,loading:g,saving:i,error:l,updateProfile:c}=je(e,{apiBaseUrl:t,scope:s}),[m,o]=react.useState(null),[a,n]=react.useState(null),[p,r]=react.useState(null),y=react.useRef(null),[S,w]=react.useState(false),T=m??h?.username??"",C=a??h?.bio??"",x=p??h?.avatarUrl,z=react.useCallback(b=>{let L=b.target.files?.[0];if(!L)return;let A=new FileReader;A.onload=()=>{r(A.result),w(true);},A.readAsDataURL(L);},[]),W=async()=>{await c({username:T||void 0,avatarUrl:p??h?.avatarUrl,bio:C||void 0})&&(w(false),d?.());};if(g)return jsxRuntime.jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let j=s==="global"||!s?"Global profile":`Stack profile (${s.stackId})`;return jsxRuntime.jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:j}),jsxRuntime.jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>y.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:x?jsxRuntime.jsx("img",{src:x,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsxRuntime.jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsxRuntime.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsxRuntime.jsx("input",{type:"text",value:T,onChange:b=>{o(b.target.value),w(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsxRuntime.jsx("input",{ref:y,type:"file",accept:"image/*",onChange:z,style:{display:"none"}})]}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsxRuntime.jsx("input",{type:"text",value:C,onChange:b=>{n(b.target.value),w(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),l&&jsxRuntime.jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:l}),S&&jsxRuntime.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsxRuntime.jsx("button",{onClick:W,disabled:i,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:i?"wait":"pointer",opacity:i?.6:1},children:i?"Saving...":"Save"}),jsxRuntime.jsx("button",{onClick:()=>{o(null),n(null),r(null),w(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function hn({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxRuntime.jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsxRuntime.jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsxRuntime.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsxRuntime.jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsxRuntime.jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function yn({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function bn({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}function Sn(e){let{apiBaseUrl:t,stacknetUrl:s="https://stacknet.magma-rpc.com",stackId:d="",transport:u,serviceKey:h,onAuthSuccess:g,onAuthError:i,onLogout:l}=e;async function c(o){if(!o.ok){let r=await o.json().catch(()=>({})),y=new Error(r.error||`Authentication failed (${o.status})`);throw i?.(y),y}let a=await o.json(),n=a.token||a.jwt,p=a.session||{userId:a.user?.id||a.userId||a.sub||"",address:a.user?.address||a.address,chain:a.user?.chain||a.chain,expiresAt:a.expiresAt||Date.now()+10080*60*1e3,authMethod:a.authMethod||a.method};return n&&await u.storeCredentials(n,p),g?.(p),p}return {async login(o,a){let n=await fetch(`${t}/api/auth/callback/credentials`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o,password:a})});return c(n)},async loginWeb3({chain:o,address:a,message:n,signature:p}){let r={chain:o,message:n,signature:p,stackId:d};o==="solana"&&(r.publicKey=a);let y=await fetch(`${t}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return c(y)},async loginOTP(o){let a=await fetch(`${t}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});return c(a)},async getSession(){let o=await u.getStoredSession();if(o&&o.expiresAt>Date.now())return o;try{let a=await u.getHeaders(),n=await fetch(`${t}/api/auth/session`,{headers:a});if(n.ok){let p=await n.json();if(p.session)return p.session}}catch{if(o)return o}return null},async checkSession(){let o=await u.getToken();if(!o)return false;try{let a=await fetch(`${t}/api/history?limit=1`,{headers:{Authorization:`Bearer ${o}`}});return a.ok?!0:a.status===401?(await u.clear(),!1):!0}catch{return true}},async getChallenge(o,a){let p=`${s}/api/v2/stacks/${encodeURIComponent(d)}/auth/web3/challenge`,r=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:o,address:a})});if(!r.ok)throw new Error("Failed to get challenge");let y=await r.json();return y.data||y},async logout(){try{let o=await u.getHeaders();await fetch(`${t}/api/auth/logout`,{method:"POST",headers:o});}catch{}await u.clear(),l?.();},async getHeaders(){let o=await u.getHeaders();return Object.keys(o).length>0?o:h?{Authorization:`Bearer ${h}`}:{}},async getToken(){return u.getToken()}}}function xn(){return {async storeCredentials(e,t){},async getToken(){return null},async getHeaders(){return {}},async getStoredSession(){let e=te();return !e||e.expiresAt<=Date.now()?null:{userId:e.userId,address:e.address,chain:e.chain,expiresAt:e.expiresAt,planId:e.planId,authMethod:e.authMethod}},async clear(){}}}var Ge="stackauth_token",He="stackauth_session";function Cn(e){return {async storeCredentials(t,s){await e.setItemAsync(Ge,t),await e.setItemAsync(He,JSON.stringify(s));},async getToken(){try{return await e.getItemAsync(Ge)}catch{return null}},async getHeaders(){let t=await this.getToken();return t?{Authorization:`Bearer ${t}`}:{}},async getStoredSession(){try{let t=await e.getItemAsync(He);return t?JSON.parse(t):null}catch{return null}},async clear(){await e.deleteItemAsync(Ge).catch(()=>{}),await e.deleteItemAsync(He).catch(()=>{});}}}
2
+ exports.ConnectWidget=pn;exports.DiscordIcon=$e;exports.EthereumIcon=yn;exports.GoogleIcon=We;exports.MetaMaskIcon=ge;exports.OTPInput=pe;exports.PhantomIcon=fe;exports.ProfileSettings=mn;exports.SolanaIcon=hn;exports.TelegramIcon=bn;exports.TwitterIcon=Fe;exports.UserUtilsProvider=tn;exports.cn=xt;exports.createAuthClient=Sn;exports.createNativeTransport=Cn;exports.createStackNetClient=ve;exports.createWebTransport=xn;exports.decodeJwtPayloadClient=Nt;exports.formatTokens=Ct;exports.readCSRFCookie=$;exports.readSessionCookie=te;exports.safeUrl=ee;exports.useAuthBridge=Ce;exports.useBillingHistory=Vt;exports.useCSRFToken=we;exports.useGoogleOneTap=Kt;exports.usePlans=Rt;exports.usePrepaidCheckout=Gt;exports.useProfile=je;exports.useSession=ne;exports.useStackAuth=Pe;exports.useStackConfig=re;exports.useSubscription=Wt;exports.useUsage=Bt;exports.useUserUtilsContext=en;exports.useWeb3Wallet=Se;exports.validateRedirectUrl=vt;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useState,useCallback,useEffect,useRef,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function wt(...e){return twMerge(clsx(e))}function xt(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function Ct(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let s=new URL(e,t);return s.origin!==t?"/":s.pathname+s.search+s.hash}catch{return "/"}}function X(e,t="#"){if(!e||typeof e!="string")return t;let s=e.trim();if(s===""||s==="#")return t;if(s.startsWith("/")||s.startsWith("./")||s.startsWith("../"))return s;try{let d=new URL(s);if(d.protocol==="http:"||d.protocol==="https:")return d.toString()}catch{}return t}function St(e){try{let t=e.split(".");if(t.length!==3)return null;let s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}function ee(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function W(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function te(){let[e,t]=useState(null),[s,d]=useState(true),u=useCallback(()=>{let i=ee();i&&i.expiresAt>Date.now()?t({userId:i.userId,address:i.address,chain:i.chain,expiresAt:i.expiresAt,planId:i.planId,authMethod:i.authMethod}):t(null),d(false);},[]);useEffect(()=>{u();},[u]);let h=useCallback(async(i="")=>{try{let l=await fetch(`${i}/api/auth/session`);if(l.ok){let c=await l.json();if(c.session)return t(c.session),c.session}return t(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:g,refresh:h,readSession:u}}function ke(e="__csrf",t="x-csrf-token"){let[s,d]=useState(null);useEffect(()=>{d(W(e));},[e]);let u=s?{[t]:s}:{};return {token:s,headers:u}}function be(){let[e,t]=useState({connected:false,address:null,chain:null,provider:null}),[s,d]=useState(null),u=useCallback(async(l="phantom")=>{d(null);try{let c=typeof window<"u"?window:null,m=l==="phantom"?c?.phantom?.solana||c?.solana:c?.solflare;if(!m)return d(`${l} wallet not found`),null;let a=(await m.connect()).publicKey.toString();return t({connected:!0,address:a,chain:"solana",provider:l}),a}catch(c){return d(c.message||"Failed to connect wallet"),null}},[]),h=useCallback(async()=>{d(null);try{let c=(typeof window<"u"?window:null)?.ethereum;if(!c)return d("MetaMask not found"),null;let m=c;c.providers?.length&&(m=c.providers.find(n=>n.isMetaMask)||c);let a=(await m.request({method:"eth_requestAccounts"}))[0];return a?(t({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(d("No account selected"),null)}catch(l){return d(l.message||"Failed to connect wallet"),null}},[]),g=useCallback(async(l,c)=>{d(null);let m=c?.chain||e.chain,o=c?.provider||e.provider,a=c?.address||e.address;try{if(m==="solana"){let n=typeof window<"u"?window:null,p=o==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!p)throw new Error("Wallet not available");let r=new TextEncoder().encode(l),y=await p.signMessage(r,"utf8"),x=new Uint8Array(y.signature||y),w="";for(let L=0;L<x.byteLength;L++)w+=String.fromCharCode(x[L]);return btoa(w)}if(m==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(y=>y.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[l,a]})}throw new Error("No wallet connected")}catch(n){return d(n.message||"Signing failed"),null}},[e]),i=useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),d(null);},[]);return {wallet:e,error:s,connectSolana:u,connectEVM:h,signMessage:g,disconnect:i}}var Mt="https://stacknet.magma-rpc.com/auth/bridge",ie="stacknet-auth-bridge";function xe(e){let t=e?.bridgeUrl||Mt,s=e?.disabled||false,d=useRef(null),[u,h]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),g=useRef([]),i=useRef(false),l=useCallback(n=>{let p={...n,protocol:ie};i.current&&d.current?.contentWindow?d.current.contentWindow.postMessage(p,new URL(t).origin):g.current.push(p);},[t]);useEffect(()=>{if(s)return;let n=r=>{if(!(!r.data||r.data.protocol!==ie)){try{if(r.origin!==new URL(t).origin)return}catch{return}switch(r.data.type){case "bridge:ready":i.current=true,h(y=>({...y,ready:true}));for(let y of g.current)d.current?.contentWindow?.postMessage(y,r.origin);g.current=[],d.current?.contentWindow?.postMessage({protocol:ie,type:"auth:check"},r.origin),d.current?.contentWindow?.postMessage({protocol:ie,type:"auth:resolve-stack"},r.origin);break;case "auth:status":h(y=>({...y,known:r.data.known,identity:r.data.identity,identityCount:r.data.identityCount||0}));break;case "auth:resolved-stack":h(y=>({...y,resolvedStackId:r.data.stackId||null}));break;}}};window.addEventListener("message",n);let p=document.createElement("iframe");return p.src=t,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),d.current=p,()=>{window.removeEventListener("message",n),p.parentNode&&p.parentNode.removeChild(p),d.current=null,i.current=false;}},[t,s]);let c=useCallback(n=>{l({type:"auth:connected",...n});},[l]),m=useCallback(n=>{l({type:"auth:disconnected",...n});},[l]),o=useCallback(()=>{l({type:"auth:clear"}),h({ready:u.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[l,u.ready]),a=useCallback(()=>{l({type:"auth:check"});},[l]);return {...u,reportConnected:c,reportDisconnected:m,clearAll:o,refresh:a}}async function Xe(e,t,s,d){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${s}`;try{let g=await fetch(h,{method:t,headers:{"Content-Type":"application/json"},body:d?JSON.stringify(d):void 0}),i=await g.json();return g.ok?i.success&&i.data!==void 0?{success:!0,data:i.data}:{success:!0,data:i}:{success:!1,error:i.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(g){return {success:false,error:{code:"NETWORK_ERROR",message:g instanceof Error?g.message:"Network error"}}}}function Ce(e){return {getNetworkStatus:()=>Xe(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>Xe(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:s})}}function ve(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:d,signMessage:u,disconnect:h}=be(),{session:g,isAuthenticated:i,refresh:l,readSession:c}=te(),{headers:m}=ke(),o=xe({disabled:typeof window>"u"}),[a,n]=useState(false),[p,r]=useState(null),[y,x]=useState(false),w=e.apiBaseUrl||"",L=e.stacknetUrl||"https://stacknet.magma-rpc.com",S=e.stackId||o.resolvedStackId||"",C=Ce({baseUrl:L,stackId:S}),D=useCallback(async(N,I,E,R)=>{n(true),r(null);try{let P=I;if(!P){let J=await E();if(!J)return n(!1),!1;P=J;}let U=await C.getWeb3Challenge(N,P);if(!U.success||!U.data)return r("Failed to get challenge"),n(!1),!1;let _=await u(U.data.message,{chain:N,provider:R,address:P});if(!_)return n(!1),!1;let G={chain:N,message:U.data.message,signature:_,stackId:S};N==="solana"&&(G.publicKey=P);let Q=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(G)});if(!Q.ok){let J=await Q.json().catch(()=>({}));return r(J.error||"Authentication failed"),n(!1),!1}return o.reportConnected({address:P,chain:N,method:R||(N==="solana"?"phantom":"metamask"),stackId:S}),c(),n(!1),!0}catch(P){return r(P.message||"Authentication failed"),n(false),false}},[w,C,u,c,o,S]),$=useCallback(async(N="phantom")=>{let I=await s(N);return I?D("solana",I,()=>s(N),N):false},[s,D]),j=useCallback(async()=>{let N=await d();return N?D("ethereum",N,d,"metamask"):false},[d,D]),b=useCallback(async N=>{n(true),r(null);try{let I=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:N})});if(!I.ok){let E=await I.json().catch(()=>({}));return r(E.error||"Invalid code"),n(!1),!1}return c(),n(!1),!0}catch(I){return r(I.message||"OTP verification failed"),n(false),false}},[w,c]),T=useCallback(async(N,I)=>{n(true),r(null);try{let E=I||`${window.location.origin}/api/auth/oauth/callback`,R=new URLSearchParams({provider:N,redirectUri:E,stackId:S}),P=await fetch(`${w}/api/auth/oauth/start?${R}`,{credentials:"include"});if(!P.ok){let _=await P.json().catch(()=>({}));return r(_.error||"Failed to start OAuth flow"),n(!1),!1}let U=await P.json();if(U.redirect_url){let _;try{_=new URL(U.redirect_url);}catch{return r("Invalid OAuth redirect URL"),n(!1),!1}let G=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return _.protocol!=="https:"||!G.some(Q=>Q.test(_.hostname))?(r(`Refusing to redirect to non-OAuth host: ${_.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",U.state||""),sessionStorage.setItem("oauth_provider",N)),window.location.href=_.toString(),!0)}return r("No redirect URL returned"),n(!1),!1}catch(E){return r(E.message||"OAuth flow failed"),n(false),false}},[w,S]),A=useCallback(async(N,I,E)=>{n(true),r(null);try{if(typeof sessionStorage<"u"){let P=sessionStorage.getItem("oauth_state"),U=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!P||P!==E)return r("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(U&&U!==N)return r("OAuth provider mismatch \u2014 refusing to complete login"),n(!1),!1}let R=await fetch(`${w}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:N,code:I,state:E,stackId:S})});if(!R.ok){let P=await R.json().catch(()=>({}));return r(P.error||"OAuth authentication failed"),n(!1),!1}return c(),n(!1),!0}catch(R){return r(R.message||"OAuth callback failed"),n(false),false}},[w,S,c]),z=useCallback(async()=>{t.address&&t.chain&&o.reportDisconnected({address:t.address,chain:t.chain,stackId:S});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:m,credentials:"include"});}catch{}h(),c();},[w,m,h,c,t,o,S]);return useEffect(()=>{if(!e.autoConnect||y||i||!o.ready||!o.known||!o.identity)return;x(true);let{chain:N,method:I}=o.identity;N==="solana"&&(I==="phantom"||I==="solflare")?$(I):N==="ethereum"&&j();},[e.autoConnect,y,i,o,$,j]),{session:g,isAuthenticated:i,wallet:t,loading:a,error:p,authenticateSolana:$,authenticateEVM:j,authenticateOTP:b,authenticateOAuth:T,authenticateOAuthCallback:A,logout:z,refresh:()=>l(w),stackId:S,bridge:{ready:o.ready,known:o.known,identity:o.identity,identityCount:o.identityCount,resolvedStackId:o.resolvedStackId}}}function oe(e,t="https://stacknet.magma-rpc.com"){let[s,d]=useState(null),[u,h]=useState(false),[g,i]=useState(null),l=useCallback(async m=>{h(true),i(null);try{let o=await fetch(`${t}/api/v2/stacks/${m}`);if(!o.ok)return i("Stack not found"),h(!1),null;let a=await o.json(),n=a.data?.stack||a.stack||a,p={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(r=>({provider:r.provider,clientId:r.clientId,enabled:r.enabled!==!1}))};return d(p),h(!1),p}catch(o){return i(o.message),h(false),null}},[t]);useEffect(()=>{e&&l(e);},[e,l]);let c=s?Ot(s):[];return {config:s,loading:u,error:g,identityProviders:c,fetchConfig:l}}function Ot(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let s of e.oauthProviders)s.enabled&&t.push({type:"oauth",id:s.provider,name:s.provider});return t}function Dt(e=""){let[t,s]=useState([]),[d,u]=useState(true),[h,g]=useState(null),i=useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/plans`);if(l.ok){let c=await l.json();s(c.plans||c||[]);}}catch(l){g(l.message);}finally{u(false);}},[e]);return useEffect(()=>{i();},[i]),{plans:t,loading:d,error:h,refresh:i}}function Rt(e=""){let[t,s]=useState(null),[d,u]=useState(true),[h,g]=useState(null),i=useCallback(async()=>{try{let m=await fetch(`${e}/api/billing/subscription`);if(m.ok){let o=await m.json();s(o.plan?o:null);}}catch(m){g(m.message);}finally{u(false);}},[e]);useEffect(()=>{i();},[i]);let l=useCallback(async m=>{let o=W(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({planId:m})})).json();return n.url||n.checkoutUrl||null},[e]),c=useCallback(async()=>{let m=W();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:m?{"x-csrf-token":m}:{}})).ok?(await i(),true):false},[e,i]);return {subscription:t,loading:d,error:h,refresh:i,subscribe:l,cancel:c}}function Wt(e=""){let[t,s]=useState(null),[d,u]=useState(true),[h,g]=useState(null),i=useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/usage`);if(l.ok){let c=await l.json();s(c);}}catch(l){g(l.message);}finally{u(false);}},[e]);return useEffect(()=>{i();},[i]),{usage:t,loading:d,error:h,refresh:i}}function Ft(e=""){let[t,s]=useState(false),[d,u]=useState(null),h=useCallback(async i=>{s(true),u(null);try{let l=W(),c=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({amountCents:i})}),m=await c.json();return c.ok?m.url||null:(u(m.error||"Purchase failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]),g=useCallback(async i=>{s(true),u(null);try{let l=W(),c=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({sessionId:i})}),m=await c.json();return c.ok?m:(u(m.error||"Verification failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]);return {purchase:h,verifySession:g,loading:t,error:d}}function Ht(e="",t){let[s,d]=useState([]),[u,h]=useState(true),[g,i]=useState(null),l=t?.limit||50,c=t?.offset||0,m=useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/history?limit=${l}&offset=${c}`);if(o.ok){let a=await o.json();d(a.records||a.history||(Array.isArray(a)?a:[]));}}catch(o){i(o.message);}finally{h(false);}},[e,l,c]);return useEffect(()=>{m();},[m]),{records:s,loading:u,error:g,refresh:m}}function Vt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function Ue(e,t){let[s,d]=useState(null),[u,h]=useState(true),[g,i]=useState(false),[l,c]=useState(null),m=t?.apiBaseUrl??"",o=t?.scope===void 0||t?.scope==="global"?"global":`stack:${t.scope.stackId}`,a=useCallback(r=>{let y=encodeURIComponent(r);if(o==="global")return `${m}/api/user/profile/${y}`;let x=o.slice(6);return `${m}/api/v2/stacks/${encodeURIComponent(x)}/members/${y}/profile`},[m,o]),n=useCallback(async()=>{if(!e){d(null),h(false);return}h(true),c(null);try{let r=await fetch(a(e));if(r.ok){let y=await r.json(),x=y.profile||y.data?.profile||y;d({mid:x.mid||e,username:x.username||"",avatarUrl:x.avatar_url||x.avatarUrl,bio:x.bio,paymentAddress:x.payment_address||x.paymentAddress,createdAt:x.created_at||x.createdAt,updatedAt:x.updated_at||x.updatedAt});}else if(r.status===404)d({mid:e,username:""});else throw new Error(`${r.status}`)}catch(r){c(r instanceof Error?r.message:"Failed to load profile");}finally{h(false);}},[e,a]);useEffect(()=>{n();},[n]);let p=useCallback(async r=>{if(!e)return false;i(true),c(null);try{let y=Vt(),x={};r.username!==void 0&&(x.username=r.username),r.avatarUrl!==void 0&&(x.avatar_url=r.avatarUrl),r.bio!==void 0&&(x.bio=r.bio),r.paymentAddress!==void 0&&(x.payment_address=r.paymentAddress);let w=await fetch(a(e),{method:"PUT",headers:{"Content-Type":"application/json",...y?{"x-csrf-token":y}:{}},credentials:"same-origin",body:JSON.stringify(x)});if(!w.ok){let C=await w.json().catch(()=>({}));throw new Error(C.error||C.message||`Update failed: ${w.status}`)}let L=await w.json(),S=L.profile||L.data?.profile||L;return d(C=>({mid:C?.mid||e,username:r.username??C?.username??"",avatarUrl:r.avatarUrl??C?.avatarUrl,bio:r.bio??C?.bio,paymentAddress:r.paymentAddress??S.payment_address??S.paymentAddress??C?.paymentAddress,createdAt:C?.createdAt,updatedAt:S.updated_at||S.updatedAt||Date.now()})),!0}catch(y){return c(y instanceof Error?y.message:"Update failed"),false}finally{i(false);}},[e,a]);return {profile:s,loading:u,saving:g,error:l,updateProfile:p,refresh:n}}var ot="google-identity-services",Yt="https://accounts.google.com/gsi/client";function Jt({stackId:e,stacknetUrl:t="https://stacknet.magma-rpc.com",apiBaseUrl:s="",autoPrompt:d=true,cancelOnTapOutside:u=true,onSuccess:h,onError:g,disabled:i=false}){let{config:l}=oe(e,t),{isAuthenticated:c,loading:m,readSession:o}=te(),[a,n]=useState(false),[p,r]=useState(null),[y,x]=useState(false),w=useRef(false),L=useRef(false),C=l?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;useEffect(()=>{if(i||!C||typeof window>"u")return;if(document.getElementById(ot)){x(true);return}let b=document.createElement("script");b.id=ot,b.src=Yt,b.async=true,b.defer=true,b.onload=()=>x(true),b.onerror=()=>{r("Failed to load Google sign-in"),g?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[i,C,g]);let D=useCallback(async b=>{n(true),r(null);try{let T=await fetch(`${s}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!T.ok){let z=(await T.json().catch(()=>({}))).error||"Google sign-in failed";r(z),g?.(z),n(!1);return}o(),n(!1),h?.();}catch(T){let A=T.message||"Google sign-in failed";r(A),g?.(A),n(false);}},[s,e,o,h,g]);useEffect(()=>{if(i){console.debug("[GoogleOneTap] Disabled");return}if(!y){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",C);return}if(!C){console.debug("[GoogleOneTap] No Google clientId from stack config");return}if(m){console.debug("[GoogleOneTap] Session still loading");return}if(c){console.debug("[GoogleOneTap] User already authenticated, skipping");return}if(!window.google?.accounts?.id){console.debug("[GoogleOneTap] GIS library not available on window");return}w.current||(console.debug("[GoogleOneTap] Initializing with clientId:",C),w.current=true,window.google.accounts.id.initialize({client_id:C,callback:D,auto_select:true,cancel_on_tap_outside:u}),d&&!L.current&&(L.current=true,console.debug("[GoogleOneTap] Showing prompt..."),window.google.accounts.id.prompt(b=>{b.isDisplayed?.()&&console.debug("[GoogleOneTap] Prompt displayed"),b.isNotDisplayed?.()&&console.debug("[GoogleOneTap] Not displayed:",b.getNotDisplayedReason?.()),b.isSkippedMoment?.()&&console.debug("[GoogleOneTap] Skipped:",b.getSkippedReason?.()),b.isDismissedMoment?.()&&console.debug("[GoogleOneTap] Dismissed:",b.getDismissedReason?.());})));},[i,y,C,m,c,D,d,u]),useEffect(()=>()=>{window.google?.accounts?.id&&w.current&&window.google.accounts.id.cancel();},[]);let $=useCallback(()=>{!window.google?.accounts?.id||!w.current||window.google.accounts.id.prompt();},[]),j=useCallback((b,T)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:T?.theme||"filled_black",size:T?.size||"large",text:T?.text||"signin_with",width:T?.width});},[]);return {available:!!C,ready:y&&!!C,loading:a,error:p,prompt:$,renderButton:j,clientId:C}}var rt=createContext(null);function qt(){let e=useContext(rt);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Xt({config:e,callbacks:t,children:s}){return jsx(rt.Provider,{value:{config:e,callbacks:t},children:s})}function ce({length:e=6,onComplete:t,disabled:s=false,error:d,className:u="",inputClassName:h=""}){let [g,i]=useState(Array(e).fill("")),l=useCallback((o,a)=>{if(a.length>1){let p=a.replace(/\D/g,"").slice(0,e).split(""),r=[...g];p.forEach((x,w)=>{o+w<e&&(r[o+w]=x);}),i(r);let y=Math.min(o+p.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),r.every(x=>x!=="")&&setTimeout(()=>t(r.join("")),100);return}if(!/^\d?$/.test(a))return;let n=[...g];n[o]=a,i(n),a&&o<e-1&&document.getElementById(`userutils-otp-${o+1}`)?.focus(),a&&o===e-1&&n.every(p=>p!=="")&&setTimeout(()=>t(n.join("")),100);},[g,e,t]),c=useCallback((o,a)=>{if(a.key==="Backspace"&&!g[o]&&o>0){document.getElementById(`userutils-otp-${o-1}`)?.focus();let n=[...g];n[o-1]="",i(n);}if(a.key==="Enter"){let n=g.join("");n.length===e&&t(n);}},[g,e,t]);useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:u,children:[jsx("div",{className:"flex gap-2 justify-center",children:g.map((o,a)=>jsx("input",{id:`userutils-otp-${a}`,type:"text",inputMode:"numeric",maxLength:e,value:o,onChange:n=>l(a,n.target.value),onKeyDown:n=>c(a,n),disabled:s,autoFocus:a===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${h}`},a))}),d&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:d})]})}ce.displayName="OTPInput";var on="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function de({className:e}){return jsx("img",{src:on,alt:"Phantom",className:e})}function ue({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function Re({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function _e({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function $e({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function dn({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:d,showOTP:u,hideHeader:h,onOTPSubmit:g,otpLabel:i="Access Code",oauthInline:l,oauthFirst:c,className:m=""}){let o=ve(e),{isAuthenticated:a,wallet:n,loading:p,error:r,authenticateSolana:y,authenticateEVM:x,authenticateOTP:w,authenticateOAuth:L,bridge:S,stackId:C}=o,D=!e.stackId&&!C,$=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:b,loading:T}=oe(C||e.stackId||null,$),[A,z]=useState(D?"stack-select":"select"),[N,I]=useState(null),[E,R]=useState(false),[P,U]=useState("idle"),[_,G]=useState(""),[Q,J]=useState([]),[ut,Be]=useState(e.stackId||null),[me,pt]=useState(false),[ft,gt]=useState(false);useEffect(()=>{if(typeof window>"u")return;let f=()=>{let V=window;pt(!!(V.phantom?.solana?.isPhantom||V.solana?.isPhantom));let K=V.ethereum;gt(!!(K?.isMetaMask||K?.providers?.some(q=>q.isMetaMask)));};f(),window.addEventListener("ethereum#initialized",f);let B=setTimeout(f,500);return ()=>{window.removeEventListener("ethereum#initialized",f),clearTimeout(B);}},[]),useEffect(()=>{A==="stack-select"&&C&&(Be(C),z("select"));},[A,C]),useEffect(()=>{if(!(!S.ready||!D)&&S.identity){let f=[];S.resolvedStackId&&f.push({stackId:S.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(f.map(async B=>{try{let V=await fetch(`${$}/api/v2/stacks/${B.stackId}`);if(V.ok){let K=await V.json(),q=K.data?.stack||K;B.name=q.displayName||q.name,B.logoUrl=q.logoUrl;}}catch{}return B})).then(J);}},[S.ready,S.identity,S.resolvedStackId,D,$]),useEffect(()=>{a&&A==="success"&&t?.();},[a,A,t]);let He=d||(b.length>0?b.filter(f=>f.type==="wallet").map(f=>f.id):["phantom","metamask"]),Qe=u!==void 0?u:b.length>0?b.some(f=>f.type==="otp"):true,Z=b.filter(f=>f.type==="oauth"),he=new Set(c||[]),Ve=Z.filter(f=>he.has(f.id)),ye=l?Z.filter(f=>!he.has(f.id)):Z,Ye=async f=>{I(f),z("connecting"),await L(f)||z("error");},mt=async()=>{I("phantom"),z("connecting");let f=await y("phantom");z(f?"success":"error");},ht=async()=>{I("metamask"),z("connecting");let f=await x();z(f?"success":"error");},yt=async f=>{U("verifying"),G(""),await(g||w)(f)?(U("success"),z("success")):(U("error"),G("Invalid or expired code"),setTimeout(()=>U("idle"),2e3));},Je=()=>{z(D&&!ut?"stack-select":"select"),I(null),R(false),U("idle"),G("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${m}`,children:[!h&&jsxs("div",{className:"mb-6 text-center",children:[j?.logoUrl&&A!=="stack-select"&&jsx("img",{src:X(j.logoUrl),alt:j.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),j?.displayName&&jsx("p",{className:"text-sm text-zinc-400 mb-2",children:j.displayName}),jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),A==="stack-select"&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:Q.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),Q.map(f=>jsxs("button",{onClick:()=>{Be(f.stackId),z("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[f.logoUrl?jsx("img",{src:X(f.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:f.name?.[0]?.toUpperCase()||"S"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-white",children:f.name||f.stackId}),jsx("p",{className:"text-xs text-zinc-500",children:f.domain})]}),jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},f.stackId)),S.ready&&!S.known&&jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),A==="select"&&T&&jsx("div",{className:"flex items-center justify-center py-8",children:jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),r&&A==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:r}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Je,children:"Try Again"})]}),A==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),A==="connecting"&&p&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxs("div",{className:"mx-auto mb-3 h-10 w-10 animate-pulse",children:[N==="phantom"&&jsx(de,{className:"h-10 w-10"}),N==="metamask"&&jsx(ue,{className:"h-10 w-10"})]}),jsx("p",{className:"font-medium text-sm text-white",children:n.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:Je,children:"Cancel"})]}),A==="select"&&!p&&!T&&jsxs(Fragment,{children:[Ve.map(f=>jsxs("button",{onClick:()=>Ye(f.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx(it,{provider:f.id}),jsx("span",{className:"font-medium text-white",children:lt(f.id,f.name)})]},f.id)),He.includes("phantom")&&jsxs("button",{onClick:mt,disabled:!me,className:`flex w-full items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${me?"cursor-pointer":"cursor-not-allowed opacity-50"}`,children:[jsx(de,{className:"h-10 w-10 flex-shrink-0 rounded-lg"}),jsx("span",{className:"flex-1 text-left font-medium text-white",children:"Phantom"}),!me&&jsx("span",{className:"text-xs text-zinc-500",children:"Not installed"})]}),He.includes("metamask")&&ft&&jsxs("button",{onClick:ht,className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx(ue,{className:"h-10 w-10 flex-shrink-0"}),jsx("span",{className:"flex-1 text-left font-medium text-white",children:"MetaMask"})]}),Qe&&!E&&jsxs("button",{onClick:()=>R(true),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e]",children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("span",{className:"flex-1 text-left font-medium text-white",children:i})]}),Qe&&E&&jsxs("div",{className:"rounded-xl border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsx(ce,{onComplete:yt,disabled:P==="verifying",error:_}),P==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),P==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),j?.webPageUrl&&P==="idle"&&(()=>{let f=X(j.webPageUrl);return f==="#"?null:jsx("a",{href:`${f.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})})()]}),(l?ye:Z).length>0&&(!l||ye.length>0)&&jsxs(Fragment,{children:[!l&&Ve.length===0&&jsxs("div",{className:"flex items-center gap-3 py-1",children:[jsx("div",{className:"flex-1 border-t border-zinc-800"}),jsx("span",{className:"text-xs text-zinc-600",children:"or continue with"}),jsx("div",{className:"flex-1 border-t border-zinc-800"})]}),(l?ye:Z.filter(f=>!he.has(f.id))).map(f=>jsxs("button",{onClick:()=>Ye(f.id),className:"flex w-full cursor-pointer items-center gap-3 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx(it,{provider:f.id}),jsx("span",{className:"font-medium text-white",children:lt(f.id,f.name)})]},f.id))]})]})]})}function it({provider:e}){switch(e){case "google":return jsx(Re,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "discord":return jsx(_e,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});case "twitter":return jsx($e,{className:"h-10 w-10 flex-shrink-0 rounded-lg"});default:return jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border border-zinc-700 bg-[#2a2a3e] text-sm text-zinc-400 font-mono",children:e[0]?.toUpperCase()})}}function lt(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||t||e}function fn({mid:e,apiBaseUrl:t="",scope:s,onSave:d,className:u}){let{profile:h,loading:g,saving:i,error:l,updateProfile:c}=Ue(e,{apiBaseUrl:t,scope:s}),[m,o]=useState(null),[a,n]=useState(null),[p,r]=useState(null),y=useRef(null),[x,w]=useState(false),L=m??h?.username??"",S=a??h?.bio??"",C=p??h?.avatarUrl,D=useCallback(b=>{let T=b.target.files?.[0];if(!T)return;let A=new FileReader;A.onload=()=>{r(A.result),w(true);},A.readAsDataURL(T);},[]),$=async()=>{await c({username:L||void 0,avatarUrl:p??h?.avatarUrl,bio:S||void 0})&&(w(false),d?.());};if(g)return jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let j=s==="global"||!s?"Global profile":`Stack profile (${s.stackId})`;return jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:j}),jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsx("button",{type:"button",onClick:()=>y.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:C?jsx("img",{src:C,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsx("input",{type:"text",value:L,onChange:b=>{o(b.target.value),w(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsx("input",{ref:y,type:"file",accept:"image/*",onChange:D,style:{display:"none"}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsx("input",{type:"text",value:S,onChange:b=>{n(b.target.value),w(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),l&&jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:l}),x&&jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsx("button",{onClick:$,disabled:i,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:i?"wait":"pointer",opacity:i?.6:1},children:i?"Saving...":"Save"}),jsx("button",{onClick:()=>{o(null),n(null),r(null),w(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function gn({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function mn({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function yn({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}function bn(e){let{apiBaseUrl:t,stacknetUrl:s="https://stacknet.magma-rpc.com",stackId:d="",transport:u,serviceKey:h,onAuthSuccess:g,onAuthError:i,onLogout:l}=e;async function c(o){if(!o.ok){let r=await o.json().catch(()=>({})),y=new Error(r.error||`Authentication failed (${o.status})`);throw i?.(y),y}let a=await o.json(),n=a.token||a.jwt,p=a.session||{userId:a.user?.id||a.userId||a.sub||"",address:a.user?.address||a.address,chain:a.user?.chain||a.chain,expiresAt:a.expiresAt||Date.now()+10080*60*1e3,authMethod:a.authMethod||a.method};return n&&await u.storeCredentials(n,p),g?.(p),p}return {async login(o,a){let n=await fetch(`${t}/api/auth/callback/credentials`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o,password:a})});return c(n)},async loginWeb3({chain:o,address:a,message:n,signature:p}){let r={chain:o,message:n,signature:p,stackId:d};o==="solana"&&(r.publicKey=a);let y=await fetch(`${t}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return c(y)},async loginOTP(o){let a=await fetch(`${t}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});return c(a)},async getSession(){let o=await u.getStoredSession();if(o&&o.expiresAt>Date.now())return o;try{let a=await u.getHeaders(),n=await fetch(`${t}/api/auth/session`,{headers:a});if(n.ok){let p=await n.json();if(p.session)return p.session}}catch{if(o)return o}return null},async checkSession(){let o=await u.getToken();if(!o)return false;try{let a=await fetch(`${t}/api/history?limit=1`,{headers:{Authorization:`Bearer ${o}`}});return a.ok?!0:a.status===401?(await u.clear(),!1):!0}catch{return true}},async getChallenge(o,a){let p=`${s}/api/v2/stacks/${encodeURIComponent(d)}/auth/web3/challenge`,r=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:o,address:a})});if(!r.ok)throw new Error("Failed to get challenge");let y=await r.json();return y.data||y},async logout(){try{let o=await u.getHeaders();await fetch(`${t}/api/auth/logout`,{method:"POST",headers:o});}catch{}await u.clear(),l?.();},async getHeaders(){let o=await u.getHeaders();return Object.keys(o).length>0?o:h?{Authorization:`Bearer ${h}`}:{}},async getToken(){return u.getToken()}}}function wn(){return {async storeCredentials(e,t){},async getToken(){return null},async getHeaders(){return {}},async getStoredSession(){let e=ee();return !e||e.expiresAt<=Date.now()?null:{userId:e.userId,address:e.address,chain:e.chain,expiresAt:e.expiresAt,planId:e.planId,authMethod:e.authMethod}},async clear(){}}}var Fe="stackauth_token",Ge="stackauth_session";function xn(e){return {async storeCredentials(t,s){await e.setItemAsync(Fe,t),await e.setItemAsync(Ge,JSON.stringify(s));},async getToken(){try{return await e.getItemAsync(Fe)}catch{return null}},async getHeaders(){let t=await this.getToken();return t?{Authorization:`Bearer ${t}`}:{}},async getStoredSession(){try{let t=await e.getItemAsync(Ge);return t?JSON.parse(t):null}catch{return null}},async clear(){await e.deleteItemAsync(Fe).catch(()=>{}),await e.deleteItemAsync(Ge).catch(()=>{});}}}
2
- export{dn as ConnectWidget,_e as DiscordIcon,mn as EthereumIcon,Re as GoogleIcon,ue as MetaMaskIcon,ce as OTPInput,de as PhantomIcon,fn as ProfileSettings,gn as SolanaIcon,yn as TelegramIcon,$e as TwitterIcon,Xt as UserUtilsProvider,wt as cn,bn as createAuthClient,xn as createNativeTransport,Ce as createStackNetClient,wn as createWebTransport,St as decodeJwtPayloadClient,xt as formatTokens,W as readCSRFCookie,ee as readSessionCookie,X as safeUrl,xe as useAuthBridge,Ht as useBillingHistory,ke as useCSRFToken,Jt as useGoogleOneTap,Dt as usePlans,Ft as usePrepaidCheckout,Ue as useProfile,te as useSession,ve as useStackAuth,oe as useStackConfig,Rt as useSubscription,Wt as useUsage,qt as useUserUtilsContext,be as useWeb3Wallet,Ct as validateRedirectUrl};
1
+ import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useState,useCallback,useEffect,useRef,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function xt(...e){return twMerge(clsx(e))}function Ct(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function vt(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let s=new URL(e,t);return s.origin!==t?"/":s.pathname+s.search+s.hash}catch{return "/"}}function ee(e,t="#"){if(!e||typeof e!="string")return t;let s=e.trim();if(s===""||s==="#")return t;if(s.startsWith("/")||s.startsWith("./")||s.startsWith("../"))return s;try{let d=new URL(s);if(d.protocol==="http:"||d.protocol==="https:")return d.toString()}catch{}return t}function Nt(e){try{let t=e.split(".");if(t.length!==3)return null;let s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}function te(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function $(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function ne(){let[e,t]=useState(null),[s,d]=useState(true),u=useCallback(()=>{let i=te();i&&i.expiresAt>Date.now()?t({userId:i.userId,address:i.address,chain:i.chain,expiresAt:i.expiresAt,planId:i.planId,authMethod:i.authMethod}):t(null),d(false);},[]);useEffect(()=>{u();},[u]);let h=useCallback(async(i="")=>{try{let l=await fetch(`${i}/api/auth/session`);if(l.ok){let c=await l.json();if(c.session)return t(c.session),c.session}return t(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:g,refresh:h,readSession:u}}function we(e="__csrf",t="x-csrf-token"){let[s,d]=useState(null);useEffect(()=>{d($(e));},[e]);let u=s?{[t]:s}:{};return {token:s,headers:u}}function Se(){let[e,t]=useState({connected:false,address:null,chain:null,provider:null}),[s,d]=useState(null),u=useCallback(async(l="phantom")=>{d(null);try{let c=typeof window<"u"?window:null,m=l==="phantom"?c?.phantom?.solana||c?.solana:c?.solflare;if(!m)return d(`${l} wallet not found`),null;let a=(await m.connect()).publicKey.toString();return t({connected:!0,address:a,chain:"solana",provider:l}),a}catch(c){return d(c.message||"Failed to connect wallet"),null}},[]),h=useCallback(async()=>{d(null);try{let c=(typeof window<"u"?window:null)?.ethereum;if(!c)return d("MetaMask not found"),null;let m=c;c.providers?.length&&(m=c.providers.find(n=>n.isMetaMask)||c);let a=(await m.request({method:"eth_requestAccounts"}))[0];return a?(t({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(d("No account selected"),null)}catch(l){return d(l.message||"Failed to connect wallet"),null}},[]),g=useCallback(async(l,c)=>{d(null);let m=c?.chain||e.chain,o=c?.provider||e.provider,a=c?.address||e.address;try{if(m==="solana"){let n=typeof window<"u"?window:null,p=o==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!p)throw new Error("Wallet not available");let r=new TextEncoder().encode(l),y=await p.signMessage(r,"utf8"),S=new Uint8Array(y.signature||y),w="";for(let T=0;T<S.byteLength;T++)w+=String.fromCharCode(S[T]);return btoa(w)}if(m==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(y=>y.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[l,a]})}throw new Error("No wallet connected")}catch(n){return d(n.message||"Signing failed"),null}},[e]),i=useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),d(null);},[]);return {wallet:e,error:s,connectSolana:u,connectEVM:h,signMessage:g,disconnect:i}}var Lt="https://stacknet.magma-rpc.com/auth/bridge",de="stacknet-auth-bridge";function Ce(e){let t=e?.bridgeUrl||Lt,s=e?.disabled||false,d=useRef(null),[u,h]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),g=useRef([]),i=useRef(false),l=useCallback(n=>{let p={...n,protocol:de};i.current&&d.current?.contentWindow?d.current.contentWindow.postMessage(p,new URL(t).origin):g.current.push(p);},[t]);useEffect(()=>{if(s)return;let n=r=>{if(!(!r.data||r.data.protocol!==de)){try{if(r.origin!==new URL(t).origin)return}catch{return}switch(r.data.type){case "bridge:ready":i.current=true,h(y=>({...y,ready:true}));for(let y of g.current)d.current?.contentWindow?.postMessage(y,r.origin);g.current=[],d.current?.contentWindow?.postMessage({protocol:de,type:"auth:check"},r.origin),d.current?.contentWindow?.postMessage({protocol:de,type:"auth:resolve-stack"},r.origin);break;case "auth:status":h(y=>({...y,known:r.data.known,identity:r.data.identity,identityCount:r.data.identityCount||0}));break;case "auth:resolved-stack":h(y=>({...y,resolvedStackId:r.data.stackId||null}));break;}}};window.addEventListener("message",n);let p=document.createElement("iframe");return p.src=t,p.style.display="none",p.setAttribute("aria-hidden","true"),p.setAttribute("tabindex","-1"),p.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(p),d.current=p,()=>{window.removeEventListener("message",n),p.parentNode&&p.parentNode.removeChild(p),d.current=null,i.current=false;}},[t,s]);let c=useCallback(n=>{l({type:"auth:connected",...n});},[l]),m=useCallback(n=>{l({type:"auth:disconnected",...n});},[l]),o=useCallback(()=>{l({type:"auth:clear"}),h({ready:u.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[l,u.ready]),a=useCallback(()=>{l({type:"auth:check"});},[l]);return {...u,reportConnected:c,reportDisconnected:m,clearAll:o,refresh:a}}async function tt(e,t,s,d){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${s}`;try{let g=await fetch(h,{method:t,headers:{"Content-Type":"application/json"},body:d?JSON.stringify(d):void 0}),i=await g.json();return g.ok?i.success&&i.data!==void 0?{success:!0,data:i.data}:{success:!0,data:i}:{success:!1,error:i.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(g){return {success:false,error:{code:"NETWORK_ERROR",message:g instanceof Error?g.message:"Network error"}}}}function ve(e){return {getNetworkStatus:()=>tt(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>tt(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:s})}}function Pe(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:d,signMessage:u,disconnect:h}=Se(),{session:g,isAuthenticated:i,refresh:l,readSession:c}=ne(),{headers:m}=we(),o=Ce({disabled:typeof window>"u"}),[a,n]=useState(false),[p,r]=useState(null),[y,S]=useState(false),w=e.apiBaseUrl||"",T=e.stacknetUrl||"https://stacknet.magma-rpc.com",C=e.stackId||o.resolvedStackId||"",x=ve({baseUrl:T,stackId:C}),z=useCallback(async(N,P,E,R)=>{n(true),r(null);try{let I=P;if(!I){let Z=await E();if(!Z)return n(!1),!1;I=Z;}let U=await x.getWeb3Challenge(N,I);if(!U.success||!U.data)return r("Failed to get challenge"),n(!1),!1;let _=await u(U.data.message,{chain:N,provider:R,address:I});if(!_)return n(!1),!1;let G={chain:N,message:U.data.message,signature:_,stackId:C};N==="solana"&&(G.publicKey=I);let V=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(G)});if(!V.ok){let Z=await V.json().catch(()=>({}));return r(Z.error||"Authentication failed"),n(!1),!1}return o.reportConnected({address:I,chain:N,method:R||(N==="solana"?"phantom":"metamask"),stackId:C}),c(),n(!1),!0}catch(I){return r(I.message||"Authentication failed"),n(false),false}},[w,x,u,c,o,C]),W=useCallback(async(N="phantom")=>{let P=await s(N);return P?z("solana",P,()=>s(N),N):false},[s,z]),j=useCallback(async()=>{let N=await d();return N?z("ethereum",N,d,"metamask"):false},[d,z]),b=useCallback(async N=>{n(true),r(null);try{let P=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:N})});if(!P.ok){let E=await P.json().catch(()=>({}));return r(E.error||"Invalid code"),n(!1),!1}return c(),n(!1),!0}catch(P){return r(P.message||"OTP verification failed"),n(false),false}},[w,c]),L=useCallback(async(N,P)=>{n(true),r(null);try{let E=P||`${window.location.origin}/api/auth/oauth/callback`,R=new URLSearchParams({provider:N,redirectUri:E,stackId:C}),I=await fetch(`${w}/api/auth/oauth/start?${R}`,{credentials:"include"});if(!I.ok){let _=await I.json().catch(()=>({}));return r(_.error||"Failed to start OAuth flow"),n(!1),!1}let U=await I.json();if(U.redirect_url){let _;try{_=new URL(U.redirect_url);}catch{return r("Invalid OAuth redirect URL"),n(!1),!1}let G=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return _.protocol!=="https:"||!G.some(V=>V.test(_.hostname))?(r(`Refusing to redirect to non-OAuth host: ${_.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",U.state||""),sessionStorage.setItem("oauth_provider",N)),window.location.href=_.toString(),!0)}return r("No redirect URL returned"),n(!1),!1}catch(E){return r(E.message||"OAuth flow failed"),n(false),false}},[w,C]),A=useCallback(async(N,P,E)=>{n(true),r(null);try{if(typeof sessionStorage<"u"){let I=sessionStorage.getItem("oauth_state"),U=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!I||I!==E)return r("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(U&&U!==N)return r("OAuth provider mismatch \u2014 refusing to complete login"),n(!1),!1}let R=await fetch(`${w}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:N,code:P,state:E,stackId:C})});if(!R.ok){let I=await R.json().catch(()=>({}));return r(I.error||"OAuth authentication failed"),n(!1),!1}return c(),n(!1),!0}catch(R){return r(R.message||"OAuth callback failed"),n(false),false}},[w,C,c]),D=useCallback(async()=>{t.address&&t.chain&&o.reportDisconnected({address:t.address,chain:t.chain,stackId:C});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:m,credentials:"include"});}catch{}h(),c();},[w,m,h,c,t,o,C]);return useEffect(()=>{if(!e.autoConnect||y||i||!o.ready||!o.known||!o.identity)return;S(true);let{chain:N,method:P}=o.identity;N==="solana"&&(P==="phantom"||P==="solflare")?W(P):N==="ethereum"&&j();},[e.autoConnect,y,i,o,W,j]),{session:g,isAuthenticated:i,wallet:t,loading:a,error:p,authenticateSolana:W,authenticateEVM:j,authenticateOTP:b,authenticateOAuth:L,authenticateOAuthCallback:A,logout:D,refresh:()=>l(w),stackId:C,bridge:{ready:o.ready,known:o.known,identity:o.identity,identityCount:o.identityCount,resolvedStackId:o.resolvedStackId}}}function re(e,t="https://stacknet.magma-rpc.com"){let[s,d]=useState(null),[u,h]=useState(false),[g,i]=useState(null),l=useCallback(async m=>{h(true),i(null);try{let o=await fetch(`${t}/api/v2/stacks/${m}`);if(!o.ok)return i("Stack not found"),h(!1),null;let a=await o.json(),n=a.data?.stack||a.stack||a,p={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(r=>({provider:r.provider,clientId:r.clientId,enabled:r.enabled!==!1}))};return d(p),h(!1),p}catch(o){return i(o.message),h(false),null}},[t]);useEffect(()=>{e&&l(e);},[e,l]);let c=s?Dt(s):[];return {config:s,loading:u,error:g,identityProviders:c,fetchConfig:l}}function Dt(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let s of e.oauthProviders)s.enabled&&t.push({type:"oauth",id:s.provider,name:s.provider});return t}function Rt(e=""){let[t,s]=useState([]),[d,u]=useState(true),[h,g]=useState(null),i=useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/plans`);if(l.ok){let c=await l.json();s(c.plans||c||[]);}}catch(l){g(l.message);}finally{u(false);}},[e]);return useEffect(()=>{i();},[i]),{plans:t,loading:d,error:h,refresh:i}}function Wt(e=""){let[t,s]=useState(null),[d,u]=useState(true),[h,g]=useState(null),i=useCallback(async()=>{try{let m=await fetch(`${e}/api/billing/subscription`);if(m.ok){let o=await m.json();s(o.plan?o:null);}}catch(m){g(m.message);}finally{u(false);}},[e]);useEffect(()=>{i();},[i]);let l=useCallback(async m=>{let o=$(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({planId:m})})).json();return n.url||n.checkoutUrl||null},[e]),c=useCallback(async()=>{let m=$();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:m?{"x-csrf-token":m}:{}})).ok?(await i(),true):false},[e,i]);return {subscription:t,loading:d,error:h,refresh:i,subscribe:l,cancel:c}}function Bt(e=""){let[t,s]=useState(null),[d,u]=useState(true),[h,g]=useState(null),i=useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/usage`);if(l.ok){let c=await l.json();s(c);}}catch(l){g(l.message);}finally{u(false);}},[e]);return useEffect(()=>{i();},[i]),{usage:t,loading:d,error:h,refresh:i}}function Gt(e=""){let[t,s]=useState(false),[d,u]=useState(null),h=useCallback(async i=>{s(true),u(null);try{let l=$(),c=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({amountCents:i})}),m=await c.json();return c.ok?m.url||null:(u(m.error||"Purchase failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]),g=useCallback(async i=>{s(true),u(null);try{let l=$(),c=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({sessionId:i})}),m=await c.json();return c.ok?m:(u(m.error||"Verification failed"),null)}catch(l){return u(l.message),null}finally{s(false);}},[e]);return {purchase:h,verifySession:g,loading:t,error:d}}function Vt(e="",t){let[s,d]=useState([]),[u,h]=useState(true),[g,i]=useState(null),l=t?.limit||50,c=t?.offset||0,m=useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/history?limit=${l}&offset=${c}`);if(o.ok){let a=await o.json();d(a.records||a.history||(Array.isArray(a)?a:[]));}}catch(o){i(o.message);}finally{h(false);}},[e,l,c]);return useEffect(()=>{m();},[m]),{records:s,loading:u,error:g,refresh:m}}function Jt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function je(e,t){let[s,d]=useState(null),[u,h]=useState(true),[g,i]=useState(false),[l,c]=useState(null),m=t?.apiBaseUrl??"",o=t?.scope===void 0||t?.scope==="global"?"global":`stack:${t.scope.stackId}`,a=useCallback(r=>{let y=encodeURIComponent(r);if(o==="global")return `${m}/api/user/profile/${y}`;let S=o.slice(6);return `${m}/api/v2/stacks/${encodeURIComponent(S)}/members/${y}/profile`},[m,o]),n=useCallback(async()=>{if(!e){d(null),h(false);return}h(true),c(null);try{let r=await fetch(a(e));if(r.ok){let y=await r.json(),S=y.profile||y.data?.profile||y;d({mid:S.mid||e,username:S.username||"",avatarUrl:S.avatar_url||S.avatarUrl,bio:S.bio,paymentAddress:S.payment_address||S.paymentAddress,createdAt:S.created_at||S.createdAt,updatedAt:S.updated_at||S.updatedAt});}else if(r.status===404)d({mid:e,username:""});else throw new Error(`${r.status}`)}catch(r){c(r instanceof Error?r.message:"Failed to load profile");}finally{h(false);}},[e,a]);useEffect(()=>{n();},[n]);let p=useCallback(async r=>{if(!e)return false;i(true),c(null);try{let y=Jt(),S={};r.username!==void 0&&(S.username=r.username),r.avatarUrl!==void 0&&(S.avatar_url=r.avatarUrl),r.bio!==void 0&&(S.bio=r.bio),r.paymentAddress!==void 0&&(S.payment_address=r.paymentAddress);let w=await fetch(a(e),{method:"PUT",headers:{"Content-Type":"application/json",...y?{"x-csrf-token":y}:{}},credentials:"same-origin",body:JSON.stringify(S)});if(!w.ok){let x=await w.json().catch(()=>({}));throw new Error(x.error||x.message||`Update failed: ${w.status}`)}let T=await w.json(),C=T.profile||T.data?.profile||T;return d(x=>({mid:x?.mid||e,username:r.username??x?.username??"",avatarUrl:r.avatarUrl??x?.avatarUrl,bio:r.bio??x?.bio,paymentAddress:r.paymentAddress??C.payment_address??C.paymentAddress??x?.paymentAddress,createdAt:x?.createdAt,updatedAt:C.updated_at||C.updatedAt||Date.now()})),!0}catch(y){return c(y instanceof Error?y.message:"Update failed"),false}finally{i(false);}},[e,a]);return {profile:s,loading:u,saving:g,error:l,updateProfile:p,refresh:n}}var st="google-identity-services",Zt="https://accounts.google.com/gsi/client";function Kt({stackId:e,stacknetUrl:t="https://stacknet.magma-rpc.com",apiBaseUrl:s="",autoPrompt:d=true,cancelOnTapOutside:u=true,onSuccess:h,onError:g,disabled:i=false}){let{config:l}=re(e,t),{isAuthenticated:c,loading:m,readSession:o}=ne(),[a,n]=useState(false),[p,r]=useState(null),[y,S]=useState(false),w=useRef(false),T=useRef(false),x=l?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;useEffect(()=>{if(i||!x||typeof window>"u")return;if(document.getElementById(st)){S(true);return}let b=document.createElement("script");b.id=st,b.src=Zt,b.async=true,b.defer=true,b.onload=()=>S(true),b.onerror=()=>{r("Failed to load Google sign-in"),g?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[i,x,g]);let z=useCallback(async b=>{n(true),r(null);try{let L=await fetch(`${s}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!L.ok){let D=(await L.json().catch(()=>({}))).error||"Google sign-in failed";r(D),g?.(D),n(!1);return}o(),n(!1),h?.();}catch(L){let A=L.message||"Google sign-in failed";r(A),g?.(A),n(false);}},[s,e,o,h,g]);useEffect(()=>{if(i){console.debug("[GoogleOneTap] Disabled");return}if(!y){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",x);return}if(!x){console.debug("[GoogleOneTap] No Google clientId from stack config");return}if(m){console.debug("[GoogleOneTap] Session still loading");return}if(c){console.debug("[GoogleOneTap] User already authenticated, skipping");return}if(!window.google?.accounts?.id){console.debug("[GoogleOneTap] GIS library not available on window");return}w.current||(console.debug("[GoogleOneTap] Initializing with clientId:",x),w.current=true,window.google.accounts.id.initialize({client_id:x,callback:z,auto_select:true,cancel_on_tap_outside:u}),d&&!T.current&&(T.current=true,console.debug("[GoogleOneTap] Showing prompt..."),window.google.accounts.id.prompt(b=>{b.isDisplayed?.()&&console.debug("[GoogleOneTap] Prompt displayed"),b.isNotDisplayed?.()&&console.debug("[GoogleOneTap] Not displayed:",b.getNotDisplayedReason?.()),b.isSkippedMoment?.()&&console.debug("[GoogleOneTap] Skipped:",b.getSkippedReason?.()),b.isDismissedMoment?.()&&console.debug("[GoogleOneTap] Dismissed:",b.getDismissedReason?.());})));},[i,y,x,m,c,z,d,u]),useEffect(()=>()=>{window.google?.accounts?.id&&w.current&&window.google.accounts.id.cancel();},[]);let W=useCallback(()=>{!window.google?.accounts?.id||!w.current||window.google.accounts.id.prompt();},[]),j=useCallback((b,L)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:L?.theme||"filled_black",size:L?.size||"large",text:L?.text||"signin_with",width:L?.width});},[]);return {available:!!x,ready:y&&!!x,loading:a,error:p,prompt:W,renderButton:j,clientId:x}}var at=createContext(null);function en(){let e=useContext(at);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function tn({config:e,callbacks:t,children:s}){return jsx(at.Provider,{value:{config:e,callbacks:t},children:s})}function pe({length:e=6,onComplete:t,disabled:s=false,error:d,className:u="",inputClassName:h=""}){let [g,i]=useState(Array(e).fill("")),l=useCallback((o,a)=>{if(a.length>1){let p=a.replace(/\D/g,"").slice(0,e).split(""),r=[...g];p.forEach((S,w)=>{o+w<e&&(r[o+w]=S);}),i(r);let y=Math.min(o+p.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),r.every(S=>S!=="")&&setTimeout(()=>t(r.join("")),100);return}if(!/^\d?$/.test(a))return;let n=[...g];n[o]=a,i(n),a&&o<e-1&&document.getElementById(`userutils-otp-${o+1}`)?.focus(),a&&o===e-1&&n.every(p=>p!=="")&&setTimeout(()=>t(n.join("")),100);},[g,e,t]),c=useCallback((o,a)=>{if(a.key==="Backspace"&&!g[o]&&o>0){document.getElementById(`userutils-otp-${o-1}`)?.focus();let n=[...g];n[o-1]="",i(n);}if(a.key==="Enter"){let n=g.join("");n.length===e&&t(n);}},[g,e,t]);useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:u,children:[jsx("div",{className:"flex gap-2 justify-center",children:g.map((o,a)=>jsx("input",{id:`userutils-otp-${a}`,type:"text",inputMode:"numeric",maxLength:e,value:o,onChange:n=>l(a,n.target.value),onKeyDown:n=>c(a,n),disabled:s,autoFocus:a===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${h}`},a))}),d&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:d})]})}pe.displayName="OTPInput";var sn="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function fe({className:e,style:t}){return jsx("img",{src:sn,alt:"Phantom",className:e,style:t})}function ge({className:e,style:t}){return jsxs("svg",{className:e,style:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function We({className:e,style:t}){return jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function $e({className:e,style:t}){return jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Fe({className:e,style:t}){return jsxs("svg",{className:e,style:t,viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function pn({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:d,showOTP:u,hideHeader:h,onOTPSubmit:g,otpLabel:i="Access Code",oauthInline:l,oauthFirst:c,className:m=""}){let o=Pe(e),{isAuthenticated:a,wallet:n,loading:p,error:r,authenticateSolana:y,authenticateEVM:S,authenticateOTP:w,authenticateOAuth:T,bridge:C,stackId:x}=o,z=!e.stackId&&!x,W=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:b,loading:L}=re(x||e.stackId||null,W),[A,D]=useState(z?"stack-select":"select"),[N,P]=useState(null),[E,R]=useState(false),[I,U]=useState("idle"),[_,G]=useState(""),[V,Z]=useState([]),[ft,Qe]=useState(e.stackId||null),[le,gt]=useState(false),[mt,ht]=useState(false);useEffect(()=>{if(typeof window>"u")return;let f=()=>{let Y=window;gt(!!(Y.phantom?.solana?.isPhantom||Y.solana?.isPhantom));let q=Y.ethereum;ht(!!(q?.isMetaMask||q?.providers?.some(X=>X.isMetaMask)));};f(),window.addEventListener("ethereum#initialized",f);let H=setTimeout(f,500);return ()=>{window.removeEventListener("ethereum#initialized",f),clearTimeout(H);}},[]),useEffect(()=>{A==="stack-select"&&x&&(Qe(x),D("select"));},[A,x]),useEffect(()=>{if(!(!C.ready||!z)&&C.identity){let f=[];C.resolvedStackId&&f.push({stackId:C.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(f.map(async H=>{try{let Y=await fetch(`${W}/api/v2/stacks/${H.stackId}`);if(Y.ok){let q=await Y.json(),X=q.data?.stack||q;H.name=X.displayName||X.name,H.logoUrl=X.logoUrl;}}catch{}return H})).then(Z);}},[C.ready,C.identity,C.resolvedStackId,z,W]),useEffect(()=>{a&&A==="success"&&t?.();},[a,A,t]);let Ve=d||(b.length>0?b.filter(f=>f.type==="wallet").map(f=>f.id):["phantom","metamask"]),Ye=u!==void 0?u:b.length>0?b.some(f=>f.type==="otp"):true,K=b.filter(f=>f.type==="oauth"),ke=new Set(c||[]),Je=K.filter(f=>ke.has(f.id)),be=l?K.filter(f=>!ke.has(f.id)):K,Ze=async f=>{P(f),D("connecting"),await T(f)||D("error");},yt=async()=>{P("phantom"),D("connecting");let f=await y("phantom");D(f?"success":"error");},kt=async()=>{P("metamask"),D("connecting");let f=await S();D(f?"success":"error");},bt=async f=>{U("verifying"),G(""),await(g||w)(f)?(U("success"),D("success")):(U("error"),G("Invalid or expired code"),setTimeout(()=>U("idle"),2e3));},Ke=()=>{D(z&&!ft?"stack-select":"select"),P(null),R(false),U("idle"),G("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${m}`,children:[!h&&jsxs("div",{className:"mb-6 text-center",children:[j?.logoUrl&&A!=="stack-select"&&jsx("img",{src:ee(j.logoUrl),alt:j.displayName||"",className:"h-16 w-16 mx-auto mb-4 rounded-xl"}),j?.displayName&&jsx("p",{className:"text-sm text-zinc-400 mb-2",children:j.displayName}),jsx("h1",{className:"font-semibold text-2xl text-white",children:"Log in or Sign up"})]}),A==="stack-select"&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:V.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),V.map(f=>jsxs("button",{onClick:()=>{Qe(f.stackId),D("select");},className:"flex w-full cursor-pointer items-center gap-4 rounded-xl border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[f.logoUrl?jsx("img",{src:ee(f.logoUrl),alt:"",className:"h-10 w-10 flex-shrink-0"}):jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:f.name?.[0]?.toUpperCase()||"S"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-white",children:f.name||f.stackId}),jsx("p",{className:"text-xs text-zinc-500",children:f.domain})]}),jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},f.stackId)),C.ready&&!C.known&&jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),A==="select"&&L&&jsx("div",{className:"flex items-center justify-center py-8",children:jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),r&&A==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:r}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Ke,children:"Try Again"})]}),A==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),A==="connecting"&&p&&jsxs("div",{style:{border:"1px solid #27272a",background:"#25252f",padding:24,textAlign:"center"},children:[jsxs("div",{style:{width:40,height:40,margin:"0 auto 12px"},children:[N==="phantom"&&jsx(fe,{style:B}),N==="metamask"&&jsx(ge,{style:B})]}),jsx("p",{style:{fontWeight:500,fontSize:14,color:"#fff"},children:n.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{style:{marginTop:4,fontSize:12,color:"#71717a"},children:"Please confirm in your wallet"}),jsx("button",{style:{marginTop:16,fontSize:14,color:"#71717a",background:"none",border:"none",cursor:"pointer"},onClick:Ke,children:"Cancel"})]}),A==="select"&&!p&&!L&&jsxs(Fragment,{children:[Je.map(f=>jsxs("button",{onClick:()=>Ze(f.id),style:ae,children:[jsx(ct,{provider:f.id}),jsx("span",{style:{fontWeight:500,color:"#fff"},children:dt(f.id,f.name)})]},f.id)),Ve.includes("phantom")&&jsxs("button",{onClick:yt,disabled:!le,style:{...ae,opacity:le?1:.5,cursor:le?"pointer":"not-allowed"},children:[jsx(fe,{style:{...B,borderRadius:8}}),jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"Phantom"}),!le&&jsx("span",{style:{fontSize:12,color:"#71717a"},children:"Not installed"})]}),Ve.includes("metamask")&&mt&&jsxs("button",{onClick:kt,style:ae,children:[jsx(ge,{style:B}),jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"MetaMask"})]}),Ye&&!E&&jsxs("button",{onClick:()=>R(true),style:ae,children:[jsx("div",{style:{...B,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e"},children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",viewBox:"0 -960 960 960",width:"20px",fill:"#a1a1aa",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:i})]}),Ye&&E&&jsxs("div",{style:{borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:24},children:[jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginBottom:16},children:"Enter your 6-digit access code"}),jsx(pe,{onComplete:bt,disabled:I==="verifying",error:_}),I==="verifying"&&jsx("p",{style:{textAlign:"center",fontSize:14,color:"#a1a1aa",marginTop:16},children:"Verifying..."}),I==="success"&&jsx("p",{style:{textAlign:"center",fontSize:14,color:"#4ade80",marginTop:16},children:"Verified!"}),j?.webPageUrl&&I==="idle"&&(()=>{let f=ee(j.webPageUrl);return f==="#"?null:jsx("a",{href:`${f.replace(/\/$/,"")}/connect/pair`,target:"_blank",rel:"noopener noreferrer",style:{display:"block",textAlign:"center",fontSize:14,color:"#71717a",marginTop:16},children:"Get code"})})()]}),(l?be:K).length>0&&(!l||be.length>0)&&jsxs(Fragment,{children:[!l&&Je.length===0&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 0"},children:[jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}}),jsx("span",{style:{fontSize:12,color:"#52525b"},children:"or continue with"}),jsx("div",{style:{flex:1,borderTop:"1px solid #27272a"}})]}),(l?be:K.filter(f=>!ke.has(f.id))).map(f=>jsxs("button",{onClick:()=>Ze(f.id),style:ae,children:[jsx(ct,{provider:f.id}),jsx("span",{style:{fontWeight:500,color:"#fff"},children:dt(f.id,f.name)})]},f.id))]})]})]})}var B={width:40,height:40,flexShrink:0},ae={display:"flex",width:"100%",alignItems:"center",gap:12,borderRadius:12,border:"1px solid #27272a",background:"#25252f",padding:16,cursor:"pointer",transition:"background 0.15s"};function ct({provider:e}){switch(e){case "google":return jsx(We,{style:{...B,borderRadius:8}});case "discord":return jsx($e,{style:{...B,borderRadius:8}});case "twitter":return jsx(Fe,{style:{...B,borderRadius:8}});default:return jsx("div",{style:{...B,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid #3f3f46",background:"#2a2a3e",fontSize:14,color:"#a1a1aa",fontFamily:"monospace"},children:e[0]?.toUpperCase()})}}function dt(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter"}[e]||t||e}function mn({mid:e,apiBaseUrl:t="",scope:s,onSave:d,className:u}){let{profile:h,loading:g,saving:i,error:l,updateProfile:c}=je(e,{apiBaseUrl:t,scope:s}),[m,o]=useState(null),[a,n]=useState(null),[p,r]=useState(null),y=useRef(null),[S,w]=useState(false),T=m??h?.username??"",C=a??h?.bio??"",x=p??h?.avatarUrl,z=useCallback(b=>{let L=b.target.files?.[0];if(!L)return;let A=new FileReader;A.onload=()=>{r(A.result),w(true);},A.readAsDataURL(L);},[]),W=async()=>{await c({username:T||void 0,avatarUrl:p??h?.avatarUrl,bio:C||void 0})&&(w(false),d?.());};if(g)return jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let j=s==="global"||!s?"Global profile":`Stack profile (${s.stackId})`;return jsxs("div",{className:u,style:{display:"grid",gap:"1.5rem"},children:[jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:j}),jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsx("button",{type:"button",onClick:()=>y.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:x?jsx("img",{src:x,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsx("input",{type:"text",value:T,onChange:b=>{o(b.target.value),w(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsx("input",{ref:y,type:"file",accept:"image/*",onChange:z,style:{display:"none"}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsx("input",{type:"text",value:C,onChange:b=>{n(b.target.value),w(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),l&&jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:l}),S&&jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsx("button",{onClick:W,disabled:i,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:i?"wait":"pointer",opacity:i?.6:1},children:i?"Saving...":"Save"}),jsx("button",{onClick:()=>{o(null),n(null),r(null),w(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 10M tokens"})]})]})}function hn({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function yn({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function bn({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}function Sn(e){let{apiBaseUrl:t,stacknetUrl:s="https://stacknet.magma-rpc.com",stackId:d="",transport:u,serviceKey:h,onAuthSuccess:g,onAuthError:i,onLogout:l}=e;async function c(o){if(!o.ok){let r=await o.json().catch(()=>({})),y=new Error(r.error||`Authentication failed (${o.status})`);throw i?.(y),y}let a=await o.json(),n=a.token||a.jwt,p=a.session||{userId:a.user?.id||a.userId||a.sub||"",address:a.user?.address||a.address,chain:a.user?.chain||a.chain,expiresAt:a.expiresAt||Date.now()+10080*60*1e3,authMethod:a.authMethod||a.method};return n&&await u.storeCredentials(n,p),g?.(p),p}return {async login(o,a){let n=await fetch(`${t}/api/auth/callback/credentials`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o,password:a})});return c(n)},async loginWeb3({chain:o,address:a,message:n,signature:p}){let r={chain:o,message:n,signature:p,stackId:d};o==="solana"&&(r.publicKey=a);let y=await fetch(`${t}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});return c(y)},async loginOTP(o){let a=await fetch(`${t}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});return c(a)},async getSession(){let o=await u.getStoredSession();if(o&&o.expiresAt>Date.now())return o;try{let a=await u.getHeaders(),n=await fetch(`${t}/api/auth/session`,{headers:a});if(n.ok){let p=await n.json();if(p.session)return p.session}}catch{if(o)return o}return null},async checkSession(){let o=await u.getToken();if(!o)return false;try{let a=await fetch(`${t}/api/history?limit=1`,{headers:{Authorization:`Bearer ${o}`}});return a.ok?!0:a.status===401?(await u.clear(),!1):!0}catch{return true}},async getChallenge(o,a){let p=`${s}/api/v2/stacks/${encodeURIComponent(d)}/auth/web3/challenge`,r=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:o,address:a})});if(!r.ok)throw new Error("Failed to get challenge");let y=await r.json();return y.data||y},async logout(){try{let o=await u.getHeaders();await fetch(`${t}/api/auth/logout`,{method:"POST",headers:o});}catch{}await u.clear(),l?.();},async getHeaders(){let o=await u.getHeaders();return Object.keys(o).length>0?o:h?{Authorization:`Bearer ${h}`}:{}},async getToken(){return u.getToken()}}}function xn(){return {async storeCredentials(e,t){},async getToken(){return null},async getHeaders(){return {}},async getStoredSession(){let e=te();return !e||e.expiresAt<=Date.now()?null:{userId:e.userId,address:e.address,chain:e.chain,expiresAt:e.expiresAt,planId:e.planId,authMethod:e.authMethod}},async clear(){}}}var Ge="stackauth_token",He="stackauth_session";function Cn(e){return {async storeCredentials(t,s){await e.setItemAsync(Ge,t),await e.setItemAsync(He,JSON.stringify(s));},async getToken(){try{return await e.getItemAsync(Ge)}catch{return null}},async getHeaders(){let t=await this.getToken();return t?{Authorization:`Bearer ${t}`}:{}},async getStoredSession(){try{let t=await e.getItemAsync(He);return t?JSON.parse(t):null}catch{return null}},async clear(){await e.deleteItemAsync(Ge).catch(()=>{}),await e.deleteItemAsync(He).catch(()=>{});}}}
2
+ export{pn as ConnectWidget,$e as DiscordIcon,yn as EthereumIcon,We as GoogleIcon,ge as MetaMaskIcon,pe as OTPInput,fe as PhantomIcon,mn as ProfileSettings,hn as SolanaIcon,bn as TelegramIcon,Fe as TwitterIcon,tn as UserUtilsProvider,xt as cn,Sn as createAuthClient,Cn as createNativeTransport,ve as createStackNetClient,xn as createWebTransport,Nt as decodeJwtPayloadClient,Ct as formatTokens,$ as readCSRFCookie,te as readSessionCookie,ee as safeUrl,Ce as useAuthBridge,Vt as useBillingHistory,we as useCSRFToken,Kt as useGoogleOneTap,Rt as usePlans,Gt as usePrepaidCheckout,je as useProfile,ne as useSession,Pe as useStackAuth,re as useStackConfig,Wt as useSubscription,Bt as useUsage,en as useUserUtilsContext,Se as useWeb3Wallet,vt as validateRedirectUrl};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacknet/userutils",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Reusable auth, billing, and security utilities for StackNet stacks and applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",