@privy-io/react-auth 2.6.3 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{u as e,a as i,b as s,c as l,C as d,d as h,s as k,P as C,e as W,f,g as T,G as U,W as R,h as S,i as P,j as N,k as O,l as M}from"./privy-provider-u_cmfixS.mjs";export{o as Captcha,p as ConnectorManager,E as EthereumWalletConnector,L as LoginModal,y as PrivyClient,m as PrivyProvider,H as SUPPORTED_CHAINS,V as VERSION,q as WalletConnector,J as addPrivyRpcToChain,I as addRpcUrlOverrideToChain,w as errorIndicatesMaxMfaRetries,x as errorIndicatesMfaTimeout,v as errorIndicatesMfaVerificationFailed,n as getAccessToken,z as useIdentityToken,F as useImportWallet,A as useLogout,r as useMfa,t as useMfaEnrollment,B as useRegisterMfaListener,D as useSolanaWallets}from"./privy-provider-u_cmfixS.mjs";export{c as useActiveWallet,a as useConnectWallet,b as useFundWallet,u as useLogin}from"./useActiveWallet-Cwj5v4eK.mjs";import{useCallback as _,useEffect as K,useContext as j}from"react";import{u as G,P as Q,a as X,I as $}from"./internal-context-O3TPYUku.mjs";import{zeroAddress as Y,getAddress as Z,createWalletClient as ee,http as te,parseSignature as re}from"viem";import{eip7702Actions as oe,hashAuthorization as ie}from"viem/experimental";export{g as getEmbeddedConnectedWallet}from"./getEmbeddedConnectedWallet-CSSBWE2p.mjs";import"react/jsx-runtime";import"mipd";import"react-device-detect";import"viem/utils";import"uuid";import"jose";import"eventemitter3";import"@coinbase/wallet-sdk";import"@privy-io/js-sdk-core";import"@marsidev/react-turnstile";import"styled-components";import"tinycolor2";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@heroicons/react/24/outline/CheckIcon";import"@heroicons/react/24/outline/Square2StackIcon";import"@heroicons/react/24/outline/WalletIcon";import"zustand";import"@walletconnect/ethereum-provider";import"@heroicons/react/24/outline/UserCircleIcon";import"@heroicons/react/24/outline/EnvelopeIcon";import"@heroicons/react/20/solid/CheckIcon";import"@heroicons/react/24/outline/PhoneIcon";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"@heroicons/react/24/outline/ArrowTopRightOnSquareIcon";import"@heroicons/react/24/solid/DocumentCheckIcon";import"@heroicons/react/24/solid/XCircleIcon";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/LockClosedIcon";import"@heroicons/react/24/outline/PencilSquareIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"@heroicons/react/24/outline/KeyIcon";import"@heroicons/react/24/outline/ArrowDownTrayIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/LockClosedIcon";import"@heroicons/react/24/outline/ShieldCheckIcon";import"qrcode";import"@heroicons/react/24/outline/FingerPrintIcon";import"@heroicons/react/24/outline/ChevronRightIcon";import"@heroicons/react/24/outline/DevicePhoneMobileIcon";import"@heroicons/react/24/outline/ChevronDownIcon";import"@heroicons/react/24/outline/CalendarIcon";import"@headlessui/react";import"@heroicons/react/24/outline/CheckCircleIcon";import"@heroicons/react/24/outline/InformationCircleIcon";import"@heroicons/react/24/outline/CreditCardIcon";import"@heroicons/react/24/outline/QrCodeIcon";import"@heroicons/react/24/solid/ArrowsRightLeftIcon";import"@heroicons/react/24/outline/GlobeAltIcon";import"ofetch";import"@heroicons/react/24/outline";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"@heroicons/react/24/outline/CloudArrowUpIcon";import"@heroicons/react/24/outline/NoSymbolIcon";import"@heroicons/react/24/outline/ClockIcon";import"@heroicons/react/24/outline/TrashIcon";import"@heroicons/react/24/solid/CheckBadgeIcon";import"@heroicons/react/24/solid/IdentificationIcon";import"@heroicons/react/24/outline/MinusCircleIcon";import"@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon";import"@heroicons/react/24/solid/ShieldCheckIcon";import"js-cookie";const ne=t=>{e("login",t);let r=i(),o=s(),{ready:n,user:a}=l(),{initLoginWithHeadlessOAuth:c,loginWithHeadlessOAuth:u,oAuthState:p,setOAuthState:w,isHeadlessOAuthLoading:m}=G(),g=_((async e=>{try{if(r.enabled&&"success"!==r.status)throw new d(r.error,null,Q.CAPTCHA_FAILURE);return await c(e.provider,r.token,e.disableSignup)}catch(e){throw w({status:"error",error:e}),e}}),[c,r]),A=_((async()=>{let e=h();try{if(a)return console.warn("Cannot login with OAuth when already logged in"),a;if(!e.inProgress)throw Error("Cannot login with OAuth because no OAuth flow is in progress");if(e.popupFlow)return}catch(e){throw w({status:"error",error:e}),e}try{return await u(e)}catch(e){throw w({status:"error",error:e}),e}finally{k()}}),[u]);return K((()=>{let e=h();n&&o&&e.inProgress&&!e.withPrivyUi&&!e.popupFlow&&A().catch((()=>{}))}),[n,o]),{initOAuth:g,loading:m,state:p}},ae=e=>{let t=i(),{emailOtpState:r,setEmailOtpState:o,initLoginWithEmail:n,loginWithCode:a}=G();return{sendCode:_((async({email:r,disableSignup:i})=>{try{let e;if(!r)throw Error("Email required to send OTP code");if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);return t.enabled&&"success"!==t.status&&(t.execute(),e=await t.waitForResult()),await n({email:r,captchaToken:e,disableSignup:i,withPrivyUi:!1})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[n]),loginWithCode:_((async({code:r})=>{try{if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);let{user:o,isNewUser:i,wasAlreadyAuthenticated:n,linkedAccount:s}=await a(r);e?.onComplete?.({user:o,isNewUser:i,wasAlreadyAuthenticated:n,loginMethod:"email",loginAccount:s})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[a,t.status]),state:r}},se=e=>{let t=i(),{initSignupWithPasskey:r,signupWithPasskey:o,passkeyAuthState:n,setPasskeyAuthState:a}=G();return{signupWithPasskey:_((async()=>{try{let i;if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);t.enabled&&"success"!==t.status&&(t.execute(),i=await t.waitForResult()),await r({captchaToken:i,withPrivyUi:!1});let{user:n,isNewUser:a,wasAlreadyAuthenticated:s,loginAccount:c}=await o();e?.onComplete?.({user:n,isNewUser:a,wasAlreadyAuthenticated:s,loginMethod:"passkey",loginAccount:c})}catch(t){throw a({status:"error",error:t}),e?.onError?.(t.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),t}}),[o,t.status]),state:n}},ce=e=>{let t=i(),{initLoginWithPasskey:r,loginWithPasskey:o,passkeyAuthState:n,setPasskeyAuthState:a}=G();return{loginWithPasskey:_((async i=>{try{let n;if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);t.enabled&&"success"!==t.status&&(t.execute(),n=await t.waitForResult()),await r({captchaToken:n,withPrivyUi:!1});let{user:a,isNewUser:s,wasAlreadyAuthenticated:c,loginAccount:l}=await o(i);e?.onComplete?.({user:a,isNewUser:s,wasAlreadyAuthenticated:c,loginMethod:"passkey",loginAccount:l})}catch(i){throw a({status:"error",error:i}),e?.onError?.(i.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),i}}),[o,t.status]),state:n}},le=e=>{let{initLinkWithPasskey:t,linkWithPasskey:r,passkeyAuthState:o,setPasskeyAuthState:i}=G();return{linkWithPasskey:_((async()=>{try{await t();let o=await r();if(!o)throw Error("Error, user not found");let i=o.linkedAccounts.filter((e=>"passkey"===e.type)).sort(((e,t)=>t.latestVerifiedAt.getTime()-e.latestVerifiedAt.getTime()))[0];e?.onSuccess?.({user:o,linkMethod:"passkey",linkedAccount:i})}catch(t){throw i({status:"error",error:t}),e?.onError?.(t.privyErrorCode||Q.UNKNOWN_AUTH_ERROR,{linkMethod:"passkey"}),t}}),[r]),state:o}},ue=e=>{let t=i(),{smsOtpState:r,setSmsOtpState:o,initLoginWithSms:n,loginWithCode:a}=G();return{sendCode:_((async({phoneNumber:r,disableSignup:i})=>{try{let e;if(!r)throw Error("SMS required to send OTP code");if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);return t.enabled&&"success"!==t.status&&(t.execute(),e=await t.waitForResult()),await n({phoneNumber:r,captchaToken:e,disableSignup:i,withPrivyUi:!1})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[n]),loginWithCode:_((async({code:r})=>{try{if(t.enabled&&"success"!==t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);let{user:o,isNewUser:i,wasAlreadyAuthenticated:n,linkedAccount:s}=await a(r);e?.onComplete?.({user:o,isNewUser:i,wasAlreadyAuthenticated:n,loginMethod:"sms",loginAccount:s})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[a,t.status]),state:r}},de=t=>{let{connectOrCreateWallet:r}=l();return e("connectOrCreateWallet",t),{connectOrCreateWallet:r}},he=e=>{let t=i(),{siweState:r,setSiweState:o,linkWithSiwe:n,generateSiweMessage:a}=G();return{generateSiweMessage:_((async({address:t,chainId:r})=>{try{if(!t||!r)throw Error("wallet address and chainId required to generate nonce");return await a({address:t,chainId:r}).then((e=>e))}catch(t){throw o({status:"error",error:t}),e?.onError?.(t.privyErrorCode||Q.UNKNOWN_AUTH_ERROR,{linkMethod:"siwe"}),t}}),[a]),linkWithSiwe:_((async({signature:r,message:i,chainId:a,walletClientType:s,connectorType:c})=>{try{if(t.enabled&&"success"!==t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);let{user:o,linkedAccount:l}=await n({message:i,signature:r,chainId:a,walletClientType:s,connectorType:c});l&&e?.onSuccess?.({user:o,linkMethod:"siwe",linkedAccount:l})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR,{linkMethod:"siwe"}),r}}),[n,t.status]),state:r}};function pe(){let{signTransaction:e}=j(C);return{signTransaction:e}}function we(t){let{linkEmail:r,linkPhone:o,linkWallet:i,linkGoogle:n,linkApple:a,linkTwitter:s,linkDiscord:c,linkGithub:l,linkLinkedIn:u,linkTiktok:d,linkSpotify:h,linkInstagram:p,linkTelegram:w,linkFarcaster:m}=j(C);return e("linkAccount",t),{linkEmail:r,linkPhone:o,linkWallet:i,linkGoogle:n,linkApple:a,linkTwitter:s,linkDiscord:c,linkGithub:l,linkLinkedIn:u,linkTiktok:d,linkSpotify:h,linkInstagram:p,linkFarcaster:m,linkTelegram:w}}function me(t){let{updateEmail:r,updatePhone:o}=j(C);return e("update",t),{updateEmail:r,updatePhone:o}}function ge(t){let{createWallet:r}=j(C);return e("createWallet",t),{createWallet:r}}const Ae=()=>{let{connectCoinbaseSmartWallet:e}=G();return{connectCoinbaseSmartWallet:e}},ye=()=>{let{startCrossAppAuthFlow:e,unlinkCrossAppAccount:t,signMessageWithCrossAppWallet:r,signTypedDataWithCrossAppWallet:o,sendTransactionWithCrossAppWallet:i}=l();return{loginWithCrossAppAccount:({appId:t})=>e({appId:t,action:"login"}),linkCrossAppAccount:({appId:t})=>e({appId:t,action:"link"}),unlinkCrossAppAccount:t,signMessage:r,signTypedData:o,sendTransaction:i}};function ke(t){let{sendTransaction:r}=j(C);return e("sendTransaction",t),{sendTransaction:r}}function Ce(t){let{setWalletPassword:r}=j(C);return e("setWalletPassword",t),{setWalletPassword:r}}function Ie(){let e=W(),{getAccessToken:t,createWallet:r}=f(),o=T(),{client:i,setUser:n,setAuthenticated:a,setIsNewUser:s,initializeWalletProxy:c,refreshSessionAndUser:l}=G();return{createGuestAccount:async()=>{if(!e.id||!i)throw Error("SDK not yet ready");i.startAuthFlow(new U(e.id));try{let{user:u,isNewUser:d}=await i.authenticate();if(d=d||!1,!u)throw new X("Unable to authenticate guest account");let h=await t(),p=await c(R);if(h&&p)try{let t=S(u,e.embeddedWallets.ethereum.createOnLogin),o=P(u,e.embeddedWallets.solana.createOnLogin);if(t&&o){let e=await r();await p.createSolana({accessToken:h,ethereumAddress:e?.address}),u=await l()}else o?(await p.createSolana({accessToken:h,ethereumAddress:N(u)?.address}),u=await l()):t?(await r(),u=await l()):n(u)}catch(e){n(u),console.warn("Unable to create embedded wallet for guest account")}return s(d),a(!0),o("login","onComplete",{user:u,isNewUser:d,wasAlreadyAuthenticated:!1,loginMethod:"guest",loginAccount:null}),u}catch(e){throw o("login","onError",e.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),e}}}}function We(t){let{setWalletRecovery:r}=j(C);return e("setWalletRecovery",t),{setWalletRecovery:r}}function fe(t){let{signMessage:r}=j(C);return e("signMessage",t),{signMessage:r}}const Ee=()=>{let{ready:e,wallets:t}=O(),{user:r}=l(),{rpcConfig:o,chains:i,appId:n}=G();return{signAuthorization:_((async(a,s)=>{if(!r)throw Error("User must be authenticated before signing with a Privy wallet");if(!e)throw Error("Wallets are not ready");let c=s?.address??N(r)?.address??Y,l=t.find((e=>Z(e.address)===Z(c)));if(!l)throw Error("Signing wallet not found.");let u=a.chainId??Number(l.chainId.split(":")[1]),d=i.find((e=>e.id===u));if(!d)throw Error("Error, chain not configured in PrivyProvider config");let h=ee({account:c,chain:d,transport:te(M(d,o,n))}).extend(oe()),p=await h.prepareAuthorization({...a,sponsor:a.sponsor||void 0}),w=await l.getEthereumProvider(),m=await w.request({method:"secp256k1_sign",params:[ie(p)]});return{...p,...re(m)}}),[e,t,r,i])}};function Te(t){let{signTypedData:r}=j(C);return e("signTypedData",t),{signTypedData:r}}const Ue=()=>{let{isModalOpen:e}=j(C);return{isOpen:e}};function Re(t){let{getAccessToken:r}=j(C);return e("accessToken",t),{getAccessToken:r}}function Se(t){let{authenticated:r,user:o}=l(),{initLoginWithOAuth:i}=G(),n=T();return e("oAuthAuthorization",t),{reauthorize:e=>Pe(r,o,i,n,e.provider)}}let Pe=async(e,t,r,o,i)=>{if(!e)throw o("linkAccount","onError",Q.MUST_BE_AUTHENTICATED,{linkMethod:i}),new X("User must be authenticated before linking an account.");if(!t?.linkedAccounts.some((e=>e.type.includes(i))))throw new X(`OAuth account of type ${i} not linked to the account.`);await r(i)};const ve=t=>{let{customAuthStatus:r}=G();return e("customAuth",t),{status:r}};function Ne(){let{getFarcasterSignerPublicKey:e,signFarcasterMessage:t,requestFarcasterSignerFromWarpcast:r}=l();return{getFarcasterSignerPublicKey:e,signFarcasterMessage:t,requestFarcasterSignerFromWarpcast:r}}const Oe=()=>{let{revokeDelegatedWallets:e,delegateWallet:t}=G();return{delegateWallet:async({address:e,chainType:r})=>await t({address:e,chainType:r,showDelegationUIs:!0}),revokeWallets:async()=>await e({showDelegationUIs:!0})}},be=()=>{let{setUser:e,client:t}=j($),{user:r}=j(C);return{user:r,refreshUser:_((async()=>{let r=await(t?.updateUserAndIdToken());return e(r??null),r}),[t,e])}},Me=e=>{let t=i(),{initLoginWithTelegram:r,loginWithTelegram:o,telegramAuthState:n,setTelegramAuthState:a}=G();return{login:_((async i=>{try{if(t.enabled&&"success"!==t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);await r(t.token,i?.disableSignup);let{user:n,isNewUser:a,loginAccount:s,wasAlreadyAuthenticated:c}=await o({intent:"login"});e?.onComplete?.({user:n,isNewUser:a,wasAlreadyAuthenticated:c,loginMethod:"telegram",loginAccount:s})}catch(i){throw a({status:"error",error:i}),e?.onError?.(i.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),i}}),[r,o,t]),state:n}},_e=()=>{let{revokeDelegatedWallets:e,delegateWallet:t}=G();return{delegateWallet:async({address:e,chainType:r})=>await t({address:e,chainType:r,showDelegationUIs:!1}),revokeWallets:async()=>await e({showDelegationUIs:!1})}};export{Ae as useConnectCoinbaseSmartWallet,de as useConnectOrCreateWallet,ge as useCreateWallet,ye as useCrossAppAccounts,ve as useCustomAuth,Oe as useDelegatedActions,Ne as useFarcasterSigner,Ie as useGuestAccounts,_e as useHeadlessDelegatedActions,we as useLinkAccount,le as useLinkWithPasskey,he as useLinkWithSiwe,ae as useLoginWithEmail,ne as useLoginWithOAuth,ce as useLoginWithPasskey,ue as useLoginWithSms,Me as useLoginWithTelegram,Ue as useModalStatus,Se as useOAuthTokens,f as usePrivy,ke as useSendTransaction,Ce as useSetWalletPassword,We as useSetWalletRecovery,Ee as useSignAuthorization,fe as useSignMessage,pe as useSignTransaction,Te as useSignTypedData,se as useSignupWithPasskey,Re as useToken,me as useUpdateAccount,be as useUser,O as useWallets};
1
+ import{u as e,a as i,b as s,c as l,C as d,d as h,s as k,P as C,e as W,f,g as T,G as U,W as R,h as S,i as P,j as N,k as O,l as M}from"./privy-provider-DSQ8FU83.mjs";export{o as Captcha,p as ConnectorManager,E as EthereumWalletConnector,L as LoginModal,y as PrivyClient,m as PrivyProvider,H as SUPPORTED_CHAINS,V as VERSION,q as WalletConnector,J as addPrivyRpcToChain,I as addRpcUrlOverrideToChain,w as errorIndicatesMaxMfaRetries,x as errorIndicatesMfaTimeout,v as errorIndicatesMfaVerificationFailed,n as getAccessToken,z as useIdentityToken,F as useImportWallet,A as useLogout,r as useMfa,t as useMfaEnrollment,B as useRegisterMfaListener,D as useSolanaWallets}from"./privy-provider-DSQ8FU83.mjs";export{c as useActiveWallet,a as useConnectWallet,b as useFundWallet,u as useLogin}from"./useActiveWallet-D0FziaS7.mjs";import{useCallback as _,useEffect as K,useContext as j}from"react";import{u as G,P as Q,a as X,I as $}from"./internal-context-O3TPYUku.mjs";import{zeroAddress as Y,getAddress as Z,createWalletClient as ee,http as te,parseSignature as re}from"viem";import{eip7702Actions as oe,hashAuthorization as ie}from"viem/experimental";export{g as getEmbeddedConnectedWallet}from"./getEmbeddedConnectedWallet-CSSBWE2p.mjs";import"react/jsx-runtime";import"mipd";import"react-device-detect";import"viem/utils";import"uuid";import"jose";import"eventemitter3";import"@coinbase/wallet-sdk";import"@privy-io/js-sdk-core";import"@marsidev/react-turnstile";import"styled-components";import"tinycolor2";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@heroicons/react/24/outline/CheckIcon";import"@heroicons/react/24/outline/Square2StackIcon";import"@heroicons/react/24/outline/WalletIcon";import"zustand";import"@walletconnect/ethereum-provider";import"@heroicons/react/24/outline/UserCircleIcon";import"@heroicons/react/24/outline/EnvelopeIcon";import"@heroicons/react/20/solid/CheckIcon";import"@heroicons/react/24/outline/PhoneIcon";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"@heroicons/react/24/outline/ArrowTopRightOnSquareIcon";import"@heroicons/react/24/solid/DocumentCheckIcon";import"@heroicons/react/24/solid/XCircleIcon";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/LockClosedIcon";import"@heroicons/react/24/outline/PencilSquareIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"@heroicons/react/24/outline/KeyIcon";import"@heroicons/react/24/outline/ArrowDownTrayIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/LockClosedIcon";import"@heroicons/react/24/outline/ShieldCheckIcon";import"qrcode";import"@heroicons/react/24/outline/FingerPrintIcon";import"@heroicons/react/24/outline/ChevronRightIcon";import"@heroicons/react/24/outline/DevicePhoneMobileIcon";import"@heroicons/react/24/outline/ChevronDownIcon";import"@heroicons/react/24/outline/CalendarIcon";import"@headlessui/react";import"@heroicons/react/24/outline/CheckCircleIcon";import"@heroicons/react/24/outline/InformationCircleIcon";import"@heroicons/react/24/outline/CreditCardIcon";import"@heroicons/react/24/outline/QrCodeIcon";import"@heroicons/react/24/solid/ArrowsRightLeftIcon";import"@heroicons/react/24/outline/GlobeAltIcon";import"ofetch";import"@heroicons/react/24/outline";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"@heroicons/react/24/outline/CloudArrowUpIcon";import"@heroicons/react/24/outline/NoSymbolIcon";import"@heroicons/react/24/outline/ClockIcon";import"@heroicons/react/24/outline/TrashIcon";import"@heroicons/react/24/solid/CheckBadgeIcon";import"@heroicons/react/24/solid/IdentificationIcon";import"@heroicons/react/24/outline/MinusCircleIcon";import"@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon";import"@heroicons/react/24/solid/ShieldCheckIcon";import"js-cookie";const ne=t=>{e("login",t);let r=i(),o=s(),{ready:n,user:a}=l(),{initLoginWithHeadlessOAuth:c,loginWithHeadlessOAuth:u,oAuthState:p,setOAuthState:w,isHeadlessOAuthLoading:m}=G(),g=_((async e=>{try{if(r.enabled&&"success"!==r.status)throw new d(r.error,null,Q.CAPTCHA_FAILURE);return await c(e.provider,r.token,e.disableSignup)}catch(e){throw w({status:"error",error:e}),e}}),[c,r]),A=_((async()=>{let e=h();try{if(a)return console.warn("Cannot login with OAuth when already logged in"),a;if(!e.inProgress)throw Error("Cannot login with OAuth because no OAuth flow is in progress");if(e.popupFlow)return}catch(e){throw w({status:"error",error:e}),e}try{return await u(e)}catch(e){throw w({status:"error",error:e}),e}finally{k()}}),[u]);return K((()=>{let e=h();n&&o&&e.inProgress&&!e.withPrivyUi&&!e.popupFlow&&A().catch((()=>{}))}),[n,o]),{initOAuth:g,loading:m,state:p}},ae=e=>{let t=i(),{emailOtpState:r,setEmailOtpState:o,initLoginWithEmail:n,loginWithCode:a}=G();return{sendCode:_((async({email:r,disableSignup:i})=>{try{let e;if(!r)throw Error("Email required to send OTP code");if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);return t.enabled&&"success"!==t.status&&(t.execute(),e=await t.waitForResult()),await n({email:r,captchaToken:e,disableSignup:i,withPrivyUi:!1})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[n]),loginWithCode:_((async({code:r})=>{try{if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);let{user:o,isNewUser:i,wasAlreadyAuthenticated:n,linkedAccount:s}=await a(r);e?.onComplete?.({user:o,isNewUser:i,wasAlreadyAuthenticated:n,loginMethod:"email",loginAccount:s})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[a,t.status]),state:r}},se=e=>{let t=i(),{initSignupWithPasskey:r,signupWithPasskey:o,passkeyAuthState:n,setPasskeyAuthState:a}=G();return{signupWithPasskey:_((async()=>{try{let i;if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);t.enabled&&"success"!==t.status&&(t.execute(),i=await t.waitForResult()),await r({captchaToken:i,withPrivyUi:!1});let{user:n,isNewUser:a,wasAlreadyAuthenticated:s,loginAccount:c}=await o();e?.onComplete?.({user:n,isNewUser:a,wasAlreadyAuthenticated:s,loginMethod:"passkey",loginAccount:c})}catch(t){throw a({status:"error",error:t}),e?.onError?.(t.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),t}}),[o,t.status]),state:n}},ce=e=>{let t=i(),{initLoginWithPasskey:r,loginWithPasskey:o,passkeyAuthState:n,setPasskeyAuthState:a}=G();return{loginWithPasskey:_((async i=>{try{let n;if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);t.enabled&&"success"!==t.status&&(t.execute(),n=await t.waitForResult()),await r({captchaToken:n,withPrivyUi:!1});let{user:a,isNewUser:s,wasAlreadyAuthenticated:c,loginAccount:l}=await o(i);e?.onComplete?.({user:a,isNewUser:s,wasAlreadyAuthenticated:c,loginMethod:"passkey",loginAccount:l})}catch(i){throw a({status:"error",error:i}),e?.onError?.(i.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),i}}),[o,t.status]),state:n}},le=e=>{let{initLinkWithPasskey:t,linkWithPasskey:r,passkeyAuthState:o,setPasskeyAuthState:i}=G();return{linkWithPasskey:_((async()=>{try{await t();let o=await r();if(!o)throw Error("Error, user not found");let i=o.linkedAccounts.filter((e=>"passkey"===e.type)).sort(((e,t)=>t.latestVerifiedAt.getTime()-e.latestVerifiedAt.getTime()))[0];e?.onSuccess?.({user:o,linkMethod:"passkey",linkedAccount:i})}catch(t){throw i({status:"error",error:t}),e?.onError?.(t.privyErrorCode||Q.UNKNOWN_AUTH_ERROR,{linkMethod:"passkey"}),t}}),[r]),state:o}},ue=e=>{let t=i(),{smsOtpState:r,setSmsOtpState:o,initLoginWithSms:n,loginWithCode:a}=G();return{sendCode:_((async({phoneNumber:r,disableSignup:i})=>{try{let e;if(!r)throw Error("SMS required to send OTP code");if(t.enabled&&"error"===t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);return t.enabled&&"success"!==t.status&&(t.execute(),e=await t.waitForResult()),await n({phoneNumber:r,captchaToken:e,disableSignup:i,withPrivyUi:!1})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[n]),loginWithCode:_((async({code:r})=>{try{if(t.enabled&&"success"!==t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);let{user:o,isNewUser:i,wasAlreadyAuthenticated:n,linkedAccount:s}=await a(r);e?.onComplete?.({user:o,isNewUser:i,wasAlreadyAuthenticated:n,loginMethod:"sms",loginAccount:s})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),r}}),[a,t.status]),state:r}},de=t=>{let{connectOrCreateWallet:r}=l();return e("connectOrCreateWallet",t),{connectOrCreateWallet:r}},he=e=>{let t=i(),{siweState:r,setSiweState:o,linkWithSiwe:n,generateSiweMessage:a}=G();return{generateSiweMessage:_((async({address:t,chainId:r})=>{try{if(!t||!r)throw Error("wallet address and chainId required to generate nonce");return await a({address:t,chainId:r}).then((e=>e))}catch(t){throw o({status:"error",error:t}),e?.onError?.(t.privyErrorCode||Q.UNKNOWN_AUTH_ERROR,{linkMethod:"siwe"}),t}}),[a]),linkWithSiwe:_((async({signature:r,message:i,chainId:a,walletClientType:s,connectorType:c})=>{try{if(t.enabled&&"success"!==t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);let{user:o,linkedAccount:l}=await n({message:i,signature:r,chainId:a,walletClientType:s,connectorType:c});l&&e?.onSuccess?.({user:o,linkMethod:"siwe",linkedAccount:l})}catch(r){throw o({status:"error",error:r}),e?.onError?.(r.privyErrorCode||Q.UNKNOWN_AUTH_ERROR,{linkMethod:"siwe"}),r}}),[n,t.status]),state:r}};function pe(){let{signTransaction:e}=j(C);return{signTransaction:e}}function we(t){let{linkEmail:r,linkPhone:o,linkWallet:i,linkGoogle:n,linkApple:a,linkTwitter:s,linkDiscord:c,linkGithub:l,linkLinkedIn:u,linkTiktok:d,linkSpotify:h,linkInstagram:p,linkTelegram:w,linkFarcaster:m}=j(C);return e("linkAccount",t),{linkEmail:r,linkPhone:o,linkWallet:i,linkGoogle:n,linkApple:a,linkTwitter:s,linkDiscord:c,linkGithub:l,linkLinkedIn:u,linkTiktok:d,linkSpotify:h,linkInstagram:p,linkFarcaster:m,linkTelegram:w}}function me(t){let{updateEmail:r,updatePhone:o}=j(C);return e("update",t),{updateEmail:r,updatePhone:o}}function ge(t){let{createWallet:r}=j(C);return e("createWallet",t),{createWallet:r}}const Ae=()=>{let{connectCoinbaseSmartWallet:e}=G();return{connectCoinbaseSmartWallet:e}},ye=()=>{let{startCrossAppAuthFlow:e,unlinkCrossAppAccount:t,signMessageWithCrossAppWallet:r,signTypedDataWithCrossAppWallet:o,sendTransactionWithCrossAppWallet:i}=l();return{loginWithCrossAppAccount:({appId:t})=>e({appId:t,action:"login"}),linkCrossAppAccount:({appId:t})=>e({appId:t,action:"link"}),unlinkCrossAppAccount:t,signMessage:r,signTypedData:o,sendTransaction:i}};function ke(t){let{sendTransaction:r}=j(C);return e("sendTransaction",t),{sendTransaction:r}}function Ce(t){let{setWalletPassword:r}=j(C);return e("setWalletPassword",t),{setWalletPassword:r}}function Ie(){let e=W(),{getAccessToken:t,createWallet:r}=f(),o=T(),{client:i,setUser:n,setAuthenticated:a,setIsNewUser:s,initializeWalletProxy:c,refreshSessionAndUser:l}=G();return{createGuestAccount:async()=>{if(!e.id||!i)throw Error("SDK not yet ready");i.startAuthFlow(new U(e.id));try{let{user:u,isNewUser:d}=await i.authenticate();if(d=d||!1,!u)throw new X("Unable to authenticate guest account");let h=await t(),p=await c(R);if(h&&p)try{let t=S(u,e.embeddedWallets.ethereum.createOnLogin),o=P(u,e.embeddedWallets.solana.createOnLogin);if(t&&o){let e=await r();await p.createSolana({accessToken:h,ethereumAddress:e?.address}),u=await l()}else o?(await p.createSolana({accessToken:h,ethereumAddress:N(u)?.address}),u=await l()):t?(await r(),u=await l()):n(u)}catch(e){n(u),console.warn("Unable to create embedded wallet for guest account")}return s(d),a(!0),o("login","onComplete",{user:u,isNewUser:d,wasAlreadyAuthenticated:!1,loginMethod:"guest",loginAccount:null}),u}catch(e){throw o("login","onError",e.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),e}}}}function We(t){let{setWalletRecovery:r}=j(C);return e("setWalletRecovery",t),{setWalletRecovery:r}}function fe(t){let{signMessage:r}=j(C);return e("signMessage",t),{signMessage:r}}const Ee=()=>{let{ready:e,wallets:t}=O(),{user:r}=l(),{rpcConfig:o,chains:i,appId:n}=G();return{signAuthorization:_((async(a,s)=>{if(!r)throw Error("User must be authenticated before signing with a Privy wallet");if(!e)throw Error("Wallets are not ready");let c=s?.address??N(r)?.address??Y,l=t.find((e=>Z(e.address)===Z(c)));if(!l)throw Error("Signing wallet not found.");let u=a.chainId??Number(l.chainId.split(":")[1]),d=i.find((e=>e.id===u));if(!d)throw Error("Error, chain not configured in PrivyProvider config");let h=ee({account:c,chain:d,transport:te(M(d,o,n))}).extend(oe()),p=await h.prepareAuthorization({...a,sponsor:a.sponsor||void 0}),w=await l.getEthereumProvider(),m=await w.request({method:"secp256k1_sign",params:[ie(p)]});return{...p,...re(m)}}),[e,t,r,i])}};function Te(t){let{signTypedData:r}=j(C);return e("signTypedData",t),{signTypedData:r}}const Ue=()=>{let{isModalOpen:e}=j(C);return{isOpen:e}};function Re(t){let{getAccessToken:r}=j(C);return e("accessToken",t),{getAccessToken:r}}function Se(t){let{authenticated:r,user:o}=l(),{initLoginWithOAuth:i}=G(),n=T();return e("oAuthAuthorization",t),{reauthorize:e=>Pe(r,o,i,n,e.provider)}}let Pe=async(e,t,r,o,i)=>{if(!e)throw o("linkAccount","onError",Q.MUST_BE_AUTHENTICATED,{linkMethod:i}),new X("User must be authenticated before linking an account.");if(!t?.linkedAccounts.some((e=>e.type.includes(i))))throw new X(`OAuth account of type ${i} not linked to the account.`);await r(i)};const ve=t=>{let{customAuthStatus:r}=G();return e("customAuth",t),{status:r}};function Ne(){let{getFarcasterSignerPublicKey:e,signFarcasterMessage:t,requestFarcasterSignerFromWarpcast:r}=l();return{getFarcasterSignerPublicKey:e,signFarcasterMessage:t,requestFarcasterSignerFromWarpcast:r}}const Oe=()=>{let{revokeDelegatedWallets:e,delegateWallet:t}=G();return{delegateWallet:async({address:e,chainType:r})=>await t({address:e,chainType:r,showDelegationUIs:!0}),revokeWallets:async()=>await e({showDelegationUIs:!0})}},be=()=>{let{setUser:e,client:t}=j($),{user:r}=j(C);return{user:r,refreshUser:_((async()=>{let r=await(t?.updateUserAndIdToken());return e(r??null),r}),[t,e])}},Me=e=>{let t=i(),{initLoginWithTelegram:r,loginWithTelegram:o,telegramAuthState:n,setTelegramAuthState:a}=G();return{login:_((async i=>{try{if(t.enabled&&"success"!==t.status)throw new d(t.error,null,Q.CAPTCHA_FAILURE);await r(t.token,i?.disableSignup);let{user:n,isNewUser:a,loginAccount:s,wasAlreadyAuthenticated:c}=await o({intent:"login"});e?.onComplete?.({user:n,isNewUser:a,wasAlreadyAuthenticated:c,loginMethod:"telegram",loginAccount:s})}catch(i){throw a({status:"error",error:i}),e?.onError?.(i.privyErrorCode||Q.UNKNOWN_AUTH_ERROR),i}}),[r,o,t]),state:n}},_e=()=>{let{revokeDelegatedWallets:e,delegateWallet:t}=G();return{delegateWallet:async({address:e,chainType:r})=>await t({address:e,chainType:r,showDelegationUIs:!1}),revokeWallets:async()=>await e({showDelegationUIs:!1})}};export{Ae as useConnectCoinbaseSmartWallet,de as useConnectOrCreateWallet,ge as useCreateWallet,ye as useCrossAppAccounts,ve as useCustomAuth,Oe as useDelegatedActions,Ne as useFarcasterSigner,Ie as useGuestAccounts,_e as useHeadlessDelegatedActions,we as useLinkAccount,le as useLinkWithPasskey,he as useLinkWithSiwe,ae as useLoginWithEmail,ne as useLoginWithOAuth,ce as useLoginWithPasskey,ue as useLoginWithSms,Me as useLoginWithTelegram,Ue as useModalStatus,Se as useOAuthTokens,f as usePrivy,ke as useSendTransaction,Ce as useSetWalletPassword,We as useSetWalletRecovery,Ee as useSignAuthorization,fe as useSignMessage,pe as useSignTransaction,Te as useSignTypedData,se as useSignupWithPasskey,Re as useToken,me as useUpdateAccount,be as useUser,O as useWallets};