@stacknet/userutils 0.1.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.
@@ -0,0 +1,2 @@
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var J=react.createContext(null);function we(){let e=react.useContext(J);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function ye({config:e,callbacks:n,children:o}){return jsxRuntime.jsx(J.Provider,{value:{config:e,callbacks:n},children:o})}function K(){let[e,n]=react.useState({connected:false,address:null,chain:null,provider:null}),[o,l]=react.useState(null),g=react.useCallback(async(m="phantom")=>{l(null);try{let s=typeof window<"u"?window:null,p=m==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!p)return l(`${m} wallet not found`),null;let t=(await p.connect()).publicKey.toString();return n({connected:!0,address:t,chain:"solana",provider:m}),t}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),y=react.useCallback(async()=>{l(null);try{let s=(typeof window<"u"?window:null)?.ethereum;if(!s)return l("MetaMask not found"),null;let p=s;s.providers?.length&&(p=s.providers.find(r=>r.isMetaMask)||s);let t=(await p.request({method:"eth_requestAccounts"}))[0];return t?(n({connected:!0,address:t,chain:"ethereum",provider:"metamask"}),t):(l("No account selected"),null)}catch(m){return l(m.message||"Failed to connect wallet"),null}},[]),d=react.useCallback(async m=>{l(null);try{if(e.chain==="solana"){let s=typeof window<"u"?window:null,p=e.provider==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!p)throw new Error("Wallet not available");let f=new TextEncoder().encode(m),t=await p.signMessage(f,"utf8"),r=t.signature||t,c="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",u=BigInt(0);for(let N of r)u=u*256n+BigInt(N);let w="";for(;u>0n;)w=c[Number(u%58n)]+w,u=u/58n;for(let N of r)if(N===0)w="1"+w;else break;return w}if(e.chain==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(t=>t.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[m,e.address]})}throw new Error("No wallet connected")}catch(s){return l(s.message||"Signing failed"),null}},[e]),i=react.useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:o,connectSolana:g,connectEVM:y,signMessage:d,disconnect:i}}function X(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(o=>o.trim()).find(o=>o.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 ee(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function ne(){let[e,n]=react.useState(null),[o,l]=react.useState(true),g=react.useCallback(()=>{let i=X();i&&i.expiresAt>Date.now()?n({userId:i.userId,address:i.address,chain:i.chain,expiresAt:i.expiresAt,planId:i.planId,authMethod:i.authMethod}):n(null),l(false);},[]);react.useEffect(()=>{g();},[g]);let y=react.useCallback(async(i="")=>{try{let m=await fetch(`${i}/api/auth/session`);if(m.ok){let s=await m.json();if(s.session)return n(s.session),s.session}return n(null),null}catch{return null}},[]),d=!!e&&e.expiresAt>Date.now();return {session:e,loading:o,isAuthenticated:d,refresh:y,readSession:g}}function ae(e="__csrf",n="x-csrf-token"){let[o,l]=react.useState(null);react.useEffect(()=>{l(ee(e));},[e]);let g=o?{[n]:o}:{};return {token:o,headers:g}}async function oe(e,n,o,l){let g=e.apiVersion||"v2",y=`${e.baseUrl}/api/${g}${o}`;try{let d=await fetch(y,{method:n,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),i=await d.json();return d.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(d){return {success:false,error:{code:"NETWORK_ERROR",message:d instanceof Error?d.message:"Network error"}}}}function re(e){return {getNetworkStatus:()=>oe(e,"GET","/network/status"),getWeb3Challenge:(n,o)=>oe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:n,address:o})}}function le(e){let{wallet:n,connectSolana:o,connectEVM:l,signMessage:g,disconnect:y}=K(),{session:d,isAuthenticated:i,refresh:m,readSession:s}=ne(),{headers:p}=ae(),[f,t]=react.useState(false),[r,c]=react.useState(null),u=e.apiBaseUrl||"",w=e.stacknetUrl||"https://stacknet.magma-rpc.com",N=re({baseUrl:w,stackId:e.stackId||""}),b=react.useCallback(async(x="phantom")=>{t(true),c(null);try{let h=await o(x);if(!h)return t(!1),!1;let M=await N.getWeb3Challenge("solana",h);if(!M.success||!M.data)return c("Failed to get challenge"),t(!1),!1;let v=await g(M.data.message);if(!v)return t(!1),!1;let D=await fetch(`${u}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"solana",message:M.data.message,signature:v,publicKey:h})});if(!D.ok){let R=await D.json().catch(()=>({}));return c(R.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(h){return c(h.message||"Authentication failed"),t(false),false}},[u,N,o,g,s]),S=react.useCallback(async()=>{t(true),c(null);try{let x=await l();if(!x)return t(!1),!1;let h=await N.getWeb3Challenge("ethereum",x);if(!h.success||!h.data)return c("Failed to get challenge"),t(!1),!1;let M=await g(h.data.message);if(!M)return t(!1),!1;let v=await fetch(`${u}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"ethereum",message:h.data.message,signature:M})});if(!v.ok){let D=await v.json().catch(()=>({}));return c(D.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(x){return c(x.message||"Authentication failed"),t(false),false}},[u,N,l,g,s]),I=react.useCallback(async x=>{t(true),c(null);try{let h=await fetch(`${u}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:x})});if(!h.ok){let M=await h.json().catch(()=>({}));return c(M.error||"Invalid code"),t(!1),!1}return s(),t(!1),!0}catch(h){return c(h.message||"OTP verification failed"),t(false),false}},[u,s]),W=react.useCallback(async()=>{try{await fetch(`${u}/api/auth/logout`,{method:"POST",headers:p});}catch{}y(),s();},[u,p,y,s]);return {session:d,isAuthenticated:i,wallet:n,loading:f,error:r,authenticateSolana:b,authenticateEVM:S,authenticateOTP:I,logout:W,refresh:()=>m(u)}}function j({length:e=6,onComplete:n,disabled:o=false,error:l,className:g="",inputClassName:y=""}){let [d,i]=react.useState(Array(e).fill("")),m=react.useCallback((f,t)=>{if(t.length>1){let c=t.replace(/\D/g,"").slice(0,e).split(""),u=[...d];c.forEach((N,b)=>{f+b<e&&(u[f+b]=N);}),i(u);let w=Math.min(f+c.length,e-1);document.getElementById(`userutils-otp-${w}`)?.focus(),u.every(N=>N!=="")&&setTimeout(()=>n(u.join("")),100);return}if(!/^\d?$/.test(t))return;let r=[...d];r[f]=t,i(r),t&&f<e-1&&document.getElementById(`userutils-otp-${f+1}`)?.focus(),t&&f===e-1&&r.every(c=>c!=="")&&setTimeout(()=>n(r.join("")),100);},[d,e,n]),s=react.useCallback((f,t)=>{if(t.key==="Backspace"&&!d[f]&&f>0){document.getElementById(`userutils-otp-${f-1}`)?.focus();let r=[...d];r[f-1]="",i(r);}if(t.key==="Enter"){let r=d.join("");r.length===e&&n(r);}},[d,e,n]);react.useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:g,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:d.map((f,t)=>jsxRuntime.jsx("input",{id:`userutils-otp-${t}`,type:"text",inputMode:"numeric",maxLength:e,value:f,onChange:r=>m(t,r.target.value),onKeyDown:r=>s(t,r),disabled:o,autoFocus:t===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},t))}),l&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}j.displayName="OTPInput";var ve="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function P({className:e}){return jsxRuntime.jsx("img",{src:ve,alt:"Phantom",className:e})}function L({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#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 F({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 V({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 Te({config:e,onSuccess:n,title:o="Log in or Sign up",showWallets:l=["phantom","metamask"],showOTP:g=true,className:y=""}){let{isAuthenticated:d,wallet:i,loading:m,error:s,authenticateSolana:p,authenticateEVM:f,authenticateOTP:t}=le(e),[r,c]=react.useState("select"),[u,w]=react.useState(null),[N,b]=react.useState(false),[S,I]=react.useState("idle"),[W,x]=react.useState(""),[h,M]=react.useState(false),[v,D]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let k=()=>{let Q=window;M(!!(Q.phantom?.solana?.isPhantom||Q.solana?.isPhantom));let _=Q.ethereum;D(!!(_?.isMetaMask||_?.providers?.some(me=>me.isMetaMask)));};k(),window.addEventListener("ethereum#initialized",k);let $=setTimeout(k,500);return ()=>{window.removeEventListener("ethereum#initialized",k),clearTimeout($);}},[]),react.useEffect(()=>{d&&r==="success"&&n?.();},[d,r,n]);let R=async()=>{w("phantom"),c("connecting");let k=await p("phantom");c(k?"success":"error");},pe=async()=>{w("metamask"),c("connecting");let k=await f();c(k?"success":"error");},ge=async k=>{I("verifying"),x(""),await t(k)?(I("success"),c("success")):(I("error"),x("Invalid or expired code"),setTimeout(()=>I("idle"),2e3));},G=()=>{c("select"),w(null),b(false),I("idle"),x("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${y}`,children:[jsxRuntime.jsx("div",{className:"mb-6 text-center",children:jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:o})}),s&&r==="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:G,children:"Try Again"})]}),r==="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..."})]}),r==="connecting"&&m&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxRuntime.jsxs("div",{className:"mx-auto mb-3 h-14 w-14 animate-pulse",children:[u==="phantom"&&jsxRuntime.jsx(P,{className:"h-14 w-14"}),u==="metamask"&&jsxRuntime.jsx(L,{className:"h-14 w-14"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:i.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:G,children:"Cancel"})]}),r==="select"&&!m&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:R,disabled:!h,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${h?"":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(P,{className:"h-14 w-14 flex-shrink-0"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"Phantom"}),!h&&jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsxRuntime.jsx(F,{className:"h-8 w-8"})]}),l.includes("metamask")&&v&&jsxRuntime.jsxs("button",{onClick:pe,className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center bg-white p-2",children:jsxRuntime.jsx(L,{className:"h-10 w-10"})}),jsxRuntime.jsx("div",{className:"flex-1 text-left",children:jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"MetaMask"})}),jsxRuntime.jsx(V,{className:"h-8 w-8"})]}),g&&!N&&jsxRuntime.jsxs("button",{onClick:()=>b(true),className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center border border-zinc-700 bg-[#2a2a3e]",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"28px",viewBox:"0 -960 960 960",width:"28px",fill:"#e3e3e3",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("div",{className:"flex-1 text-left",children:jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"Access Code"})})]}),g&&N&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsxRuntime.jsx(j,{onComplete:ge,disabled:S==="verifying",error:W}),S==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),S==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function Ue({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function je({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function Le({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function We({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
2
+ exports.ConnectWidget=Te;exports.DiscordIcon=Le;exports.EthereumIcon=V;exports.GoogleIcon=je;exports.MetaMaskIcon=L;exports.OTPInput=j;exports.PhantomIcon=P;exports.SolanaIcon=F;exports.TelegramIcon=We;exports.TwitterIcon=Ue;exports.UserUtilsProvider=ye;exports.useUserUtilsContext=we;
@@ -0,0 +1,73 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { f as UserUtilsConfig, e as UserUtilsCallbacks } from '../index-BrziGArs.cjs';
4
+
5
+ interface UserUtilsContextValue {
6
+ config: UserUtilsConfig;
7
+ callbacks?: UserUtilsCallbacks;
8
+ }
9
+ declare function useUserUtilsContext(): UserUtilsContextValue;
10
+ interface UserUtilsProviderProps {
11
+ config: UserUtilsConfig;
12
+ callbacks?: UserUtilsCallbacks;
13
+ children: ReactNode;
14
+ }
15
+ declare function UserUtilsProvider({ config, callbacks, children }: UserUtilsProviderProps): react_jsx_runtime.JSX.Element;
16
+
17
+ interface ConnectWidgetProps {
18
+ config: UserUtilsConfig;
19
+ onSuccess?: () => void;
20
+ title?: string;
21
+ showWallets?: ('phantom' | 'metamask')[];
22
+ showOTP?: boolean;
23
+ showEmail?: boolean;
24
+ className?: string;
25
+ }
26
+ declare function ConnectWidget({ config, onSuccess, title, showWallets, showOTP, className, }: ConnectWidgetProps): react_jsx_runtime.JSX.Element;
27
+
28
+ interface OTPInputProps {
29
+ length?: number;
30
+ onComplete: (code: string) => void;
31
+ disabled?: boolean;
32
+ error?: string;
33
+ className?: string;
34
+ inputClassName?: string;
35
+ }
36
+ declare function OTPInput({ length, onComplete, disabled, error, className, inputClassName, }: OTPInputProps): react_jsx_runtime.JSX.Element;
37
+ declare namespace OTPInput {
38
+ var displayName: string;
39
+ }
40
+
41
+ declare function PhantomIcon({ className }: {
42
+ className?: string;
43
+ }): react_jsx_runtime.JSX.Element;
44
+
45
+ declare function MetaMaskIcon({ className }: {
46
+ className?: string;
47
+ }): react_jsx_runtime.JSX.Element;
48
+
49
+ declare function SolanaIcon({ className }: {
50
+ className?: string;
51
+ }): react_jsx_runtime.JSX.Element;
52
+
53
+ declare function EthereumIcon({ className }: {
54
+ className?: string;
55
+ }): react_jsx_runtime.JSX.Element;
56
+
57
+ declare function TwitterIcon({ className }: {
58
+ className?: string;
59
+ }): react_jsx_runtime.JSX.Element;
60
+
61
+ declare function GoogleIcon({ className }: {
62
+ className?: string;
63
+ }): react_jsx_runtime.JSX.Element;
64
+
65
+ declare function DiscordIcon({ className }: {
66
+ className?: string;
67
+ }): react_jsx_runtime.JSX.Element;
68
+
69
+ declare function TelegramIcon({ className }: {
70
+ className?: string;
71
+ }): react_jsx_runtime.JSX.Element;
72
+
73
+ export { ConnectWidget, type ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, type OTPInputProps, PhantomIcon, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, type UserUtilsProviderProps, useUserUtilsContext };
@@ -0,0 +1,73 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { f as UserUtilsConfig, e as UserUtilsCallbacks } from '../index-BrziGArs.js';
4
+
5
+ interface UserUtilsContextValue {
6
+ config: UserUtilsConfig;
7
+ callbacks?: UserUtilsCallbacks;
8
+ }
9
+ declare function useUserUtilsContext(): UserUtilsContextValue;
10
+ interface UserUtilsProviderProps {
11
+ config: UserUtilsConfig;
12
+ callbacks?: UserUtilsCallbacks;
13
+ children: ReactNode;
14
+ }
15
+ declare function UserUtilsProvider({ config, callbacks, children }: UserUtilsProviderProps): react_jsx_runtime.JSX.Element;
16
+
17
+ interface ConnectWidgetProps {
18
+ config: UserUtilsConfig;
19
+ onSuccess?: () => void;
20
+ title?: string;
21
+ showWallets?: ('phantom' | 'metamask')[];
22
+ showOTP?: boolean;
23
+ showEmail?: boolean;
24
+ className?: string;
25
+ }
26
+ declare function ConnectWidget({ config, onSuccess, title, showWallets, showOTP, className, }: ConnectWidgetProps): react_jsx_runtime.JSX.Element;
27
+
28
+ interface OTPInputProps {
29
+ length?: number;
30
+ onComplete: (code: string) => void;
31
+ disabled?: boolean;
32
+ error?: string;
33
+ className?: string;
34
+ inputClassName?: string;
35
+ }
36
+ declare function OTPInput({ length, onComplete, disabled, error, className, inputClassName, }: OTPInputProps): react_jsx_runtime.JSX.Element;
37
+ declare namespace OTPInput {
38
+ var displayName: string;
39
+ }
40
+
41
+ declare function PhantomIcon({ className }: {
42
+ className?: string;
43
+ }): react_jsx_runtime.JSX.Element;
44
+
45
+ declare function MetaMaskIcon({ className }: {
46
+ className?: string;
47
+ }): react_jsx_runtime.JSX.Element;
48
+
49
+ declare function SolanaIcon({ className }: {
50
+ className?: string;
51
+ }): react_jsx_runtime.JSX.Element;
52
+
53
+ declare function EthereumIcon({ className }: {
54
+ className?: string;
55
+ }): react_jsx_runtime.JSX.Element;
56
+
57
+ declare function TwitterIcon({ className }: {
58
+ className?: string;
59
+ }): react_jsx_runtime.JSX.Element;
60
+
61
+ declare function GoogleIcon({ className }: {
62
+ className?: string;
63
+ }): react_jsx_runtime.JSX.Element;
64
+
65
+ declare function DiscordIcon({ className }: {
66
+ className?: string;
67
+ }): react_jsx_runtime.JSX.Element;
68
+
69
+ declare function TelegramIcon({ className }: {
70
+ className?: string;
71
+ }): react_jsx_runtime.JSX.Element;
72
+
73
+ export { ConnectWidget, type ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, type OTPInputProps, PhantomIcon, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, type UserUtilsProviderProps, useUserUtilsContext };
@@ -0,0 +1,2 @@
1
+ import {createContext,useContext,useState,useCallback,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var J=createContext(null);function we(){let e=useContext(J);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function ye({config:e,callbacks:n,children:o}){return jsx(J.Provider,{value:{config:e,callbacks:n},children:o})}function K(){let[e,n]=useState({connected:false,address:null,chain:null,provider:null}),[o,l]=useState(null),g=useCallback(async(m="phantom")=>{l(null);try{let s=typeof window<"u"?window:null,p=m==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!p)return l(`${m} wallet not found`),null;let t=(await p.connect()).publicKey.toString();return n({connected:!0,address:t,chain:"solana",provider:m}),t}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),y=useCallback(async()=>{l(null);try{let s=(typeof window<"u"?window:null)?.ethereum;if(!s)return l("MetaMask not found"),null;let p=s;s.providers?.length&&(p=s.providers.find(r=>r.isMetaMask)||s);let t=(await p.request({method:"eth_requestAccounts"}))[0];return t?(n({connected:!0,address:t,chain:"ethereum",provider:"metamask"}),t):(l("No account selected"),null)}catch(m){return l(m.message||"Failed to connect wallet"),null}},[]),d=useCallback(async m=>{l(null);try{if(e.chain==="solana"){let s=typeof window<"u"?window:null,p=e.provider==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!p)throw new Error("Wallet not available");let f=new TextEncoder().encode(m),t=await p.signMessage(f,"utf8"),r=t.signature||t,c="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",u=BigInt(0);for(let N of r)u=u*256n+BigInt(N);let w="";for(;u>0n;)w=c[Number(u%58n)]+w,u=u/58n;for(let N of r)if(N===0)w="1"+w;else break;return w}if(e.chain==="ethereum"){let p=(typeof window<"u"?window:null)?.ethereum;if(p?.providers?.length&&(p=p.providers.find(t=>t.isMetaMask)||p),!p)throw new Error("MetaMask not available");return await p.request({method:"personal_sign",params:[m,e.address]})}throw new Error("No wallet connected")}catch(s){return l(s.message||"Signing failed"),null}},[e]),i=useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:o,connectSolana:g,connectEVM:y,signMessage:d,disconnect:i}}function X(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(o=>o.trim()).find(o=>o.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 ee(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function ne(){let[e,n]=useState(null),[o,l]=useState(true),g=useCallback(()=>{let i=X();i&&i.expiresAt>Date.now()?n({userId:i.userId,address:i.address,chain:i.chain,expiresAt:i.expiresAt,planId:i.planId,authMethod:i.authMethod}):n(null),l(false);},[]);useEffect(()=>{g();},[g]);let y=useCallback(async(i="")=>{try{let m=await fetch(`${i}/api/auth/session`);if(m.ok){let s=await m.json();if(s.session)return n(s.session),s.session}return n(null),null}catch{return null}},[]),d=!!e&&e.expiresAt>Date.now();return {session:e,loading:o,isAuthenticated:d,refresh:y,readSession:g}}function ae(e="__csrf",n="x-csrf-token"){let[o,l]=useState(null);useEffect(()=>{l(ee(e));},[e]);let g=o?{[n]:o}:{};return {token:o,headers:g}}async function oe(e,n,o,l){let g=e.apiVersion||"v2",y=`${e.baseUrl}/api/${g}${o}`;try{let d=await fetch(y,{method:n,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),i=await d.json();return d.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(d){return {success:false,error:{code:"NETWORK_ERROR",message:d instanceof Error?d.message:"Network error"}}}}function re(e){return {getNetworkStatus:()=>oe(e,"GET","/network/status"),getWeb3Challenge:(n,o)=>oe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:n,address:o})}}function le(e){let{wallet:n,connectSolana:o,connectEVM:l,signMessage:g,disconnect:y}=K(),{session:d,isAuthenticated:i,refresh:m,readSession:s}=ne(),{headers:p}=ae(),[f,t]=useState(false),[r,c]=useState(null),u=e.apiBaseUrl||"",w=e.stacknetUrl||"https://stacknet.magma-rpc.com",N=re({baseUrl:w,stackId:e.stackId||""}),b=useCallback(async(x="phantom")=>{t(true),c(null);try{let h=await o(x);if(!h)return t(!1),!1;let M=await N.getWeb3Challenge("solana",h);if(!M.success||!M.data)return c("Failed to get challenge"),t(!1),!1;let v=await g(M.data.message);if(!v)return t(!1),!1;let D=await fetch(`${u}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"solana",message:M.data.message,signature:v,publicKey:h})});if(!D.ok){let R=await D.json().catch(()=>({}));return c(R.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(h){return c(h.message||"Authentication failed"),t(false),false}},[u,N,o,g,s]),S=useCallback(async()=>{t(true),c(null);try{let x=await l();if(!x)return t(!1),!1;let h=await N.getWeb3Challenge("ethereum",x);if(!h.success||!h.data)return c("Failed to get challenge"),t(!1),!1;let M=await g(h.data.message);if(!M)return t(!1),!1;let v=await fetch(`${u}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"ethereum",message:h.data.message,signature:M})});if(!v.ok){let D=await v.json().catch(()=>({}));return c(D.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(x){return c(x.message||"Authentication failed"),t(false),false}},[u,N,l,g,s]),I=useCallback(async x=>{t(true),c(null);try{let h=await fetch(`${u}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:x})});if(!h.ok){let M=await h.json().catch(()=>({}));return c(M.error||"Invalid code"),t(!1),!1}return s(),t(!1),!0}catch(h){return c(h.message||"OTP verification failed"),t(false),false}},[u,s]),W=useCallback(async()=>{try{await fetch(`${u}/api/auth/logout`,{method:"POST",headers:p});}catch{}y(),s();},[u,p,y,s]);return {session:d,isAuthenticated:i,wallet:n,loading:f,error:r,authenticateSolana:b,authenticateEVM:S,authenticateOTP:I,logout:W,refresh:()=>m(u)}}function j({length:e=6,onComplete:n,disabled:o=false,error:l,className:g="",inputClassName:y=""}){let [d,i]=useState(Array(e).fill("")),m=useCallback((f,t)=>{if(t.length>1){let c=t.replace(/\D/g,"").slice(0,e).split(""),u=[...d];c.forEach((N,b)=>{f+b<e&&(u[f+b]=N);}),i(u);let w=Math.min(f+c.length,e-1);document.getElementById(`userutils-otp-${w}`)?.focus(),u.every(N=>N!=="")&&setTimeout(()=>n(u.join("")),100);return}if(!/^\d?$/.test(t))return;let r=[...d];r[f]=t,i(r),t&&f<e-1&&document.getElementById(`userutils-otp-${f+1}`)?.focus(),t&&f===e-1&&r.every(c=>c!=="")&&setTimeout(()=>n(r.join("")),100);},[d,e,n]),s=useCallback((f,t)=>{if(t.key==="Backspace"&&!d[f]&&f>0){document.getElementById(`userutils-otp-${f-1}`)?.focus();let r=[...d];r[f-1]="",i(r);}if(t.key==="Enter"){let r=d.join("");r.length===e&&n(r);}},[d,e,n]);useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:g,children:[jsx("div",{className:"flex gap-2 justify-center",children:d.map((f,t)=>jsx("input",{id:`userutils-otp-${t}`,type:"text",inputMode:"numeric",maxLength:e,value:f,onChange:r=>m(t,r.target.value),onKeyDown:r=>s(t,r),disabled:o,autoFocus:t===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},t))}),l&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}j.displayName="OTPInput";var ve="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function P({className:e}){return jsx("img",{src:ve,alt:"Phantom",className:e})}function L({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#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 F({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function V({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Te({config:e,onSuccess:n,title:o="Log in or Sign up",showWallets:l=["phantom","metamask"],showOTP:g=true,className:y=""}){let{isAuthenticated:d,wallet:i,loading:m,error:s,authenticateSolana:p,authenticateEVM:f,authenticateOTP:t}=le(e),[r,c]=useState("select"),[u,w]=useState(null),[N,b]=useState(false),[S,I]=useState("idle"),[W,x]=useState(""),[h,M]=useState(false),[v,D]=useState(false);useEffect(()=>{if(typeof window>"u")return;let k=()=>{let Q=window;M(!!(Q.phantom?.solana?.isPhantom||Q.solana?.isPhantom));let _=Q.ethereum;D(!!(_?.isMetaMask||_?.providers?.some(me=>me.isMetaMask)));};k(),window.addEventListener("ethereum#initialized",k);let $=setTimeout(k,500);return ()=>{window.removeEventListener("ethereum#initialized",k),clearTimeout($);}},[]),useEffect(()=>{d&&r==="success"&&n?.();},[d,r,n]);let R=async()=>{w("phantom"),c("connecting");let k=await p("phantom");c(k?"success":"error");},pe=async()=>{w("metamask"),c("connecting");let k=await f();c(k?"success":"error");},ge=async k=>{I("verifying"),x(""),await t(k)?(I("success"),c("success")):(I("error"),x("Invalid or expired code"),setTimeout(()=>I("idle"),2e3));},G=()=>{c("select"),w(null),b(false),I("idle"),x("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${y}`,children:[jsx("div",{className:"mb-6 text-center",children:jsx("h1",{className:"font-semibold text-2xl text-white",children:o})}),s&&r==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:s}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:G,children:"Try Again"})]}),r==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),r==="connecting"&&m&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxs("div",{className:"mx-auto mb-3 h-14 w-14 animate-pulse",children:[u==="phantom"&&jsx(P,{className:"h-14 w-14"}),u==="metamask"&&jsx(L,{className:"h-14 w-14"})]}),jsx("p",{className:"font-medium text-sm text-white",children:i.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:G,children:"Cancel"})]}),r==="select"&&!m&&jsxs(Fragment,{children:[l.includes("phantom")&&jsxs("button",{onClick:R,disabled:!h,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${h?"":"cursor-not-allowed opacity-50"}`,children:[jsx(P,{className:"h-14 w-14 flex-shrink-0"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-lg text-white",children:"Phantom"}),!h&&jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsx(F,{className:"h-8 w-8"})]}),l.includes("metamask")&&v&&jsxs("button",{onClick:pe,className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center bg-white p-2",children:jsx(L,{className:"h-10 w-10"})}),jsx("div",{className:"flex-1 text-left",children:jsx("span",{className:"font-medium text-lg text-white",children:"MetaMask"})}),jsx(V,{className:"h-8 w-8"})]}),g&&!N&&jsxs("button",{onClick:()=>b(true),className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center border border-zinc-700 bg-[#2a2a3e]",children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"28px",viewBox:"0 -960 960 960",width:"28px",fill:"#e3e3e3",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("div",{className:"flex-1 text-left",children:jsx("span",{className:"font-medium text-lg text-white",children:"Access Code"})})]}),g&&N&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsx(j,{onComplete:ge,disabled:S==="verifying",error:W}),S==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),S==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function Ue({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function je({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function Le({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function We({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
2
+ export{Te as ConnectWidget,Le as DiscordIcon,V as EthereumIcon,je as GoogleIcon,L as MetaMaskIcon,j as OTPInput,P as PhantomIcon,F as SolanaIcon,We as TelegramIcon,Ue as TwitterIcon,ye as UserUtilsProvider,we as useUserUtilsContext};
@@ -0,0 +1,2 @@
1
+ 'use strict';var react=require('react');function A(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith("stackauth_session="));if(!e)return null;let i=e.slice(18);return JSON.parse(atob(i.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function k(e="__csrf"){if(typeof document>"u")return null;let i=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${e}=`));return i?i.slice(e.length+1):null}function R(){let[e,i]=react.useState(null),[o,l]=react.useState(true),c=react.useCallback(()=>{let n=A();n&&n.expiresAt>Date.now()?i({userId:n.userId,address:n.address,chain:n.chain,expiresAt:n.expiresAt,planId:n.planId,authMethod:n.authMethod}):i(null),l(false);},[]);react.useEffect(()=>{c();},[c]);let f=react.useCallback(async(n="")=>{try{let s=await fetch(`${n}/api/auth/session`);if(s.ok){let t=await s.json();if(t.session)return i(t.session),t.session}return i(null),null}catch{return null}},[]),u=!!e&&e.expiresAt>Date.now();return {session:e,loading:o,isAuthenticated:u,refresh:f,readSession:c}}function E(e="__csrf",i="x-csrf-token"){let[o,l]=react.useState(null);react.useEffect(()=>{l(k(e));},[e]);let c=o?{[i]:o}:{};return {token:o,headers:c}}function N(){let[e,i]=react.useState({connected:false,address:null,chain:null,provider:null}),[o,l]=react.useState(null),c=react.useCallback(async(s="phantom")=>{l(null);try{let t=typeof window<"u"?window:null,r=s==="phantom"?t?.phantom?.solana||t?.solana:t?.solflare;if(!r)return l(`${s} wallet not found`),null;let a=(await r.connect()).publicKey.toString();return i({connected:!0,address:a,chain:"solana",provider:s}),a}catch(t){return l(t.message||"Failed to connect wallet"),null}},[]),f=react.useCallback(async()=>{l(null);try{let t=(typeof window<"u"?window:null)?.ethereum;if(!t)return l("MetaMask not found"),null;let r=t;t.providers?.length&&(r=t.providers.find(m=>m.isMetaMask)||t);let a=(await r.request({method:"eth_requestAccounts"}))[0];return a?(i({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(l("No account selected"),null)}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),u=react.useCallback(async s=>{l(null);try{if(e.chain==="solana"){let t=typeof window<"u"?window:null,r=e.provider==="phantom"?t?.phantom?.solana||t?.solana:t?.solflare;if(!r)throw new Error("Wallet not available");let d=new TextEncoder().encode(s),a=await r.signMessage(d,"utf8"),m=a.signature||a,h="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",p=BigInt(0);for(let w of m)p=p*256n+BigInt(w);let S="";for(;p>0n;)S=h[Number(p%58n)]+S,p=p/58n;for(let w of m)if(w===0)S="1"+S;else break;return S}if(e.chain==="ethereum"){let r=(typeof window<"u"?window:null)?.ethereum;if(r?.providers?.length&&(r=r.providers.find(a=>a.isMetaMask)||r),!r)throw new Error("MetaMask not available");return await r.request({method:"personal_sign",params:[s,e.address]})}throw new Error("No wallet connected")}catch(t){return l(t.message||"Signing failed"),null}},[e]),n=react.useCallback(()=>{i({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:o,connectSolana:c,connectEVM:f,signMessage:u,disconnect:n}}async function _(e,i,o,l){let c=e.apiVersion||"v2",f=`${e.baseUrl}/api/${c}${o}`;try{let u=await fetch(f,{method:i,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),n=await u.json();return u.ok?n.success&&n.data!==void 0?{success:!0,data:n.data}:{success:!0,data:n}:{success:!1,error:n.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(u){return {success:false,error:{code:"NETWORK_ERROR",message:u instanceof Error?u.message:"Network error"}}}}function J(e){return {getNetworkStatus:()=>_(e,"GET","/network/status"),getWeb3Challenge:(i,o)=>_(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:i,address:o})}}function X(e){let{wallet:i,connectSolana:o,connectEVM:l,signMessage:c,disconnect:f}=N(),{session:u,isAuthenticated:n,refresh:s,readSession:t}=R(),{headers:r}=E(),[d,a]=react.useState(false),[m,h]=react.useState(null),p=e.apiBaseUrl||"",S=e.stacknetUrl||"https://stacknet.magma-rpc.com",w=J({baseUrl:S,stackId:e.stackId||""}),q=react.useCallback(async(b="phantom")=>{a(true),h(null);try{let g=await o(b);if(!g)return a(!1),!1;let y=await w.getWeb3Challenge("solana",g);if(!y.success||!y.data)return h("Failed to get challenge"),a(!1),!1;let C=await c(y.data.message);if(!C)return a(!1),!1;let P=await fetch(`${p}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"solana",message:y.data.message,signature:C,publicKey:g})});if(!P.ok){let G=await P.json().catch(()=>({}));return h(G.error||"Authentication failed"),a(!1),!1}return t(),a(!1),!0}catch(g){return h(g.message||"Authentication failed"),a(false),false}},[p,w,o,c,t]),H=react.useCallback(async()=>{a(true),h(null);try{let b=await l();if(!b)return a(!1),!1;let g=await w.getWeb3Challenge("ethereum",b);if(!g.success||!g.data)return h("Failed to get challenge"),a(!1),!1;let y=await c(g.data.message);if(!y)return a(!1),!1;let C=await fetch(`${p}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"ethereum",message:g.data.message,signature:y})});if(!C.ok){let P=await C.json().catch(()=>({}));return h(P.error||"Authentication failed"),a(!1),!1}return t(),a(!1),!0}catch(b){return h(b.message||"Authentication failed"),a(false),false}},[p,w,l,c,t]),K=react.useCallback(async b=>{a(true),h(null);try{let g=await fetch(`${p}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:b})});if(!g.ok){let y=await g.json().catch(()=>({}));return h(y.error||"Invalid code"),a(!1),!1}return t(),a(!1),!0}catch(g){return h(g.message||"OTP verification failed"),a(false),false}},[p,t]),D=react.useCallback(async()=>{try{await fetch(`${p}/api/auth/logout`,{method:"POST",headers:r});}catch{}f(),t();},[p,r,f,t]);return {session:u,isAuthenticated:n,wallet:i,loading:d,error:m,authenticateSolana:q,authenticateEVM:H,authenticateOTP:K,logout:D,refresh:()=>s(p)}}function ee(e=""){let[i,o]=react.useState([]),[l,c]=react.useState(true),[f,u]=react.useState(null),n=react.useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/plans`);if(s.ok){let t=await s.json();o(t.plans||t||[]);}}catch(s){u(s.message);}finally{c(false);}},[e]);return react.useEffect(()=>{n();},[n]),{plans:i,loading:l,error:f,refresh:n}}function ne(e=""){let[i,o]=react.useState(null),[l,c]=react.useState(true),[f,u]=react.useState(null),n=react.useCallback(async()=>{try{let r=await fetch(`${e}/api/billing/subscription`);if(r.ok){let d=await r.json();o(d.plan?d:null);}}catch(r){u(r.message);}finally{c(false);}},[e]);react.useEffect(()=>{n();},[n]);let s=react.useCallback(async r=>{let d=k(),m=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...d?{"x-csrf-token":d}:{}},body:JSON.stringify({planId:r})})).json();return m.url||m.checkoutUrl||null},[e]),t=react.useCallback(async()=>{let r=k();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:r?{"x-csrf-token":r}:{}})).ok?(await n(),true):false},[e,n]);return {subscription:i,loading:l,error:f,refresh:n,subscribe:s,cancel:t}}function ae(e=""){let[i,o]=react.useState(null),[l,c]=react.useState(true),[f,u]=react.useState(null),n=react.useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/usage`);if(s.ok){let t=await s.json();o(t);}}catch(s){u(s.message);}finally{c(false);}},[e]);return react.useEffect(()=>{n();},[n]),{usage:i,loading:l,error:f,refresh:n}}function oe(e=""){let[i,o]=react.useState(false),[l,c]=react.useState(null),f=react.useCallback(async n=>{o(true),c(null);try{let s=k(),t=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({amountCents:n})}),r=await t.json();return t.ok?r.url||null:(c(r.error||"Purchase failed"),null)}catch(s){return c(s.message),null}finally{o(false);}},[e]),u=react.useCallback(async n=>{o(true),c(null);try{let s=k(),t=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({sessionId:n})}),r=await t.json();return t.ok?r:(c(r.error||"Verification failed"),null)}catch(s){return c(s.message),null}finally{o(false);}},[e]);return {purchase:f,verifySession:u,loading:i,error:l}}function ce(e="",i){let[o,l]=react.useState([]),[c,f]=react.useState(true),[u,n]=react.useState(null),s=i?.limit||50,t=i?.offset||0,r=react.useCallback(async()=>{try{let d=await fetch(`${e}/api/billing/history?limit=${s}&offset=${t}`);if(d.ok){let a=await d.json();l(a.records||a.history||(Array.isArray(a)?a:[]));}}catch(d){n(d.message);}finally{f(false);}},[e,s,t]);return react.useEffect(()=>{r();},[r]),{records:o,loading:c,error:u,refresh:r}}
2
+ exports.useBillingHistory=ce;exports.useCSRFToken=E;exports.usePlans=ee;exports.usePrepaidCheckout=oe;exports.useSession=R;exports.useStackAuth=X;exports.useSubscription=ne;exports.useUsage=ae;exports.useWeb3Wallet=N;
@@ -0,0 +1,101 @@
1
+ import { c as PublicSession, W as Web3Chain, f as UserUtilsConfig, B as BillingPlan, d as Subscription, U as UsageSummary, b as PrepaidVerifyResult, a as BillingRecord } from '../index-BrziGArs.cjs';
2
+
3
+ /**
4
+ * Hook to read the public session cookie for UI state.
5
+ * Never exposes the JWT — only the public projection (userId, address, expiresAt).
6
+ */
7
+ declare function useSession(): {
8
+ session: PublicSession | null;
9
+ loading: boolean;
10
+ isAuthenticated: boolean;
11
+ refresh: (apiBaseUrl?: string) => Promise<any>;
12
+ readSession: () => void;
13
+ };
14
+
15
+ /**
16
+ * Hook to read the CSRF token cookie.
17
+ * Returns the token and a headers object to include in mutation requests.
18
+ */
19
+ declare function useCSRFToken(cookieName?: string, headerName?: string): {
20
+ token: string | null;
21
+ headers: Record<string, string>;
22
+ };
23
+
24
+ interface WalletState {
25
+ connected: boolean;
26
+ address: string | null;
27
+ chain: Web3Chain | null;
28
+ provider: 'phantom' | 'solflare' | 'metamask' | null;
29
+ }
30
+ /**
31
+ * Hook for connecting Web3 wallets (Phantom, Solflare, MetaMask).
32
+ * Handles wallet detection, connection, and message signing.
33
+ */
34
+ declare function useWeb3Wallet(): {
35
+ wallet: WalletState;
36
+ error: string | null;
37
+ connectSolana: (provider?: "phantom" | "solflare") => Promise<string | null>;
38
+ connectEVM: () => Promise<string | null>;
39
+ signMessage: (message: string) => Promise<string | null>;
40
+ disconnect: () => void;
41
+ };
42
+
43
+ /**
44
+ * Master auth hook — combines wallet connection, challenge/sign/verify,
45
+ * OTP, and session management. All auth state flows through server routes
46
+ * (HttpOnly cookies), never touches localStorage or document.cookie directly.
47
+ */
48
+ declare function useStackAuth(config: UserUtilsConfig): {
49
+ session: PublicSession | null;
50
+ isAuthenticated: boolean;
51
+ wallet: WalletState;
52
+ loading: boolean;
53
+ error: string | null;
54
+ authenticateSolana: (provider?: "phantom" | "solflare") => Promise<boolean>;
55
+ authenticateEVM: () => Promise<boolean>;
56
+ authenticateOTP: (code: string) => Promise<boolean>;
57
+ logout: () => Promise<void>;
58
+ refresh: () => Promise<any>;
59
+ };
60
+
61
+ declare function usePlans(apiBaseUrl?: string): {
62
+ plans: BillingPlan[];
63
+ loading: boolean;
64
+ error: string | null;
65
+ refresh: () => Promise<void>;
66
+ };
67
+
68
+ declare function useSubscription(apiBaseUrl?: string): {
69
+ subscription: Subscription | null;
70
+ loading: boolean;
71
+ error: string | null;
72
+ refresh: () => Promise<void>;
73
+ subscribe: (planId: string) => Promise<string | null>;
74
+ cancel: () => Promise<boolean>;
75
+ };
76
+
77
+ declare function useUsage(apiBaseUrl?: string): {
78
+ usage: UsageSummary | null;
79
+ loading: boolean;
80
+ error: string | null;
81
+ refresh: () => Promise<void>;
82
+ };
83
+
84
+ declare function usePrepaidCheckout(apiBaseUrl?: string): {
85
+ purchase: (amountCents: number) => Promise<string | null>;
86
+ verifySession: (sessionId: string) => Promise<PrepaidVerifyResult | null>;
87
+ loading: boolean;
88
+ error: string | null;
89
+ };
90
+
91
+ declare function useBillingHistory(apiBaseUrl?: string, opts?: {
92
+ limit?: number;
93
+ offset?: number;
94
+ }): {
95
+ records: BillingRecord[];
96
+ loading: boolean;
97
+ error: string | null;
98
+ refresh: () => Promise<void>;
99
+ };
100
+
101
+ export { type WalletState, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet };
@@ -0,0 +1,101 @@
1
+ import { c as PublicSession, W as Web3Chain, f as UserUtilsConfig, B as BillingPlan, d as Subscription, U as UsageSummary, b as PrepaidVerifyResult, a as BillingRecord } from '../index-BrziGArs.js';
2
+
3
+ /**
4
+ * Hook to read the public session cookie for UI state.
5
+ * Never exposes the JWT — only the public projection (userId, address, expiresAt).
6
+ */
7
+ declare function useSession(): {
8
+ session: PublicSession | null;
9
+ loading: boolean;
10
+ isAuthenticated: boolean;
11
+ refresh: (apiBaseUrl?: string) => Promise<any>;
12
+ readSession: () => void;
13
+ };
14
+
15
+ /**
16
+ * Hook to read the CSRF token cookie.
17
+ * Returns the token and a headers object to include in mutation requests.
18
+ */
19
+ declare function useCSRFToken(cookieName?: string, headerName?: string): {
20
+ token: string | null;
21
+ headers: Record<string, string>;
22
+ };
23
+
24
+ interface WalletState {
25
+ connected: boolean;
26
+ address: string | null;
27
+ chain: Web3Chain | null;
28
+ provider: 'phantom' | 'solflare' | 'metamask' | null;
29
+ }
30
+ /**
31
+ * Hook for connecting Web3 wallets (Phantom, Solflare, MetaMask).
32
+ * Handles wallet detection, connection, and message signing.
33
+ */
34
+ declare function useWeb3Wallet(): {
35
+ wallet: WalletState;
36
+ error: string | null;
37
+ connectSolana: (provider?: "phantom" | "solflare") => Promise<string | null>;
38
+ connectEVM: () => Promise<string | null>;
39
+ signMessage: (message: string) => Promise<string | null>;
40
+ disconnect: () => void;
41
+ };
42
+
43
+ /**
44
+ * Master auth hook — combines wallet connection, challenge/sign/verify,
45
+ * OTP, and session management. All auth state flows through server routes
46
+ * (HttpOnly cookies), never touches localStorage or document.cookie directly.
47
+ */
48
+ declare function useStackAuth(config: UserUtilsConfig): {
49
+ session: PublicSession | null;
50
+ isAuthenticated: boolean;
51
+ wallet: WalletState;
52
+ loading: boolean;
53
+ error: string | null;
54
+ authenticateSolana: (provider?: "phantom" | "solflare") => Promise<boolean>;
55
+ authenticateEVM: () => Promise<boolean>;
56
+ authenticateOTP: (code: string) => Promise<boolean>;
57
+ logout: () => Promise<void>;
58
+ refresh: () => Promise<any>;
59
+ };
60
+
61
+ declare function usePlans(apiBaseUrl?: string): {
62
+ plans: BillingPlan[];
63
+ loading: boolean;
64
+ error: string | null;
65
+ refresh: () => Promise<void>;
66
+ };
67
+
68
+ declare function useSubscription(apiBaseUrl?: string): {
69
+ subscription: Subscription | null;
70
+ loading: boolean;
71
+ error: string | null;
72
+ refresh: () => Promise<void>;
73
+ subscribe: (planId: string) => Promise<string | null>;
74
+ cancel: () => Promise<boolean>;
75
+ };
76
+
77
+ declare function useUsage(apiBaseUrl?: string): {
78
+ usage: UsageSummary | null;
79
+ loading: boolean;
80
+ error: string | null;
81
+ refresh: () => Promise<void>;
82
+ };
83
+
84
+ declare function usePrepaidCheckout(apiBaseUrl?: string): {
85
+ purchase: (amountCents: number) => Promise<string | null>;
86
+ verifySession: (sessionId: string) => Promise<PrepaidVerifyResult | null>;
87
+ loading: boolean;
88
+ error: string | null;
89
+ };
90
+
91
+ declare function useBillingHistory(apiBaseUrl?: string, opts?: {
92
+ limit?: number;
93
+ offset?: number;
94
+ }): {
95
+ records: BillingRecord[];
96
+ loading: boolean;
97
+ error: string | null;
98
+ refresh: () => Promise<void>;
99
+ };
100
+
101
+ export { type WalletState, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet };
@@ -0,0 +1,2 @@
1
+ import {useState,useCallback,useEffect}from'react';function A(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith("stackauth_session="));if(!e)return null;let i=e.slice(18);return JSON.parse(atob(i.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function k(e="__csrf"){if(typeof document>"u")return null;let i=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${e}=`));return i?i.slice(e.length+1):null}function R(){let[e,i]=useState(null),[o,l]=useState(true),c=useCallback(()=>{let n=A();n&&n.expiresAt>Date.now()?i({userId:n.userId,address:n.address,chain:n.chain,expiresAt:n.expiresAt,planId:n.planId,authMethod:n.authMethod}):i(null),l(false);},[]);useEffect(()=>{c();},[c]);let f=useCallback(async(n="")=>{try{let s=await fetch(`${n}/api/auth/session`);if(s.ok){let t=await s.json();if(t.session)return i(t.session),t.session}return i(null),null}catch{return null}},[]),u=!!e&&e.expiresAt>Date.now();return {session:e,loading:o,isAuthenticated:u,refresh:f,readSession:c}}function E(e="__csrf",i="x-csrf-token"){let[o,l]=useState(null);useEffect(()=>{l(k(e));},[e]);let c=o?{[i]:o}:{};return {token:o,headers:c}}function N(){let[e,i]=useState({connected:false,address:null,chain:null,provider:null}),[o,l]=useState(null),c=useCallback(async(s="phantom")=>{l(null);try{let t=typeof window<"u"?window:null,r=s==="phantom"?t?.phantom?.solana||t?.solana:t?.solflare;if(!r)return l(`${s} wallet not found`),null;let a=(await r.connect()).publicKey.toString();return i({connected:!0,address:a,chain:"solana",provider:s}),a}catch(t){return l(t.message||"Failed to connect wallet"),null}},[]),f=useCallback(async()=>{l(null);try{let t=(typeof window<"u"?window:null)?.ethereum;if(!t)return l("MetaMask not found"),null;let r=t;t.providers?.length&&(r=t.providers.find(m=>m.isMetaMask)||t);let a=(await r.request({method:"eth_requestAccounts"}))[0];return a?(i({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(l("No account selected"),null)}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),u=useCallback(async s=>{l(null);try{if(e.chain==="solana"){let t=typeof window<"u"?window:null,r=e.provider==="phantom"?t?.phantom?.solana||t?.solana:t?.solflare;if(!r)throw new Error("Wallet not available");let d=new TextEncoder().encode(s),a=await r.signMessage(d,"utf8"),m=a.signature||a,h="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",p=BigInt(0);for(let w of m)p=p*256n+BigInt(w);let S="";for(;p>0n;)S=h[Number(p%58n)]+S,p=p/58n;for(let w of m)if(w===0)S="1"+S;else break;return S}if(e.chain==="ethereum"){let r=(typeof window<"u"?window:null)?.ethereum;if(r?.providers?.length&&(r=r.providers.find(a=>a.isMetaMask)||r),!r)throw new Error("MetaMask not available");return await r.request({method:"personal_sign",params:[s,e.address]})}throw new Error("No wallet connected")}catch(t){return l(t.message||"Signing failed"),null}},[e]),n=useCallback(()=>{i({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:o,connectSolana:c,connectEVM:f,signMessage:u,disconnect:n}}async function _(e,i,o,l){let c=e.apiVersion||"v2",f=`${e.baseUrl}/api/${c}${o}`;try{let u=await fetch(f,{method:i,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),n=await u.json();return u.ok?n.success&&n.data!==void 0?{success:!0,data:n.data}:{success:!0,data:n}:{success:!1,error:n.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(u){return {success:false,error:{code:"NETWORK_ERROR",message:u instanceof Error?u.message:"Network error"}}}}function J(e){return {getNetworkStatus:()=>_(e,"GET","/network/status"),getWeb3Challenge:(i,o)=>_(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:i,address:o})}}function X(e){let{wallet:i,connectSolana:o,connectEVM:l,signMessage:c,disconnect:f}=N(),{session:u,isAuthenticated:n,refresh:s,readSession:t}=R(),{headers:r}=E(),[d,a]=useState(false),[m,h]=useState(null),p=e.apiBaseUrl||"",S=e.stacknetUrl||"https://stacknet.magma-rpc.com",w=J({baseUrl:S,stackId:e.stackId||""}),q=useCallback(async(b="phantom")=>{a(true),h(null);try{let g=await o(b);if(!g)return a(!1),!1;let y=await w.getWeb3Challenge("solana",g);if(!y.success||!y.data)return h("Failed to get challenge"),a(!1),!1;let C=await c(y.data.message);if(!C)return a(!1),!1;let P=await fetch(`${p}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"solana",message:y.data.message,signature:C,publicKey:g})});if(!P.ok){let G=await P.json().catch(()=>({}));return h(G.error||"Authentication failed"),a(!1),!1}return t(),a(!1),!0}catch(g){return h(g.message||"Authentication failed"),a(false),false}},[p,w,o,c,t]),H=useCallback(async()=>{a(true),h(null);try{let b=await l();if(!b)return a(!1),!1;let g=await w.getWeb3Challenge("ethereum",b);if(!g.success||!g.data)return h("Failed to get challenge"),a(!1),!1;let y=await c(g.data.message);if(!y)return a(!1),!1;let C=await fetch(`${p}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"ethereum",message:g.data.message,signature:y})});if(!C.ok){let P=await C.json().catch(()=>({}));return h(P.error||"Authentication failed"),a(!1),!1}return t(),a(!1),!0}catch(b){return h(b.message||"Authentication failed"),a(false),false}},[p,w,l,c,t]),K=useCallback(async b=>{a(true),h(null);try{let g=await fetch(`${p}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:b})});if(!g.ok){let y=await g.json().catch(()=>({}));return h(y.error||"Invalid code"),a(!1),!1}return t(),a(!1),!0}catch(g){return h(g.message||"OTP verification failed"),a(false),false}},[p,t]),D=useCallback(async()=>{try{await fetch(`${p}/api/auth/logout`,{method:"POST",headers:r});}catch{}f(),t();},[p,r,f,t]);return {session:u,isAuthenticated:n,wallet:i,loading:d,error:m,authenticateSolana:q,authenticateEVM:H,authenticateOTP:K,logout:D,refresh:()=>s(p)}}function ee(e=""){let[i,o]=useState([]),[l,c]=useState(true),[f,u]=useState(null),n=useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/plans`);if(s.ok){let t=await s.json();o(t.plans||t||[]);}}catch(s){u(s.message);}finally{c(false);}},[e]);return useEffect(()=>{n();},[n]),{plans:i,loading:l,error:f,refresh:n}}function ne(e=""){let[i,o]=useState(null),[l,c]=useState(true),[f,u]=useState(null),n=useCallback(async()=>{try{let r=await fetch(`${e}/api/billing/subscription`);if(r.ok){let d=await r.json();o(d.plan?d:null);}}catch(r){u(r.message);}finally{c(false);}},[e]);useEffect(()=>{n();},[n]);let s=useCallback(async r=>{let d=k(),m=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...d?{"x-csrf-token":d}:{}},body:JSON.stringify({planId:r})})).json();return m.url||m.checkoutUrl||null},[e]),t=useCallback(async()=>{let r=k();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:r?{"x-csrf-token":r}:{}})).ok?(await n(),true):false},[e,n]);return {subscription:i,loading:l,error:f,refresh:n,subscribe:s,cancel:t}}function ae(e=""){let[i,o]=useState(null),[l,c]=useState(true),[f,u]=useState(null),n=useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/usage`);if(s.ok){let t=await s.json();o(t);}}catch(s){u(s.message);}finally{c(false);}},[e]);return useEffect(()=>{n();},[n]),{usage:i,loading:l,error:f,refresh:n}}function oe(e=""){let[i,o]=useState(false),[l,c]=useState(null),f=useCallback(async n=>{o(true),c(null);try{let s=k(),t=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({amountCents:n})}),r=await t.json();return t.ok?r.url||null:(c(r.error||"Purchase failed"),null)}catch(s){return c(s.message),null}finally{o(false);}},[e]),u=useCallback(async n=>{o(true),c(null);try{let s=k(),t=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({sessionId:n})}),r=await t.json();return t.ok?r:(c(r.error||"Verification failed"),null)}catch(s){return c(s.message),null}finally{o(false);}},[e]);return {purchase:f,verifySession:u,loading:i,error:l}}function ce(e="",i){let[o,l]=useState([]),[c,f]=useState(true),[u,n]=useState(null),s=i?.limit||50,t=i?.offset||0,r=useCallback(async()=>{try{let d=await fetch(`${e}/api/billing/history?limit=${s}&offset=${t}`);if(d.ok){let a=await d.json();l(a.records||a.history||(Array.isArray(a)?a:[]));}}catch(d){n(d.message);}finally{f(false);}},[e,s,t]);return useEffect(()=>{r();},[r]),{records:o,loading:c,error:u,refresh:r}}
2
+ export{ce as useBillingHistory,E as useCSRFToken,ee as usePlans,oe as usePrepaidCheckout,R as useSession,X as useStackAuth,ne as useSubscription,ae as useUsage,N as useWeb3Wallet};