@stacknet/userutils 0.1.0 → 0.2.2
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/components/index.cjs +2 -2
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.d.cts +59 -2
- package/dist/hooks/index.d.ts +59 -2
- package/dist/hooks/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -1,2 +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=
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var se=react.createContext(null);function xe(){let e=react.useContext(se);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Ce({config:e,callbacks:n,children:l}){return jsxRuntime.jsx(se.Provider,{value:{config:e,callbacks:n},children:l})}function re(){let[e,n]=react.useState({connected:false,address:null,chain:null,provider:null}),[l,r]=react.useState(null),h=react.useCallback(async(f="phantom")=>{r(null);try{let o=typeof window<"u"?window:null,m=f==="phantom"?o?.phantom?.solana||o?.solana:o?.solflare;if(!m)return r(`${f} wallet not found`),null;let a=(await m.connect()).publicKey.toString();return n({connected:!0,address:a,chain:"solana",provider:f}),a}catch(o){return r(o.message||"Failed to connect wallet"),null}},[]),w=react.useCallback(async()=>{r(null);try{let o=(typeof window<"u"?window:null)?.ethereum;if(!o)return r("MetaMask not found"),null;let m=o;o.providers?.length&&(m=o.providers.find(t=>t.isMetaMask)||o);let a=(await m.request({method:"eth_requestAccounts"}))[0];return a?(n({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(r("No account selected"),null)}catch(f){return r(f.message||"Failed to connect wallet"),null}},[]),g=react.useCallback(async f=>{r(null);try{if(e.chain==="solana"){let o=typeof window<"u"?window:null,m=e.provider==="phantom"?o?.phantom?.solana||o?.solana:o?.solflare;if(!m)throw new Error("Wallet not available");let s=new TextEncoder().encode(f),a=await m.signMessage(s,"utf8"),t=a.signature||a,d="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",c=BigInt(0);for(let C of t)c=c*256n+BigInt(C);let y="";for(;c>0n;)y=d[Number(c%58n)]+y,c=c/58n;for(let C of t)if(C===0)y="1"+y;else break;return y}if(e.chain==="ethereum"){let m=(typeof window<"u"?window:null)?.ethereum;if(m?.providers?.length&&(m=m.providers.find(a=>a.isMetaMask)||m),!m)throw new Error("MetaMask not available");return await m.request({method:"personal_sign",params:[f,e.address]})}throw new Error("No wallet connected")}catch(o){return r(o.message||"Signing failed"),null}},[e]),i=react.useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),r(null);},[]);return {wallet:e,error:l,connectSolana:h,connectEVM:w,signMessage:g,disconnect:i}}function ie(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(l=>l.trim()).find(l=>l.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 ae(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(l=>l.trim()).find(l=>l.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function de(){let[e,n]=react.useState(null),[l,r]=react.useState(true),h=react.useCallback(()=>{let i=ie();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),r(false);},[]);react.useEffect(()=>{h();},[h]);let w=react.useCallback(async(i="")=>{try{let f=await fetch(`${i}/api/auth/session`);if(f.ok){let o=await f.json();if(o.session)return n(o.session),o.session}return n(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:l,isAuthenticated:g,refresh:w,readSession:h}}function ue(e="__csrf",n="x-csrf-token"){let[l,r]=react.useState(null);react.useEffect(()=>{r(ae(e));},[e]);let h=l?{[n]:l}:{};return {token:l,headers:h}}var ze="https://stacknet.magma-rpc.com/auth/bridge",J="stacknet-auth-bridge";function pe(e){let n=e?.bridgeUrl||ze,l=e?.disabled||false,r=react.useRef(null),[h,w]=react.useState({ready:false,known:false,identity:null,identityCount:0}),g=react.useRef([]),i=react.useRef(false),f=react.useCallback(t=>{let d={...t,protocol:J};i.current&&r.current?.contentWindow?r.current.contentWindow.postMessage(d,new URL(n).origin):g.current.push(d);},[n]);react.useEffect(()=>{if(l)return;let t=c=>{if(!(!c.data||c.data.protocol!==J)){try{if(c.origin!==new URL(n).origin)return}catch{return}switch(c.data.type){case "bridge:ready":i.current=true,w(y=>({...y,ready:true}));for(let y of g.current)r.current?.contentWindow?.postMessage(y,c.origin);g.current=[],r.current?.contentWindow?.postMessage({protocol:J,type:"auth:check"},c.origin);break;case "auth:status":w(y=>({...y,known:c.data.known,identity:c.data.identity,identityCount:c.data.identityCount||0}));break;}}};window.addEventListener("message",t);let d=document.createElement("iframe");return d.src=n,d.style.display="none",d.setAttribute("aria-hidden","true"),d.setAttribute("tabindex","-1"),d.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(d),r.current=d,()=>{window.removeEventListener("message",t),d.parentNode&&d.parentNode.removeChild(d),r.current=null,i.current=false;}},[n,l]);let o=react.useCallback(t=>{f({type:"auth:connected",...t});},[f]),m=react.useCallback(t=>{f({type:"auth:disconnected",...t});},[f]),s=react.useCallback(()=>{f({type:"auth:clear"}),w({ready:h.ready,known:false,identity:null,identityCount:0});},[f,h.ready]),a=react.useCallback(()=>{f({type:"auth:check"});},[f]);return {...h,reportConnected:o,reportDisconnected:m,clearAll:s,refresh:a}}async function fe(e,n,l,r){let h=e.apiVersion||"v2",w=`${e.baseUrl}/api/${h}${l}`;try{let g=await fetch(w,{method:n,headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):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 ge(e){return {getNetworkStatus:()=>fe(e,"GET","/network/status"),getWeb3Challenge:(n,l)=>fe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:n,address:l})}}function me(e={apiBaseUrl:""}){let{wallet:n,connectSolana:l,connectEVM:r,signMessage:h,disconnect:w}=re(),{session:g,isAuthenticated:i,refresh:f,readSession:o}=de(),{headers:m}=ue(),s=pe({disabled:typeof window>"u"}),[a,t]=react.useState(false),[d,c]=react.useState(null),[y,C]=react.useState(false),x=e.apiBaseUrl||"",A=e.stacknetUrl||"https://stacknet.magma-rpc.com",I=ge({baseUrl:A,stackId:e.stackId||""}),z=react.useCallback(async(k,N,T,$)=>{t(true),c(null);try{let L=N;if(!L){let U=await T();if(!U)return t(!1),!1;L=U;}let b=await I.getWeb3Challenge(k,L);if(!b.success||!b.data)return c("Failed to get challenge"),t(!1),!1;let O=await h(b.data.message);if(!O)return t(!1),!1;let S={chain:k,message:b.data.message,signature:O};k==="solana"&&(S.publicKey=L);let E=await fetch(`${x}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)});if(!E.ok){let U=await E.json().catch(()=>({}));return c(U.error||"Authentication failed"),t(!1),!1}return s.reportConnected({address:L,chain:k,method:$||(k==="solana"?"phantom":"metamask"),stackId:e.stackId}),o(),t(!1),!0}catch(L){return c(L.message||"Authentication failed"),t(false),false}},[x,I,h,o,s,e.stackId]),v=react.useCallback(async(k="phantom")=>{let N=await l(k);return N?z("solana",N,()=>l(k),k):false},[l,z]),j=react.useCallback(async()=>{let k=await r();return k?z("ethereum",k,r,"metamask"):false},[r,z]),G=react.useCallback(async k=>{t(true),c(null);try{let N=await fetch(`${x}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:k})});if(!N.ok){let T=await N.json().catch(()=>({}));return c(T.error||"Invalid code"),t(!1),!1}return o(),t(!1),!0}catch(N){return c(N.message||"OTP verification failed"),t(false),false}},[x,o]),V=react.useCallback(async()=>{n.address&&n.chain&&s.reportDisconnected({address:n.address,chain:n.chain,stackId:e.stackId});try{await fetch(`${x}/api/auth/logout`,{method:"POST",headers:m});}catch{}w(),o();},[x,m,w,o,n,s,e.stackId]);return react.useEffect(()=>{if(!e.autoConnect||y||i||!s.ready||!s.known||!s.identity)return;C(true);let{chain:k,method:N}=s.identity;k==="solana"&&(N==="phantom"||N==="solflare")?v(N):k==="ethereum"&&j();},[e.autoConnect,y,i,s,v,j]),{session:g,isAuthenticated:i,wallet:n,loading:a,error:d,authenticateSolana:v,authenticateEVM:j,authenticateOTP:G,logout:V,refresh:()=>f(x),bridge:{ready:s.ready,known:s.known,identity:s.identity,identityCount:s.identityCount}}}function H({length:e=6,onComplete:n,disabled:l=false,error:r,className:h="",inputClassName:w=""}){let [g,i]=react.useState(Array(e).fill("")),f=react.useCallback((s,a)=>{if(a.length>1){let d=a.replace(/\D/g,"").slice(0,e).split(""),c=[...g];d.forEach((C,x)=>{s+x<e&&(c[s+x]=C);}),i(c);let y=Math.min(s+d.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),c.every(C=>C!=="")&&setTimeout(()=>n(c.join("")),100);return}if(!/^\d?$/.test(a))return;let t=[...g];t[s]=a,i(t),a&&s<e-1&&document.getElementById(`userutils-otp-${s+1}`)?.focus(),a&&s===e-1&&t.every(d=>d!=="")&&setTimeout(()=>n(t.join("")),100);},[g,e,n]),o=react.useCallback((s,a)=>{if(a.key==="Backspace"&&!g[s]&&s>0){document.getElementById(`userutils-otp-${s-1}`)?.focus();let t=[...g];t[s-1]="",i(t);}if(a.key==="Enter"){let t=g.join("");t.length===e&&n(t);}},[g,e,n]);react.useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:h,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:g.map((s,a)=>jsxRuntime.jsx("input",{id:`userutils-otp-${a}`,type:"text",inputMode:"numeric",maxLength:e,value:s,onChange:t=>f(a,t.target.value),onKeyDown:t=>o(a,t),disabled:l,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 ${w}`},a))}),r&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:r})]})}H.displayName="OTPInput";var Te="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function Y({className:e}){return jsxRuntime.jsx("img",{src:Te,alt:"Phantom",className:e})}function F({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function ee({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 ne({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 We({config:e,onSuccess:n,title:l="Log in or Sign up",showWallets:r=["phantom","metamask"],showOTP:h=true,className:w=""}){let{isAuthenticated:g,wallet:i,loading:f,error:o,authenticateSolana:m,authenticateEVM:s,authenticateOTP:a}=me(e),[t,d]=react.useState("select"),[c,y]=react.useState(null),[C,x]=react.useState(false),[A,I]=react.useState("idle"),[z,v]=react.useState(""),[j,G]=react.useState(false),[V,k]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let b=()=>{let S=window;G(!!(S.phantom?.solana?.isPhantom||S.solana?.isPhantom));let E=S.ethereum;k(!!(E?.isMetaMask||E?.providers?.some(U=>U.isMetaMask)));};b(),window.addEventListener("ethereum#initialized",b);let O=setTimeout(b,500);return ()=>{window.removeEventListener("ethereum#initialized",b),clearTimeout(O);}},[]),react.useEffect(()=>{g&&t==="success"&&n?.();},[g,t,n]);let N=async()=>{y("phantom"),d("connecting");let b=await m("phantom");d(b?"success":"error");},T=async()=>{y("metamask"),d("connecting");let b=await s();d(b?"success":"error");},$=async b=>{I("verifying"),v(""),await a(b)?(I("success"),d("success")):(I("error"),v("Invalid or expired code"),setTimeout(()=>I("idle"),2e3));},L=()=>{d("select"),y(null),x(false),I("idle"),v("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${w}`,children:[jsxRuntime.jsx("div",{className:"mb-6 text-center",children:jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:l})}),o&&t==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:o}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:L,children:"Try Again"})]}),t==="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..."})]}),t==="connecting"&&f&&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:[c==="phantom"&&jsxRuntime.jsx(Y,{className:"h-14 w-14"}),c==="metamask"&&jsxRuntime.jsx(F,{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:L,children:"Cancel"})]}),t==="select"&&!f&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:N,disabled:!j,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${j?"":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(Y,{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"}),!j&&jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsxRuntime.jsx(ee,{className:"h-8 w-8"})]}),r.includes("metamask")&&V&&jsxRuntime.jsxs("button",{onClick:T,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(F,{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(ne,{className:"h-8 w-8"})]}),h&&!C&&jsxRuntime.jsxs("button",{onClick:()=>x(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"})})]}),h&&C&&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(H,{onComplete:$,disabled:A==="verifying",error:z}),A==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),A==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function Be({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"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 He({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 Fe({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 Ge({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=We;exports.DiscordIcon=Fe;exports.EthereumIcon=ne;exports.GoogleIcon=He;exports.MetaMaskIcon=F;exports.OTPInput=H;exports.PhantomIcon=Y;exports.SolanaIcon=ee;exports.TelegramIcon=Ge;exports.TwitterIcon=Be;exports.UserUtilsProvider=Ce;exports.useUserUtilsContext=xe;
|
package/dist/components/index.js
CHANGED
|
@@ -1,2 +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{
|
|
1
|
+
import {createContext,useContext,useState,useCallback,useEffect,useRef}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var se=createContext(null);function xe(){let e=useContext(se);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Ce({config:e,callbacks:n,children:l}){return jsx(se.Provider,{value:{config:e,callbacks:n},children:l})}function re(){let[e,n]=useState({connected:false,address:null,chain:null,provider:null}),[l,r]=useState(null),h=useCallback(async(f="phantom")=>{r(null);try{let o=typeof window<"u"?window:null,m=f==="phantom"?o?.phantom?.solana||o?.solana:o?.solflare;if(!m)return r(`${f} wallet not found`),null;let a=(await m.connect()).publicKey.toString();return n({connected:!0,address:a,chain:"solana",provider:f}),a}catch(o){return r(o.message||"Failed to connect wallet"),null}},[]),w=useCallback(async()=>{r(null);try{let o=(typeof window<"u"?window:null)?.ethereum;if(!o)return r("MetaMask not found"),null;let m=o;o.providers?.length&&(m=o.providers.find(t=>t.isMetaMask)||o);let a=(await m.request({method:"eth_requestAccounts"}))[0];return a?(n({connected:!0,address:a,chain:"ethereum",provider:"metamask"}),a):(r("No account selected"),null)}catch(f){return r(f.message||"Failed to connect wallet"),null}},[]),g=useCallback(async f=>{r(null);try{if(e.chain==="solana"){let o=typeof window<"u"?window:null,m=e.provider==="phantom"?o?.phantom?.solana||o?.solana:o?.solflare;if(!m)throw new Error("Wallet not available");let s=new TextEncoder().encode(f),a=await m.signMessage(s,"utf8"),t=a.signature||a,d="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",c=BigInt(0);for(let C of t)c=c*256n+BigInt(C);let y="";for(;c>0n;)y=d[Number(c%58n)]+y,c=c/58n;for(let C of t)if(C===0)y="1"+y;else break;return y}if(e.chain==="ethereum"){let m=(typeof window<"u"?window:null)?.ethereum;if(m?.providers?.length&&(m=m.providers.find(a=>a.isMetaMask)||m),!m)throw new Error("MetaMask not available");return await m.request({method:"personal_sign",params:[f,e.address]})}throw new Error("No wallet connected")}catch(o){return r(o.message||"Signing failed"),null}},[e]),i=useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),r(null);},[]);return {wallet:e,error:l,connectSolana:h,connectEVM:w,signMessage:g,disconnect:i}}function ie(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(l=>l.trim()).find(l=>l.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 ae(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(l=>l.trim()).find(l=>l.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function de(){let[e,n]=useState(null),[l,r]=useState(true),h=useCallback(()=>{let i=ie();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),r(false);},[]);useEffect(()=>{h();},[h]);let w=useCallback(async(i="")=>{try{let f=await fetch(`${i}/api/auth/session`);if(f.ok){let o=await f.json();if(o.session)return n(o.session),o.session}return n(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:l,isAuthenticated:g,refresh:w,readSession:h}}function ue(e="__csrf",n="x-csrf-token"){let[l,r]=useState(null);useEffect(()=>{r(ae(e));},[e]);let h=l?{[n]:l}:{};return {token:l,headers:h}}var ze="https://stacknet.magma-rpc.com/auth/bridge",J="stacknet-auth-bridge";function pe(e){let n=e?.bridgeUrl||ze,l=e?.disabled||false,r=useRef(null),[h,w]=useState({ready:false,known:false,identity:null,identityCount:0}),g=useRef([]),i=useRef(false),f=useCallback(t=>{let d={...t,protocol:J};i.current&&r.current?.contentWindow?r.current.contentWindow.postMessage(d,new URL(n).origin):g.current.push(d);},[n]);useEffect(()=>{if(l)return;let t=c=>{if(!(!c.data||c.data.protocol!==J)){try{if(c.origin!==new URL(n).origin)return}catch{return}switch(c.data.type){case "bridge:ready":i.current=true,w(y=>({...y,ready:true}));for(let y of g.current)r.current?.contentWindow?.postMessage(y,c.origin);g.current=[],r.current?.contentWindow?.postMessage({protocol:J,type:"auth:check"},c.origin);break;case "auth:status":w(y=>({...y,known:c.data.known,identity:c.data.identity,identityCount:c.data.identityCount||0}));break;}}};window.addEventListener("message",t);let d=document.createElement("iframe");return d.src=n,d.style.display="none",d.setAttribute("aria-hidden","true"),d.setAttribute("tabindex","-1"),d.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(d),r.current=d,()=>{window.removeEventListener("message",t),d.parentNode&&d.parentNode.removeChild(d),r.current=null,i.current=false;}},[n,l]);let o=useCallback(t=>{f({type:"auth:connected",...t});},[f]),m=useCallback(t=>{f({type:"auth:disconnected",...t});},[f]),s=useCallback(()=>{f({type:"auth:clear"}),w({ready:h.ready,known:false,identity:null,identityCount:0});},[f,h.ready]),a=useCallback(()=>{f({type:"auth:check"});},[f]);return {...h,reportConnected:o,reportDisconnected:m,clearAll:s,refresh:a}}async function fe(e,n,l,r){let h=e.apiVersion||"v2",w=`${e.baseUrl}/api/${h}${l}`;try{let g=await fetch(w,{method:n,headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):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 ge(e){return {getNetworkStatus:()=>fe(e,"GET","/network/status"),getWeb3Challenge:(n,l)=>fe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:n,address:l})}}function me(e={apiBaseUrl:""}){let{wallet:n,connectSolana:l,connectEVM:r,signMessage:h,disconnect:w}=re(),{session:g,isAuthenticated:i,refresh:f,readSession:o}=de(),{headers:m}=ue(),s=pe({disabled:typeof window>"u"}),[a,t]=useState(false),[d,c]=useState(null),[y,C]=useState(false),x=e.apiBaseUrl||"",A=e.stacknetUrl||"https://stacknet.magma-rpc.com",I=ge({baseUrl:A,stackId:e.stackId||""}),z=useCallback(async(k,N,T,$)=>{t(true),c(null);try{let L=N;if(!L){let U=await T();if(!U)return t(!1),!1;L=U;}let b=await I.getWeb3Challenge(k,L);if(!b.success||!b.data)return c("Failed to get challenge"),t(!1),!1;let O=await h(b.data.message);if(!O)return t(!1),!1;let S={chain:k,message:b.data.message,signature:O};k==="solana"&&(S.publicKey=L);let E=await fetch(`${x}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)});if(!E.ok){let U=await E.json().catch(()=>({}));return c(U.error||"Authentication failed"),t(!1),!1}return s.reportConnected({address:L,chain:k,method:$||(k==="solana"?"phantom":"metamask"),stackId:e.stackId}),o(),t(!1),!0}catch(L){return c(L.message||"Authentication failed"),t(false),false}},[x,I,h,o,s,e.stackId]),v=useCallback(async(k="phantom")=>{let N=await l(k);return N?z("solana",N,()=>l(k),k):false},[l,z]),j=useCallback(async()=>{let k=await r();return k?z("ethereum",k,r,"metamask"):false},[r,z]),G=useCallback(async k=>{t(true),c(null);try{let N=await fetch(`${x}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:k})});if(!N.ok){let T=await N.json().catch(()=>({}));return c(T.error||"Invalid code"),t(!1),!1}return o(),t(!1),!0}catch(N){return c(N.message||"OTP verification failed"),t(false),false}},[x,o]),V=useCallback(async()=>{n.address&&n.chain&&s.reportDisconnected({address:n.address,chain:n.chain,stackId:e.stackId});try{await fetch(`${x}/api/auth/logout`,{method:"POST",headers:m});}catch{}w(),o();},[x,m,w,o,n,s,e.stackId]);return useEffect(()=>{if(!e.autoConnect||y||i||!s.ready||!s.known||!s.identity)return;C(true);let{chain:k,method:N}=s.identity;k==="solana"&&(N==="phantom"||N==="solflare")?v(N):k==="ethereum"&&j();},[e.autoConnect,y,i,s,v,j]),{session:g,isAuthenticated:i,wallet:n,loading:a,error:d,authenticateSolana:v,authenticateEVM:j,authenticateOTP:G,logout:V,refresh:()=>f(x),bridge:{ready:s.ready,known:s.known,identity:s.identity,identityCount:s.identityCount}}}function H({length:e=6,onComplete:n,disabled:l=false,error:r,className:h="",inputClassName:w=""}){let [g,i]=useState(Array(e).fill("")),f=useCallback((s,a)=>{if(a.length>1){let d=a.replace(/\D/g,"").slice(0,e).split(""),c=[...g];d.forEach((C,x)=>{s+x<e&&(c[s+x]=C);}),i(c);let y=Math.min(s+d.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),c.every(C=>C!=="")&&setTimeout(()=>n(c.join("")),100);return}if(!/^\d?$/.test(a))return;let t=[...g];t[s]=a,i(t),a&&s<e-1&&document.getElementById(`userutils-otp-${s+1}`)?.focus(),a&&s===e-1&&t.every(d=>d!=="")&&setTimeout(()=>n(t.join("")),100);},[g,e,n]),o=useCallback((s,a)=>{if(a.key==="Backspace"&&!g[s]&&s>0){document.getElementById(`userutils-otp-${s-1}`)?.focus();let t=[...g];t[s-1]="",i(t);}if(a.key==="Enter"){let t=g.join("");t.length===e&&n(t);}},[g,e,n]);useCallback(()=>{i(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:h,children:[jsx("div",{className:"flex gap-2 justify-center",children:g.map((s,a)=>jsx("input",{id:`userutils-otp-${a}`,type:"text",inputMode:"numeric",maxLength:e,value:s,onChange:t=>f(a,t.target.value),onKeyDown:t=>o(a,t),disabled:l,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 ${w}`},a))}),r&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:r})]})}H.displayName="OTPInput";var Te="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function Y({className:e}){return jsx("img",{src:Te,alt:"Phantom",className:e})}function F({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function ee({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 ne({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 We({config:e,onSuccess:n,title:l="Log in or Sign up",showWallets:r=["phantom","metamask"],showOTP:h=true,className:w=""}){let{isAuthenticated:g,wallet:i,loading:f,error:o,authenticateSolana:m,authenticateEVM:s,authenticateOTP:a}=me(e),[t,d]=useState("select"),[c,y]=useState(null),[C,x]=useState(false),[A,I]=useState("idle"),[z,v]=useState(""),[j,G]=useState(false),[V,k]=useState(false);useEffect(()=>{if(typeof window>"u")return;let b=()=>{let S=window;G(!!(S.phantom?.solana?.isPhantom||S.solana?.isPhantom));let E=S.ethereum;k(!!(E?.isMetaMask||E?.providers?.some(U=>U.isMetaMask)));};b(),window.addEventListener("ethereum#initialized",b);let O=setTimeout(b,500);return ()=>{window.removeEventListener("ethereum#initialized",b),clearTimeout(O);}},[]),useEffect(()=>{g&&t==="success"&&n?.();},[g,t,n]);let N=async()=>{y("phantom"),d("connecting");let b=await m("phantom");d(b?"success":"error");},T=async()=>{y("metamask"),d("connecting");let b=await s();d(b?"success":"error");},$=async b=>{I("verifying"),v(""),await a(b)?(I("success"),d("success")):(I("error"),v("Invalid or expired code"),setTimeout(()=>I("idle"),2e3));},L=()=>{d("select"),y(null),x(false),I("idle"),v("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${w}`,children:[jsx("div",{className:"mb-6 text-center",children:jsx("h1",{className:"font-semibold text-2xl text-white",children:l})}),o&&t==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:o}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:L,children:"Try Again"})]}),t==="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..."})]}),t==="connecting"&&f&&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:[c==="phantom"&&jsx(Y,{className:"h-14 w-14"}),c==="metamask"&&jsx(F,{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:L,children:"Cancel"})]}),t==="select"&&!f&&jsxs(Fragment,{children:[r.includes("phantom")&&jsxs("button",{onClick:N,disabled:!j,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${j?"":"cursor-not-allowed opacity-50"}`,children:[jsx(Y,{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"}),!j&&jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsx(ee,{className:"h-8 w-8"})]}),r.includes("metamask")&&V&&jsxs("button",{onClick:T,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(F,{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(ne,{className:"h-8 w-8"})]}),h&&!C&&jsxs("button",{onClick:()=>x(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"})})]}),h&&C&&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(H,{onComplete:$,disabled:A==="verifying",error:z}),A==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),A==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function Be({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"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 He({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 Fe({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 Ge({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{We as ConnectWidget,Fe as DiscordIcon,ne as EthereumIcon,He as GoogleIcon,F as MetaMaskIcon,H as OTPInput,Y as PhantomIcon,ee as SolanaIcon,Ge as TelegramIcon,Be as TwitterIcon,Ce as UserUtilsProvider,xe as useUserUtilsContext};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,2 +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=
|
|
1
|
+
'use strict';var react=require('react');function G(){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 r=e.slice(18);return JSON.parse(atob(r.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function k(e="__csrf"){if(typeof document>"u")return null;let r=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${e}=`));return r?r.slice(e.length+1):null}function O(){let[e,r]=react.useState(null),[o,i]=react.useState(true),c=react.useCallback(()=>{let s=G();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),i(false);},[]);react.useEffect(()=>{c();},[c]);let p=react.useCallback(async(s="")=>{try{let t=await fetch(`${s}/api/auth/session`);if(t.ok){let n=await t.json();if(n.session)return r(n.session),n.session}return r(null),null}catch{return null}},[]),d=!!e&&e.expiresAt>Date.now();return {session:e,loading:o,isAuthenticated:d,refresh:p,readSession:c}}function M(e="__csrf",r="x-csrf-token"){let[o,i]=react.useState(null);react.useEffect(()=>{i(k(e));},[e]);let c=o?{[r]:o}:{};return {token:o,headers:c}}function $(){let[e,r]=react.useState({connected:false,address:null,chain:null,provider:null}),[o,i]=react.useState(null),c=react.useCallback(async(t="phantom")=>{i(null);try{let n=typeof window<"u"?window:null,a=t==="phantom"?n?.phantom?.solana||n?.solana:n?.solflare;if(!a)return i(`${t} wallet not found`),null;let h=(await a.connect()).publicKey.toString();return r({connected:!0,address:h,chain:"solana",provider:t}),h}catch(n){return i(n.message||"Failed to connect wallet"),null}},[]),p=react.useCallback(async()=>{i(null);try{let n=(typeof window<"u"?window:null)?.ethereum;if(!n)return i("MetaMask not found"),null;let a=n;n.providers?.length&&(a=n.providers.find(u=>u.isMetaMask)||n);let h=(await a.request({method:"eth_requestAccounts"}))[0];return h?(r({connected:!0,address:h,chain:"ethereum",provider:"metamask"}),h):(i("No account selected"),null)}catch(t){return i(t.message||"Failed to connect wallet"),null}},[]),d=react.useCallback(async t=>{i(null);try{if(e.chain==="solana"){let n=typeof window<"u"?window:null,a=e.provider==="phantom"?n?.phantom?.solana||n?.solana:n?.solflare;if(!a)throw new Error("Wallet not available");let l=new TextEncoder().encode(t),h=await a.signMessage(l,"utf8"),u=h.signature||h,m="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",f=BigInt(0);for(let C of u)f=f*256n+BigInt(C);let y="";for(;f>0n;)y=m[Number(f%58n)]+y,f=f/58n;for(let C of u)if(C===0)y="1"+y;else break;return y}if(e.chain==="ethereum"){let a=(typeof window<"u"?window:null)?.ethereum;if(a?.providers?.length&&(a=a.providers.find(h=>h.isMetaMask)||a),!a)throw new Error("MetaMask not available");return await a.request({method:"personal_sign",params:[t,e.address]})}throw new Error("No wallet connected")}catch(n){return i(n.message||"Signing failed"),null}},[e]),s=react.useCallback(()=>{r({connected:false,address:null,chain:null,provider:null}),i(null);},[]);return {wallet:e,error:o,connectSolana:c,connectEVM:p,signMessage:d,disconnect:s}}var de="https://stacknet.magma-rpc.com/auth/bridge",U="stacknet-auth-bridge";function v(e){let r=e?.bridgeUrl||de,o=e?.disabled||false,i=react.useRef(null),[c,p]=react.useState({ready:false,known:false,identity:null,identityCount:0}),d=react.useRef([]),s=react.useRef(false),t=react.useCallback(u=>{let m={...u,protocol:U};s.current&&i.current?.contentWindow?i.current.contentWindow.postMessage(m,new URL(r).origin):d.current.push(m);},[r]);react.useEffect(()=>{if(o)return;let u=f=>{if(!(!f.data||f.data.protocol!==U)){try{if(f.origin!==new URL(r).origin)return}catch{return}switch(f.data.type){case "bridge:ready":s.current=true,p(y=>({...y,ready:true}));for(let y of d.current)i.current?.contentWindow?.postMessage(y,f.origin);d.current=[],i.current?.contentWindow?.postMessage({protocol:U,type:"auth:check"},f.origin);break;case "auth:status":p(y=>({...y,known:f.data.known,identity:f.data.identity,identityCount:f.data.identityCount||0}));break;}}};window.addEventListener("message",u);let m=document.createElement("iframe");return m.src=r,m.style.display="none",m.setAttribute("aria-hidden","true"),m.setAttribute("tabindex","-1"),m.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(m),i.current=m,()=>{window.removeEventListener("message",u),m.parentNode&&m.parentNode.removeChild(m),i.current=null,s.current=false;}},[r,o]);let n=react.useCallback(u=>{t({type:"auth:connected",...u});},[t]),a=react.useCallback(u=>{t({type:"auth:disconnected",...u});},[t]),l=react.useCallback(()=>{t({type:"auth:clear"}),p({ready:c.ready,known:false,identity:null,identityCount:0});},[t,c.ready]),h=react.useCallback(()=>{t({type:"auth:check"});},[t]);return {...c,reportConnected:n,reportDisconnected:a,clearAll:l,refresh:h}}async function Y(e,r,o,i){let c=e.apiVersion||"v2",p=`${e.baseUrl}/api/${c}${o}`;try{let d=await fetch(p,{method:r,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),s=await d.json();return d.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(d){return {success:false,error:{code:"NETWORK_ERROR",message:d instanceof Error?d.message:"Network error"}}}}function Z(e){return {getNetworkStatus:()=>Y(e,"GET","/network/status"),getWeb3Challenge:(r,o)=>Y(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:r,address:o})}}function pe(e={apiBaseUrl:""}){let{wallet:r,connectSolana:o,connectEVM:i,signMessage:c,disconnect:p}=$(),{session:d,isAuthenticated:s,refresh:t,readSession:n}=O(),{headers:a}=M(),l=v({disabled:typeof window>"u"}),[h,u]=react.useState(false),[m,f]=react.useState(null),[y,C]=react.useState(false),w=e.apiBaseUrl||"",ne=e.stacknetUrl||"https://stacknet.magma-rpc.com",D=Z({baseUrl:ne,stackId:e.stackId||""}),R=react.useCallback(async(g,b,N,ae)=>{u(true),f(null);try{let S=b;if(!S){let W=await N();if(!W)return u(!1),!1;S=W;}let E=await D.getWeb3Challenge(g,S);if(!E.success||!E.data)return f("Failed to get challenge"),u(!1),!1;let H=await c(E.data.message);if(!H)return u(!1),!1;let q={chain:g,message:E.data.message,signature:H};g==="solana"&&(q.publicKey=S);let K=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(q)});if(!K.ok){let W=await K.json().catch(()=>({}));return f(W.error||"Authentication failed"),u(!1),!1}return l.reportConnected({address:S,chain:g,method:ae||(g==="solana"?"phantom":"metamask"),stackId:e.stackId}),n(),u(!1),!0}catch(S){return f(S.message||"Authentication failed"),u(false),false}},[w,D,c,n,l,e.stackId]),A=react.useCallback(async(g="phantom")=>{let b=await o(g);return b?R("solana",b,()=>o(g),g):false},[o,R]),I=react.useCallback(async()=>{let g=await i();return g?R("ethereum",g,i,"metamask"):false},[i,R]),se=react.useCallback(async g=>{u(true),f(null);try{let b=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:g})});if(!b.ok){let N=await b.json().catch(()=>({}));return f(N.error||"Invalid code"),u(!1),!1}return n(),u(!1),!0}catch(b){return f(b.message||"OTP verification failed"),u(false),false}},[w,n]),re=react.useCallback(async()=>{r.address&&r.chain&&l.reportDisconnected({address:r.address,chain:r.chain,stackId:e.stackId});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:a});}catch{}p(),n();},[w,a,p,n,r,l,e.stackId]);return react.useEffect(()=>{if(!e.autoConnect||y||s||!l.ready||!l.known||!l.identity)return;C(true);let{chain:g,method:b}=l.identity;g==="solana"&&(b==="phantom"||b==="solflare")?A(b):g==="ethereum"&&I();},[e.autoConnect,y,s,l,A,I]),{session:d,isAuthenticated:s,wallet:r,loading:h,error:m,authenticateSolana:A,authenticateEVM:I,authenticateOTP:se,logout:re,refresh:()=>t(w),bridge:{ready:l.ready,known:l.known,identity:l.identity,identityCount:l.identityCount}}}function ge(e=""){let[r,o]=react.useState([]),[i,c]=react.useState(true),[p,d]=react.useState(null),s=react.useCallback(async()=>{try{let t=await fetch(`${e}/api/billing/plans`);if(t.ok){let n=await t.json();o(n.plans||n||[]);}}catch(t){d(t.message);}finally{c(false);}},[e]);return react.useEffect(()=>{s();},[s]),{plans:r,loading:i,error:p,refresh:s}}function be(e=""){let[r,o]=react.useState(null),[i,c]=react.useState(true),[p,d]=react.useState(null),s=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/subscription`);if(a.ok){let l=await a.json();o(l.plan?l:null);}}catch(a){d(a.message);}finally{c(false);}},[e]);react.useEffect(()=>{s();},[s]);let t=react.useCallback(async a=>{let l=k(),u=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({planId:a})})).json();return u.url||u.checkoutUrl||null},[e]),n=react.useCallback(async()=>{let a=k();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:a?{"x-csrf-token":a}:{}})).ok?(await s(),true):false},[e,s]);return {subscription:r,loading:i,error:p,refresh:s,subscribe:t,cancel:n}}function Se(e=""){let[r,o]=react.useState(null),[i,c]=react.useState(true),[p,d]=react.useState(null),s=react.useCallback(async()=>{try{let t=await fetch(`${e}/api/billing/usage`);if(t.ok){let n=await t.json();o(n);}}catch(t){d(t.message);}finally{c(false);}},[e]);return react.useEffect(()=>{s();},[s]),{usage:r,loading:i,error:p,refresh:s}}function Ce(e=""){let[r,o]=react.useState(false),[i,c]=react.useState(null),p=react.useCallback(async s=>{o(true),c(null);try{let t=k(),n=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-csrf-token":t}:{}},body:JSON.stringify({amountCents:s})}),a=await n.json();return n.ok?a.url||null:(c(a.error||"Purchase failed"),null)}catch(t){return c(t.message),null}finally{o(false);}},[e]),d=react.useCallback(async s=>{o(true),c(null);try{let t=k(),n=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-csrf-token":t}:{}},body:JSON.stringify({sessionId:s})}),a=await n.json();return n.ok?a:(c(a.error||"Verification failed"),null)}catch(t){return c(t.message),null}finally{o(false);}},[e]);return {purchase:p,verifySession:d,loading:r,error:i}}function Re(e="",r){let[o,i]=react.useState([]),[c,p]=react.useState(true),[d,s]=react.useState(null),t=r?.limit||50,n=r?.offset||0,a=react.useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/history?limit=${t}&offset=${n}`);if(l.ok){let h=await l.json();i(h.records||h.history||(Array.isArray(h)?h:[]));}}catch(l){s(l.message);}finally{p(false);}},[e,t,n]);return react.useEffect(()=>{a();},[a]),{records:o,loading:c,error:d,refresh:a}}
|
|
2
|
+
exports.useAuthBridge=v;exports.useBillingHistory=Re;exports.useCSRFToken=M;exports.usePlans=ge;exports.usePrepaidCheckout=Ce;exports.useSession=O;exports.useStackAuth=pe;exports.useSubscription=be;exports.useUsage=Se;exports.useWeb3Wallet=$;
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -40,12 +40,62 @@ declare function useWeb3Wallet(): {
|
|
|
40
40
|
disconnect: () => void;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
interface BridgeIdentity {
|
|
44
|
+
address: string;
|
|
45
|
+
chain: Web3Chain;
|
|
46
|
+
method: string | null;
|
|
47
|
+
stackCount: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hook for cross-domain auth state sharing via iframe bridge.
|
|
51
|
+
*
|
|
52
|
+
* Embeds an invisible iframe from stacknet.magma-rpc.com that stores
|
|
53
|
+
* auth preferences (which wallet/chain the user used) in its localStorage.
|
|
54
|
+
* When the user visits a different stack app, the bridge reports the
|
|
55
|
+
* preferred wallet so the app can auto-connect.
|
|
56
|
+
*
|
|
57
|
+
* NEVER transmits JWTs. Only shares: address, chain, method, stackId.
|
|
58
|
+
*/
|
|
59
|
+
declare function useAuthBridge(opts?: {
|
|
60
|
+
/** Override bridge URL (default: https://stacknet.magma-rpc.com/auth/bridge) */
|
|
61
|
+
bridgeUrl?: string;
|
|
62
|
+
/** Disable the bridge entirely */
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
}): {
|
|
65
|
+
reportConnected: (params: {
|
|
66
|
+
address: string;
|
|
67
|
+
chain: Web3Chain;
|
|
68
|
+
method?: string;
|
|
69
|
+
stackId?: string;
|
|
70
|
+
}) => void;
|
|
71
|
+
reportDisconnected: (params: {
|
|
72
|
+
address: string;
|
|
73
|
+
chain: Web3Chain;
|
|
74
|
+
stackId?: string;
|
|
75
|
+
}) => void;
|
|
76
|
+
clearAll: () => void;
|
|
77
|
+
refresh: () => void;
|
|
78
|
+
ready: boolean;
|
|
79
|
+
known: boolean;
|
|
80
|
+
identity: BridgeIdentity | null;
|
|
81
|
+
identityCount: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
43
84
|
/**
|
|
44
85
|
* Master auth hook — combines wallet connection, challenge/sign/verify,
|
|
45
86
|
* OTP, and session management. All auth state flows through server routes
|
|
46
87
|
* (HttpOnly cookies), never touches localStorage or document.cookie directly.
|
|
88
|
+
*
|
|
89
|
+
* When `autoConnect` is true, uses the cross-domain iframe bridge to detect
|
|
90
|
+
* if the user has previously authenticated on another stack and auto-triggers
|
|
91
|
+
* the wallet connect flow.
|
|
47
92
|
*/
|
|
48
|
-
declare function useStackAuth(config
|
|
93
|
+
declare function useStackAuth(config?: UserUtilsConfig & {
|
|
94
|
+
/** Auto-connect using bridge identity if available (default: false) */
|
|
95
|
+
autoConnect?: boolean;
|
|
96
|
+
/** Stack ID for bridge tracking */
|
|
97
|
+
stackId?: string;
|
|
98
|
+
}): {
|
|
49
99
|
session: PublicSession | null;
|
|
50
100
|
isAuthenticated: boolean;
|
|
51
101
|
wallet: WalletState;
|
|
@@ -56,6 +106,13 @@ declare function useStackAuth(config: UserUtilsConfig): {
|
|
|
56
106
|
authenticateOTP: (code: string) => Promise<boolean>;
|
|
57
107
|
logout: () => Promise<void>;
|
|
58
108
|
refresh: () => Promise<any>;
|
|
109
|
+
/** Bridge state — known identities from other stacks */
|
|
110
|
+
bridge: {
|
|
111
|
+
ready: boolean;
|
|
112
|
+
known: boolean;
|
|
113
|
+
identity: BridgeIdentity | null;
|
|
114
|
+
identityCount: number;
|
|
115
|
+
};
|
|
59
116
|
};
|
|
60
117
|
|
|
61
118
|
declare function usePlans(apiBaseUrl?: string): {
|
|
@@ -98,4 +155,4 @@ declare function useBillingHistory(apiBaseUrl?: string, opts?: {
|
|
|
98
155
|
refresh: () => Promise<void>;
|
|
99
156
|
};
|
|
100
157
|
|
|
101
|
-
export { type WalletState, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet };
|
|
158
|
+
export { type BridgeIdentity, type WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -40,12 +40,62 @@ declare function useWeb3Wallet(): {
|
|
|
40
40
|
disconnect: () => void;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
interface BridgeIdentity {
|
|
44
|
+
address: string;
|
|
45
|
+
chain: Web3Chain;
|
|
46
|
+
method: string | null;
|
|
47
|
+
stackCount: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hook for cross-domain auth state sharing via iframe bridge.
|
|
51
|
+
*
|
|
52
|
+
* Embeds an invisible iframe from stacknet.magma-rpc.com that stores
|
|
53
|
+
* auth preferences (which wallet/chain the user used) in its localStorage.
|
|
54
|
+
* When the user visits a different stack app, the bridge reports the
|
|
55
|
+
* preferred wallet so the app can auto-connect.
|
|
56
|
+
*
|
|
57
|
+
* NEVER transmits JWTs. Only shares: address, chain, method, stackId.
|
|
58
|
+
*/
|
|
59
|
+
declare function useAuthBridge(opts?: {
|
|
60
|
+
/** Override bridge URL (default: https://stacknet.magma-rpc.com/auth/bridge) */
|
|
61
|
+
bridgeUrl?: string;
|
|
62
|
+
/** Disable the bridge entirely */
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
}): {
|
|
65
|
+
reportConnected: (params: {
|
|
66
|
+
address: string;
|
|
67
|
+
chain: Web3Chain;
|
|
68
|
+
method?: string;
|
|
69
|
+
stackId?: string;
|
|
70
|
+
}) => void;
|
|
71
|
+
reportDisconnected: (params: {
|
|
72
|
+
address: string;
|
|
73
|
+
chain: Web3Chain;
|
|
74
|
+
stackId?: string;
|
|
75
|
+
}) => void;
|
|
76
|
+
clearAll: () => void;
|
|
77
|
+
refresh: () => void;
|
|
78
|
+
ready: boolean;
|
|
79
|
+
known: boolean;
|
|
80
|
+
identity: BridgeIdentity | null;
|
|
81
|
+
identityCount: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
43
84
|
/**
|
|
44
85
|
* Master auth hook — combines wallet connection, challenge/sign/verify,
|
|
45
86
|
* OTP, and session management. All auth state flows through server routes
|
|
46
87
|
* (HttpOnly cookies), never touches localStorage or document.cookie directly.
|
|
88
|
+
*
|
|
89
|
+
* When `autoConnect` is true, uses the cross-domain iframe bridge to detect
|
|
90
|
+
* if the user has previously authenticated on another stack and auto-triggers
|
|
91
|
+
* the wallet connect flow.
|
|
47
92
|
*/
|
|
48
|
-
declare function useStackAuth(config
|
|
93
|
+
declare function useStackAuth(config?: UserUtilsConfig & {
|
|
94
|
+
/** Auto-connect using bridge identity if available (default: false) */
|
|
95
|
+
autoConnect?: boolean;
|
|
96
|
+
/** Stack ID for bridge tracking */
|
|
97
|
+
stackId?: string;
|
|
98
|
+
}): {
|
|
49
99
|
session: PublicSession | null;
|
|
50
100
|
isAuthenticated: boolean;
|
|
51
101
|
wallet: WalletState;
|
|
@@ -56,6 +106,13 @@ declare function useStackAuth(config: UserUtilsConfig): {
|
|
|
56
106
|
authenticateOTP: (code: string) => Promise<boolean>;
|
|
57
107
|
logout: () => Promise<void>;
|
|
58
108
|
refresh: () => Promise<any>;
|
|
109
|
+
/** Bridge state — known identities from other stacks */
|
|
110
|
+
bridge: {
|
|
111
|
+
ready: boolean;
|
|
112
|
+
known: boolean;
|
|
113
|
+
identity: BridgeIdentity | null;
|
|
114
|
+
identityCount: number;
|
|
115
|
+
};
|
|
59
116
|
};
|
|
60
117
|
|
|
61
118
|
declare function usePlans(apiBaseUrl?: string): {
|
|
@@ -98,4 +155,4 @@ declare function useBillingHistory(apiBaseUrl?: string, opts?: {
|
|
|
98
155
|
refresh: () => Promise<void>;
|
|
99
156
|
};
|
|
100
157
|
|
|
101
|
-
export { type WalletState, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet };
|
|
158
|
+
export { type BridgeIdentity, type WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,2 +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{
|
|
1
|
+
import {useState,useCallback,useEffect,useRef}from'react';function G(){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 r=e.slice(18);return JSON.parse(atob(r.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function k(e="__csrf"){if(typeof document>"u")return null;let r=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${e}=`));return r?r.slice(e.length+1):null}function O(){let[e,r]=useState(null),[o,i]=useState(true),c=useCallback(()=>{let s=G();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),i(false);},[]);useEffect(()=>{c();},[c]);let p=useCallback(async(s="")=>{try{let t=await fetch(`${s}/api/auth/session`);if(t.ok){let n=await t.json();if(n.session)return r(n.session),n.session}return r(null),null}catch{return null}},[]),d=!!e&&e.expiresAt>Date.now();return {session:e,loading:o,isAuthenticated:d,refresh:p,readSession:c}}function M(e="__csrf",r="x-csrf-token"){let[o,i]=useState(null);useEffect(()=>{i(k(e));},[e]);let c=o?{[r]:o}:{};return {token:o,headers:c}}function $(){let[e,r]=useState({connected:false,address:null,chain:null,provider:null}),[o,i]=useState(null),c=useCallback(async(t="phantom")=>{i(null);try{let n=typeof window<"u"?window:null,a=t==="phantom"?n?.phantom?.solana||n?.solana:n?.solflare;if(!a)return i(`${t} wallet not found`),null;let h=(await a.connect()).publicKey.toString();return r({connected:!0,address:h,chain:"solana",provider:t}),h}catch(n){return i(n.message||"Failed to connect wallet"),null}},[]),p=useCallback(async()=>{i(null);try{let n=(typeof window<"u"?window:null)?.ethereum;if(!n)return i("MetaMask not found"),null;let a=n;n.providers?.length&&(a=n.providers.find(u=>u.isMetaMask)||n);let h=(await a.request({method:"eth_requestAccounts"}))[0];return h?(r({connected:!0,address:h,chain:"ethereum",provider:"metamask"}),h):(i("No account selected"),null)}catch(t){return i(t.message||"Failed to connect wallet"),null}},[]),d=useCallback(async t=>{i(null);try{if(e.chain==="solana"){let n=typeof window<"u"?window:null,a=e.provider==="phantom"?n?.phantom?.solana||n?.solana:n?.solflare;if(!a)throw new Error("Wallet not available");let l=new TextEncoder().encode(t),h=await a.signMessage(l,"utf8"),u=h.signature||h,m="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",f=BigInt(0);for(let C of u)f=f*256n+BigInt(C);let y="";for(;f>0n;)y=m[Number(f%58n)]+y,f=f/58n;for(let C of u)if(C===0)y="1"+y;else break;return y}if(e.chain==="ethereum"){let a=(typeof window<"u"?window:null)?.ethereum;if(a?.providers?.length&&(a=a.providers.find(h=>h.isMetaMask)||a),!a)throw new Error("MetaMask not available");return await a.request({method:"personal_sign",params:[t,e.address]})}throw new Error("No wallet connected")}catch(n){return i(n.message||"Signing failed"),null}},[e]),s=useCallback(()=>{r({connected:false,address:null,chain:null,provider:null}),i(null);},[]);return {wallet:e,error:o,connectSolana:c,connectEVM:p,signMessage:d,disconnect:s}}var de="https://stacknet.magma-rpc.com/auth/bridge",U="stacknet-auth-bridge";function v(e){let r=e?.bridgeUrl||de,o=e?.disabled||false,i=useRef(null),[c,p]=useState({ready:false,known:false,identity:null,identityCount:0}),d=useRef([]),s=useRef(false),t=useCallback(u=>{let m={...u,protocol:U};s.current&&i.current?.contentWindow?i.current.contentWindow.postMessage(m,new URL(r).origin):d.current.push(m);},[r]);useEffect(()=>{if(o)return;let u=f=>{if(!(!f.data||f.data.protocol!==U)){try{if(f.origin!==new URL(r).origin)return}catch{return}switch(f.data.type){case "bridge:ready":s.current=true,p(y=>({...y,ready:true}));for(let y of d.current)i.current?.contentWindow?.postMessage(y,f.origin);d.current=[],i.current?.contentWindow?.postMessage({protocol:U,type:"auth:check"},f.origin);break;case "auth:status":p(y=>({...y,known:f.data.known,identity:f.data.identity,identityCount:f.data.identityCount||0}));break;}}};window.addEventListener("message",u);let m=document.createElement("iframe");return m.src=r,m.style.display="none",m.setAttribute("aria-hidden","true"),m.setAttribute("tabindex","-1"),m.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(m),i.current=m,()=>{window.removeEventListener("message",u),m.parentNode&&m.parentNode.removeChild(m),i.current=null,s.current=false;}},[r,o]);let n=useCallback(u=>{t({type:"auth:connected",...u});},[t]),a=useCallback(u=>{t({type:"auth:disconnected",...u});},[t]),l=useCallback(()=>{t({type:"auth:clear"}),p({ready:c.ready,known:false,identity:null,identityCount:0});},[t,c.ready]),h=useCallback(()=>{t({type:"auth:check"});},[t]);return {...c,reportConnected:n,reportDisconnected:a,clearAll:l,refresh:h}}async function Y(e,r,o,i){let c=e.apiVersion||"v2",p=`${e.baseUrl}/api/${c}${o}`;try{let d=await fetch(p,{method:r,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),s=await d.json();return d.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(d){return {success:false,error:{code:"NETWORK_ERROR",message:d instanceof Error?d.message:"Network error"}}}}function Z(e){return {getNetworkStatus:()=>Y(e,"GET","/network/status"),getWeb3Challenge:(r,o)=>Y(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:r,address:o})}}function pe(e={apiBaseUrl:""}){let{wallet:r,connectSolana:o,connectEVM:i,signMessage:c,disconnect:p}=$(),{session:d,isAuthenticated:s,refresh:t,readSession:n}=O(),{headers:a}=M(),l=v({disabled:typeof window>"u"}),[h,u]=useState(false),[m,f]=useState(null),[y,C]=useState(false),w=e.apiBaseUrl||"",ne=e.stacknetUrl||"https://stacknet.magma-rpc.com",D=Z({baseUrl:ne,stackId:e.stackId||""}),R=useCallback(async(g,b,N,ae)=>{u(true),f(null);try{let S=b;if(!S){let W=await N();if(!W)return u(!1),!1;S=W;}let E=await D.getWeb3Challenge(g,S);if(!E.success||!E.data)return f("Failed to get challenge"),u(!1),!1;let H=await c(E.data.message);if(!H)return u(!1),!1;let q={chain:g,message:E.data.message,signature:H};g==="solana"&&(q.publicKey=S);let K=await fetch(`${w}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(q)});if(!K.ok){let W=await K.json().catch(()=>({}));return f(W.error||"Authentication failed"),u(!1),!1}return l.reportConnected({address:S,chain:g,method:ae||(g==="solana"?"phantom":"metamask"),stackId:e.stackId}),n(),u(!1),!0}catch(S){return f(S.message||"Authentication failed"),u(false),false}},[w,D,c,n,l,e.stackId]),A=useCallback(async(g="phantom")=>{let b=await o(g);return b?R("solana",b,()=>o(g),g):false},[o,R]),I=useCallback(async()=>{let g=await i();return g?R("ethereum",g,i,"metamask"):false},[i,R]),se=useCallback(async g=>{u(true),f(null);try{let b=await fetch(`${w}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:g})});if(!b.ok){let N=await b.json().catch(()=>({}));return f(N.error||"Invalid code"),u(!1),!1}return n(),u(!1),!0}catch(b){return f(b.message||"OTP verification failed"),u(false),false}},[w,n]),re=useCallback(async()=>{r.address&&r.chain&&l.reportDisconnected({address:r.address,chain:r.chain,stackId:e.stackId});try{await fetch(`${w}/api/auth/logout`,{method:"POST",headers:a});}catch{}p(),n();},[w,a,p,n,r,l,e.stackId]);return useEffect(()=>{if(!e.autoConnect||y||s||!l.ready||!l.known||!l.identity)return;C(true);let{chain:g,method:b}=l.identity;g==="solana"&&(b==="phantom"||b==="solflare")?A(b):g==="ethereum"&&I();},[e.autoConnect,y,s,l,A,I]),{session:d,isAuthenticated:s,wallet:r,loading:h,error:m,authenticateSolana:A,authenticateEVM:I,authenticateOTP:se,logout:re,refresh:()=>t(w),bridge:{ready:l.ready,known:l.known,identity:l.identity,identityCount:l.identityCount}}}function ge(e=""){let[r,o]=useState([]),[i,c]=useState(true),[p,d]=useState(null),s=useCallback(async()=>{try{let t=await fetch(`${e}/api/billing/plans`);if(t.ok){let n=await t.json();o(n.plans||n||[]);}}catch(t){d(t.message);}finally{c(false);}},[e]);return useEffect(()=>{s();},[s]),{plans:r,loading:i,error:p,refresh:s}}function be(e=""){let[r,o]=useState(null),[i,c]=useState(true),[p,d]=useState(null),s=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/subscription`);if(a.ok){let l=await a.json();o(l.plan?l:null);}}catch(a){d(a.message);}finally{c(false);}},[e]);useEffect(()=>{s();},[s]);let t=useCallback(async a=>{let l=k(),u=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...l?{"x-csrf-token":l}:{}},body:JSON.stringify({planId:a})})).json();return u.url||u.checkoutUrl||null},[e]),n=useCallback(async()=>{let a=k();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:a?{"x-csrf-token":a}:{}})).ok?(await s(),true):false},[e,s]);return {subscription:r,loading:i,error:p,refresh:s,subscribe:t,cancel:n}}function Se(e=""){let[r,o]=useState(null),[i,c]=useState(true),[p,d]=useState(null),s=useCallback(async()=>{try{let t=await fetch(`${e}/api/billing/usage`);if(t.ok){let n=await t.json();o(n);}}catch(t){d(t.message);}finally{c(false);}},[e]);return useEffect(()=>{s();},[s]),{usage:r,loading:i,error:p,refresh:s}}function Ce(e=""){let[r,o]=useState(false),[i,c]=useState(null),p=useCallback(async s=>{o(true),c(null);try{let t=k(),n=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-csrf-token":t}:{}},body:JSON.stringify({amountCents:s})}),a=await n.json();return n.ok?a.url||null:(c(a.error||"Purchase failed"),null)}catch(t){return c(t.message),null}finally{o(false);}},[e]),d=useCallback(async s=>{o(true),c(null);try{let t=k(),n=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-csrf-token":t}:{}},body:JSON.stringify({sessionId:s})}),a=await n.json();return n.ok?a:(c(a.error||"Verification failed"),null)}catch(t){return c(t.message),null}finally{o(false);}},[e]);return {purchase:p,verifySession:d,loading:r,error:i}}function Re(e="",r){let[o,i]=useState([]),[c,p]=useState(true),[d,s]=useState(null),t=r?.limit||50,n=r?.offset||0,a=useCallback(async()=>{try{let l=await fetch(`${e}/api/billing/history?limit=${t}&offset=${n}`);if(l.ok){let h=await l.json();i(h.records||h.history||(Array.isArray(h)?h:[]));}}catch(l){s(l.message);}finally{p(false);}},[e,t,n]);return useEffect(()=>{a();},[a]),{records:o,loading:c,error:d,refresh:a}}
|
|
2
|
+
export{v as useAuthBridge,Re as useBillingHistory,M as useCSRFToken,ge as usePlans,Ce as usePrepaidCheckout,O as useSession,pe as useStackAuth,be as useSubscription,Se as useUsage,$ 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 Se(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function ve(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 Ie(e,n){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let r=new URL(e,n);return r.origin!==n?"/":r.pathname+r.search+r.hash}catch{return "/"}}function Te(e){try{let n=e.split(".");if(n.length!==3)return null;let r=atob(n[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)}catch{return null}}function F(){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 n=e.slice(18);return JSON.parse(atob(n.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function M(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function Q(){let[e,n]=react.useState(null),[r,l]=react.useState(true),u=react.useCallback(()=>{let o=F();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);},[]);react.useEffect(()=>{u();},[u]);let h=react.useCallback(async(o="")=>{try{let a=await fetch(`${o}/api/auth/session`);if(a.ok){let s=await a.json();if(s.session)return n(s.session),s.session}return n(null),null}catch{return null}},[]),f=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:f,refresh:h,readSession:u}}function H(e="__csrf",n="x-csrf-token"){let[r,l]=react.useState(null);react.useEffect(()=>{l(M(e));},[e]);let u=r?{[n]:r}:{};return {token:r,headers:u}}function V(){let[e,n]=react.useState({connected:false,address:null,chain:null,provider:null}),[r,l]=react.useState(null),u=react.useCallback(async(a="phantom")=>{l(null);try{let s=typeof window<"u"?window:null,i=a==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!i)return l(`${a} wallet not found`),null;let t=(await i.connect()).publicKey.toString();return n({connected:!0,address:t,chain:"solana",provider:a}),t}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),h=react.useCallback(async()=>{l(null);try{let s=(typeof window<"u"?window:null)?.ethereum;if(!s)return l("MetaMask not found"),null;let i=s;s.providers?.length&&(i=s.providers.find(d=>d.isMetaMask)||s);let t=(await i.request({method:"eth_requestAccounts"}))[0];return t?(n({connected:!0,address:t,chain:"ethereum",provider:"metamask"}),t):(l("No account selected"),null)}catch(a){return l(a.message||"Failed to connect wallet"),null}},[]),f=react.useCallback(async a=>{l(null);try{if(e.chain==="solana"){let s=typeof window<"u"?window:null,i=e.provider==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!i)throw new Error("Wallet not available");let c=new TextEncoder().encode(a),t=await i.signMessage(c,"utf8"),d=t.signature||t,m="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",g=BigInt(0);for(let w of d)g=g*256n+BigInt(w);let x="";for(;g>0n;)x=m[Number(g%58n)]+x,g=g/58n;for(let w of d)if(w===0)x="1"+x;else break;return x}if(e.chain==="ethereum"){let i=(typeof window<"u"?window:null)?.ethereum;if(i?.providers?.length&&(i=i.providers.find(t=>t.isMetaMask)||i),!i)throw new Error("MetaMask not available");return await i.request({method:"personal_sign",params:[a,e.address]})}throw new Error("No wallet connected")}catch(s){return l(s.message||"Signing failed"),null}},[e]),o=react.useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:r,connectSolana:u,connectEVM:h,signMessage:f,disconnect:o}}async function fe(e,n,r,l){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${r}`;try{let f=await fetch(h,{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 B(e){return {getNetworkStatus:()=>fe(e,"GET","/network/status"),getWeb3Challenge:(n,r)=>fe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:n,address:r})}}function Y(e){let{wallet:n,connectSolana:r,connectEVM:l,signMessage:u,disconnect:h}=V(),{session:f,isAuthenticated:o,refresh:a,readSession:s}=Q(),{headers:i}=H(),[c,t]=react.useState(false),[d,m]=react.useState(null),g=e.apiBaseUrl||"",x=e.stacknetUrl||"https://stacknet.magma-rpc.com",w=B({baseUrl:x,stackId:e.stackId||""}),S=react.useCallback(async(N="phantom")=>{t(true),m(null);try{let y=await r(N);if(!y)return t(!1),!1;let C=await w.getWeb3Challenge("solana",y);if(!C.success||!C.data)return m("Failed to get challenge"),t(!1),!1;let I=await u(C.data.message);if(!I)return t(!1),!1;let z=await fetch(`${g}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"solana",message:C.data.message,signature:I,publicKey:y})});if(!z.ok){let W=await z.json().catch(()=>({}));return m(W.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(y){return m(y.message||"Authentication failed"),t(false),false}},[g,w,r,u,s]),D=react.useCallback(async()=>{t(true),m(null);try{let N=await l();if(!N)return t(!1),!1;let y=await w.getWeb3Challenge("ethereum",N);if(!y.success||!y.data)return m("Failed to get challenge"),t(!1),!1;let C=await u(y.data.message);if(!C)return t(!1),!1;let I=await fetch(`${g}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"ethereum",message:y.data.message,signature:C})});if(!I.ok){let z=await I.json().catch(()=>({}));return m(z.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(N){return m(N.message||"Authentication failed"),t(false),false}},[g,w,l,u,s]),v=react.useCallback(async N=>{t(true),m(null);try{let y=await fetch(`${g}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:N})});if(!y.ok){let C=await y.json().catch(()=>({}));return m(C.error||"Invalid code"),t(!1),!1}return s(),t(!1),!0}catch(y){return m(y.message||"OTP verification failed"),t(false),false}},[g,s]),_=react.useCallback(async()=>{try{await fetch(`${g}/api/auth/logout`,{method:"POST",headers:i});}catch{}h(),s();},[g,i,h,s]);return {session:f,isAuthenticated:o,wallet:n,loading:c,error:d,authenticateSolana:S,authenticateEVM:D,authenticateOTP:v,logout:_,refresh:()=>a(g)}}function Ue(e=""){let[n,r]=react.useState([]),[l,u]=react.useState(true),[h,f]=react.useState(null),o=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/plans`);if(a.ok){let s=await a.json();r(s.plans||s||[]);}}catch(a){f(a.message);}finally{u(false);}},[e]);return react.useEffect(()=>{o();},[o]),{plans:n,loading:l,error:h,refresh:o}}function Le(e=""){let[n,r]=react.useState(null),[l,u]=react.useState(true),[h,f]=react.useState(null),o=react.useCallback(async()=>{try{let i=await fetch(`${e}/api/billing/subscription`);if(i.ok){let c=await i.json();r(c.plan?c:null);}}catch(i){f(i.message);}finally{u(false);}},[e]);react.useEffect(()=>{o();},[o]);let a=react.useCallback(async i=>{let c=M(),d=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...c?{"x-csrf-token":c}:{}},body:JSON.stringify({planId:i})})).json();return d.url||d.checkoutUrl||null},[e]),s=react.useCallback(async()=>{let i=M();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:i?{"x-csrf-token":i}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:n,loading:l,error:h,refresh:o,subscribe:a,cancel:s}}function _e(e=""){let[n,r]=react.useState(null),[l,u]=react.useState(true),[h,f]=react.useState(null),o=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/usage`);if(a.ok){let s=await a.json();r(s);}}catch(a){f(a.message);}finally{u(false);}},[e]);return react.useEffect(()=>{o();},[o]),{usage:n,loading:l,error:h,refresh:o}}function We(e=""){let[n,r]=react.useState(false),[l,u]=react.useState(null),h=react.useCallback(async o=>{r(true),u(null);try{let a=M(),s=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({amountCents:o})}),i=await s.json();return s.ok?i.url||null:(u(i.error||"Purchase failed"),null)}catch(a){return u(a.message),null}finally{r(false);}},[e]),f=react.useCallback(async o=>{r(true),u(null);try{let a=M(),s=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({sessionId:o})}),i=await s.json();return s.ok?i:(u(i.error||"Verification failed"),null)}catch(a){return u(a.message),null}finally{r(false);}},[e]);return {purchase:h,verifySession:f,loading:n,error:l}}function Qe(e="",n){let[r,l]=react.useState([]),[u,h]=react.useState(true),[f,o]=react.useState(null),a=n?.limit||50,s=n?.offset||0,i=react.useCallback(async()=>{try{let c=await fetch(`${e}/api/billing/history?limit=${a}&offset=${s}`);if(c.ok){let t=await c.json();l(t.records||t.history||(Array.isArray(t)?t:[]));}}catch(c){o(c.message);}finally{h(false);}},[e,a,s]);return react.useEffect(()=>{i();},[i]),{records:r,loading:u,error:f,refresh:i}}var ge=react.createContext(null);function Be(){let e=react.useContext(ge);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Ye({config:e,callbacks:n,children:r}){return jsxRuntime.jsx(ge.Provider,{value:{config:e,callbacks:n},children:r})}function A({length:e=6,onComplete:n,disabled:r=false,error:l,className:u="",inputClassName:h=""}){let [f,o]=react.useState(Array(e).fill("")),a=react.useCallback((c,t)=>{if(t.length>1){let m=t.replace(/\D/g,"").slice(0,e).split(""),g=[...f];m.forEach((w,S)=>{c+S<e&&(g[c+S]=w);}),o(g);let x=Math.min(c+m.length,e-1);document.getElementById(`userutils-otp-${x}`)?.focus(),g.every(w=>w!=="")&&setTimeout(()=>n(g.join("")),100);return}if(!/^\d?$/.test(t))return;let d=[...f];d[c]=t,o(d),t&&c<e-1&&document.getElementById(`userutils-otp-${c+1}`)?.focus(),t&&c===e-1&&d.every(m=>m!=="")&&setTimeout(()=>n(d.join("")),100);},[f,e,n]),s=react.useCallback((c,t)=>{if(t.key==="Backspace"&&!f[c]&&c>0){document.getElementById(`userutils-otp-${c-1}`)?.focus();let d=[...f];d[c-1]="",o(d);}if(t.key==="Enter"){let d=f.join("");d.length===e&&n(d);}},[f,e,n]);react.useCallback(()=>{o(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:f.map((c,t)=>jsxRuntime.jsx("input",{id:`userutils-otp-${t}`,type:"text",inputMode:"numeric",maxLength:e,value:c,onChange:d=>a(t,d.target.value),onKeyDown:d=>s(t,d),disabled:r,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 ${h}`},t))}),l&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}A.displayName="OTPInput";var Ke="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function L({className:e}){return jsxRuntime.jsx("img",{src:Ke,alt:"Phantom",className:e})}function E({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 se({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 re({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function tt({config:e,onSuccess:n,title:r="Log in or Sign up",showWallets:l=["phantom","metamask"],showOTP:u=true,className:h=""}){let{isAuthenticated:f,wallet:o,loading:a,error:s,authenticateSolana:i,authenticateEVM:c,authenticateOTP:t}=Y(e),[d,m]=react.useState("select"),[g,x]=react.useState(null),[w,S]=react.useState(false),[D,v]=react.useState("idle"),[_,N]=react.useState(""),[y,C]=react.useState(false),[I,z]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let k=()=>{let $=window;C(!!($.phantom?.solana?.isPhantom||$.solana?.isPhantom));let ie=$.ethereum;z(!!(ie?.isMetaMask||ie?.providers?.some(be=>be.isMetaMask)));};k(),window.addEventListener("ethereum#initialized",k);let ae=setTimeout(k,500);return ()=>{window.removeEventListener("ethereum#initialized",k),clearTimeout(ae);}},[]),react.useEffect(()=>{f&&d==="success"&&n?.();},[f,d,n]);let W=async()=>{x("phantom"),m("connecting");let k=await i("phantom");m(k?"success":"error");},Ne=async()=>{x("metamask"),m("connecting");let k=await c();m(k?"success":"error");},Ce=async k=>{v("verifying"),N(""),await t(k)?(v("success"),m("success")):(v("error"),N("Invalid or expired code"),setTimeout(()=>v("idle"),2e3));},oe=()=>{m("select"),x(null),S(false),v("idle"),N("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${h}`,children:[jsxRuntime.jsx("div",{className:"mb-6 text-center",children:jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:r})}),s&&d==="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:oe,children:"Try Again"})]}),d==="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..."})]}),d==="connecting"&&a&&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:[g==="phantom"&&jsxRuntime.jsx(L,{className:"h-14 w-14"}),g==="metamask"&&jsxRuntime.jsx(E,{className:"h-14 w-14"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:o.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:oe,children:"Cancel"})]}),d==="select"&&!a&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:W,disabled:!y,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${y?"":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(L,{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"}),!y&&jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsxRuntime.jsx(se,{className:"h-8 w-8"})]}),l.includes("metamask")&&I&&jsxRuntime.jsxs("button",{onClick:Ne,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(E,{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(re,{className:"h-8 w-8"})]}),u&&!w&&jsxRuntime.jsxs("button",{onClick:()=>S(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"})})]}),u&&w&&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(A,{onComplete:Ce,disabled:D==="verifying",error:_}),D==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),D==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function nt({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 ot({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 it({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 ct({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=
|
|
1
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function ve(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function Te(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 De(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 Ae(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 J(){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 I(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 K(){let[e,t]=react.useState(null),[s,l]=react.useState(true),p=react.useCallback(()=>{let n=J();n&&n.expiresAt>Date.now()?t({userId:n.userId,address:n.address,chain:n.chain,expiresAt:n.expiresAt,planId:n.planId,authMethod:n.authMethod}):t(null),l(false);},[]);react.useEffect(()=>{p();},[p]);let y=react.useCallback(async(n="")=>{try{let o=await fetch(`${n}/api/auth/session`);if(o.ok){let r=await o.json();if(r.session)return t(r.session),r.session}return t(null),null}catch{return null}},[]),d=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:d,refresh:y,readSession:p}}function q(e="__csrf",t="x-csrf-token"){let[s,l]=react.useState(null);react.useEffect(()=>{l(I(e));},[e]);let p=s?{[t]:s}:{};return {token:s,headers:p}}function X(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[s,l]=react.useState(null),p=react.useCallback(async(o="phantom")=>{l(null);try{let r=typeof window<"u"?window:null,c=o==="phantom"?r?.phantom?.solana||r?.solana:r?.solflare;if(!c)return l(`${o} wallet not found`),null;let u=(await c.connect()).publicKey.toString();return t({connected:!0,address:u,chain:"solana",provider:o}),u}catch(r){return l(r.message||"Failed to connect wallet"),null}},[]),y=react.useCallback(async()=>{l(null);try{let r=(typeof window<"u"?window:null)?.ethereum;if(!r)return l("MetaMask not found"),null;let c=r;r.providers?.length&&(c=r.providers.find(i=>i.isMetaMask)||r);let u=(await c.request({method:"eth_requestAccounts"}))[0];return u?(t({connected:!0,address:u,chain:"ethereum",provider:"metamask"}),u):(l("No account selected"),null)}catch(o){return l(o.message||"Failed to connect wallet"),null}},[]),d=react.useCallback(async o=>{l(null);try{if(e.chain==="solana"){let r=typeof window<"u"?window:null,c=e.provider==="phantom"?r?.phantom?.solana||r?.solana:r?.solflare;if(!c)throw new Error("Wallet not available");let a=new TextEncoder().encode(o),u=await c.signMessage(a,"utf8"),i=u.signature||u,g="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",f=BigInt(0);for(let C of i)f=f*256n+BigInt(C);let k="";for(;f>0n;)k=g[Number(f%58n)]+k,f=f/58n;for(let C of i)if(C===0)k="1"+k;else break;return k}if(e.chain==="ethereum"){let c=(typeof window<"u"?window:null)?.ethereum;if(c?.providers?.length&&(c=c.providers.find(u=>u.isMetaMask)||c),!c)throw new Error("MetaMask not available");return await c.request({method:"personal_sign",params:[o,e.address]})}throw new Error("No wallet connected")}catch(r){return l(r.message||"Signing failed"),null}},[e]),n=react.useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:s,connectSolana:p,connectEVM:y,signMessage:d,disconnect:n}}var Re="https://stacknet.magma-rpc.com/auth/bridge",te="stacknet-auth-bridge";function ne(e){let t=e?.bridgeUrl||Re,s=e?.disabled||false,l=react.useRef(null),[p,y]=react.useState({ready:false,known:false,identity:null,identityCount:0}),d=react.useRef([]),n=react.useRef(false),o=react.useCallback(i=>{let g={...i,protocol:te};n.current&&l.current?.contentWindow?l.current.contentWindow.postMessage(g,new URL(t).origin):d.current.push(g);},[t]);react.useEffect(()=>{if(s)return;let i=f=>{if(!(!f.data||f.data.protocol!==te)){try{if(f.origin!==new URL(t).origin)return}catch{return}switch(f.data.type){case "bridge:ready":n.current=true,y(k=>({...k,ready:true}));for(let k of d.current)l.current?.contentWindow?.postMessage(k,f.origin);d.current=[],l.current?.contentWindow?.postMessage({protocol:te,type:"auth:check"},f.origin);break;case "auth:status":y(k=>({...k,known:f.data.known,identity:f.data.identity,identityCount:f.data.identityCount||0}));break;}}};window.addEventListener("message",i);let g=document.createElement("iframe");return g.src=t,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",i),g.parentNode&&g.parentNode.removeChild(g),l.current=null,n.current=false;}},[t,s]);let r=react.useCallback(i=>{o({type:"auth:connected",...i});},[o]),c=react.useCallback(i=>{o({type:"auth:disconnected",...i});},[o]),a=react.useCallback(()=>{o({type:"auth:clear"}),y({ready:p.ready,known:false,identity:null,identityCount:0});},[o,p.ready]),u=react.useCallback(()=>{o({type:"auth:check"});},[o]);return {...p,reportConnected:r,reportDisconnected:c,clearAll:a,refresh:u}}async function we(e,t,s,l){let p=e.apiVersion||"v2",y=`${e.baseUrl}/api/${p}${s}`;try{let d=await fetch(y,{method:t,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),n=await d.json();return d.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(d){return {success:false,error:{code:"NETWORK_ERROR",message:d instanceof Error?d.message:"Network error"}}}}function oe(e){return {getNetworkStatus:()=>we(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>we(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:t,address:s})}}function re(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:l,signMessage:p,disconnect:y}=X(),{session:d,isAuthenticated:n,refresh:o,readSession:r}=K(),{headers:c}=q(),a=ne({disabled:typeof window>"u"}),[u,i]=react.useState(false),[g,f]=react.useState(null),[k,C]=react.useState(false),N=e.apiBaseUrl||"",U=e.stacknetUrl||"https://stacknet.magma-rpc.com",S=oe({baseUrl:U,stackId:e.stackId||""}),D=react.useCallback(async(w,b,z,G)=>{i(true),f(null);try{let L=b;if(!L){let P=await z();if(!P)return i(!1),!1;L=P;}let x=await S.getWeb3Challenge(w,L);if(!x.success||!x.data)return f("Failed to get challenge"),i(!1),!1;let O=await p(x.data.message);if(!O)return i(!1),!1;let A={chain:w,message:x.data.message,signature:O};w==="solana"&&(A.publicKey=L);let E=await fetch(`${N}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)});if(!E.ok){let P=await E.json().catch(()=>({}));return f(P.error||"Authentication failed"),i(!1),!1}return a.reportConnected({address:L,chain:w,method:G||(w==="solana"?"phantom":"metamask"),stackId:e.stackId}),r(),i(!1),!0}catch(L){return f(L.message||"Authentication failed"),i(false),false}},[N,S,p,r,a,e.stackId]),j=react.useCallback(async(w="phantom")=>{let b=await s(w);return b?D("solana",b,()=>s(w),w):false},[s,D]),v=react.useCallback(async()=>{let w=await l();return w?D("ethereum",w,l,"metamask"):false},[l,D]),Y=react.useCallback(async w=>{i(true),f(null);try{let b=await fetch(`${N}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:w})});if(!b.ok){let z=await b.json().catch(()=>({}));return f(z.error||"Invalid code"),i(!1),!1}return r(),i(!1),!0}catch(b){return f(b.message||"OTP verification failed"),i(false),false}},[N,r]),Z=react.useCallback(async()=>{t.address&&t.chain&&a.reportDisconnected({address:t.address,chain:t.chain,stackId:e.stackId});try{await fetch(`${N}/api/auth/logout`,{method:"POST",headers:c});}catch{}y(),r();},[N,c,y,r,t,a,e.stackId]);return react.useEffect(()=>{if(!e.autoConnect||k||n||!a.ready||!a.known||!a.identity)return;C(true);let{chain:w,method:b}=a.identity;w==="solana"&&(b==="phantom"||b==="solflare")?j(b):w==="ethereum"&&v();},[e.autoConnect,k,n,a,j,v]),{session:d,isAuthenticated:n,wallet:t,loading:u,error:g,authenticateSolana:j,authenticateEVM:v,authenticateOTP:Y,logout:Z,refresh:()=>o(N),bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount}}}function $e(e=""){let[t,s]=react.useState([]),[l,p]=react.useState(true),[y,d]=react.useState(null),n=react.useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/plans`);if(o.ok){let r=await o.json();s(r.plans||r||[]);}}catch(o){d(o.message);}finally{p(false);}},[e]);return react.useEffect(()=>{n();},[n]),{plans:t,loading:l,error:y,refresh:n}}function Qe(e=""){let[t,s]=react.useState(null),[l,p]=react.useState(true),[y,d]=react.useState(null),n=react.useCallback(async()=>{try{let c=await fetch(`${e}/api/billing/subscription`);if(c.ok){let a=await c.json();s(a.plan?a:null);}}catch(c){d(c.message);}finally{p(false);}},[e]);react.useEffect(()=>{n();},[n]);let o=react.useCallback(async c=>{let a=I(),i=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({planId:c})})).json();return i.url||i.checkoutUrl||null},[e]),r=react.useCallback(async()=>{let c=I();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:c?{"x-csrf-token":c}:{}})).ok?(await n(),true):false},[e,n]);return {subscription:t,loading:l,error:y,refresh:n,subscribe:o,cancel:r}}function Ye(e=""){let[t,s]=react.useState(null),[l,p]=react.useState(true),[y,d]=react.useState(null),n=react.useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/usage`);if(o.ok){let r=await o.json();s(r);}}catch(o){d(o.message);}finally{p(false);}},[e]);return react.useEffect(()=>{n();},[n]),{usage:t,loading:l,error:y,refresh:n}}function Ze(e=""){let[t,s]=react.useState(false),[l,p]=react.useState(null),y=react.useCallback(async n=>{s(true),p(null);try{let o=I(),r=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({amountCents:n})}),c=await r.json();return r.ok?c.url||null:(p(c.error||"Purchase failed"),null)}catch(o){return p(o.message),null}finally{s(false);}},[e]),d=react.useCallback(async n=>{s(true),p(null);try{let o=I(),r=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({sessionId:n})}),c=await r.json();return r.ok?c:(p(c.error||"Verification failed"),null)}catch(o){return p(o.message),null}finally{s(false);}},[e]);return {purchase:y,verifySession:d,loading:t,error:l}}function Ke(e="",t){let[s,l]=react.useState([]),[p,y]=react.useState(true),[d,n]=react.useState(null),o=t?.limit||50,r=t?.offset||0,c=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/history?limit=${o}&offset=${r}`);if(a.ok){let u=await a.json();l(u.records||u.history||(Array.isArray(u)?u:[]));}}catch(a){n(a.message);}finally{y(false);}},[e,o,r]);return react.useEffect(()=>{c();},[c]),{records:s,loading:p,error:d,refresh:c}}var Ne=react.createContext(null);function et(){let e=react.useContext(Ne);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function tt({config:e,callbacks:t,children:s}){return jsxRuntime.jsx(Ne.Provider,{value:{config:e,callbacks:t},children:s})}function F({length:e=6,onComplete:t,disabled:s=false,error:l,className:p="",inputClassName:y=""}){let [d,n]=react.useState(Array(e).fill("")),o=react.useCallback((a,u)=>{if(u.length>1){let g=u.replace(/\D/g,"").slice(0,e).split(""),f=[...d];g.forEach((C,N)=>{a+N<e&&(f[a+N]=C);}),n(f);let k=Math.min(a+g.length,e-1);document.getElementById(`userutils-otp-${k}`)?.focus(),f.every(C=>C!=="")&&setTimeout(()=>t(f.join("")),100);return}if(!/^\d?$/.test(u))return;let i=[...d];i[a]=u,n(i),u&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),u&&a===e-1&&i.every(g=>g!=="")&&setTimeout(()=>t(i.join("")),100);},[d,e,t]),r=react.useCallback((a,u)=>{if(u.key==="Backspace"&&!d[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let i=[...d];i[a-1]="",n(i);}if(u.key==="Enter"){let i=d.join("");i.length===e&&t(i);}},[d,e,t]);react.useCallback(()=>{n(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:p,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:d.map((a,u)=>jsxRuntime.jsx("input",{id:`userutils-otp-${u}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:i=>o(u,i.target.value),onKeyDown:i=>r(u,i),disabled:s,autoFocus:u===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},u))}),l&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}F.displayName="OTPInput";var rt="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function Q({className:e}){return jsxRuntime.jsx("img",{src:rt,alt:"Phantom",className:e})}function H({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function fe({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 me({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 ct({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:l=["phantom","metamask"],showOTP:p=true,className:y=""}){let{isAuthenticated:d,wallet:n,loading:o,error:r,authenticateSolana:c,authenticateEVM:a,authenticateOTP:u}=re(e),[i,g]=react.useState("select"),[f,k]=react.useState(null),[C,N]=react.useState(false),[U,S]=react.useState("idle"),[D,j]=react.useState(""),[v,Y]=react.useState(false),[Z,w]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let x=()=>{let A=window;Y(!!(A.phantom?.solana?.isPhantom||A.solana?.isPhantom));let E=A.ethereum;w(!!(E?.isMetaMask||E?.providers?.some(P=>P.isMetaMask)));};x(),window.addEventListener("ethereum#initialized",x);let O=setTimeout(x,500);return ()=>{window.removeEventListener("ethereum#initialized",x),clearTimeout(O);}},[]),react.useEffect(()=>{d&&i==="success"&&t?.();},[d,i,t]);let b=async()=>{k("phantom"),g("connecting");let x=await c("phantom");g(x?"success":"error");},z=async()=>{k("metamask"),g("connecting");let x=await a();g(x?"success":"error");},G=async x=>{S("verifying"),j(""),await u(x)?(S("success"),g("success")):(S("error"),j("Invalid or expired code"),setTimeout(()=>S("idle"),2e3));},L=()=>{g("select"),k(null),N(false),S("idle"),j("");};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:s})}),r&&i==="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:L,children:"Try Again"})]}),i==="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..."})]}),i==="connecting"&&o&&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:[f==="phantom"&&jsxRuntime.jsx(Q,{className:"h-14 w-14"}),f==="metamask"&&jsxRuntime.jsx(H,{className:"h-14 w-14"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:n.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:L,children:"Cancel"})]}),i==="select"&&!o&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:b,disabled:!v,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${v?"":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(Q,{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"}),!v&&jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsxRuntime.jsx(fe,{className:"h-8 w-8"})]}),l.includes("metamask")&&Z&&jsxRuntime.jsxs("button",{onClick:z,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(H,{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(me,{className:"h-8 w-8"})]}),p&&!C&&jsxRuntime.jsxs("button",{onClick:()=>N(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"})})]}),p&&C&&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(F,{onComplete:G,disabled:U==="verifying",error:D}),U==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),U==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function dt({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 ft({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 mt({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 yt({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=ct;exports.DiscordIcon=mt;exports.EthereumIcon=me;exports.GoogleIcon=ft;exports.MetaMaskIcon=H;exports.OTPInput=F;exports.PhantomIcon=Q;exports.SolanaIcon=fe;exports.TelegramIcon=yt;exports.TwitterIcon=dt;exports.UserUtilsProvider=tt;exports.cn=ve;exports.createStackNetClient=oe;exports.decodeJwtPayloadClient=Ae;exports.formatTokens=Te;exports.readCSRFCookie=I;exports.readSessionCookie=J;exports.useAuthBridge=ne;exports.useBillingHistory=Ke;exports.useCSRFToken=q;exports.usePlans=$e;exports.usePrepaidCheckout=Ze;exports.useSession=K;exports.useStackAuth=re;exports.useSubscription=Qe;exports.useUsage=Ye;exports.useUserUtilsContext=et;exports.useWeb3Wallet=X;exports.validateRedirectUrl=De;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './index-BrziGArs.cjs';
|
|
2
2
|
export { B as BillingPlan, a as BillingRecord, M as MPCNode, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig } from './index-BrziGArs.cjs';
|
|
3
3
|
export { cn, decodeJwtPayloadClient, formatTokens, readCSRFCookie, readSessionCookie, validateRedirectUrl } from './utils/index.cjs';
|
|
4
|
-
export { WalletState, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.cjs';
|
|
4
|
+
export { BridgeIdentity, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.cjs';
|
|
5
5
|
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.cjs';
|
|
6
6
|
import 'clsx';
|
|
7
7
|
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './index-BrziGArs.js';
|
|
2
2
|
export { B as BillingPlan, a as BillingRecord, M as MPCNode, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig } from './index-BrziGArs.js';
|
|
3
3
|
export { cn, decodeJwtPayloadClient, formatTokens, readCSRFCookie, readSessionCookie, validateRedirectUrl } from './utils/index.js';
|
|
4
|
-
export { WalletState, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.js';
|
|
4
|
+
export { BridgeIdentity, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.js';
|
|
5
5
|
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.js';
|
|
6
6
|
import 'clsx';
|
|
7
7
|
import 'react/jsx-runtime';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useState,useCallback,useEffect,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function Se(...e){return twMerge(clsx(e))}function ve(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 Ie(e,n){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let r=new URL(e,n);return r.origin!==n?"/":r.pathname+r.search+r.hash}catch{return "/"}}function Te(e){try{let n=e.split(".");if(n.length!==3)return null;let r=atob(n[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)}catch{return null}}function F(){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 n=e.slice(18);return JSON.parse(atob(n.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function M(e="__csrf"){if(typeof document>"u")return null;let n=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return n?n.slice(e.length+1):null}function Q(){let[e,n]=useState(null),[r,l]=useState(true),u=useCallback(()=>{let o=F();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(()=>{u();},[u]);let h=useCallback(async(o="")=>{try{let a=await fetch(`${o}/api/auth/session`);if(a.ok){let s=await a.json();if(s.session)return n(s.session),s.session}return n(null),null}catch{return null}},[]),f=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:f,refresh:h,readSession:u}}function H(e="__csrf",n="x-csrf-token"){let[r,l]=useState(null);useEffect(()=>{l(M(e));},[e]);let u=r?{[n]:r}:{};return {token:r,headers:u}}function V(){let[e,n]=useState({connected:false,address:null,chain:null,provider:null}),[r,l]=useState(null),u=useCallback(async(a="phantom")=>{l(null);try{let s=typeof window<"u"?window:null,i=a==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!i)return l(`${a} wallet not found`),null;let t=(await i.connect()).publicKey.toString();return n({connected:!0,address:t,chain:"solana",provider:a}),t}catch(s){return l(s.message||"Failed to connect wallet"),null}},[]),h=useCallback(async()=>{l(null);try{let s=(typeof window<"u"?window:null)?.ethereum;if(!s)return l("MetaMask not found"),null;let i=s;s.providers?.length&&(i=s.providers.find(d=>d.isMetaMask)||s);let t=(await i.request({method:"eth_requestAccounts"}))[0];return t?(n({connected:!0,address:t,chain:"ethereum",provider:"metamask"}),t):(l("No account selected"),null)}catch(a){return l(a.message||"Failed to connect wallet"),null}},[]),f=useCallback(async a=>{l(null);try{if(e.chain==="solana"){let s=typeof window<"u"?window:null,i=e.provider==="phantom"?s?.phantom?.solana||s?.solana:s?.solflare;if(!i)throw new Error("Wallet not available");let c=new TextEncoder().encode(a),t=await i.signMessage(c,"utf8"),d=t.signature||t,m="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",g=BigInt(0);for(let w of d)g=g*256n+BigInt(w);let x="";for(;g>0n;)x=m[Number(g%58n)]+x,g=g/58n;for(let w of d)if(w===0)x="1"+x;else break;return x}if(e.chain==="ethereum"){let i=(typeof window<"u"?window:null)?.ethereum;if(i?.providers?.length&&(i=i.providers.find(t=>t.isMetaMask)||i),!i)throw new Error("MetaMask not available");return await i.request({method:"personal_sign",params:[a,e.address]})}throw new Error("No wallet connected")}catch(s){return l(s.message||"Signing failed"),null}},[e]),o=useCallback(()=>{n({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:r,connectSolana:u,connectEVM:h,signMessage:f,disconnect:o}}async function fe(e,n,r,l){let u=e.apiVersion||"v2",h=`${e.baseUrl}/api/${u}${r}`;try{let f=await fetch(h,{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 B(e){return {getNetworkStatus:()=>fe(e,"GET","/network/status"),getWeb3Challenge:(n,r)=>fe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:n,address:r})}}function Y(e){let{wallet:n,connectSolana:r,connectEVM:l,signMessage:u,disconnect:h}=V(),{session:f,isAuthenticated:o,refresh:a,readSession:s}=Q(),{headers:i}=H(),[c,t]=useState(false),[d,m]=useState(null),g=e.apiBaseUrl||"",x=e.stacknetUrl||"https://stacknet.magma-rpc.com",w=B({baseUrl:x,stackId:e.stackId||""}),S=useCallback(async(N="phantom")=>{t(true),m(null);try{let y=await r(N);if(!y)return t(!1),!1;let C=await w.getWeb3Challenge("solana",y);if(!C.success||!C.data)return m("Failed to get challenge"),t(!1),!1;let I=await u(C.data.message);if(!I)return t(!1),!1;let z=await fetch(`${g}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"solana",message:C.data.message,signature:I,publicKey:y})});if(!z.ok){let W=await z.json().catch(()=>({}));return m(W.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(y){return m(y.message||"Authentication failed"),t(false),false}},[g,w,r,u,s]),D=useCallback(async()=>{t(true),m(null);try{let N=await l();if(!N)return t(!1),!1;let y=await w.getWeb3Challenge("ethereum",N);if(!y.success||!y.data)return m("Failed to get challenge"),t(!1),!1;let C=await u(y.data.message);if(!C)return t(!1),!1;let I=await fetch(`${g}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chain:"ethereum",message:y.data.message,signature:C})});if(!I.ok){let z=await I.json().catch(()=>({}));return m(z.error||"Authentication failed"),t(!1),!1}return s(),t(!1),!0}catch(N){return m(N.message||"Authentication failed"),t(false),false}},[g,w,l,u,s]),v=useCallback(async N=>{t(true),m(null);try{let y=await fetch(`${g}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:N})});if(!y.ok){let C=await y.json().catch(()=>({}));return m(C.error||"Invalid code"),t(!1),!1}return s(),t(!1),!0}catch(y){return m(y.message||"OTP verification failed"),t(false),false}},[g,s]),_=useCallback(async()=>{try{await fetch(`${g}/api/auth/logout`,{method:"POST",headers:i});}catch{}h(),s();},[g,i,h,s]);return {session:f,isAuthenticated:o,wallet:n,loading:c,error:d,authenticateSolana:S,authenticateEVM:D,authenticateOTP:v,logout:_,refresh:()=>a(g)}}function Ue(e=""){let[n,r]=useState([]),[l,u]=useState(true),[h,f]=useState(null),o=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/plans`);if(a.ok){let s=await a.json();r(s.plans||s||[]);}}catch(a){f(a.message);}finally{u(false);}},[e]);return useEffect(()=>{o();},[o]),{plans:n,loading:l,error:h,refresh:o}}function Le(e=""){let[n,r]=useState(null),[l,u]=useState(true),[h,f]=useState(null),o=useCallback(async()=>{try{let i=await fetch(`${e}/api/billing/subscription`);if(i.ok){let c=await i.json();r(c.plan?c:null);}}catch(i){f(i.message);}finally{u(false);}},[e]);useEffect(()=>{o();},[o]);let a=useCallback(async i=>{let c=M(),d=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...c?{"x-csrf-token":c}:{}},body:JSON.stringify({planId:i})})).json();return d.url||d.checkoutUrl||null},[e]),s=useCallback(async()=>{let i=M();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:i?{"x-csrf-token":i}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:n,loading:l,error:h,refresh:o,subscribe:a,cancel:s}}function _e(e=""){let[n,r]=useState(null),[l,u]=useState(true),[h,f]=useState(null),o=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/usage`);if(a.ok){let s=await a.json();r(s);}}catch(a){f(a.message);}finally{u(false);}},[e]);return useEffect(()=>{o();},[o]),{usage:n,loading:l,error:h,refresh:o}}function We(e=""){let[n,r]=useState(false),[l,u]=useState(null),h=useCallback(async o=>{r(true),u(null);try{let a=M(),s=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({amountCents:o})}),i=await s.json();return s.ok?i.url||null:(u(i.error||"Purchase failed"),null)}catch(a){return u(a.message),null}finally{r(false);}},[e]),f=useCallback(async o=>{r(true),u(null);try{let a=M(),s=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({sessionId:o})}),i=await s.json();return s.ok?i:(u(i.error||"Verification failed"),null)}catch(a){return u(a.message),null}finally{r(false);}},[e]);return {purchase:h,verifySession:f,loading:n,error:l}}function Qe(e="",n){let[r,l]=useState([]),[u,h]=useState(true),[f,o]=useState(null),a=n?.limit||50,s=n?.offset||0,i=useCallback(async()=>{try{let c=await fetch(`${e}/api/billing/history?limit=${a}&offset=${s}`);if(c.ok){let t=await c.json();l(t.records||t.history||(Array.isArray(t)?t:[]));}}catch(c){o(c.message);}finally{h(false);}},[e,a,s]);return useEffect(()=>{i();},[i]),{records:r,loading:u,error:f,refresh:i}}var ge=createContext(null);function Be(){let e=useContext(ge);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Ye({config:e,callbacks:n,children:r}){return jsx(ge.Provider,{value:{config:e,callbacks:n},children:r})}function A({length:e=6,onComplete:n,disabled:r=false,error:l,className:u="",inputClassName:h=""}){let [f,o]=useState(Array(e).fill("")),a=useCallback((c,t)=>{if(t.length>1){let m=t.replace(/\D/g,"").slice(0,e).split(""),g=[...f];m.forEach((w,S)=>{c+S<e&&(g[c+S]=w);}),o(g);let x=Math.min(c+m.length,e-1);document.getElementById(`userutils-otp-${x}`)?.focus(),g.every(w=>w!=="")&&setTimeout(()=>n(g.join("")),100);return}if(!/^\d?$/.test(t))return;let d=[...f];d[c]=t,o(d),t&&c<e-1&&document.getElementById(`userutils-otp-${c+1}`)?.focus(),t&&c===e-1&&d.every(m=>m!=="")&&setTimeout(()=>n(d.join("")),100);},[f,e,n]),s=useCallback((c,t)=>{if(t.key==="Backspace"&&!f[c]&&c>0){document.getElementById(`userutils-otp-${c-1}`)?.focus();let d=[...f];d[c-1]="",o(d);}if(t.key==="Enter"){let d=f.join("");d.length===e&&n(d);}},[f,e,n]);useCallback(()=>{o(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:u,children:[jsx("div",{className:"flex gap-2 justify-center",children:f.map((c,t)=>jsx("input",{id:`userutils-otp-${t}`,type:"text",inputMode:"numeric",maxLength:e,value:c,onChange:d=>a(t,d.target.value),onKeyDown:d=>s(t,d),disabled:r,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 ${h}`},t))}),l&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}A.displayName="OTPInput";var Ke="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function L({className:e}){return jsx("img",{src:Ke,alt:"Phantom",className:e})}function E({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 se({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 re({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function tt({config:e,onSuccess:n,title:r="Log in or Sign up",showWallets:l=["phantom","metamask"],showOTP:u=true,className:h=""}){let{isAuthenticated:f,wallet:o,loading:a,error:s,authenticateSolana:i,authenticateEVM:c,authenticateOTP:t}=Y(e),[d,m]=useState("select"),[g,x]=useState(null),[w,S]=useState(false),[D,v]=useState("idle"),[_,N]=useState(""),[y,C]=useState(false),[I,z]=useState(false);useEffect(()=>{if(typeof window>"u")return;let k=()=>{let $=window;C(!!($.phantom?.solana?.isPhantom||$.solana?.isPhantom));let ie=$.ethereum;z(!!(ie?.isMetaMask||ie?.providers?.some(be=>be.isMetaMask)));};k(),window.addEventListener("ethereum#initialized",k);let ae=setTimeout(k,500);return ()=>{window.removeEventListener("ethereum#initialized",k),clearTimeout(ae);}},[]),useEffect(()=>{f&&d==="success"&&n?.();},[f,d,n]);let W=async()=>{x("phantom"),m("connecting");let k=await i("phantom");m(k?"success":"error");},Ne=async()=>{x("metamask"),m("connecting");let k=await c();m(k?"success":"error");},Ce=async k=>{v("verifying"),N(""),await t(k)?(v("success"),m("success")):(v("error"),N("Invalid or expired code"),setTimeout(()=>v("idle"),2e3));},oe=()=>{m("select"),x(null),S(false),v("idle"),N("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${h}`,children:[jsx("div",{className:"mb-6 text-center",children:jsx("h1",{className:"font-semibold text-2xl text-white",children:r})}),s&&d==="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:oe,children:"Try Again"})]}),d==="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..."})]}),d==="connecting"&&a&&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:[g==="phantom"&&jsx(L,{className:"h-14 w-14"}),g==="metamask"&&jsx(E,{className:"h-14 w-14"})]}),jsx("p",{className:"font-medium text-sm text-white",children:o.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:oe,children:"Cancel"})]}),d==="select"&&!a&&jsxs(Fragment,{children:[l.includes("phantom")&&jsxs("button",{onClick:W,disabled:!y,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${y?"":"cursor-not-allowed opacity-50"}`,children:[jsx(L,{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"}),!y&&jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsx(se,{className:"h-8 w-8"})]}),l.includes("metamask")&&I&&jsxs("button",{onClick:Ne,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(E,{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(re,{className:"h-8 w-8"})]}),u&&!w&&jsxs("button",{onClick:()=>S(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"})})]}),u&&w&&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(A,{onComplete:Ce,disabled:D==="verifying",error:_}),D==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),D==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function nt({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 ot({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 it({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 ct({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{
|
|
1
|
+
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useState,useCallback,useEffect,useRef,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function ve(...e){return twMerge(clsx(e))}function Te(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 De(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 Ae(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 J(){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 I(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 K(){let[e,t]=useState(null),[s,l]=useState(true),p=useCallback(()=>{let n=J();n&&n.expiresAt>Date.now()?t({userId:n.userId,address:n.address,chain:n.chain,expiresAt:n.expiresAt,planId:n.planId,authMethod:n.authMethod}):t(null),l(false);},[]);useEffect(()=>{p();},[p]);let y=useCallback(async(n="")=>{try{let o=await fetch(`${n}/api/auth/session`);if(o.ok){let r=await o.json();if(r.session)return t(r.session),r.session}return t(null),null}catch{return null}},[]),d=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:d,refresh:y,readSession:p}}function q(e="__csrf",t="x-csrf-token"){let[s,l]=useState(null);useEffect(()=>{l(I(e));},[e]);let p=s?{[t]:s}:{};return {token:s,headers:p}}function X(){let[e,t]=useState({connected:false,address:null,chain:null,provider:null}),[s,l]=useState(null),p=useCallback(async(o="phantom")=>{l(null);try{let r=typeof window<"u"?window:null,c=o==="phantom"?r?.phantom?.solana||r?.solana:r?.solflare;if(!c)return l(`${o} wallet not found`),null;let u=(await c.connect()).publicKey.toString();return t({connected:!0,address:u,chain:"solana",provider:o}),u}catch(r){return l(r.message||"Failed to connect wallet"),null}},[]),y=useCallback(async()=>{l(null);try{let r=(typeof window<"u"?window:null)?.ethereum;if(!r)return l("MetaMask not found"),null;let c=r;r.providers?.length&&(c=r.providers.find(i=>i.isMetaMask)||r);let u=(await c.request({method:"eth_requestAccounts"}))[0];return u?(t({connected:!0,address:u,chain:"ethereum",provider:"metamask"}),u):(l("No account selected"),null)}catch(o){return l(o.message||"Failed to connect wallet"),null}},[]),d=useCallback(async o=>{l(null);try{if(e.chain==="solana"){let r=typeof window<"u"?window:null,c=e.provider==="phantom"?r?.phantom?.solana||r?.solana:r?.solflare;if(!c)throw new Error("Wallet not available");let a=new TextEncoder().encode(o),u=await c.signMessage(a,"utf8"),i=u.signature||u,g="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",f=BigInt(0);for(let C of i)f=f*256n+BigInt(C);let k="";for(;f>0n;)k=g[Number(f%58n)]+k,f=f/58n;for(let C of i)if(C===0)k="1"+k;else break;return k}if(e.chain==="ethereum"){let c=(typeof window<"u"?window:null)?.ethereum;if(c?.providers?.length&&(c=c.providers.find(u=>u.isMetaMask)||c),!c)throw new Error("MetaMask not available");return await c.request({method:"personal_sign",params:[o,e.address]})}throw new Error("No wallet connected")}catch(r){return l(r.message||"Signing failed"),null}},[e]),n=useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:s,connectSolana:p,connectEVM:y,signMessage:d,disconnect:n}}var Re="https://stacknet.magma-rpc.com/auth/bridge",te="stacknet-auth-bridge";function ne(e){let t=e?.bridgeUrl||Re,s=e?.disabled||false,l=useRef(null),[p,y]=useState({ready:false,known:false,identity:null,identityCount:0}),d=useRef([]),n=useRef(false),o=useCallback(i=>{let g={...i,protocol:te};n.current&&l.current?.contentWindow?l.current.contentWindow.postMessage(g,new URL(t).origin):d.current.push(g);},[t]);useEffect(()=>{if(s)return;let i=f=>{if(!(!f.data||f.data.protocol!==te)){try{if(f.origin!==new URL(t).origin)return}catch{return}switch(f.data.type){case "bridge:ready":n.current=true,y(k=>({...k,ready:true}));for(let k of d.current)l.current?.contentWindow?.postMessage(k,f.origin);d.current=[],l.current?.contentWindow?.postMessage({protocol:te,type:"auth:check"},f.origin);break;case "auth:status":y(k=>({...k,known:f.data.known,identity:f.data.identity,identityCount:f.data.identityCount||0}));break;}}};window.addEventListener("message",i);let g=document.createElement("iframe");return g.src=t,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",i),g.parentNode&&g.parentNode.removeChild(g),l.current=null,n.current=false;}},[t,s]);let r=useCallback(i=>{o({type:"auth:connected",...i});},[o]),c=useCallback(i=>{o({type:"auth:disconnected",...i});},[o]),a=useCallback(()=>{o({type:"auth:clear"}),y({ready:p.ready,known:false,identity:null,identityCount:0});},[o,p.ready]),u=useCallback(()=>{o({type:"auth:check"});},[o]);return {...p,reportConnected:r,reportDisconnected:c,clearAll:a,refresh:u}}async function we(e,t,s,l){let p=e.apiVersion||"v2",y=`${e.baseUrl}/api/${p}${s}`;try{let d=await fetch(y,{method:t,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),n=await d.json();return d.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(d){return {success:false,error:{code:"NETWORK_ERROR",message:d instanceof Error?d.message:"Network error"}}}}function oe(e){return {getNetworkStatus:()=>we(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>we(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:t,address:s})}}function re(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:l,signMessage:p,disconnect:y}=X(),{session:d,isAuthenticated:n,refresh:o,readSession:r}=K(),{headers:c}=q(),a=ne({disabled:typeof window>"u"}),[u,i]=useState(false),[g,f]=useState(null),[k,C]=useState(false),N=e.apiBaseUrl||"",U=e.stacknetUrl||"https://stacknet.magma-rpc.com",S=oe({baseUrl:U,stackId:e.stackId||""}),D=useCallback(async(w,b,z,G)=>{i(true),f(null);try{let L=b;if(!L){let P=await z();if(!P)return i(!1),!1;L=P;}let x=await S.getWeb3Challenge(w,L);if(!x.success||!x.data)return f("Failed to get challenge"),i(!1),!1;let O=await p(x.data.message);if(!O)return i(!1),!1;let A={chain:w,message:x.data.message,signature:O};w==="solana"&&(A.publicKey=L);let E=await fetch(`${N}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)});if(!E.ok){let P=await E.json().catch(()=>({}));return f(P.error||"Authentication failed"),i(!1),!1}return a.reportConnected({address:L,chain:w,method:G||(w==="solana"?"phantom":"metamask"),stackId:e.stackId}),r(),i(!1),!0}catch(L){return f(L.message||"Authentication failed"),i(false),false}},[N,S,p,r,a,e.stackId]),j=useCallback(async(w="phantom")=>{let b=await s(w);return b?D("solana",b,()=>s(w),w):false},[s,D]),v=useCallback(async()=>{let w=await l();return w?D("ethereum",w,l,"metamask"):false},[l,D]),Y=useCallback(async w=>{i(true),f(null);try{let b=await fetch(`${N}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:w})});if(!b.ok){let z=await b.json().catch(()=>({}));return f(z.error||"Invalid code"),i(!1),!1}return r(),i(!1),!0}catch(b){return f(b.message||"OTP verification failed"),i(false),false}},[N,r]),Z=useCallback(async()=>{t.address&&t.chain&&a.reportDisconnected({address:t.address,chain:t.chain,stackId:e.stackId});try{await fetch(`${N}/api/auth/logout`,{method:"POST",headers:c});}catch{}y(),r();},[N,c,y,r,t,a,e.stackId]);return useEffect(()=>{if(!e.autoConnect||k||n||!a.ready||!a.known||!a.identity)return;C(true);let{chain:w,method:b}=a.identity;w==="solana"&&(b==="phantom"||b==="solflare")?j(b):w==="ethereum"&&v();},[e.autoConnect,k,n,a,j,v]),{session:d,isAuthenticated:n,wallet:t,loading:u,error:g,authenticateSolana:j,authenticateEVM:v,authenticateOTP:Y,logout:Z,refresh:()=>o(N),bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount}}}function $e(e=""){let[t,s]=useState([]),[l,p]=useState(true),[y,d]=useState(null),n=useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/plans`);if(o.ok){let r=await o.json();s(r.plans||r||[]);}}catch(o){d(o.message);}finally{p(false);}},[e]);return useEffect(()=>{n();},[n]),{plans:t,loading:l,error:y,refresh:n}}function Qe(e=""){let[t,s]=useState(null),[l,p]=useState(true),[y,d]=useState(null),n=useCallback(async()=>{try{let c=await fetch(`${e}/api/billing/subscription`);if(c.ok){let a=await c.json();s(a.plan?a:null);}}catch(c){d(c.message);}finally{p(false);}},[e]);useEffect(()=>{n();},[n]);let o=useCallback(async c=>{let a=I(),i=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({planId:c})})).json();return i.url||i.checkoutUrl||null},[e]),r=useCallback(async()=>{let c=I();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:c?{"x-csrf-token":c}:{}})).ok?(await n(),true):false},[e,n]);return {subscription:t,loading:l,error:y,refresh:n,subscribe:o,cancel:r}}function Ye(e=""){let[t,s]=useState(null),[l,p]=useState(true),[y,d]=useState(null),n=useCallback(async()=>{try{let o=await fetch(`${e}/api/billing/usage`);if(o.ok){let r=await o.json();s(r);}}catch(o){d(o.message);}finally{p(false);}},[e]);return useEffect(()=>{n();},[n]),{usage:t,loading:l,error:y,refresh:n}}function Ze(e=""){let[t,s]=useState(false),[l,p]=useState(null),y=useCallback(async n=>{s(true),p(null);try{let o=I(),r=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({amountCents:n})}),c=await r.json();return r.ok?c.url||null:(p(c.error||"Purchase failed"),null)}catch(o){return p(o.message),null}finally{s(false);}},[e]),d=useCallback(async n=>{s(true),p(null);try{let o=I(),r=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...o?{"x-csrf-token":o}:{}},body:JSON.stringify({sessionId:n})}),c=await r.json();return r.ok?c:(p(c.error||"Verification failed"),null)}catch(o){return p(o.message),null}finally{s(false);}},[e]);return {purchase:y,verifySession:d,loading:t,error:l}}function Ke(e="",t){let[s,l]=useState([]),[p,y]=useState(true),[d,n]=useState(null),o=t?.limit||50,r=t?.offset||0,c=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/history?limit=${o}&offset=${r}`);if(a.ok){let u=await a.json();l(u.records||u.history||(Array.isArray(u)?u:[]));}}catch(a){n(a.message);}finally{y(false);}},[e,o,r]);return useEffect(()=>{c();},[c]),{records:s,loading:p,error:d,refresh:c}}var Ne=createContext(null);function et(){let e=useContext(Ne);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function tt({config:e,callbacks:t,children:s}){return jsx(Ne.Provider,{value:{config:e,callbacks:t},children:s})}function F({length:e=6,onComplete:t,disabled:s=false,error:l,className:p="",inputClassName:y=""}){let [d,n]=useState(Array(e).fill("")),o=useCallback((a,u)=>{if(u.length>1){let g=u.replace(/\D/g,"").slice(0,e).split(""),f=[...d];g.forEach((C,N)=>{a+N<e&&(f[a+N]=C);}),n(f);let k=Math.min(a+g.length,e-1);document.getElementById(`userutils-otp-${k}`)?.focus(),f.every(C=>C!=="")&&setTimeout(()=>t(f.join("")),100);return}if(!/^\d?$/.test(u))return;let i=[...d];i[a]=u,n(i),u&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),u&&a===e-1&&i.every(g=>g!=="")&&setTimeout(()=>t(i.join("")),100);},[d,e,t]),r=useCallback((a,u)=>{if(u.key==="Backspace"&&!d[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let i=[...d];i[a-1]="",n(i);}if(u.key==="Enter"){let i=d.join("");i.length===e&&t(i);}},[d,e,t]);useCallback(()=>{n(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:p,children:[jsx("div",{className:"flex gap-2 justify-center",children:d.map((a,u)=>jsx("input",{id:`userutils-otp-${u}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:i=>o(u,i.target.value),onKeyDown:i=>r(u,i),disabled:s,autoFocus:u===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${y}`},u))}),l&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}F.displayName="OTPInput";var rt="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function Q({className:e}){return jsx("img",{src:rt,alt:"Phantom",className:e})}function H({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function fe({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 me({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 ct({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:l=["phantom","metamask"],showOTP:p=true,className:y=""}){let{isAuthenticated:d,wallet:n,loading:o,error:r,authenticateSolana:c,authenticateEVM:a,authenticateOTP:u}=re(e),[i,g]=useState("select"),[f,k]=useState(null),[C,N]=useState(false),[U,S]=useState("idle"),[D,j]=useState(""),[v,Y]=useState(false),[Z,w]=useState(false);useEffect(()=>{if(typeof window>"u")return;let x=()=>{let A=window;Y(!!(A.phantom?.solana?.isPhantom||A.solana?.isPhantom));let E=A.ethereum;w(!!(E?.isMetaMask||E?.providers?.some(P=>P.isMetaMask)));};x(),window.addEventListener("ethereum#initialized",x);let O=setTimeout(x,500);return ()=>{window.removeEventListener("ethereum#initialized",x),clearTimeout(O);}},[]),useEffect(()=>{d&&i==="success"&&t?.();},[d,i,t]);let b=async()=>{k("phantom"),g("connecting");let x=await c("phantom");g(x?"success":"error");},z=async()=>{k("metamask"),g("connecting");let x=await a();g(x?"success":"error");},G=async x=>{S("verifying"),j(""),await u(x)?(S("success"),g("success")):(S("error"),j("Invalid or expired code"),setTimeout(()=>S("idle"),2e3));},L=()=>{g("select"),k(null),N(false),S("idle"),j("");};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:s})}),r&&i==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:r}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:L,children:"Try Again"})]}),i==="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..."})]}),i==="connecting"&&o&&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:[f==="phantom"&&jsx(Q,{className:"h-14 w-14"}),f==="metamask"&&jsx(H,{className:"h-14 w-14"})]}),jsx("p",{className:"font-medium text-sm text-white",children:n.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:L,children:"Cancel"})]}),i==="select"&&!o&&jsxs(Fragment,{children:[l.includes("phantom")&&jsxs("button",{onClick:b,disabled:!v,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${v?"":"cursor-not-allowed opacity-50"}`,children:[jsx(Q,{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"}),!v&&jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsx(fe,{className:"h-8 w-8"})]}),l.includes("metamask")&&Z&&jsxs("button",{onClick:z,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(H,{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(me,{className:"h-8 w-8"})]}),p&&!C&&jsxs("button",{onClick:()=>N(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"})})]}),p&&C&&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(F,{onComplete:G,disabled:U==="verifying",error:D}),U==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),U==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"})]})]})]})}function dt({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 ft({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 mt({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 yt({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{ct as ConnectWidget,mt as DiscordIcon,me as EthereumIcon,ft as GoogleIcon,H as MetaMaskIcon,F as OTPInput,Q as PhantomIcon,fe as SolanaIcon,yt as TelegramIcon,dt as TwitterIcon,tt as UserUtilsProvider,ve as cn,oe as createStackNetClient,Ae as decodeJwtPayloadClient,Te as formatTokens,I as readCSRFCookie,J as readSessionCookie,ne as useAuthBridge,Ke as useBillingHistory,q as useCSRFToken,$e as usePlans,Ze as usePrepaidCheckout,K as useSession,re as useStackAuth,Qe as useSubscription,Ye as useUsage,et as useUserUtilsContext,X as useWeb3Wallet,De as validateRedirectUrl};
|