@stacknet/userutils 0.5.4 → 0.6.0
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.
- package/dist/adapters/index.d.cts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/{auth-DR2aYcor.d.cts → auth-c1d7Eji2.d.cts} +6 -0
- package/dist/{auth-DR2aYcor.d.ts → auth-c1d7Eji2.d.ts} +6 -0
- package/dist/components/index.cjs +2 -2
- package/dist/components/index.d.cts +8 -3
- package/dist/components/index.d.ts +8 -3
- package/dist/components/index.js +2 -2
- package/dist/config-CLzVWDrU.d.cts +177 -0
- package/dist/config-xNca5ufB.d.ts +177 -0
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.d.cts +52 -3
- package/dist/hooks/index.d.ts +52 -3
- package/dist/hooks/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -2
- package/dist/server/index.cjs +2 -2
- package/dist/server/index.d.cts +116 -21
- package/dist/server/index.d.ts +116 -21
- package/dist/server/index.js +2 -2
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/{types-CAoB_5kk.d.cts → types-B_Vj6cr4.d.cts} +1 -1
- package/dist/{types-Dghy_8Wh.d.ts → types-Cu0do-w-.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/config-Bjh8PEhY.d.cts +0 -123
- package/dist/config-_ZjAzNkJ.d.ts +0 -123
package/dist/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {useState,useCallback,useEffect,useRef}from'react';function le(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith("stackauth_session="));if(!e)return null;let r=e.slice(18);return JSON.parse(atob(r.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function U(e="__csrf"){if(typeof document>"u")return null;let r=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${e}=`));return r?r.slice(e.length+1):null}function M(){let[e,r]=useState(null),[i,l]=useState(true),d=useCallback(()=>{let s=le();s&&s.expiresAt>Date.now()?r({userId:s.userId,address:s.address,chain:s.chain,expiresAt:s.expiresAt,planId:s.planId,authMethod:s.authMethod}):r(null),l(false);},[]);useEffect(()=>{d();},[d]);let f=useCallback(async(s="")=>{try{let a=await fetch(`${s}/api/auth/session`);if(a.ok){let o=await a.json();if(o.session)return r(o.session),o.session}return r(null),null}catch{return null}},[]),p=!!e&&e.expiresAt>Date.now();return {session:e,loading:i,isAuthenticated:p,refresh:f,readSession:d}}function K(e="__csrf",r="x-csrf-token"){let[i,l]=useState(null);useEffect(()=>{l(U(e));},[e]);let d=i?{[r]:i}:{};return {token:i,headers:d}}function V(){let[e,r]=useState({connected:false,address:null,chain:null,provider:null}),[i,l]=useState(null),d=useCallback(async(a="phantom")=>{l(null);try{let o=typeof window<"u"?window:null,u=a==="phantom"?o?.phantom?.solana||o?.solana:o?.solflare;if(!u)return l(`${a} wallet not found`),null;let h=(await u.connect()).publicKey.toString();return r({connected:!0,address:h,chain:"solana",provider:a}),h}catch(o){return l(o.message||"Failed to connect wallet"),null}},[]),f=useCallback(async()=>{l(null);try{let o=(typeof window<"u"?window:null)?.ethereum;if(!o)return l("MetaMask not found"),null;let u=o;o.providers?.length&&(u=o.providers.find(t=>t.isMetaMask)||o);let h=(await u.request({method:"eth_requestAccounts"}))[0];return h?(r({connected:!0,address:h,chain:"ethereum",provider:"metamask"}),h):(l("No account selected"),null)}catch(a){return l(a.message||"Failed to connect wallet"),null}},[]),p=useCallback(async(a,o)=>{l(null);let u=o?.chain||e.chain,c=o?.provider||e.provider,h=o?.address||e.address;try{if(u==="solana"){let t=typeof window<"u"?window:null,g=c==="solflare"?t?.solflare:t?.phantom?.solana||t?.solana;if(!g)throw new Error("Wallet not available");let n=new TextEncoder().encode(a),m=await g.signMessage(n,"utf8"),y=new Uint8Array(m.signature||m),w="";for(let A=0;A<y.byteLength;A++)w+=String.fromCharCode(y[A]);return btoa(w)}if(u==="ethereum"){let g=(typeof window<"u"?window:null)?.ethereum;if(g?.providers?.length&&(g=g.providers.find(m=>m.isMetaMask)||g),!g)throw new Error("MetaMask not available");return await g.request({method:"personal_sign",params:[a,h]})}throw new Error("No wallet connected")}catch(t){return l(t.message||"Signing failed"),null}},[e]),s=useCallback(()=>{r({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:i,connectSolana:d,connectEVM:f,signMessage:p,disconnect:s}}var Pe="https://stacknet.magma-rpc.com/auth/bridge",J="stacknet-auth-bridge";function q(e){let r=e?.bridgeUrl||Pe,i=e?.disabled||false,l=useRef(null),[d,f]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),p=useRef([]),s=useRef(false),a=useCallback(t=>{let g={...t,protocol:J};s.current&&l.current?.contentWindow?l.current.contentWindow.postMessage(g,new URL(r).origin):p.current.push(g);},[r]);useEffect(()=>{if(i)return;let t=n=>{if(!(!n.data||n.data.protocol!==J)){try{if(n.origin!==new URL(r).origin)return}catch{return}switch(n.data.type){case "bridge:ready":s.current=true,f(m=>({...m,ready:true}));for(let m of p.current)l.current?.contentWindow?.postMessage(m,n.origin);p.current=[],l.current?.contentWindow?.postMessage({protocol:J,type:"auth:check"},n.origin),l.current?.contentWindow?.postMessage({protocol:J,type:"auth:resolve-stack"},n.origin);break;case "auth:status":f(m=>({...m,known:n.data.known,identity:n.data.identity,identityCount:n.data.identityCount||0}));break;case "auth:resolved-stack":f(m=>({...m,resolvedStackId:n.data.stackId||null}));break;}}};window.addEventListener("message",t);let g=document.createElement("iframe");return g.src=r,g.style.display="none",g.setAttribute("aria-hidden","true"),g.setAttribute("tabindex","-1"),g.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(g),l.current=g,()=>{window.removeEventListener("message",t),g.parentNode&&g.parentNode.removeChild(g),l.current=null,s.current=false;}},[r,i]);let o=useCallback(t=>{a({type:"auth:connected",...t});},[a]),u=useCallback(t=>{a({type:"auth:disconnected",...t});},[a]),c=useCallback(()=>{a({type:"auth:clear"}),f({ready:d.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[a,d.ready]),h=useCallback(()=>{a({type:"auth:check"});},[a]);return {...d,reportConnected:o,reportDisconnected:u,clearAll:c,refresh:h}}async function fe(e,r,i,l){let d=e.apiVersion||"v2",f=`${e.baseUrl}/api/${d}${i}`;try{let p=await fetch(f,{method:r,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),s=await p.json();return p.ok?s.success&&s.data!==void 0?{success:!0,data:s.data}:{success:!0,data:s}:{success:!1,error:s.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(p){return {success:false,error:{code:"NETWORK_ERROR",message:p instanceof Error?p.message:"Network error"}}}}function pe(e){return {getNetworkStatus:()=>fe(e,"GET","/network/status"),getWeb3Challenge:(r,i)=>fe(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:r,address:i})}}function Ae(e={apiBaseUrl:""}){let{wallet:r,connectSolana:i,connectEVM:l,signMessage:d,disconnect:f}=V(),{session:p,isAuthenticated:s,refresh:a,readSession:o}=M(),{headers:u}=K(),c=q({disabled:typeof window>"u"}),[h,t]=useState(false),[g,n]=useState(null),[m,y]=useState(false),w=e.apiBaseUrl||"",A=e.stacknetUrl||"https://stacknet.magma-rpc.com",C=e.stackId||c.resolvedStackId||"",S=pe({baseUrl:A,stackId:C}),E=useCallback(async(k,P,T,x)=>{t(true),n(null);try{let v=P;if(!v){let D=await T();if(!D)return t(!1),!1;v=D;}let O=await S.getWeb3Challenge(k,v);if(!O.success||!O.data)return n("Failed to get challenge"),t(!1),!1;let R=await d(O.data.message,{chain:k,provider:x,address:v});if(!R)return t(!1),!1;let G={chain:k,message:O.data.message,signature:R,stackId:C};k==="solana"&&(G.publicKey=v);let F=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(G)});if(!F.ok){let D=await F.json().catch(()=>({}));return n(D.error||"Authentication failed"),t(!1),!1}return c.reportConnected({address:v,chain:k,method:x||(k==="solana"?"phantom":"metamask"),stackId:C}),o(),t(!1),!0}catch(v){return n(v.message||"Authentication failed"),t(false),false}},[w,S,d,o,c,C]),$=useCallback(async(k="phantom")=>{let P=await i(k);return P?E("solana",P,()=>i(k),k):false},[i,E]),W=useCallback(async()=>{let k=await l();return k?E("ethereum",k,l,"metamask"):false},[l,E]),b=useCallback(async k=>{t(true),n(null);try{let P=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:k})});if(!P.ok){let T=await P.json().catch(()=>({}));return n(T.error||"Invalid code"),t(!1),!1}return o(),t(!1),!0}catch(P){return n(P.message||"OTP verification failed"),t(false),false}},[w,o]),I=useCallback(async(k,P)=>{t(true),n(null);try{let T=P||`${window.location.origin}/api/auth/oauth/callback`,x=new URLSearchParams({provider:k,redirectUri:T,stackId:C}),v=await fetch(`${w}/api/auth/oauth/start?${x}`,{credentials:"include"});if(!v.ok){let R=await v.json().catch(()=>({}));return n(R.error||"Failed to start OAuth flow"),t(!1),!1}let O=await v.json();if(O.redirect_url){let R;try{R=new URL(O.redirect_url);}catch{return n("Invalid OAuth redirect URL"),t(!1),!1}let G=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return R.protocol!=="https:"||!G.some(F=>F.test(R.hostname))?(n(`Refusing to redirect to non-OAuth host: ${R.hostname}`),t(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",O.state||""),sessionStorage.setItem("oauth_provider",k)),window.location.href=R.toString(),!0)}return n("No redirect URL returned"),t(!1),!1}catch(T){return n(T.message||"OAuth flow failed"),t(false),false}},[w,C]),N=useCallback(async(k,P,T)=>{t(true),n(null);try{if(typeof sessionStorage<"u"){let v=sessionStorage.getItem("oauth_state"),O=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!v||v!==T)return n("OAuth state mismatch \u2014 refusing to complete login"),t(!1),!1;if(O&&O!==k)return n("OAuth provider mismatch \u2014 refusing to complete login"),t(!1),!1}let x=await fetch(`${w}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:k,code:P,state:T,stackId:C})});if(!x.ok){let v=await x.json().catch(()=>({}));return n(v.error||"OAuth authentication failed"),t(!1),!1}return o(),t(!1),!0}catch(x){return n(x.message||"OAuth callback failed"),t(false),false}},[w,C,o]),j=useCallback(async()=>{r.address&&r.chain&&c.reportDisconnected({address:r.address,chain:r.chain,stackId:C});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:u,credentials:"include"});}catch{}f(),o();},[w,u,f,o,r,c,C]);return useEffect(()=>{if(!e.autoConnect||m||s||!c.ready||!c.known||!c.identity)return;y(true);let{chain:k,method:P}=c.identity;k==="solana"&&(P==="phantom"||P==="solflare")?$(P):k==="ethereum"&&W();},[e.autoConnect,m,s,c,$,W]),{session:p,isAuthenticated:s,wallet:r,loading:h,error:g,authenticateSolana:$,authenticateEVM:W,authenticateOTP:b,authenticateOAuth:I,authenticateOAuthCallback:N,logout:j,refresh:()=>a(w),stackId:C,bridge:{ready:c.ready,known:c.known,identity:c.identity,identityCount:c.identityCount,resolvedStackId:c.resolvedStackId}}}function Y(e,r="https://stacknet.magma-rpc.com"){let[i,l]=useState(null),[d,f]=useState(false),[p,s]=useState(null),a=useCallback(async u=>{f(true),s(null);try{let c=await fetch(`${r}/api/v2/stacks/${u}`);if(!c.ok)return s("Stack not found"),f(!1),null;let h=await c.json(),t=h.data?.stack||h.stack||h,g={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 l(g),f(!1),g}catch(c){return s(c.message),f(false),null}},[r]);useEffect(()=>{e&&a(e);},[e,a]);let o=i?Te(i):[];return {config:i,loading:d,error:p,identityProviders:o,fetchConfig:a}}function Te(e){let r=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(r.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),r.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&r.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&r.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let i of e.oauthProviders)i.enabled&&r.push({type:"oauth",id:i.provider,name:i.provider});return r}function Ue(e=""){let[r,i]=useState([]),[l,d]=useState(true),[f,p]=useState(null),s=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/plans`);if(a.ok){let o=await a.json();i(o.plans||o||[]);}}catch(a){p(a.message);}finally{d(false);}},[e]);return useEffect(()=>{s();},[s]),{plans:r,loading:l,error:f,refresh:s}}function _e(e=""){let[r,i]=useState(null),[l,d]=useState(true),[f,p]=useState(null),s=useCallback(async()=>{try{let u=await fetch(`${e}/api/billing/subscription`);if(u.ok){let c=await u.json();i(c.plan?c:null);}}catch(u){p(u.message);}finally{d(false);}},[e]);useEffect(()=>{s();},[s]);let a=useCallback(async u=>{let c=U(),t=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...c?{"x-csrf-token":c}:{}},body:JSON.stringify({planId:u})})).json();return t.url||t.checkoutUrl||null},[e]),o=useCallback(async()=>{let u=U();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:u?{"x-csrf-token":u}:{}})).ok?(await s(),true):false},[e,s]);return {subscription:r,loading:l,error:f,refresh:s,subscribe:a,cancel:o}}function Ne(e=""){let[r,i]=useState(null),[l,d]=useState(true),[f,p]=useState(null),s=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/usage`);if(a.ok){let o=await a.json();i(o);}}catch(a){p(a.message);}finally{d(false);}},[e]);return useEffect(()=>{s();},[s]),{usage:r,loading:l,error:f,refresh:s}}function Me(e=""){let[r,i]=useState(false),[l,d]=useState(null),f=useCallback(async s=>{i(true),d(null);try{let a=U(),o=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({amountCents:s})}),u=await o.json();return o.ok?u.url||null:(d(u.error||"Purchase failed"),null)}catch(a){return d(a.message),null}finally{i(false);}},[e]),p=useCallback(async s=>{i(true),d(null);try{let a=U(),o=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({sessionId:s})}),u=await o.json();return o.ok?u:(d(u.error||"Verification failed"),null)}catch(a){return d(a.message),null}finally{i(false);}},[e]);return {purchase:f,verifySession:p,loading:r,error:l}}function Ge(e="",r){let[i,l]=useState([]),[d,f]=useState(true),[p,s]=useState(null),a=r?.limit||50,o=r?.offset||0,u=useCallback(async()=>{try{let c=await fetch(`${e}/api/billing/history?limit=${a}&offset=${o}`);if(c.ok){let h=await c.json();l(h.records||h.history||(Array.isArray(h)?h:[]));}}catch(c){s(c.message);}finally{f(false);}},[e,a,o]);return useEffect(()=>{u();},[u]),{records:i,loading:d,error:p,refresh:u}}function De(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("__csrf="));return e?e.slice(7):null}function Be(e,r){let[i,l]=useState(null),[d,f]=useState(true),[p,s]=useState(false),[a,o]=useState(null),u=r?.apiBaseUrl??"",c=r?.scope===void 0||r?.scope==="global"?"global":`stack:${r.scope.stackId}`,h=useCallback(n=>{let m=encodeURIComponent(n);if(c==="global")return `${u}/api/user/profile/${m}`;let y=c.slice(6);return `${u}/api/v2/stacks/${encodeURIComponent(y)}/members/${m}/profile`},[u,c]),t=useCallback(async()=>{if(!e){l(null),f(false);return}f(true),o(null);try{let n=await fetch(h(e));if(n.ok){let m=await n.json(),y=m.profile||m.data?.profile||m;l({mid:y.mid||e,username:y.username||"",avatarUrl:y.avatar_url||y.avatarUrl,bio:y.bio,paymentAddress:y.payment_address||y.paymentAddress,createdAt:y.created_at||y.createdAt,updatedAt:y.updated_at||y.updatedAt});}else if(n.status===404)l({mid:e,username:""});else throw new Error(`${n.status}`)}catch(n){o(n instanceof Error?n.message:"Failed to load profile");}finally{f(false);}},[e,h]);useEffect(()=>{t();},[t]);let g=useCallback(async n=>{if(!e)return false;s(true),o(null);try{let m=De(),y={};n.username!==void 0&&(y.username=n.username),n.avatarUrl!==void 0&&(y.avatar_url=n.avatarUrl),n.bio!==void 0&&(y.bio=n.bio),n.paymentAddress!==void 0&&(y.payment_address=n.paymentAddress);let w=await fetch(h(e),{method:"PUT",headers:{"Content-Type":"application/json",...m?{"x-csrf-token":m}:{}},credentials:"same-origin",body:JSON.stringify(y)});if(!w.ok){let S=await w.json().catch(()=>({}));throw new Error(S.error||S.message||`Update failed: ${w.status}`)}let A=await w.json(),C=A.profile||A.data?.profile||A;return l(S=>({mid:S?.mid||e,username:n.username??S?.username??"",avatarUrl:n.avatarUrl??S?.avatarUrl,bio:n.bio??S?.bio,paymentAddress:n.paymentAddress??C.payment_address??C.paymentAddress??S?.paymentAddress,createdAt:S?.createdAt,updatedAt:C.updated_at||C.updatedAt||Date.now()})),!0}catch(m){return o(m instanceof Error?m.message:"Update failed"),false}finally{s(false);}},[e,h]);return {profile:i,loading:d,saving:p,error:a,updateProfile:g,refresh:t}}var ye="google-identity-services",Je="https://accounts.google.com/gsi/client";function He({stackId:e,stacknetUrl:r="https://stacknet.magma-rpc.com",apiBaseUrl:i="",autoPrompt:l=true,cancelOnTapOutside:d=true,onSuccess:f,onError:p,disabled:s=false}){let{config:a}=Y(e,r),{isAuthenticated:o,loading:u,readSession:c}=M(),[h,t]=useState(false),[g,n]=useState(null),[m,y]=useState(false),w=useRef(false),A=useRef(false),S=a?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;useEffect(()=>{if(s||!S||typeof window>"u")return;if(document.getElementById(ye)){y(true);return}let b=document.createElement("script");b.id=ye,b.src=Je,b.async=true,b.defer=true,b.onload=()=>y(true),b.onerror=()=>{n("Failed to load Google sign-in"),p?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[s,S,p]);let E=useCallback(async b=>{t(true),n(null);try{let I=await fetch(`${i}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!I.ok){let j=(await I.json().catch(()=>({}))).error||"Google sign-in failed";n(j),p?.(j),t(!1);return}c(),t(!1),f?.();}catch(I){let N=I.message||"Google sign-in failed";n(N),p?.(N),t(false);}},[i,e,c,f,p]);useEffect(()=>{if(s){console.debug("[GoogleOneTap] Disabled");return}if(!m){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",S);return}if(!S){console.debug("[GoogleOneTap] No Google clientId from stack config");return}if(u){console.debug("[GoogleOneTap] Session still loading");return}if(o){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:",S),w.current=true,window.google.accounts.id.initialize({client_id:S,callback:E,auto_select:true,cancel_on_tap_outside:d}),l&&!A.current&&(A.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?.());})));},[s,m,S,u,o,E,l,d]),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();},[]),W=useCallback((b,I)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:I?.theme||"filled_black",size:I?.size||"large",text:I?.text||"signin_with",width:I?.width});},[]);return {available:!!S,ready:m&&!!S,loading:h,error:g,prompt:$,renderButton:W,clientId:S}}
|
|
2
|
-
export{q as useAuthBridge,
|
|
1
|
+
import {useState,useCallback,useEffect,useRef}from'react';function ce(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith("stackauth_session="));if(!e)return null;let n=e.slice(18);return JSON.parse(atob(n.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function x(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function L(){let[e,n]=useState(null),[i,l]=useState(true),d=useCallback(()=>{let o=ce();o&&o.expiresAt>Date.now()?n({userId:o.userId,address:o.address,chain:o.chain,expiresAt:o.expiresAt,planId:o.planId,authMethod:o.authMethod}):n(null),l(false);},[]);useEffect(()=>{d();},[d]);let g=useCallback(async(o="")=>{try{let s=await fetch(`${o}/api/auth/session`);if(s.ok){let a=await s.json();if(a.session)return n(a.session),a.session}return n(null),null}catch{return null}},[]),f=!!e&&e.expiresAt>Date.now();return {session:e,loading:i,isAuthenticated:f,refresh:g,readSession:d}}function K(e="__csrf",n="x-csrf-token"){let[i,l]=useState(null);useEffect(()=>{l(x(e));},[e]);let d=i?{[n]:i}:{};return {token:i,headers:d}}function V(){let[e,n]=useState({connected:false,address:null,chain:null,provider:null}),[i,l]=useState(null),d=useCallback(async(s="phantom")=>{l(null);try{let a=typeof window<"u"?window:null,c=s==="phantom"?a?.phantom?.solana||a?.solana:a?.solflare;if(!c)return l(`${s} wallet not found`),null;let m=(await c.connect()).publicKey.toString();return n({connected:!0,address:m,chain:"solana",provider:s}),m}catch(a){return l(a.message||"Failed to connect wallet"),null}},[]),g=useCallback(async()=>{l(null);try{let a=(typeof window<"u"?window:null)?.ethereum;if(!a)return l("MetaMask not found"),null;let c=a;a.providers?.length&&(c=a.providers.find(t=>t.isMetaMask)||a);let m=(await c.request({method:"eth_requestAccounts"}))[0];return m?(n({connected:!0,address:m,chain:"ethereum",provider:"metamask"}),m):(l("No account selected"),null)}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),f=useCallback(async(s,a)=>{l(null);let c=a?.chain||e.chain,u=a?.provider||e.provider,m=a?.address||e.address;try{if(c==="solana"){let t=typeof window<"u"?window:null,p=u==="solflare"?t?.solflare:t?.phantom?.solana||t?.solana;if(!p)throw new Error("Wallet not available");let r=new TextEncoder().encode(s),h=await p.signMessage(r,"utf8"),y=new Uint8Array(h.signature||h),w="";for(let A=0;A<y.byteLength;A++)w+=String.fromCharCode(y[A]);return btoa(w)}if(c==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(h=>h.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[s,m]})}throw new Error("No wallet connected")}catch(t){return l(t.message||"Signing failed"),null}},[e]),o=useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:i,connectSolana:d,connectEVM:g,signMessage:f,disconnect:o}}var Ae="https://stacknet.magma-rpc.com/auth/bridge",D="stacknet-auth-bridge";function q(e){let n=e?.bridgeUrl||Ae,i=e?.disabled||false,l=useRef(null),[d,g]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),f=useRef([]),o=useRef(false),s=useCallback(t=>{let p={...t,protocol:D};o.current&&l.current?.contentWindow?l.current.contentWindow.postMessage(p,new URL(n).origin):f.current.push(p);},[n]);useEffect(()=>{if(i)return;let t=r=>{if(!(!r.data||r.data.protocol!==D)){try{if(r.origin!==new URL(n).origin)return}catch{return}switch(r.data.type){case "bridge:ready":o.current=true,g(h=>({...h,ready:true}));for(let h of f.current)l.current?.contentWindow?.postMessage(h,r.origin);f.current=[],l.current?.contentWindow?.postMessage({protocol:D,type:"auth:check"},r.origin),l.current?.contentWindow?.postMessage({protocol:D,type:"auth:resolve-stack"},r.origin);break;case "auth:status":g(h=>({...h,known:r.data.known,identity:r.data.identity,identityCount:r.data.identityCount||0}));break;case "auth:resolved-stack":g(h=>({...h,resolvedStackId:r.data.stackId||null}));break;}}};window.addEventListener("message",t);let p=document.createElement("iframe");return p.src=n,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),l.current=p,()=>{window.removeEventListener("message",t),p.parentNode&&p.parentNode.removeChild(p),l.current=null,o.current=false;}},[n,i]);let a=useCallback(t=>{s({type:"auth:connected",...t});},[s]),c=useCallback(t=>{s({type:"auth:disconnected",...t});},[s]),u=useCallback(()=>{s({type:"auth:clear"}),g({ready:d.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[s,d.ready]),m=useCallback(()=>{s({type:"auth:check"});},[s]);return {...d,reportConnected:a,reportDisconnected:c,clearAll:u,refresh:m}}async function ge(e,n,i,l){let d=e.apiVersion||"v2",g=`${e.baseUrl}/api/${d}${i}`;try{let f=await fetch(g,{method:n,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),o=await f.json();return f.ok?o.success&&o.data!==void 0?{success:!0,data:o.data}:{success:!0,data:o}:{success:!1,error:o.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(f){return {success:false,error:{code:"NETWORK_ERROR",message:f instanceof Error?f.message:"Network error"}}}}function pe(e){return {getNetworkStatus:()=>ge(e,"GET","/network/status"),getWeb3Challenge:(n,i)=>ge(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:n,address:i})}}function Te(e={apiBaseUrl:""}){let{wallet:n,connectSolana:i,connectEVM:l,signMessage:d,disconnect:g}=V(),{session:f,isAuthenticated:o,refresh:s,readSession:a}=L(),{headers:c}=K(),u=q({disabled:typeof window>"u"}),[m,t]=useState(false),[p,r]=useState(null),[h,y]=useState(false),w=e.apiBaseUrl||"",A=e.stacknetUrl||"https://stacknet.magma-rpc.com",C=e.stackId||u.resolvedStackId||"",S=pe({baseUrl:A,stackId:C}),E=useCallback(async(k,P,O,R)=>{t(true),r(null);try{let v=P;if(!v){let B=await O();if(!B)return t(!1),!1;v=B;}let T=await S.getWeb3Challenge(k,v);if(!T.success||!T.data)return r("Failed to get challenge"),t(!1),!1;let U=await d(T.data.message,{chain:k,provider:R,address:v});if(!U)return t(!1),!1;let G={chain:k,message:T.data.message,signature:U,stackId:C};k==="solana"&&(G.publicKey=v);let J=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(G)});if(!J.ok){let B=await J.json().catch(()=>({}));return r(B.error||"Authentication failed"),t(!1),!1}return u.reportConnected({address:v,chain:k,method:R||(k==="solana"?"phantom":"metamask"),stackId:C}),a(),t(!1),!0}catch(v){return r(v.message||"Authentication failed"),t(false),false}},[w,S,d,a,u,C]),$=useCallback(async(k="phantom")=>{let P=await i(k);return P?E("solana",P,()=>i(k),k):false},[i,E]),W=useCallback(async()=>{let k=await l();return k?E("ethereum",k,l,"metamask"):false},[l,E]),b=useCallback(async k=>{t(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:k})});if(!P.ok){let O=await P.json().catch(()=>({}));return r(O.error||"Invalid code"),t(!1),!1}return a(),t(!1),!0}catch(P){return r(P.message||"OTP verification failed"),t(false),false}},[w,a]),I=useCallback(async(k,P)=>{t(true),r(null);try{let O=P||`${window.location.origin}/api/auth/oauth/callback`,R=new URLSearchParams({provider:k,redirectUri:O,stackId:C}),v=await fetch(`${w}/api/auth/oauth/start?${R}`,{credentials:"include"});if(!v.ok){let U=await v.json().catch(()=>({}));return r(U.error||"Failed to start OAuth flow"),t(!1),!1}let T=await v.json();if(T.redirect_url){let U;try{U=new URL(T.redirect_url);}catch{return r("Invalid OAuth redirect URL"),t(!1),!1}let G=[/(^|\.)accounts\.google\.com$/,/(^|\.)discord\.com$/,/(^|\.)github\.com$/,/(^|\.)x\.com$/,/(^|\.)twitter\.com$/,/(^|\.)apple\.com$/];return U.protocol!=="https:"||!G.some(J=>J.test(U.hostname))?(r(`Refusing to redirect to non-OAuth host: ${U.hostname}`),t(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",T.state||""),sessionStorage.setItem("oauth_provider",k)),window.location.href=U.toString(),!0)}return r("No redirect URL returned"),t(!1),!1}catch(O){return r(O.message||"OAuth flow failed"),t(false),false}},[w,C]),N=useCallback(async(k,P,O)=>{t(true),r(null);try{if(typeof sessionStorage<"u"){let v=sessionStorage.getItem("oauth_state"),T=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!v||v!==O)return r("OAuth state mismatch \u2014 refusing to complete login"),t(!1),!1;if(T&&T!==k)return r("OAuth provider mismatch \u2014 refusing to complete login"),t(!1),!1}let R=await fetch(`${w}/api/auth/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:k,code:P,state:O,stackId:C})});if(!R.ok){let v=await R.json().catch(()=>({}));return r(v.error||"OAuth authentication failed"),t(!1),!1}return a(),t(!1),!0}catch(R){return r(R.message||"OAuth callback failed"),t(false),false}},[w,C,a]),j=useCallback(async()=>{n.address&&n.chain&&u.reportDisconnected({address:n.address,chain:n.chain,stackId:C});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:c,credentials:"include"});}catch{}g(),a();},[w,c,g,a,n,u,C]);return useEffect(()=>{if(!e.autoConnect||h||o||!u.ready||!u.known||!u.identity)return;y(true);let{chain:k,method:P}=u.identity;k==="solana"&&(P==="phantom"||P==="solflare")?$(P):k==="ethereum"&&W();},[e.autoConnect,h,o,u,$,W]),{session:f,isAuthenticated:o,wallet:n,loading:m,error:p,authenticateSolana:$,authenticateEVM:W,authenticateOTP:b,authenticateOAuth:I,authenticateOAuthCallback:N,logout:j,refresh:()=>s(w),stackId:C,bridge:{ready:u.ready,known:u.known,identity:u.identity,identityCount:u.identityCount,resolvedStackId:u.resolvedStackId}}}function Y(e,n="https://stacknet.magma-rpc.com"){let[i,l]=useState(null),[d,g]=useState(false),[f,o]=useState(null),s=useCallback(async c=>{g(true),o(null);try{let u=await fetch(`${n}/api/v2/stacks/${c}`);if(!u.ok)return o("Stack not found"),g(!1),null;let m=await u.json(),t=m.data?.stack||m.stack||m,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(r=>({provider:r.provider,clientId:r.clientId,enabled:r.enabled!==!1}))};return l(p),g(!1),p}catch(u){return o(u.message),g(false),null}},[n]);useEffect(()=>{e&&s(e);},[e,s]);let a=i?Re(i):[];return {config:i,loading:d,error:f,identityProviders:a,fetchConfig:s}}function Re(e){let n=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(n.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),n.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&n.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&n.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let i of e.oauthProviders)i.enabled&&n.push({type:"oauth",id:i.provider,name:i.provider});return n}function _e(e=""){let[n,i]=useState([]),[l,d]=useState(true),[g,f]=useState(null),o=useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/plans`);if(s.ok){let a=await s.json();i(a.plans||a||[]);}}catch(s){f(s.message);}finally{d(false);}},[e]);return useEffect(()=>{o();},[o]),{plans:n,loading:l,error:g,refresh:o}}function We(e=""){let[n,i]=useState(null),[l,d]=useState(true),[g,f]=useState(null),o=useCallback(async()=>{try{let c=await fetch(`${e}/api/billing/subscription`);if(c.ok){let u=await c.json();i(u.plan?u:null);}}catch(c){f(c.message);}finally{d(false);}},[e]);useEffect(()=>{o();},[o]);let s=useCallback(async c=>{let u=x(),t=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...u?{"x-csrf-token":u}:{}},body:JSON.stringify({planId:c})})).json();return t.url||t.checkoutUrl||null},[e]),a=useCallback(async()=>{let c=x();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:c?{"x-csrf-token":c}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:n,loading:l,error:g,refresh:o,subscribe:s,cancel:a}}function Me(e=""){let[n,i]=useState(null),[l,d]=useState(true),[g,f]=useState(null),o=useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/usage`);if(s.ok){let a=await s.json();i(a);}}catch(s){f(s.message);}finally{d(false);}},[e]);return useEffect(()=>{o();},[o]),{usage:n,loading:l,error:g,refresh:o}}function je(e=""){let[n,i]=useState(false),[l,d]=useState(null),g=useCallback(async o=>{i(true),d(null);try{let s=x(),a=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({amountCents:o})}),c=await a.json();return a.ok?c.url||null:(d(c.error||"Purchase failed"),null)}catch(s){return d(s.message),null}finally{i(false);}},[e]),f=useCallback(async o=>{i(true),d(null);try{let s=x(),a=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({sessionId:o})}),c=await a.json();return a.ok?c:(d(c.error||"Verification failed"),null)}catch(s){return d(s.message),null}finally{i(false);}},[e]);return {purchase:g,verifySession:f,loading:n,error:l}}function Be(e="",n){let[i,l]=useState([]),[d,g]=useState(true),[f,o]=useState(null),s=n?.limit||50,a=n?.offset||0,c=useCallback(async()=>{try{let u=await fetch(`${e}/api/billing/history?limit=${s}&offset=${a}`);if(u.ok){let m=await u.json();l(m.records||m.history||(Array.isArray(m)?m:[]));}}catch(u){o(u.message);}finally{g(false);}},[e,s,a]);return useEffect(()=>{c();},[c]),{records:i,loading:d,error:f,refresh:c}}function De(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith("__csrf="));return e?e.slice(7):null}function He(e,n){let[i,l]=useState(null),[d,g]=useState(true),[f,o]=useState(false),[s,a]=useState(null),c=n?.apiBaseUrl??"",u=n?.scope===void 0||n?.scope==="global"?"global":`stack:${n.scope.stackId}`,m=useCallback(r=>{let h=encodeURIComponent(r);if(u==="global")return `${c}/api/user/profile/${h}`;let y=u.slice(6);return `${c}/api/v2/stacks/${encodeURIComponent(y)}/members/${h}/profile`},[c,u]),t=useCallback(async()=>{if(!e){l(null),g(false);return}g(true),a(null);try{let r=await fetch(m(e));if(r.ok){let h=await r.json(),y=h.profile||h.data?.profile||h;l({mid:y.mid||e,username:y.username||"",avatarUrl:y.avatar_url||y.avatarUrl,bio:y.bio,paymentAddress:y.payment_address||y.paymentAddress,createdAt:y.created_at||y.createdAt,updatedAt:y.updated_at||y.updatedAt});}else if(r.status===404)l({mid:e,username:""});else throw new Error(`${r.status}`)}catch(r){a(r instanceof Error?r.message:"Failed to load profile");}finally{g(false);}},[e,m]);useEffect(()=>{t();},[t]);let p=useCallback(async r=>{if(!e)return false;o(true),a(null);try{let h=De(),y={};r.username!==void 0&&(y.username=r.username),r.avatarUrl!==void 0&&(y.avatar_url=r.avatarUrl),r.bio!==void 0&&(y.bio=r.bio),r.paymentAddress!==void 0&&(y.payment_address=r.paymentAddress);let w=await fetch(m(e),{method:"PUT",headers:{"Content-Type":"application/json",...h?{"x-csrf-token":h}:{}},credentials:"same-origin",body:JSON.stringify(y)});if(!w.ok){let S=await w.json().catch(()=>({}));throw new Error(S.error||S.message||`Update failed: ${w.status}`)}let A=await w.json(),C=A.profile||A.data?.profile||A;return l(S=>({mid:S?.mid||e,username:r.username??S?.username??"",avatarUrl:r.avatarUrl??S?.avatarUrl,bio:r.bio??S?.bio,paymentAddress:r.paymentAddress??C.payment_address??C.paymentAddress??S?.paymentAddress,createdAt:S?.createdAt,updatedAt:C.updated_at||C.updatedAt||Date.now()})),!0}catch(h){return a(h instanceof Error?h.message:"Update failed"),false}finally{o(false);}},[e,m]);return {profile:i,loading:d,saving:f,error:s,updateProfile:p,refresh:t}}var be="google-identity-services",Ke="https://accounts.google.com/gsi/client";function Ve({stackId:e,stacknetUrl:n="https://stacknet.magma-rpc.com",apiBaseUrl:i="",autoPrompt:l=true,cancelOnTapOutside:d=true,onSuccess:g,onError:f,disabled:o=false}){let{config:s}=Y(e,n),{isAuthenticated:a,loading:c,readSession:u}=L(),[m,t]=useState(false),[p,r]=useState(null),[h,y]=useState(false),w=useRef(false),A=useRef(false),S=s?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;useEffect(()=>{if(o||!S||typeof window>"u")return;if(document.getElementById(be)){y(true);return}let b=document.createElement("script");b.id=be,b.src=Ke,b.async=true,b.defer=true,b.onload=()=>y(true),b.onerror=()=>{r("Failed to load Google sign-in"),f?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[o,S,f]);let E=useCallback(async b=>{t(true),r(null);try{let I=await fetch(`${i}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!I.ok){let j=(await I.json().catch(()=>({}))).error||"Google sign-in failed";r(j),f?.(j),t(!1);return}u(),t(!1),g?.();}catch(I){let N=I.message||"Google sign-in failed";r(N),f?.(N),t(false);}},[i,e,u,g,f]);useEffect(()=>{if(o){console.debug("[GoogleOneTap] Disabled");return}if(!h){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",S);return}if(!S){console.debug("[GoogleOneTap] No Google clientId from stack config");return}if(c){console.debug("[GoogleOneTap] Session still loading");return}if(a){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:",S),w.current=true,window.google.accounts.id.initialize({client_id:S,callback:E,auto_select:true,cancel_on_tap_outside:d}),l&&!A.current&&(A.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?.());})));},[o,h,S,c,a,E,l,d]),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();},[]),W=useCallback((b,I)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:I?.theme||"filled_black",size:I?.size||"large",text:I?.text||"signin_with",width:I?.width});},[]);return {available:!!S,ready:h&&!!S,loading:m,error:p,prompt:$,renderButton:W,clientId:S}}var qe="/api";function Qe(e,n){return `${(n||(typeof window<"u"?window.location.origin:"")).replace(/\/$/,"")}/?ref=${encodeURIComponent(e)}`}function Xe(e={}){let{shareBaseUrl:n,autoMint:i=true}=e,[l,d]=useState(null),[g,f]=useState(true),[o,s]=useState(null),a=useCallback(async()=>{f(true),s(null);try{let m=i?"POST":"GET",t=await fetch(`${qe}/social/join-code`,{method:m,credentials:"include"});if(!t.ok){d(null),t.status===401?s("not_authenticated"):s(`HTTP ${t.status}`);return}let p=await t.json();d(p?.code??null);}catch(m){s(m?.message||"network_error"),d(null);}finally{f(false);}},[i]);useEffect(()=>{a();},[a]);let c=l?Qe(l,n):null,u=useCallback(async()=>{if(!c)return false;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(c),!0}catch{}return false},[c]);return {code:l,shareUrl:c,loading:g,error:o,refresh:a,copyShareLink:u}}
|
|
2
|
+
export{q as useAuthBridge,Be as useBillingHistory,K as useCSRFToken,Ve as useGoogleOneTap,Xe as useJoinCode,_e as usePlans,je as usePrepaidCheckout,He as useProfile,L as useSession,Te as useStackAuth,Y as useStackConfig,We as useSubscription,Me as useUsage,V as useWeb3Wallet};
|
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 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=
|
|
1
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function It(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function Nt(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 At(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let r=new URL(e,t);return r.origin!==t?"/":r.pathname+r.search+r.hash}catch{return "/"}}function ee(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 d=new URL(r);if(d.protocol==="http:"||d.protocol==="https:")return d.toString()}catch{}return t}function Mt(e){try{let t=e.split(".");if(t.length!==3)return null;let r=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)}catch{return null}}function te(){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 F(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 ne(){let[e,t]=react.useState(null),[r,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:r,isAuthenticated:g,refresh:h,readSession:u}}function we(e="__csrf",t="x-csrf-token"){let[r,d]=react.useState(null);react.useEffect(()=>{d(F(e));},[e]);let u=r?{[t]:r}:{};return {token:r,headers:u}}function Ce(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[r,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 s=new TextEncoder().encode(l),y=await p.signMessage(s,"utf8"),C=new Uint8Array(y.signature||y),w="";for(let T=0;T<C.byteLength;T++)w+=String.fromCharCode(C[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:r,connectSolana:u,connectEVM:h,signMessage:g,disconnect:i}}var Dt="https://stacknet.magma-rpc.com/auth/bridge",de="stacknet-auth-bridge";function xe(e){let t=e?.bridgeUrl||Dt,r=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(r)return;let n=s=>{if(!(!s.data||s.data.protocol!==de)){try{if(s.origin!==new URL(t).origin)return}catch{return}switch(s.data.type){case "bridge:ready":i.current=true,h(y=>({...y,ready:true}));for(let y of g.current)d.current?.contentWindow?.postMessage(y,s.origin);g.current=[],d.current?.contentWindow?.postMessage({protocol:de,type:"auth:check"},s.origin),d.current?.contentWindow?.postMessage({protocol:de,type:"auth:resolve-stack"},s.origin);break;case "auth:status":h(y=>({...y,known:s.data.known,identity:s.data.identity,identityCount:s.data.identityCount||0}));break;case "auth:resolved-stack":h(y=>({...y,resolvedStackId:s.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,r]);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 ot(e,t,r,d){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${r}`;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:()=>ot(e,"GET","/network/status"),getWeb3Challenge:(t,r)=>ot(e,"POST",`/stacks/${encodeURIComponent(e.stackId)}/auth/web3/challenge`,{chain:t,address:r})}}function Ie(e={apiBaseUrl:""}){let{wallet:t,connectSolana:r,connectEVM:d,signMessage:u,disconnect:h}=Ce(),{session:g,isAuthenticated:i,refresh:l,readSession:c}=ne(),{headers:m}=we(),o=xe({disabled:typeof window>"u"}),[a,n]=react.useState(false),[p,s]=react.useState(null),[y,C]=react.useState(false),w=e.apiBaseUrl||"",T=e.stacknetUrl||"https://stacknet.magma-rpc.com",x=e.stackId||o.resolvedStackId||"",S=ve({baseUrl:T,stackId:x}),z=react.useCallback(async(P,I,E,R)=>{n(true),s(null);try{let N=I;if(!N){let Z=await E();if(!Z)return n(!1),!1;N=Z;}let L=await S.getWeb3Challenge(P,N);if(!L.success||!L.data)return s("Failed to get challenge"),n(!1),!1;let _=await u(L.data.message,{chain:P,provider:R,address:N});if(!_)return n(!1),!1;let G={chain:P,message:L.data.message,signature:_,stackId:x};P==="solana"&&(G.publicKey=N);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 Z=await Q.json().catch(()=>({}));return s(Z.error||"Authentication failed"),n(!1),!1}return o.reportConnected({address:N,chain:P,method:R||(P==="solana"?"phantom":"metamask"),stackId:x}),c(),n(!1),!0}catch(N){return s(N.message||"Authentication failed"),n(false),false}},[w,S,u,c,o,x]),$=react.useCallback(async(P="phantom")=>{let I=await r(P);return I?z("solana",I,()=>r(P),P):false},[r,z]),j=react.useCallback(async()=>{let P=await d();return P?z("ethereum",P,d,"metamask"):false},[d,z]),b=react.useCallback(async P=>{n(true),s(null);try{let I=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:P})});if(!I.ok){let E=await I.json().catch(()=>({}));return s(E.error||"Invalid code"),n(!1),!1}return c(),n(!1),!0}catch(I){return s(I.message||"OTP verification failed"),n(false),false}},[w,c]),U=react.useCallback(async(P,I)=>{n(true),s(null);try{let E=I||`${window.location.origin}/api/auth/oauth/callback`,R=new URLSearchParams({provider:P,redirectUri:E,stackId:x}),N=await fetch(`${w}/api/auth/oauth/start?${R}`,{credentials:"include"});if(!N.ok){let _=await N.json().catch(()=>({}));return s(_.error||"Failed to start OAuth flow"),n(!1),!1}let L=await N.json();if(L.redirect_url){let _;try{_=new URL(L.redirect_url);}catch{return s("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))?(s(`Refusing to redirect to non-OAuth host: ${_.hostname}`),n(!1),!1):(typeof sessionStorage<"u"&&(sessionStorage.setItem("oauth_state",L.state||""),sessionStorage.setItem("oauth_provider",P)),window.location.href=_.toString(),!0)}return s("No redirect URL returned"),n(!1),!1}catch(E){return s(E.message||"OAuth flow failed"),n(false),false}},[w,x]),A=react.useCallback(async(P,I,E)=>{n(true),s(null);try{if(typeof sessionStorage<"u"){let N=sessionStorage.getItem("oauth_state"),L=sessionStorage.getItem("oauth_provider");if(sessionStorage.removeItem("oauth_state"),sessionStorage.removeItem("oauth_provider"),!N||N!==E)return s("OAuth state mismatch \u2014 refusing to complete login"),n(!1),!1;if(L&&L!==P)return s("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:P,code:I,state:E,stackId:x})});if(!R.ok){let N=await R.json().catch(()=>({}));return s(N.error||"OAuth authentication failed"),n(!1),!1}return c(),n(!1),!0}catch(R){return s(R.message||"OAuth callback failed"),n(false),false}},[w,x,c]),D=react.useCallback(async()=>{t.address&&t.chain&&o.reportDisconnected({address:t.address,chain:t.chain,stackId:x});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:m,credentials:"include"});}catch{}h(),c();},[w,m,h,c,t,o,x]);return react.useEffect(()=>{if(!e.autoConnect||y||i||!o.ready||!o.known||!o.identity)return;C(true);let{chain:P,method:I}=o.identity;P==="solana"&&(I==="phantom"||I==="solflare")?$(I):P==="ethereum"&&j();},[e.autoConnect,y,i,o,$,j]),{session:g,isAuthenticated:i,wallet:t,loading:a,error:p,authenticateSolana:$,authenticateEVM:j,authenticateOTP:b,authenticateOAuth:U,authenticateOAuthCallback:A,logout:D,refresh:()=>l(w),stackId:x,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[r,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(s=>({provider:s.provider,clientId:s.clientId,enabled:s.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=r?_t(r):[];return {config:r,loading:u,error:g,identityProviders:c,fetchConfig:l}}function _t(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 Ft(e=""){let[t,r]=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();r(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 Gt(e=""){let[t,r]=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();r(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=F(),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=F();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 Qt(e=""){let[t,r]=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();r(c);}}catch(l){g(l.message);}finally{u(false);}},[e]);return react.useEffect(()=>{i();},[i]),{usage:t,loading:d,error:h,refresh:i}}function Vt(e=""){let[t,r]=react.useState(false),[d,u]=react.useState(null),h=react.useCallback(async i=>{r(true),u(null);try{let l=F(),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{r(false);}},[e]),g=react.useCallback(async i=>{r(true),u(null);try{let l=F(),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{r(false);}},[e]);return {purchase:h,verifySession:g,loading:t,error:d}}function Kt(e="",t){let[r,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:r,loading:u,error:g,refresh:m}}function Xt(){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[r,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(s=>{let y=encodeURIComponent(s);if(o==="global")return `${m}/api/user/profile/${y}`;let C=o.slice(6);return `${m}/api/v2/stacks/${encodeURIComponent(C)}/members/${y}/profile`},[m,o]),n=react.useCallback(async()=>{if(!e){d(null),h(false);return}h(true),c(null);try{let s=await fetch(a(e));if(s.ok){let y=await s.json(),C=y.profile||y.data?.profile||y;d({mid:C.mid||e,username:C.username||"",avatarUrl:C.avatar_url||C.avatarUrl,bio:C.bio,paymentAddress:C.payment_address||C.paymentAddress,createdAt:C.created_at||C.createdAt,updatedAt:C.updated_at||C.updatedAt});}else if(s.status===404)d({mid:e,username:""});else throw new Error(`${s.status}`)}catch(s){c(s instanceof Error?s.message:"Failed to load profile");}finally{h(false);}},[e,a]);react.useEffect(()=>{n();},[n]);let p=react.useCallback(async s=>{if(!e)return false;i(true),c(null);try{let y=Xt(),C={};s.username!==void 0&&(C.username=s.username),s.avatarUrl!==void 0&&(C.avatar_url=s.avatarUrl),s.bio!==void 0&&(C.bio=s.bio),s.paymentAddress!==void 0&&(C.payment_address=s.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(C)});if(!w.ok){let S=await w.json().catch(()=>({}));throw new Error(S.error||S.message||`Update failed: ${w.status}`)}let T=await w.json(),x=T.profile||T.data?.profile||T;return d(S=>({mid:S?.mid||e,username:s.username??S?.username??"",avatarUrl:s.avatarUrl??S?.avatarUrl,bio:s.bio??S?.bio,paymentAddress:s.paymentAddress??x.payment_address??x.paymentAddress??S?.paymentAddress,createdAt:S?.createdAt,updatedAt:x.updated_at||x.updatedAt||Date.now()})),!0}catch(y){return c(y instanceof Error?y.message:"Update failed"),false}finally{i(false);}},[e,a]);return {profile:r,loading:u,saving:g,error:l,updateProfile:p,refresh:n}}var it="google-identity-services",en="https://accounts.google.com/gsi/client";function tn({stackId:e,stacknetUrl:t="https://stacknet.magma-rpc.com",apiBaseUrl:r="",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,s]=react.useState(null),[y,C]=react.useState(false),w=react.useRef(false),T=react.useRef(false),S=l?.oauthProviders?.find(b=>b.provider==="google"&&b.enabled&&b.clientId)?.clientId||null;react.useEffect(()=>{if(i||!S||typeof window>"u")return;if(document.getElementById(it)){C(true);return}let b=document.createElement("script");b.id=it,b.src=en,b.async=true,b.defer=true,b.onload=()=>C(true),b.onerror=()=>{s("Failed to load Google sign-in"),g?.("Failed to load Google Identity Services script");},document.head.appendChild(b);},[i,S,g]);let z=react.useCallback(async b=>{n(true),s(null);try{let U=await fetch(`${r}/api/auth/google/one-tap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({credential:b.credential,stackId:e})});if(!U.ok){let D=(await U.json().catch(()=>({}))).error||"Google sign-in failed";s(D),g?.(D),n(!1);return}o(),n(!1),h?.();}catch(U){let A=U.message||"Google sign-in failed";s(A),g?.(A),n(false);}},[r,e,o,h,g]);react.useEffect(()=>{if(i){console.debug("[GoogleOneTap] Disabled");return}if(!y){console.debug("[GoogleOneTap] Script not loaded yet, clientId:",S);return}if(!S){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:",S),w.current=true,window.google.accounts.id.initialize({client_id:S,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,S,m,c,z,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,U)=>{!b||!window.google?.accounts?.id||!w.current||window.google.accounts.id.renderButton(b,{theme:U?.theme||"filled_black",size:U?.size||"large",text:U?.text||"signin_with",width:U?.width});},[]);return {available:!!S,ready:y&&!!S,loading:a,error:p,prompt:$,renderButton:j,clientId:S}}var on="/api";function rn(e,t){return `${(t||(typeof window<"u"?window.location.origin:"")).replace(/\/$/,"")}/?ref=${encodeURIComponent(e)}`}function sn(e={}){let{shareBaseUrl:t,autoMint:r=true}=e,[d,u]=react.useState(null),[h,g]=react.useState(true),[i,l]=react.useState(null),c=react.useCallback(async()=>{g(true),l(null);try{let a=r?"POST":"GET",n=await fetch(`${on}/social/join-code`,{method:a,credentials:"include"});if(!n.ok){u(null),n.status===401?l("not_authenticated"):l(`HTTP ${n.status}`);return}let p=await n.json();u(p?.code??null);}catch(a){l(a?.message||"network_error"),u(null);}finally{g(false);}},[r]);react.useEffect(()=>{c();},[c]);let m=d?rn(d,t):null,o=react.useCallback(async()=>{if(!m)return false;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(m),!0}catch{}return false},[m]);return {code:d,shareUrl:m,loading:h,error:i,refresh:c,copyShareLink:o}}var ct=react.createContext(null);function cn(){let e=react.useContext(ct);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function dn({config:e,callbacks:t,children:r}){return jsxRuntime.jsx(ct.Provider,{value:{config:e,callbacks:t},children:r})}function pe({length:e=6,onComplete:t,disabled:r=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(""),s=[...g];p.forEach((C,w)=>{o+w<e&&(s[o+w]=C);}),i(s);let y=Math.min(o+p.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),s.every(C=>C!=="")&&setTimeout(()=>t(s.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:r,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 gn="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function fe({className:e,style:t}){return jsxRuntime.jsx("img",{src:gn,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 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:"#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 Be({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 Ge({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:"#000000"}),jsxRuntime.jsx("path",{d:"M21.3611 16.7384C21.3807 18.9244 23.2792 19.6519 23.3001 19.661C23.2841 19.7124 22.9971 20.6962 22.3005 21.7115C21.6987 22.5892 21.0742 23.4636 20.0904 23.4816C19.1237 23.4994 18.8127 22.9098 17.7076 22.9098C16.6029 22.9098 16.2574 23.4636 15.3423 23.4994C14.3928 23.5352 13.6694 22.5504 13.0626 21.676C11.8226 19.8879 10.8747 16.6229 12.1471 14.4182C12.7791 13.3234 13.9087 12.6304 15.1346 12.6126C16.0668 12.5948 16.9468 13.2378 17.5167 13.2378C18.0865 13.2378 19.1555 12.4647 20.2795 12.579C20.7501 12.5986 22.0715 12.7692 22.9207 14.0122C22.852 14.0549 21.3453 14.9328 21.3611 16.7384ZM19.5432 11.392C20.0472 10.7809 20.3862 9.93 20.2939 9.08325C19.5709 9.11221 18.6961 9.56574 18.1749 10.1763C17.708 10.717 17.2995 11.582 17.4096 12.4111C18.2158 12.4736 19.0391 12.003 19.5432 11.392Z",fill:"#FFFFFF"})]})}function Cn({config:e,onSuccess:t,title:r="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=Ie(e),{isAuthenticated:a,wallet:n,loading:p,error:s,authenticateSolana:y,authenticateEVM:C,authenticateOTP:w,authenticateOAuth:T,bridge:x,stackId:S}=o,z=!e.stackId&&!S,$=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:j,identityProviders:b,loading:U}=re(S||e.stackId||null,$),[A,D]=react.useState(z?"stack-select":"select"),[P,I]=react.useState(null),[E,R]=react.useState(false),[N,L]=react.useState("idle"),[_,G]=react.useState(""),[Q,Z]=react.useState([]),[yt,Ve]=react.useState(e.stackId||null),[le,kt]=react.useState(false),[bt,wt]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let f=()=>{let V=window;kt(!!(V.phantom?.solana?.isPhantom||V.solana?.isPhantom));let q=V.ethereum;wt(!!(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"&&S&&(Ve(S),D("select"));},[A,S]),react.useEffect(()=>{if(!(!x.ready||!z)&&x.identity){let f=[];x.resolvedStackId&&f.push({stackId:x.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(f.map(async H=>{try{let V=await fetch(`${$}/api/v2/stacks/${H.stackId}`);if(V.ok){let q=await V.json(),X=q.data?.stack||q;H.name=X.displayName||X.name,H.logoUrl=X.logoUrl;}}catch{}return H})).then(Z);}},[x.ready,x.identity,x.resolvedStackId,z,$]),react.useEffect(()=>{a&&A==="success"&&t?.();},[a,A,t]);let Ye=d||(b.length>0?b.filter(f=>f.type==="wallet").map(f=>f.id):["phantom","metamask"]),Ze=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||[]),Ke=K.filter(f=>ke.has(f.id)),be=l?K.filter(f=>!ke.has(f.id)):K,qe=async f=>{I(f),D("connecting"),await T(f)||D("error");},Ct=async()=>{I("phantom"),D("connecting");let f=await y("phantom");D(f?"success":"error");},St=async()=>{I("metamask"),D("connecting");let f=await C();D(f?"success":"error");},xt=async f=>{L("verifying"),G(""),await(g||w)(f)?(L("success"),D("success")):(L("error"),G("Invalid or expired code"),setTimeout(()=>L("idle"),2e3));},Xe=()=>{D(z&&!yt?"stack-select":"select"),I(null),R(false),L("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: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:()=>{Ve(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)),x.ready&&!x.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"&&U&&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%"}})}),s&&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:s}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Xe,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:[P==="phantom"&&jsxRuntime.jsx(fe,{style:W}),P==="metamask"&&jsxRuntime.jsx(ge,{style:W})]}),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:Xe,children:"Cancel"})]}),A==="select"&&!p&&!U&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Ke.map(f=>jsxRuntime.jsxs("button",{onClick:()=>qe(f.id),style:ae,children:[jsxRuntime.jsx(ft,{provider:f.id}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:"#fff"},children:gt(f.id,f.name)})]},f.id)),Ye.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:Ct,disabled:!le,style:{...ae,opacity:le?1:.5,cursor:le?"pointer":"not-allowed"},children:[jsxRuntime.jsx(fe,{style:{...W,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"})]}),Ye.includes("metamask")&&bt&&jsxRuntime.jsxs("button",{onClick:St,style:ae,children:[jsxRuntime.jsx(ge,{style:W}),jsxRuntime.jsx("span",{style:{flex:1,textAlign:"left",fontWeight:500,color:"#fff"},children:"MetaMask"})]}),Ze&&!E&&jsxRuntime.jsxs("button",{onClick:()=>R(true),style:ae,children:[jsxRuntime.jsx("div",{style:{...W,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})]}),Ze&&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:xt,disabled:N==="verifying",error:_}),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!"}),j?.webPageUrl&&N==="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&&Ke.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:()=>qe(f.id),style:ae,children:[jsxRuntime.jsx(ft,{provider:f.id}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:"#fff"},children:gt(f.id,f.name)})]},f.id))]})]})]})}var W={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 ft({provider:e}){switch(e){case "google":return jsxRuntime.jsx(We,{style:{...W,borderRadius:8}});case "discord":return jsxRuntime.jsx(Fe,{style:{...W,borderRadius:8}});case "twitter":return jsxRuntime.jsx(Be,{style:{...W,borderRadius:8}});case "apple":return jsxRuntime.jsx(Ge,{style:{...W,borderRadius:8}});default:return jsxRuntime.jsx("div",{style:{...W,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 gt(e,t){return {google:"Google",discord:"Discord",twitter:"Twitter",apple:"Apple"}[e]||t||e}function vn({mid:e,apiBaseUrl:t="",scope:r,onSave:d,className:u}){let{profile:h,loading:g,saving:i,error:l,updateProfile:c}=je(e,{apiBaseUrl:t,scope:r}),[m,o]=react.useState(null),[a,n]=react.useState(null),[p,s]=react.useState(null),y=react.useRef(null),[C,w]=react.useState(false),T=m??h?.username??"",x=a??h?.bio??"",S=p??h?.avatarUrl,z=react.useCallback(b=>{let U=b.target.files?.[0];if(!U)return;let A=new FileReader;A.onload=()=>{s(A.result),w(true);},A.readAsDataURL(U);},[]),$=async()=>{await c({username:T||void 0,avatarUrl:p??h?.avatarUrl,bio:x||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=r==="global"||!r?"Global profile":`Stack profile (${r.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:S?jsxRuntime.jsx("img",{src:S,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:x,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}),C&&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),s(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 Pn({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 In({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 An({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 Tn(e){let{apiBaseUrl:t,stacknetUrl:r="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 s=await o.json().catch(()=>({})),y=new Error(s.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 s={chain:o,message:n,signature:p,stackId:d};o==="solana"&&(s.publicKey=a);let y=await fetch(`${t}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});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=`${r}/api/v2/stacks/${encodeURIComponent(d)}/auth/web3/challenge`,s=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:o,address:a})});if(!s.ok)throw new Error("Failed to get challenge");let y=await s.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 Un(){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 Je="stackauth_token",Qe="stackauth_session";function Ln(e){return {async storeCredentials(t,r){await e.setItemAsync(Je,t),await e.setItemAsync(Qe,JSON.stringify(r));},async getToken(){try{return await e.getItemAsync(Je)}catch{return null}},async getHeaders(){let t=await this.getToken();return t?{Authorization:`Bearer ${t}`}:{}},async getStoredSession(){try{let t=await e.getItemAsync(Qe);return t?JSON.parse(t):null}catch{return null}},async clear(){await e.deleteItemAsync(Je).catch(()=>{}),await e.deleteItemAsync(Qe).catch(()=>{});}}}
|
|
2
|
+
exports.AppleIcon=Ge;exports.ConnectWidget=Cn;exports.DiscordIcon=Fe;exports.EthereumIcon=In;exports.GoogleIcon=We;exports.MetaMaskIcon=ge;exports.OTPInput=pe;exports.PhantomIcon=fe;exports.ProfileSettings=vn;exports.SolanaIcon=Pn;exports.TelegramIcon=An;exports.TwitterIcon=Be;exports.UserUtilsProvider=dn;exports.cn=It;exports.createAuthClient=Tn;exports.createNativeTransport=Ln;exports.createStackNetClient=ve;exports.createWebTransport=Un;exports.decodeJwtPayloadClient=Mt;exports.formatTokens=Nt;exports.readCSRFCookie=F;exports.readSessionCookie=te;exports.safeUrl=ee;exports.useAuthBridge=xe;exports.useBillingHistory=Kt;exports.useCSRFToken=we;exports.useGoogleOneTap=tn;exports.useJoinCode=sn;exports.usePlans=Ft;exports.usePrepaidCheckout=Vt;exports.useProfile=je;exports.useSession=ne;exports.useStackAuth=Ie;exports.useStackConfig=re;exports.useSubscription=Gt;exports.useUsage=Qt;exports.useUserUtilsContext=cn;exports.useWeb3Wallet=Ce;exports.validateRedirectUrl=At;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './auth-
|
|
2
|
-
export { M as MPCNode, P as PublicSession, S as Session } from './auth-
|
|
3
|
-
export { B as BillingPlan, a as BillingRecord, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, S as Subscription, U as UsageSummary, c as UserUtilsCallbacks, d as UserUtilsConfig } from './config-
|
|
1
|
+
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './auth-c1d7Eji2.cjs';
|
|
2
|
+
export { M as MPCNode, P as PublicSession, S as Session } from './auth-c1d7Eji2.cjs';
|
|
3
|
+
export { B as BillingPlan, a as BillingRecord, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, S as Subscription, U as UsageSummary, c as UserUtilsCallbacks, d as UserUtilsConfig } from './config-CLzVWDrU.cjs';
|
|
4
4
|
export { ProfileScope, ProfileUpdateInput, UserProfile } from './types/index.cjs';
|
|
5
5
|
export { cn, decodeJwtPayloadClient, formatTokens, readCSRFCookie, readSessionCookie, safeUrl, validateRedirectUrl } from './utils/index.cjs';
|
|
6
|
-
export { BridgeIdentity, GoogleOneTapConfig, StackPublicConfig, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, useGoogleOneTap, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.cjs';
|
|
7
|
-
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, ProfileSettings, ProfileSettingsProps, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.cjs';
|
|
6
|
+
export { BridgeIdentity, GoogleOneTapConfig, StackPublicConfig, UseJoinCodeConfig, UseJoinCodeResult, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, useGoogleOneTap, useJoinCode, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.cjs';
|
|
7
|
+
export { AppleIcon, ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, ProfileSettings, ProfileSettingsProps, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.cjs';
|
|
8
8
|
export { createAuthClient } from './core/index.cjs';
|
|
9
|
-
export { A as AuthClient, a as AuthClientConfig, b as AuthTransport } from './types-
|
|
9
|
+
export { A as AuthClient, a as AuthClientConfig, b as AuthTransport } from './types-B_Vj6cr4.cjs';
|
|
10
10
|
export { SecureStorage, createNativeTransport, createWebTransport } from './adapters/index.cjs';
|
|
11
11
|
import 'clsx';
|
|
12
12
|
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './auth-
|
|
2
|
-
export { M as MPCNode, P as PublicSession, S as Session } from './auth-
|
|
3
|
-
export { B as BillingPlan, a as BillingRecord, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, S as Subscription, U as UsageSummary, c as UserUtilsCallbacks, d as UserUtilsConfig } from './config-
|
|
1
|
+
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './auth-c1d7Eji2.js';
|
|
2
|
+
export { M as MPCNode, P as PublicSession, S as Session } from './auth-c1d7Eji2.js';
|
|
3
|
+
export { B as BillingPlan, a as BillingRecord, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, S as Subscription, U as UsageSummary, c as UserUtilsCallbacks, d as UserUtilsConfig } from './config-xNca5ufB.js';
|
|
4
4
|
export { ProfileScope, ProfileUpdateInput, UserProfile } from './types/index.js';
|
|
5
5
|
export { cn, decodeJwtPayloadClient, formatTokens, readCSRFCookie, readSessionCookie, safeUrl, validateRedirectUrl } from './utils/index.js';
|
|
6
|
-
export { BridgeIdentity, GoogleOneTapConfig, StackPublicConfig, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, useGoogleOneTap, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.js';
|
|
7
|
-
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, ProfileSettings, ProfileSettingsProps, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.js';
|
|
6
|
+
export { BridgeIdentity, GoogleOneTapConfig, StackPublicConfig, UseJoinCodeConfig, UseJoinCodeResult, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, useGoogleOneTap, useJoinCode, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.js';
|
|
7
|
+
export { AppleIcon, ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, ProfileSettings, ProfileSettingsProps, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.js';
|
|
8
8
|
export { createAuthClient } from './core/index.js';
|
|
9
|
-
export { A as AuthClient, a as AuthClientConfig, b as AuthTransport } from './types-
|
|
9
|
+
export { A as AuthClient, a as AuthClientConfig, b as AuthTransport } from './types-Cu0do-w-.js';
|
|
10
10
|
export { SecureStorage, createNativeTransport, createWebTransport } from './adapters/index.js';
|
|
11
11
|
import 'clsx';
|
|
12
12
|
import 'react/jsx-runtime';
|