@privy-io/react-auth 1.55.2-beta-20240201162656 → 1.55.2-beta-20240201194530

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/esm/index.js CHANGED
@@ -2608,4 +2608,4 @@ You will need this password to access your ${e} wallet on a new device. Please k
2608
2608
  opacity: 1;
2609
2609
  }
2610
2610
  }
2611
- `;import{jsx as Ne,jsxs as Ff}from"react/jsx-runtime";var c2={["LANDING"]:fm,["AWAITING_PASSWORDLESS_CODE"]:tp,["AWAITING_CONNECTION"]:vp,["AWAITING_CONNECT_ONLY_CONNECTION"]:Ep,["AWAITING_FARCASTER_CONNECTION"]:Ru,["PHANTOM_INTERSTITIAL_SCREEN"]:Sf,["LOGIN_FAILED_SCREEN"]:bm,["AWAITING_OAUTH_SCREEN"]:Ef,["ALLOWLIST_REJECTION_SCREEN"]:zd,["INSTALL_PHANTOM_SCREEN"]:Vu,["LINK_EMAIL_SCREEN"]:hm,["LINK_PHONE_SCREEN"]:ym,["LINK_WALLET_SCREEN"]:gm,["CONNECT_ONLY_LANDING_SCREEN"]:hp,["CONNECT_ONLY_AUTHENTICATED_SCREEN"]:up,["EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN"]:lu,["EMBEDDED_WALLET_CREATED_SCREEN"]:Rp,["EMBEDDED_WALLET_CONNECTING_SCREEN"]:kp,["EMBEDDED_WALLET_RECOVERY_SCREEN"]:pu,["EMBEDDED_WALLET_KEY_EXPORT_SCREEN"]:Np,["EMBEDDED_WALLET_SIGN_REQUEST_SCREEN"]:Nf,["EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN"]:Wf,["FIAT_ON_RAMP_PROMPT_SCREEN"]:Ou,["FIAT_ON_RAMP_STATUS_SCREEN"]:Uu,["EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN"]:du,["EMBEDDED_WALLET_PASSWORD_UPDATE_SCREEN"]:cu,["MFA_ENROLLMENT_FLOW_SCREEN"]:Lm,["CAPTCHA_SCREEN"]:ip,["ERROR_SCREEN"]:uu,["IN_APP_BROWSER_LOGIN_NOT_POSSIBLE"]:Fu},d2=["LANDING","AWAITING_CONNECTION"],p2=({isMfaVerifying:e,onMfaVerificationComplete:t})=>{let{ready:o,isModalOpen:r}=F(),{headless:n}=k(),{ready:i,currentScreen:a}=S(),{status:s,execute:l,reset:c,enabled:u}=ce(),f=a2(null),y=Ld(f),v=r&&a&&d2.includes(a)&&!n&&s==="ready";if(Uf(()=>{v&&l()},[v]),Uf(()=>{!r&&u&&c()},[r,u]),(!o||!i)&&a!=="AWAITING_OAUTH_SCREEN")return Ff(an,{children:[Ne(x,{}),Ne(q,{}),Ne(Tm,{children:Ne(ft,{})}),Ne(J,{}),Ne(K,{})]});if(!a&&e)return Ne(an,{style:{height:y},children:Ne("div",{ref:f,children:Ne(Yl,{open:e,onClose:t})})});if(!a)return null;let g=c2[a];return Ne(an,{style:{height:y},children:Ff("div",{ref:f,children:[Ne(lo,{if:!!e,children:Ne(g,{})}),Ne(lo,{if:!e,children:Ne(Yl,{open:e,onClose:t})})]})})},u2=()=>{let{closePrivyModal:e}=k(),{onUserCloseViaDialogOrKeybindRef:t}=S();return{gracefulClosePrivyModal:i2(()=>{if(t?.current)t.current(),t.current=null;else return e({shouldCallAuthOnSuccess:!1})},[e])}},Bf=({open:e})=>{let{app:t}=S(),{gracefulClosePrivyModal:o}=u2(),[r,n]=s2(!1);Is({onMfaRequired:()=>{t?.mfa.noPromptOnMfaRequired||n(!0)}});let i=Ne(Df,{children:Ne(p2,{isMfaVerifying:r,onMfaVerificationComplete:()=>n(!1)})}),a=e||r,s=t?.render.inDialog?Ne(Pm,{open:a,id:"privy-dialog",onClick:()=>o(),children:i}):i;if(typeof window<"u"&&t?.render.inParentNodeId){let l=document.getElementById(t.render.inParentNodeId);if(l)return l2.createPortal(s,l)}return s};var Pt={appearance:{theme:"light",accentColor:"#676FFF",walletList:["detected_wallets","metamask","coinbase_wallet","rainbow","wallet_connect"]},walletConnectCloudProjectId:Fc,rpcConfig:{rpcUrls:{},rpcTimeouts:{}},captchaEnabled:!1,_render:{inDialog:!0,inParentNodeId:null},fiatOnRamp:{useSandbox:!1}};var m2=new Set(["metamask","coinbase_wallet","rainbow","zerion","phantom","wallet_connect","detected_wallets"]),f2=e=>m2.has(e),h2=(e,t,o)=>o.indexOf(e)===t,Hf=({input:e})=>e?e.filter(f2).filter(h2):Pt.appearance.walletList;var Gf={id:43114,name:"Avalanche",network:"avalanche",nativeCurrency:{decimals:18,name:"Avalanche",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax.network/ext/bc/C/rpc"]},public:{http:["https://api.avax.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://snowtrace.io"},default:{name:"SnowTrace",url:"https://snowtrace.io"}}};var zf={id:43113,name:"Avalanche Fuji",network:"avalanche-fuji",nativeCurrency:{decimals:18,name:"Avalanche Fuji",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax-test.network/ext/bc/C/rpc"]},public:{http:["https://api.avax-test.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://testnet.snowtrace.io"},default:{name:"SnowTrace",url:"https://testnet.snowtrace.io"}},testnet:!0};var Vf={id:42220,name:"Celo Mainnet",network:"celo",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://forno.celo.org"]},infura:{http:["https://celo-mainnet.infura.io/v3"]},public:{http:["https://forno.celo.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/mainnet"},etherscan:{name:"CeloScan",url:"https://celoscan.io"}},testnet:!1};var $f={id:44787,name:"Celo Alfajores Testnet",network:"celo-alfajores",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://alfajores-forno.celo-testnet.org"]},infura:{http:["https://celo-alfajores.infura.io/v3"]},public:{http:["https://alfajores-forno.celo-testnet.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/alfajores"},etherscan:{name:"CeloScan",url:"https://alfajores.celoscan.io/"}},testnet:!0};var jf={id:314,name:"Filecoin - Mainnet",network:"filecoin-mainnet",nativeCurrency:{decimals:18,name:"filecoin",symbol:"FIL"},rpcUrls:{default:{http:["https://api.node.glif.io/rpc/v1"]},public:{http:["https://api.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filfox",url:"https://filfox.info/en"},filscan:{name:"Filscan",url:"https://filscan.io"},filscout:{name:"Filscout",url:"https://filscout.io/en"},glif:{name:"Glif",url:"https://explorer.glif.io"}}};var qf={id:314159,name:"Filecoin - Calibration testnet",network:"filecoin-calibration",nativeCurrency:{decimals:18,name:"testnet filecoin",symbol:"tFIL"},rpcUrls:{default:{http:["https://api.calibration.node.glif.io/rpc/v1"]},public:{http:["https://api.calibration.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filscan",url:"https://calibration.filscan.io"}}};var Kf={id:5,network:"goerli",name:"Goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-goerli.g.alchemy.com/v2"],webSocket:["wss://eth-goerli.g.alchemy.com/v2"]},infura:{http:["https://goerli.infura.io/v3"],webSocket:["wss://goerli.infura.io/ws/v3"]},default:{http:["https://rpc.ankr.com/eth_goerli"]},public:{http:["https://rpc.ankr.com/eth_goerli"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli.etherscan.io"},default:{name:"Etherscan",url:"https://goerli.etherscan.io"}},testnet:!0};var Yf={id:17e3,name:"Holesky",network:"holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://ethereum-holesky.publicnode.com"]},public:{http:["https://ethereum-holesky.publicnode.com"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://holesky.etherscan.io"},default:{name:"EtherScan",url:"https://holesky.etherscan.io"}}};var Jf={id:59144,network:"linea-mainnet",name:"Linea Mainnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-mainnet.infura.io/v3"],webSocket:["wss://linea-mainnet.infura.io/ws/v3"]},default:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]},public:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://lineascan.build"},etherscan:{name:"Etherscan",url:"https://lineascan.build"}},testnet:!1};var Qf={id:59140,network:"linea-testnet",name:"Linea Goerli Testnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-goerli.infura.io/v3"],webSocket:["wss://linea-goerli.infura.io/ws/v3"]},default:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]},public:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://goerli.lineascan.build"},etherscan:{name:"Etherscan",url:"https://goerli.lineascan.build"}},testnet:!0};var is={id:1,network:"homestead",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-mainnet.g.alchemy.com/v2"],webSocket:["wss://eth-mainnet.g.alchemy.com/v2"]},infura:{http:["https://mainnet.infura.io/v3"],webSocket:["wss://mainnet.infura.io/ws/v3"]},default:{http:["https://cloudflare-eth.com"]},public:{http:["https://cloudflare-eth.com"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://etherscan.io"},default:{name:"Etherscan",url:"https://etherscan.io"}}};var Zf={id:17001,name:"Redstone Holesky",network:"redstone-holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.holesky.redstone.xyz"]},public:{http:["https://rpc.holesky.redstone.xyz"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"},default:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"}}};var Xf={id:11155111,network:"sepolia",name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"SEP",decimals:18},rpcUrls:{alchemy:{http:["https://eth-sepolia.g.alchemy.com/v2"],webSocket:["wss://eth-sepolia.g.alchemy.com/v2"]},infura:{http:["https://sepolia.infura.io/v3"],webSocket:["wss://sepolia.infura.io/ws/v3"]},default:{http:["https://rpc.sepolia.org"]},public:{http:["https://rpc.sepolia.org"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://sepolia.etherscan.io"},default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}},testnet:!0};var ai=[Ba,Ha,Ga,Kf,Xf,is,ja,qa,Ka,oi,ri,Vf,$f,jf,qf,za,Va,$a,Jf,Qf,Gf,zf,Ya,Qa,Ja,Yf,Zf],QD=new Set(ai.map(e=>e.id));import vr from"tinycolor2";var eh="#FFFFFF",y2="#000000",g2=eh,v2="#1E1E1D";function w2(e){return e<.8&&e>.2&&console.warn("Background color is not light or dark enough, which could lead to accessibility issues."),e>.5?"light":"dark"}function qo(e,t){let o=Math.max(0,Math.min(1,e.toHsl().l+t));return vr({...e.toHsl(),l:o})}function th({backgroundTheme:e,accentHex:t,successHex:o="#51BA81",warnHex:r="#FFB74D",errorHex:n="#EC6351",whiteHex:i=eh,blackHex:a=y2}){let s;switch(e){case"light":s=g2;break;case"dark":s=v2;break;default:s=e;break}let l=vr(s),c=vr(t),u=vr(o),f=vr(r),y=vr(n),v=w2(l.getLuminance()),g=qo(l,v==="light"?-.04:.11),E=qo(l,v==="light"?-.88:.87),P=qo(l,v==="light"?-.77:.75),C=qo(l,v==="light"?-.43:.45).desaturate(v==="light"?60:20),_=qo(l,v==="light"?-.08:.25).desaturate(v==="light"?60:20),R=qo(c,.15),W=qo(c,-.06),N=vr(c.getLuminance()>.5?a:i),M=qo(u,-.16);return{colorScheme:v,background:l.toHslString(),background2:g.toHslString(),foreground:E.toHslString(),foreground2:P.toHslString(),foreground3:C.toHslString(),foreground4:_.toHslString(),accent:c.toHslString(),accentLight:R.toHslString(),accentDark:W.toHslString(),foregroundAccent:N.toHslString(),success:u.toHslString(),successDark:M.toHslString(),error:y.toHslString(),warn:f.toHslString()}}function as(e,t){let o=["google","twitter","discord","tiktok","linkedin","github","apple","farcaster"],r=t?.loginMethods?.filter(Z=>o.includes(Z)),n,i,a,s,l,c,u,f,y,v,g;t?.loginMethods?(n=t.loginMethods.includes("email"),i=t.loginMethods.includes("sms"),a=t.loginMethods.includes("wallet"),s=r?.includes("google"),l=r?.includes("twitter"),c=r?.includes("discord"),u=r?.includes("tiktok"),y=r?.includes("github"),f=r?.includes("linkedin"),v=r?.includes("apple"),g=r?.includes("farcaster")):(n=e.emailAuth,i=e.smsAuth,a=e.walletAuth,s=e.googleOAuth,l=e.twitterOAuth,c=e.discordOAuth,y=e.githubOAuth,u=e.tiktokOAuth,f=e.linkedinOAuth,v=e.appleOAuth,g=e.farcasterAuth);let E=[n,i].filter(Boolean),P=[s,l,c,y,u,f,v,g].filter(Boolean),C=[a].filter(Boolean);if(E.length+P.length+C.length===0)throw new Error("You must enable at least one login method");let _=t?.appearance?.showWalletLoginFirst!==void 0?t?.appearance?.showWalletLoginFirst:e.showWalletLoginFirst;_&&C.length===0?(console.warn("You should only enable `showWalletLoginFirst` when `wallet` logins are also enabled. `showWalletLoginFirst` has been set to false"),_=!1):!_&&P.length+E.length===0&&(console.warn("You should only disable `showWalletLoginFirst` when `email`, `sms`, or social logins are also enabled. `showWalletLoginFirst` has been set to true"),_=!0);let R=Hf({isWalletLoginEnabled:a,input:t?.appearance?.walletList});if(t?.embeddedWallets?.waitForTransactionConfirmation===!1&&t.embeddedWallets.noPromptOnSignature!==!0)throw new Error("Overriding `config.embeddedWallets.waitForTransactionConfirmation` requires that you also enable `config.embeddedWallets.noPromptOnSignature`");let W=t?.intl?.defaultCountry??"US",{chains:N,defaultChain:M}=C2({additionalChains:t?.additionalChains,supportedChains:t?.supportedChains,defaultChainFromConfig:t?.defaultChain,hasRpcConfigDefined:Object.keys(t?.rpcConfig?.rpcUrls??{}).length>0}),L=!!t?.defaultChain||!!t?.supportedChains,U=t?.customAuth?.getCustomAccessToken&&t?.customAuth?.enabled!==!1;return{id:e.id,name:e.name,allowlistConfig:e.allowlistConfig,appearance:{logo:t?.appearance?.logo??e.logoUrl,palette:th({backgroundTheme:t?.appearance?.theme??Pt.appearance.theme,accentHex:t?.appearance?.accentColor??e.accentColor??Pt.appearance.accentColor}),loginGroupPriority:_?"web3-first":"web2-first",hideDirectWeb2Inputs:!!t?.appearance?.hideDirectWeb2Inputs,walletList:R},loginMethods:{wallet:a,email:n,sms:i,google:s,twitter:l,discord:c,github:y,tiktok:u,linkedin:f,apple:v,farcaster:g},legal:{termsAndConditionsUrl:t?.legal?.termsAndConditionsUrl??e.termsAndConditionsUrl,privacyPolicyUrl:t?.legal?.privacyPolicyUrl??e.privacyPolicyUrl},walletConnectCloudProjectId:t?.walletConnectCloudProjectId??e.walletConnectCloudProjectId??Pt.walletConnectCloudProjectId,rpcConfig:{rpcUrls:t?.rpcConfig?.rpcUrls??Pt.rpcConfig.rpcUrls,rpcTimeouts:t?.rpcConfig?.rpcTimeouts??Pt.rpcConfig.rpcTimeouts},chains:N,defaultChain:M,intl:{defaultCountry:W},shouldSwitchChainOnConnect:L,captchaEnabled:e.captchaEnabled??Pt.captchaEnabled,captchaSiteKey:e.captchaSiteKey,embeddedWallets:{...e.embeddedWalletConfig,...U?{createOnLogin:"all-users",requireUserPasswordOnCreate:!1,noPromptOnSignature:!0}:{},waitForTransactionConfirmation:!0,priceDisplay:{primary:"fiat-currency",secondary:"native-token"},...t?.embeddedWallets},mfa:{methods:e.mfaMethods??[],noPromptOnMfaRequired:t?.mfa?.noPromptOnMfaRequired??!1},customAuth:U?{enabled:!0,...t.customAuth}:void 0,fiatOnRamp:{enabled:e.fiatOnRampEnabled,useSandbox:t?.fiatOnRamp?.useSandbox??Pt.fiatOnRamp.useSandbox},loginConfig:{twitterOAuthOnMobileEnabled:e.twitterOAuthOnMobileEnabled??!1},render:{inDialog:t?._render?.inDialog??Pt._render.inDialog,inParentNodeId:t?._render?.inParentNodeId??Pt._render.inParentNodeId}}}function oh(e,t){if(!e)return{legacyCreateEmbeddedWalletFlag:t};let{appearance:o,additionalChains:r,supportedChains:n,defaultChain:i,...a}=e;return{...a,...r?{additionalChains:r.map(l=>l.id)}:void 0,...n?{supportedChains:n.map(l=>l.id)}:void 0,...i?{defaultChain:i.id}:void 0,...o?{...o,...o.logo&&typeof o.logo?{logo:"component"}:void 0}:void 0,legacyCreateEmbeddedWalletFlag:t}}function C2({additionalChains:e,supportedChains:t,defaultChainFromConfig:o,hasRpcConfigDefined:r}){let n;if(e&&t&&console.warn("You should only specify one of `additionalChains` or `supportedChains`. Using `supportedChains`."),t){if(t.length===0)throw new Error("`supportedChains` must contain at least one chain");t.filter(l=>l.rpcUrls.privyWalletOverride).length>0&&r&&console.warn("You have specified at least one `supportedChain` with `privyWalletOverride` but also have `rpcConfig` defined. The `rpcConfig` will be ignored. `rpcConfig` is deprecated and you should use `privyWalletOverride` in a `supportedChain`."),n=t.map(l=>l.rpcUrls.privyWalletOverride?l:ai.find(u=>u.id===l.id)??l)}else n=ai.concat(e??[]);let i=t?n[0]:is,a=o??i;if(!n.find(s=>s.id===a.id))throw new Error("`defaultChain` must be included in `supportedChains`");return{chains:n,defaultChain:a}}import{useRef as b2,useEffect as E2}from"react";var ss=class{constructor(){this.callbacks={}}enqueue(t,o){this.callbacks[t]=o}dequeue(t,o){let r=this.callbacks[o];if(!r)throw new Error(`cannot dequeue ${t} event: no event found for id ${o}`);switch(delete this.callbacks[o],t){case"privy:iframe:ready":return r;case"privy:wallet:create":return r;case"privy:wallet:connect":return r;case"privy:wallet:recover":return r;case"privy:wallet:rpc":return r;case"privy:wallet:set-recovery-password":return r;case"privy:mfa:verify":return r;case"privy:mfa:init-enrollment":return r;case"privy:mfa:submit-enrollment":return r;case"privy:mfa:unenroll":return r;default:throw new Error(`invalid wallet event type ${t}`)}}};async function wr(e,t,o,r,n,i=!1){let a=i,s=async u=>{if(a&&t&&t.length>0){u===(i?0:1)?n("configureMfa","onMfaRequired",t):r.current?.reject(new Te("missing_or_invalid_mfa","MFA verification failed, retry."));let f=await new Promise((y,v)=>{o.current={resolve:y,reject:v};let g=1e3*60*5;setTimeout(()=>{let E=new Te("mfa_timeout","Timed out waiting for MFA code");r.current?.reject(E),v(E)},g)});return await e(f)}return await e()},l=4,c=null;for(let u=0;u<l;u++)try{c=await s(u),r.current?.resolve(void 0);break}catch(f){if(f.type==="missing_or_invalid_mfa")a=!0;else throw r.current?.resolve(void 0),f}if(c===null){let u=new Te("mfa_verification_max_attempts_reached","Max MFA verification attempts reached");throw r.current?.reject(u),u}return c}import{jsx as k2}from"react/jsx-runtime";var P2=function(e){return()=>`id-${e++}`}(0);function T2(e){return typeof e.event=="string"&&/^privy:.+/.test(e.event)}function eo(e){return e.error!==void 0}var Dt=new ss,ec=new Map,x2=(e,t)=>typeof t=="bigint"?t.toString():t,S2=(e,t)=>`${e}${JSON.stringify(t,x2)}`;function to(e,t,o){let r=o.contentWindow;if(!r)throw new Error("iframe not initialized");let n=S2(e,t);if(e==="privy:wallet:create"){let a=ec.get(n);if(a)return a}let i=new Promise((a,s)=>{let l=P2();Dt.enqueue(l,{resolve:a,reject:s}),r.postMessage({id:l,event:e,data:t},"*")}).finally(()=>{ec.delete(n)});return ec.set(n,i),i}function _2(e){switch(e.event){case"privy:iframe:ready":let t=Dt.dequeue(e.event,e.id);return eo(e)?t.reject(new Te(e.error.type,e.error.message)):t.resolve(e.data);case"privy:wallet:create":let o=Dt.dequeue(e.event,e.id);return eo(e)?o.reject(new Te(e.error.type,e.error.message)):o.resolve(e.data);case"privy:wallet:connect":let r=Dt.dequeue(e.event,e.id);return eo(e)?r.reject(new Te(e.error.type,e.error.message)):r.resolve(e.data);case"privy:wallet:recover":let n=Dt.dequeue(e.event,e.id);return eo(e)?n.reject(new Te(e.error.type,e.error.message)):n.resolve(e.data);case"privy:wallet:rpc":let i=Dt.dequeue(e.event,e.id);return eo(e)?i.reject(new Te(e.error.type,e.error.message)):i.resolve(e.data);case"privy:wallet:set-recovery-password":let a=Dt.dequeue(e.event,e.id);return eo(e)?a.reject(new Te(e.error.type,e.error.message)):a.resolve(e.data);case"privy:mfa:verify":let s=Dt.dequeue(e.event,e.id);return eo(e)?s.reject(new Te(e.error.type,e.error.message)):s.resolve(e.data);case"privy:mfa:init-enrollment":{let l=Dt.dequeue(e.event,e.id);return eo(e)?l.reject(new Te(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:submit-enrollment":{let l=Dt.dequeue(e.event,e.id);return eo(e)?l.reject(new Te(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:unenroll":{let l=Dt.dequeue(e.event,e.id);return eo(e)?l.reject(new Te(e.error.type,e.error.message)):l.resolve(e.data)}default:console.warn("Unsupported wallet proxy method:",e)}}function rh(e){let t=b2(null),o=Ud();return E2(()=>{let r=t.current;if(!r)return;function n(c){c&&c.origin===e.origin&&T2(c.data)&&_2(c.data)}let i={create(c){return to("privy:wallet:create",c,r)},connect(c){return to("privy:wallet:connect",c,r)},recover(c){return wr(u=>to("privy:wallet:recover",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},rpc(c){return wr(u=>to("privy:wallet:rpc",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},setRecoveryPassword(c){return wr(u=>to("privy:wallet:set-recovery-password",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},verifyMfa(c){return wr(u=>to("privy:mfa:verify",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},initEnrollMfa(c){return wr(u=>to("privy:mfa:init-enrollment",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},submitEnrollMfa(c){return to("privy:mfa:submit-enrollment",c,r)},unenrollMfa(c){return wr(u=>to("privy:mfa:unenroll",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)}};window.addEventListener("message",n);let a=()=>e.onLoad(i),s=(...c)=>{console.warn("Privy iframe failed to load: ",...c),e.onLoadFailed()},l=new AbortController;return rd(()=>to("privy:iframe:ready",{},r),{abortSignal:l.signal}).then(a,s),()=>{window.removeEventListener("message",n),l.abort()}},[t.current,e.mfaMethods]),k2("iframe",{ref:t,width:"0",height:"0",style:{display:"none",height:"0px",width:"0px"},src:Ti(e.origin,`/apps/${e.appId}/embedded-wallets`,{caid:e.clientAnalyticsId})})}var ls=class{constructor(t,o){this.meta={action:t,phoneNumber:o}}async init(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Auth flow has no API instance");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set when initialzing authentication.");try{let t=Lc();await this.api.post(t,{action:this.meta.action,phoneNumber:this.meta.phoneNumber})}catch(t){throw oe(t)}}async authenticate(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Mfa flow has no API instance");if(!this.meta.smsCode)throw new w("sms code must be set prior to calling authenticate.");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set prior to calling authenticate.");try{let t=Oc(),o=await this.api.post(t,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return ut(o)}catch(t){throw oe(t)}}};import{jsx as vo,jsxs as nh}from"react/jsx-runtime";var li;function N2(e){return typeof e=="string"&&e.length===25}function De(){if(!li){let e=ee.get(Jo);return Promise.resolve(e||null)}return li.getAccessToken()}var ih,cd=(e,t)=>ih(e,t),ah,dd=(e,t)=>ah(e,t),sh,pd=()=>sh(),L2=()=>{let t=new URLSearchParams(window.location.search).get("privy_token");if(!t)return;ee.put(vn,t);let o=new URL(window.location.href);o.searchParams.delete("privy_token"),window.history.pushState({},"",o)},O2=({config:e,...t})=>{if(!N2(t.appId))throw new w("Cannot initialize the Privy provider with an invalid Privy app ID");li||(li=new Pn({appId:t.appId,apiUrl:t.apiUrl||vi}));let o=Object.assign({},e);return t.createPrivyWalletOnLogin!==void 0&&o.embeddedWallets?.createOnLogin===void 0&&(o.embeddedWallets||(o.embeddedWallets={}),o.embeddedWallets.createOnLogin=t.createPrivyWalletOnLogin?"users-without-wallets":"off"),t.createPrivyWalletOnLogin!==void 0&&e?.embeddedWallets?.createOnLogin&&console.warn("Both `createPrivyWalletOnLogin` and `config.embeddedWallets.createOnLogin` are set. `createPrivyWalletOnLogin` is deprecated and should be removed."),vo(D2,{...t,config:o,client:li})},D2=e=>{let t=e.client,[o,r]=ye(!1),[n,i]=ye(!1),[a,s]=ye(!1),[l,c]=ye(null),[u,f]=ye(!1),[y,v]=ye([]),g=si(y),[E,P]=ye(!1),[C,_]=ye(null),[R,W]=ye(!1),[N,M]=ye({status:"disconnected",connectedWallet:null,connectError:null,connector:null,connectRetry:T}),[L,U]=ye(null),[Y,Z]=ye(null),[A,H]=ye(null),[V,we]=ye({showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,linkedinOAuth:!1,appleOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null,embeddedWalletConfig:{createOnLogin:"off",requireUserPasswordOnCreate:!1},fiatOnRampEnabled:!1,captchaEnabled:!1,captchaSiteKey:""}),[O,ge]=ye(()=>{let p=oh(e.config,e.createPrivyWalletOnLogin);return t.createAnalyticsEvent("sdk_initialize",p),as(V,e.config)}),[Tt,ve]=ye(!0),[_e,Le]=ye({}),[ne,wo]=ye(null),[Co,Ko]=ye(null),[Ye,ke]=ye(!1),[bo,Cr]=ye(!1),X=si(null),Ut=si(null),te=si(Od);t.onStoreToken=p=>{p&&ie(te,"accessToken","onAccessTokenGranted",p)},t.onDeleteToken=()=>{ie(te,"accessToken","onAccessTokenRemoved")};let Ce=si(),ds=I2(p=>{let d=t.connectors?.walletsReady||!1;return a&&l?.linkedAccounts?.some(b=>b.type==="wallet"&&b.walletClientType==="privy")?d&&p?.some(b=>b?.walletClientType==="privy"):d},[a,l?.linkedAccounts,t?.connectors?.walletsReady]),ae=p=>{_("CAPTCHA_SCREEN"),setTimeout(()=>{r(!0)},15),t.createAnalyticsEvent("modal_open",{initialScreen:p})},ro=p=>{O.embeddedWallets.createOnLogin!=="off"&&ve(!0),ae(p)};oo(()=>{if(!A||!l){t.connectors?.removeEmbeddedWalletConnector();return}let p=l?.linkedAccounts.filter(d=>d.type==="wallet"&&d.walletClient==="privy");if(p&&p.length>0){let d=p[0].address;t.connectors?.addEmbeddedWalletConnector(A,d,O.defaultChain)}},[A,l]),oo(()=>{A&&Co?.(A)},[A]),oo(()=>{(async()=>{if(!O.customAuth?.enabled)return;ve(!0);let{getCustomAccessToken:d,isLoading:m}=O.customAuth;if(!(!n||m))try{let b=await d();if(!b){await hn.logout();return}if(a)return;t.startAuthFlow(new Tr(b));let{user:I,isNewUser:$}=await t.authenticate();I||await hn.logout(),c(I||null),P($||!1),s(!0),Cr(!0)}catch(b){console.warn(b),a&&await hn.logout()}})()},[O.customAuth?.enabled,O.customAuth?.getCustomAccessToken,O.customAuth?.isLoading,n,a]),oo(()=>{bo&&A&&l&&xo(l,e.config?.embeddedWallets?.createOnLogin)&&(Cr(!1),rc(l,_r).catch(console.error))},[bo&&A&&l]),oo(()=>{async function p(){let d=await t.getServerConfig();we(d);let m=as(d,e.config);ge(m),d.customApiUrl&&t.updateApiUrl(d.customApiUrl);let b=ps();L2();let I=R2();U(I),t.initializeConnectorManager(m.walletConnectCloudProjectId,m.rpcConfig,m.chains,m.defaultChain,I,m.appearance.walletList),await t.connectors?.initialize();let $=await t.getAuthenticatedUser();e.config?.customAuth?.enabled||(s(!!$),$&&ie(te,"login","onComplete",$,!1,!0,null),c($)),b||be.setReadyToTrue(),b&&$&&f(!0),tt()}n||p()},[t,ne,n]),oo(()=>{let p=as(V,e.config);ge(p)},[e.config,V]);let ps=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_oauth_code"),m=p.get("privy_oauth_state"),b=p.get("privy_oauth_provider");return d&&m&&b?(t.startAuthFlow(new To(b,d,m)),ro("AWAITING_OAUTH_SCREEN"),!0):!1},fn=async(p,d,m,b)=>{let I=await t.connectors?.createWalletConnector(p,d)||null;Eo(I,d,m,b)};async function Eo(p,d,m,b){if(!p)return M({status:"disconnected",connectedWallet:null,connectError:new z("Unable to connect to wallet."),connector:null,connectRetry:T}),b?.(null,m);p instanceof $t&&d&&p.resetConnection(d),M({connector:p,status:"connecting",connectedWallet:null,connectError:null,connectRetry:()=>Eo(p,d,m,b)});try{let I=await p.connect({showPrompt:!0});if(O.shouldSwitchChainOnConnect&&!O.chains.find($=>$.id===Number(I?.chainId))&&!(I?.connectorType==="wallet_connect_v2"&&I?.walletClientType==="metamask")){M($=>({...$,connector:p,status:"switching_to_supported_chain",connectedWallet:null,connectError:null,connectRetry:T}));try{await I?.switchChain(O.defaultChain.id),I&&(I.chainId=kr(er(O.defaultChain.id)))}catch{console.warn(`Unable to switch to default chain: ${O.defaultChain.id}`)}}return M($=>({...$,status:"connected",connectedWallet:I,connectError:null,connectRetry:T})),I&&!R&&ie(te,"connectWallet","onSuccess",I),b?.(I,m)}catch(I){return I instanceof Oe?(console.warn(I.cause?I.cause:I.message),R||ie(te,"connectWallet","onError",I.privyErrorCode||"generic_connect_wallet_error")):(console.warn(I),R||ie(te,"connectWallet","onError","unknown_connect_wallet_error")),M($=>({...$,status:"disconnected",connectedWallet:null,connectError:I})),b?.(null,m)}}let Ae=async(p,d)=>{if(p===null)return;let m=new Zo(p,d);t.startAuthFlow(m)},tt=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_connector"),m=p.get("privy_wallet_client");if(!d||!m)return;if(m==="phantom"&&!So()&&ro("LOGIN_FAILED_SCREEN"),!t.connectors)throw new w("Connector not initialized");ae("AWAITING_CONNECTION");let b=new URL(window.location.href);b.searchParams.delete("privy_connector"),b.searchParams.delete("privy_wallet_client"),window.history.pushState({},"",b),fn(d,m,void 0,Ae)};oo(()=>{n&&a&&l===null&&t.getAuthenticatedUser().then(c)},[n,a,l,t]);let ot=()=>{if(!a)throw new w("User must be authenticated before linking a wallet.");f(!0),ae("LINK_WALLET_SCREEN")},oc=p=>{if(!a||!l)return!1;for(let d of l.linkedAccounts)if(d.type==="wallet"&&d.address===p.address)return!0;return!1},xt=async p=>{if(!t.connectors)throw new w("Connector not initialized");let d=t.connectors.findWalletConnector(p.connectorType,p.walletClientType)||null;if(M(m=>({...m,connector:d,status:"connected",connectedWallet:p,connectError:null,connectRetry:T})),O.captchaEnabled&&!a){let m={callback:b=>Ae(p,b),userIntentRequired:!1,onSuccessNavigateTo:"AWAITING_CONNECTION",onErrorNavigateTo:"ERROR_SCREEN"};Le({captchaModalData:m}),ro("CAPTCHA_SCREEN")}else await Ae(p),ro("AWAITING_CONNECTION")},br=async(p,d)=>{if(!O.fiatOnRamp.enabled)throw new w("Fiat on-ramp is not enabled");if(!d||!d.provider||d.provider==="moonpay"){let{signedUrl:m,externalTransactionId:b}=await Nu(t,p,d?.config??{},O.appearance.palette,O.fiatOnRamp.useSandbox);return{signedUrl:m,externalTransactionId:b}}else throw new w("Unsupported fund provider. Currently supported option is `moonpay`.")},ci=()=>{v(p=>{let d=t.connectors?.wallets.map(m=>({...m,linked:oc(m),loginOrLink:async()=>{if(!await m.isConnected())throw new w("Wallet is not connected");if(m.connectorType==="embedded"&&m.walletClientType==="privy")throw new w("Cannot link or login with embedded wallet");xt(m)},fund:async b=>{let{signedUrl:I,externalTransactionId:$}=await br(m.address,b);Le({fiatOnRampPrompt:{signedUrl:I},fiatOnRampStatus:{externalTransactionId:$}}),ae("FIAT_ON_RAMP_PROMPT_SCREEN")},unlink:async()=>{if(!a)throw new w("User is not authenticated.");if(m.connectorType==="embedded"&&m.walletClientType==="privy")throw new w("Cannot unlink an embedded wallet");let b=await t.unlinkWallet(m.address);c(b)}}))||[];return ke(ds(d)),Si(p,d)?p:d})};oo(()=>{ci()},[l?.linkedAccounts,a,n]),oo(()=>{if(n){if(!t.connectors)throw new w("Connector not initialized");ci(),t.connectors.on("walletsUpdated",ci)}},[n]);let dh=()=>{ae(a?"CONNECT_ONLY_AUTHENTICATED_SCREEN":"CONNECT_ONLY_LANDING_SCREEN")};oo(()=>{if(!y[0])return;let p=y[0],d=g.current.find(b=>b.address===p.address),m=l?.linkedAccounts.find(b=>b.type==="wallet"&&b.address===p.address);if(!d&&m){let b=Object.assign({},l);b.wallet=m&&{address:m.address,chainType:m.chainType,chainId:m.chainId,walletClient:m.walletClient,walletClientType:m.walletClientType,connectorType:m.connectorType},c(b)}g.current=y},[y]);let rc=async(p,d)=>{if(le(p))throw ie(te,"createWallet","onError","embedded_wallet_already_exists"),new Error("Only one Privy wallet per user is currently allowed");let[b,I]=await Promise.all([be.initializeWalletProxy(d),De()]);if(!b&&e.config?.customAuth?.enabled)throw ie(te,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to connect to wallet proxy");if(!b||!I||e.config?.embeddedWallets?.requireUserPasswordOnCreate)return new Promise(($,de)=>{ve(!0),Le({createWallet:{onSuccess:pt=>{ie(te,"createWallet","onSuccess",pt),$(pt)},onFailure:pt=>{ie(te,"createWallet","onError","unknown_embedded_wallet_error"),de(pt)},callAuthOnSuccessOnClose:!1}}),ae("EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN")});{await b.create({accessToken:I});let $=await be.refreshUser(),de=le($);if(!de)throw ie(te,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to create wallet");return ie(te,"createWallet","onSuccess",de),de}},ph=p=>{if(!O.chains.map(d=>d.id).includes(p))throw new z(`Chain ID ${p} is not supported. It must be added to the config.supportedChains property of the PrivyProvider.`,"unsupported_chain_id")},nc=(p,d,m)=>new Promise(async(b,I)=>{if(!a||!l){I(new Error("User must be authenticated before signing with a Privy wallet"));return}let $=le(l);if(!$){I(new Error("Must have a Privy wallet before signing"));return}ve(!0);let de=t.connectors?.findWalletConnector("embedded","privy")?.proxyProvider,Er=p.chainId?Number(p.chainId):de.chainId;ph(Er);let pt=Object.assign({},p,{chainId:Er}),yn=async()=>{let Po=await De();if(!Po||!A){I(new Error("Must have valid access token and Privy wallet to send transaction"));return}try{if(!await be.recoverEmbeddedWallet()){I(new Error("Unable to connect to wallet"));return}let sc=new A2(kt(pt.chainId,O.chains,O.rpcConfig)),mh=await pn($.address,pt,sc),fh=await Za(Po,$.address,A,mh,sc);b(fh)}catch(di){I(di)}};if(O.embeddedWallets.noPromptOnSignature)d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config"),yn();else{let Po={transactionRequest:pt,onSuccess:b,onFailure:I,uiOptions:d||{},fundWalletConfig:m},di={onCompleteNavigateTo:"EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN",onFailure:I};Le({connectWallet:di,sendTransaction:Po}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}});function ic(){return new Promise(async(p,d)=>{let m=await De();if(!m||!A)throw new Error("Must have valid access token to enroll in MFA");try{await A.verifyMfa({accessToken:m}),p()}catch(b){d(b)}})}let hn={ready:n,authenticated:a,user:l,walletConnectors:t.connectors||null,connectWallet:dh,linkWallet:ot,linkEmail:()=>{if(!a)throw new w("User must be authenticated before linking an email address.");if(l?.email)throw new w("User already has an email linked to their account.");f(!0),ae("LINK_EMAIL_SCREEN")},linkPhone:()=>{if(!a)throw new w("User must be authenticated before linking a phone number.");if(l?.phone)throw new w("User already has a phone number linked to their account.");f(!0),ae("LINK_PHONE_SCREEN")},linkGoogle:async()=>{if(!a)throw new w("User must be authenticated before linking a Google account.");if(l?.google)throw new w("User already has a Google account linked to their account.");await be.initLoginWithOAuth("google")},linkTwitter:async()=>{if(!a)throw new w("User must be authenticated before linking a Twitter account.");if(l?.twitter)throw new w("User already has a Twitter account linked to their account.");await be.initLoginWithOAuth("twitter")},linkDiscord:async()=>{if(!a)throw new w("User must be authenticated before linking a Discord account.");if(l?.discord)throw new w("User already has a Discord account linked to their account.");await be.initLoginWithOAuth("discord")},linkGithub:async()=>{if(!a)throw new w("User must be authenticated before linking a GitHub account.");if(l?.github)throw new w("User already has a Github account linked to their account.");await be.initLoginWithOAuth("github")},linkTiktok:async()=>{if(!a)throw new w("User must be authenticated before linking a TikTok account.");if(l?.tiktok)throw new w("User already has a Tiktok account linked to their account.");await be.initLoginWithOAuth("tiktok")},linkLinkedIn:async()=>{if(!a)throw new w("User must be authenticated before linking a LinkedIn account.");if(l?.linkedin)throw new w("User already has a LinkedIn account linked to their account.");await be.initLoginWithOAuth("linkedin")},linkApple:async()=>{if(!a)throw new w("User must be authenticated before linking an Apple account.");await be.initLoginWithOAuth("apple")},linkFarcaster:async()=>{if(!a)throw new w("User must be authenticated before linking a Farcaster account.");await be.initLoginWithFarcaster(),f(!0),ae("AWAITING_FARCASTER_CONNECTION")},login:async()=>{if(n||(await new Promise(p=>{wo(()=>p)}),wo(null)),a){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}W(!0),ro("LANDING")},logout:async()=>{await t.logout(),c(null),s(!1),_(null),ie(te,"logout","onSuccess"),f(!1),r(!1),ee.del(wn)},getAccessToken:()=>t.getAccessToken(),getEthereumProvider:()=>{if(!l||!l.wallet)return new se;let p=y.find(m=>l.wallet&&m.address===l.wallet.address),d=t.connectors?.walletConnectors.find(m=>m.wallets.find(b=>b.address===p?.address));return!p||!d?new se:d.proxyProvider},getEthersProvider:()=>{if(!l||!l.wallet)return new tc(new Gt(new se));let p=y.find(m=>l.wallet&&m.address===l.wallet.address),d=t.connectors?.walletConnectors.find(m=>m.wallets.find(b=>b.address===p?.address));return!p||!d?new tc(new Gt(new se)):new tc(new Gt(d.proxyProvider))},getWeb3jsProvider:()=>{if(!l||!l.wallet)return new Ao(new se);let p=y.find(m=>l.wallet&&m.address===l.wallet.address),d=t.connectors?.walletConnectors.find(m=>m.wallets.find(b=>b.address===p?.address));return!p||!d?new Ao(new se):new Ao(d.proxyProvider)},unlinkWallet:async p=>{let d=await t.unlinkWallet(p);return c(d),d},unlinkEmail:async p=>{let d=await t.unlinkEmail(p);return c(d),d},unlinkPhone:async p=>{let d=await t.unlinkPhone(p);return c(d),d},unlinkGoogle:async p=>{let d=await t.unlinkOAuth("google",p);return c(d),d},unlinkTwitter:async p=>{let d=await t.unlinkOAuth("twitter",p);return c(d),d},unlinkDiscord:async p=>{let d=await t.unlinkOAuth("discord",p);return c(d),d},unlinkGithub:async p=>{let d=await t.unlinkOAuth("github",p);return c(d),d},unlinkTiktok:async p=>{let d=await t.unlinkOAuth("tiktok",p);return c(d),d},unlinkLinkedIn:async p=>{let d=await t.unlinkOAuth("linkedin",p);return c(d),d},unlinkApple:async p=>{let d=await t.unlinkOAuth("apple",p);return c(d),d},unlinkFarcaster:async p=>{let d=await t.unlinkFarcaster(p);return c(d),d},setActiveWallet:async p=>{let d=y.find(b=>cs(b.address)===cs(p)),m=l?.linkedAccounts.find(b=>b.type==="wallet"&&cs(b.address)===cs(p));if(!d||!await d.isConnected())Z(p),ot();else if(!d.linked)d.loginOrLink();else{let b=Object.assign({},l);b.wallet=m&&{address:m.address,chainType:m.chainType,chainId:m.chainId,walletClient:m.walletClient,walletClientType:m.walletClientType,connectorType:m.connectorType},c(b)}},forkSession:()=>t.forkSession(),createWallet:async()=>{if(!a||!l)throw ie(te,"createWallet","onError","must_be_authenticated"),new Error("User must be authenticated before creating a Privy wallet");return rc(l,15e3)},setWalletPassword:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before adding password to Privy wallet"));return}let m=le(l);if(!m||!A){d(new Error("Must have a Privy wallet to add a password"));return}if(m.recoveryMethod==="user-passcode"){d(new Error("Cannot set password. Embedded wallet already has a password."));return}await ic(),ve(!0);let b={onSuccess:p,onFailure:d,callAuthOnSuccessOnClose:!1},I={onCompleteNavigateTo:"EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN",onFailure:d};Le({setWalletPassword:b,connectWallet:I}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}),signMessage:(p,d)=>new Promise(async(m,b)=>{if(!a||!l){b(new Error("User must be authenticated before signing with a Privy wallet"));return}let I=le(l);if(!I){b(new Error("Must have a Privy wallet before signing"));return}if(typeof p!="string"||p.length<1){b(new Error("Message must be a non-empty string"));return}ve(!0);let $=async()=>{if(!a)throw new Error("User must be authenticated before signing with a Privy wallet");let de=await De();if(!A||!de)throw new Error("Unable to connect to wallet");if(!await be.recoverEmbeddedWallet())throw new Error("Unable to connect to wallet");t.createAnalyticsEvent("embedded_wallet_sign_message_started",{walletAddress:I.address});let{response:pt}=await A.rpc({accessToken:de,address:I.address,request:{method:"personal_sign",params:[p,I.address]}}),yn=pt.data;return t.createAnalyticsEvent("embedded_wallet_sign_message_completed",{walletAddress:I.address}),yn};if(O.embeddedWallets.noPromptOnSignature){d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config");try{let de=await $();m(de)}catch(de){b(de??new ze("Unable to sign message"))}}else{let pt={message:p,confirmAndSignMessage:$,onSuccess:Po=>{m(Po)},onFailure:Po=>{b(Po)},uiOptions:d||{}},yn={onCompleteNavigateTo:"EMBEDDED_WALLET_SIGN_REQUEST_SCREEN",onFailure:b};Le({signMessage:pt,connectWallet:yn}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}}),sendTransaction:async(p,d,m)=>{let I=await(await nc(p,d,m)).wait();return es(I)},exportWallet:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before exporting their Privy wallet"));return}let m=le(l);if(!m){d(new Error("Must have a Privy wallet before exporting"));return}ve(!0);let b={onCompleteNavigateTo:"EMBEDDED_WALLET_KEY_EXPORT_SCREEN",onFailure:d},I=await De();if(!I||!A){d(new Error("Must have valid access token to enroll in MFA"));return}if(!A){d(new Error("Must have a Privy wallet before exporting"));return}try{try{await A.connect({accessToken:I,address:m.address}),await A.verifyMfa({accessToken:I})}catch(de){if(ar(de)&&m.recoveryMethod==="privy")await A.recover({accessToken:I,address:m.address});else throw de}}catch(de){d(de);return}let $={appId:e.appId,origin:t.apiUrl,onSuccess:p,onFailure:d};Le({keyExport:$,connectWallet:b}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}),promptMfa:ic,async init(p){let d;switch(p){case"sms":d=new ls("verify");break;case"totp":return;default:throw new Error(`Unsupported MFA method: ${p}`)}t.startMfaFlow(d),await d.init()},async submit(p,d){switch(p){case"totp":case"sms":X.current?.resolve({mfaMethod:p,mfaCode:d}),await new Promise((m,b)=>{Ut.current={resolve:m,reject:b}});break;default:throw X.current?.reject(new w("Unsupported MFA method")),new w(`Unsupported MFA method: ${p}`)}},cancel(){X.current?.reject(new w("MFA canceled"))},async initEnrollmentWithSms(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to enroll in MFA");await A.initEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber})},enrollInMfa(p){return new Promise((d,m)=>{if(!p){be.closePrivyModal(),d();return}O.mfa.noPromptOnMfaRequired&&console.warn("[Privy Warning] Triggering the 'showMfaEnrollmentModal' function when 'noPromptOnMfaRequired' is set to true is unexpected. If this is intentional, ensure that you are building custom UIs for MFA verification."),Le({mfaEnrollmentFlow:{mfaMethods:O.mfa.methods,onSuccess:d,onFailure:m}}),ae("MFA_ENROLLMENT_FLOW_SCREEN")})},async initEnrollmentWithTotp(){let p=await De();if(!p||!A)throw new Error("Must have valid access token to enroll in MFA");let d=await A.initEnrollMfa({method:"totp",accessToken:p});return{secret:d.secret,authUrl:d.authUrl}},async submitEnrollmentWithSms(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to enroll in MFA");await A.submitEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber,code:p.mfaCode});let m=await t.getAuthenticatedUser();c(m)},async submitEnrollmentWithTotp(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to enroll in MFA");await A.submitEnrollMfa({method:"totp",accessToken:d,code:p.mfaCode});let m=await t.getAuthenticatedUser();c(m)},async unenroll(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to remove MFA");await A.unenrollMfa({method:p,accessToken:d});let m=await t.getAuthenticatedUser();c(m)},loginWithCode(p){return be.loginWithCode(p)},initLoginWithEmail(p){return be.initLoginWithEmail(p)},initLoginWithSms(p){return be.initLoginWithSms(p)},isModalOpen:o};ih=hn.signMessage,ah=async(...p)=>{let d=await nc(...p);return O.embeddedWallets.waitForTransactionConfirmation&&await d.wait(),d};let ac=!!e.config?.headless,be=(()=>({headless:ac,isNewUserThisSession:E,isLinking:u,linkingHint:Y,pendingTransaction:null,walletConnectionStatus:N,mipdStore:L,connectors:t.connectors?.walletConnectors??[],rpcConfig:O.rpcConfig,chains:O.chains,showFiatPrices:O.embeddedWallets.priceDisplay.primary!=="native-token",clientAnalyticsId:t.clientAnalyticsId,nativeTokenSymbolForChainId:p=>O.chains.find(d=>d.id===Number(p))?.nativeCurrency.symbol,initializeWalletProxy:async p=>{if(A)return A;let d=new Promise(I=>{Ko(()=>$=>I($))}),m=new Promise(I=>setTimeout(()=>I(null),p)),b=await Promise.race([d,m]);return Ko(null),b},getAuthFlow:()=>t.authFlow,getAuthMeta:()=>t.authFlow?.meta,closePrivyModal:(p={shouldCallAuthOnSuccess:!0})=>{let d=n&&a&&l;p.shouldCallAuthOnSuccess&&d?(ie(te,"login","onComplete",l,E,!1,Ce.current??null),e.onSuccess?.(l,E)):R&&ie(te,"login","onError","exited_auth_flow"),Z(null),W(!1),f(!1),P(!1),r(!1),setTimeout(()=>{t.authFlow=void 0},200),t.createAnalyticsEvent("modal_closed")},openPrivyModal:ae,connectWallet:Eo,initLoginWithWallet:async(p,d)=>{Ce.current="siwe",Ae(p,d)},loginWithWallet:async()=>{if(!n)throw new Pr;if(!(t.authFlow instanceof Zo))throw new w("Must initialize SIWE flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(m){throw ie(te,"login","onError",m.privyErrorCode||"generic_connect_wallet_error"),m}c(p||l||null),P(d||!1),s(!0)},initLoginWithFarcaster:async p=>{let d=new gn(p);t.startAuthFlow(d);try{Ce.current="farcaster",await d.initializeFarcasterConnect(),M2&&d.meta.connectUri&&window.open(d.meta.connectUri,"_blank","noopener noreferrer")}catch(m){throw ie(te,"login","onError",m.privyErrorCode||"unknown_auth_error"),m}},loginWithFarcaster:async()=>{if(!n)throw new Pr;if(!(t.authFlow instanceof gn))throw new w("Must initialize Farcaster flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(m){throw ie(te,"login","onError",m.privyErrorCode||"generic_connect_wallet_error"),m}c(p||null),P(d||!1),s(!0)},initLoginWithOAuth:async(p,d)=>{if(!Jc()){ro("IN_APP_BROWSER_LOGIN_NOT_POSSIBLE");return}let m=new To(p);d&&m.addCaptchaToken(d),t.startAuthFlow(m);let b=await t.authFlow.getAuthorizationUrl();b&&b.url&&window.location.assign(b.url)},loginWithOAuth:async p=>{if(!(t.authFlow instanceof To))throw new w("Must initialize OAuth flow before calling loginWithOAuth");let d=St.get(xr),m=t.authFlow.meta.stateCode;if(d!==m)throw t.createAnalyticsEvent("possible_phishing_attempt",{provider:p,storedStateCode:d??"",returnedStateCode:m??""}),new w("Unexpected auth flow. This may be a phishing attempt.");let b,I;if(a)b=await t.link();else try{({user:b,isNewUser:I}=await t.authenticate()),Ce.current=p}catch($){throw ie(te,"login","onError",$.privyErrorCode||"unknown_auth_error"),$}c(b),P(I||!1),s(!0)},initLoginWithEmail:async(p,d)=>{let m=new Yo(p,d);t.startAuthFlow(m);try{Ce.current="email",await m.sendCodeEmail()}catch(b){throw ie(te,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},initLoginWithSms:async(p,d)=>{let m=new Xo(p,d);t.startAuthFlow(m);try{Ce.current="sms",await m.sendSmsCode()}catch(b){throw ie(te,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},resendEmailCode:async()=>{await t.authFlow?.sendCodeEmail()},resendSmsCode:async()=>{await t.authFlow?.sendSmsCode()},loginWithCode:async p=>{if(!n)throw new Pr;if(t.authFlow instanceof Yo)t.authFlow.meta.emailCode=p.trim();else if(t.authFlow instanceof Xo)t.authFlow.meta.smsCode=p.trim();else throw new w("Must initialize a passwordless code flow first");let d,m;a?d=await t.link():{user:d,isNewUser:m}=await t.authenticate(),c(d||l||null),P(m||!1),s(!0)},refreshUser:async()=>{let p=await t.getAuthenticatedUser();return c(p),p},walletProxy:A,createAnalyticsEvent:(p,d,m)=>t.createAnalyticsEvent(p,d,m),getUsdTokenPrice:p=>t.getUsdTokenPrice(p),recoverEmbeddedWallet:async()=>new Promise(async(p,d)=>{let m=l?.linkedAccounts.find(I=>I.type==="wallet"&&I.walletClientType==="privy"),b=await De();if(!b||!A||!m){d(new Error("Must have valid access token and Privy wallet to recover wallet"));return}ve(!0);try{await A.connect({accessToken:b,address:m.address}),p(!0)}catch(I){ar(I)&&m.recoveryMethod==="privy"?(t.createAnalyticsEvent("embedded_wallet_pinless_recovery_started",{walletAddress:m.address}),(await A.recover({address:m.address,accessToken:b})).address||d(new Error("Unable to recover wallet")),t.createAnalyticsEvent("embedded_wallet_recovery_completed",{walletAddress:m.address}),p(!0)):ar(I)?(Le({recoverWallet:{privyWallet:m,onFailure:d,onSuccess:()=>p(!0)}}),ae("EMBEDDED_WALLET_RECOVERY_SCREEN")):d(I)}}),getFiatOnRampConfig:br,setReadyToTrue:()=>{i(!0),ne?.()},updateWallets:()=>ci()}))();sh=be.recoverEmbeddedWallet;let uh=W2(()=>({wallets:y,ready:Ye}),[y,Ye]);return vo(Ee.Provider,{value:hn,children:vo(Rs.Provider,{value:te,children:vo($l.Provider,{value:uh,children:nh(Md,{...O,children:[e.children,nh(As.Provider,{value:be,children:[!ac&&O.captchaEnabled&&vo(ks,{delayedExecution:!1}),vo(Of,{theme:{...O.appearance.palette||{}}}),vo(gd,{appConfig:O,data:_e,setModalData:Le,setInitialScreen:_,initialScreen:C,authenticated:a,children:vo(Bf,{open:o})}),Tt&&V.id?vo(rh,{appId:e.appId,clientAnalyticsId:t.clientAnalyticsId,origin:t.apiUrl,mfaMethods:l?.mfaMethods,mfaPromise:X,mfaSubmitPromise:Ut,onLoad:H,onLoadFailed:()=>null}):null]})]})})})})};import{useContext as U2}from"react";function F2(e){let{login:t}=U2(Ee);return mt("login",e),{login:t}}import{useContext as B2}from"react";function H2(e){let{logout:t}=B2(Ee);return mt("logout",e),{logout:t}}import{useCallback as lh}from"react";var G2=()=>{let e=ce(),{initLoginWithEmail:t,loginWithCode:o}=F(),r=lh(async({email:i})=>{if(!i)throw new Error("Email required to send OTP code");return e.status==="disabled",t(i)},[t]),n=lh(async({code:i})=>{if(e.enabled&&e.status==="error")throw new ao(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};import{useCallback as ch}from"react";var z2=()=>{let e=ce(),{initLoginWithSms:t,loginWithCode:o}=F(),r=ch(async({phoneNumber:i})=>{if(!i)throw new Error("SMS required to send OTP code");return e.status==="disabled",t(i)},[t]),n=ch(async({code:i})=>{if(e.enabled&&e.status!=="success")throw new ao(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};import{useContext as V2}from"react";function $2(e){let{connectWallet:t}=V2(Ee);return mt("connectWallet",e),{connectWallet:t}}import{useContext as j2}from"react";function q2(e){let{createWallet:t}=j2(Ee);return mt("createWallet",e),{createWallet:t}}import{useContext as K2}from"react";var Y2=()=>{let{isModalOpen:e}=K2(Ee);return{isOpen:e}};import{useContext as J2}from"react";function Q2(e){let{getAccessToken:t}=J2(Ee);return mt("accessToken",e),{getAccessToken:t}}function Z2(e,t){return{...e,rpcUrls:{...e.rpcUrls,privyWalletOverride:{http:[t]}}}}export{Gt as AsExternalProvider,ks as Captcha,En as ConnectorManager,Pn as PrivyClient,O2 as PrivyProvider,se as PrivyProxyProvider,ai as SUPPORTED_CHAINS,fs as VERSION,Xe as WalletConnector,Z2 as addRpcUrlOverrideToChain,Zs as errorIndicatesMaxMfaRetries,qr as errorIndicatesMfaTimeout,Kr as errorIndicatesMfaVerificationFailed,De as getAccessToken,$2 as useConnectWallet,q2 as useCreateWallet,F2 as useLogin,G2 as useLoginWithEmail,z2 as useLoginWithSms,H2 as useLogout,ln as useMfa,Jn as useMfaEnrollment,Y2 as useModalStatus,F as usePrivy,Is as useRegisterMfaListener,Q2 as useToken,ni as useWallets};
2611
+ `;import{jsx as Ne,jsxs as Ff}from"react/jsx-runtime";var c2={["LANDING"]:fm,["AWAITING_PASSWORDLESS_CODE"]:tp,["AWAITING_CONNECTION"]:vp,["AWAITING_CONNECT_ONLY_CONNECTION"]:Ep,["AWAITING_FARCASTER_CONNECTION"]:Ru,["PHANTOM_INTERSTITIAL_SCREEN"]:Sf,["LOGIN_FAILED_SCREEN"]:bm,["AWAITING_OAUTH_SCREEN"]:Ef,["ALLOWLIST_REJECTION_SCREEN"]:zd,["INSTALL_PHANTOM_SCREEN"]:Vu,["LINK_EMAIL_SCREEN"]:hm,["LINK_PHONE_SCREEN"]:ym,["LINK_WALLET_SCREEN"]:gm,["CONNECT_ONLY_LANDING_SCREEN"]:hp,["CONNECT_ONLY_AUTHENTICATED_SCREEN"]:up,["EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN"]:lu,["EMBEDDED_WALLET_CREATED_SCREEN"]:Rp,["EMBEDDED_WALLET_CONNECTING_SCREEN"]:kp,["EMBEDDED_WALLET_RECOVERY_SCREEN"]:pu,["EMBEDDED_WALLET_KEY_EXPORT_SCREEN"]:Np,["EMBEDDED_WALLET_SIGN_REQUEST_SCREEN"]:Nf,["EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN"]:Wf,["FIAT_ON_RAMP_PROMPT_SCREEN"]:Ou,["FIAT_ON_RAMP_STATUS_SCREEN"]:Uu,["EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN"]:du,["EMBEDDED_WALLET_PASSWORD_UPDATE_SCREEN"]:cu,["MFA_ENROLLMENT_FLOW_SCREEN"]:Lm,["CAPTCHA_SCREEN"]:ip,["ERROR_SCREEN"]:uu,["IN_APP_BROWSER_LOGIN_NOT_POSSIBLE"]:Fu},d2=["LANDING","AWAITING_CONNECTION"],p2=({isMfaVerifying:e,onMfaVerificationComplete:t})=>{let{ready:o,isModalOpen:r}=F(),{headless:n}=k(),{ready:i,currentScreen:a}=S(),{status:s,execute:l,reset:c,enabled:u}=ce(),f=a2(null),y=Ld(f),v=r&&a&&d2.includes(a)&&!n&&s==="ready";if(Uf(()=>{v&&l()},[v]),Uf(()=>{!r&&u&&c()},[r,u]),(!o||!i)&&a!=="AWAITING_OAUTH_SCREEN")return Ff(an,{children:[Ne(x,{}),Ne(q,{}),Ne(Tm,{children:Ne(ft,{})}),Ne(J,{}),Ne(K,{})]});if(!a&&e)return Ne(an,{style:{height:y},children:Ne("div",{ref:f,children:Ne(Yl,{open:e,onClose:t})})});if(!a)return null;let g=c2[a];return Ne(an,{style:{height:y},children:Ff("div",{ref:f,children:[Ne(lo,{if:!!e,children:Ne(g,{})}),Ne(lo,{if:!e,children:Ne(Yl,{open:e,onClose:t})})]})})},u2=()=>{let{closePrivyModal:e}=k(),{onUserCloseViaDialogOrKeybindRef:t}=S();return{gracefulClosePrivyModal:i2(()=>{if(t?.current)t.current(),t.current=null;else return e({shouldCallAuthOnSuccess:!1})},[e])}},Bf=({open:e})=>{let{app:t}=S(),{gracefulClosePrivyModal:o}=u2(),[r,n]=s2(!1);Is({onMfaRequired:()=>{t?.mfa.noPromptOnMfaRequired||n(!0)}});let i=Ne(Df,{children:Ne(p2,{isMfaVerifying:r,onMfaVerificationComplete:()=>n(!1)})}),a=e||r,s=t?.render.inDialog?Ne(Pm,{open:a,id:"privy-dialog",onClick:()=>o(),children:i}):i;if(typeof window<"u"&&t?.render.inParentNodeId){let l=document.getElementById(t.render.inParentNodeId);if(l)return l2.createPortal(s,l)}return s};var Pt={appearance:{theme:"light",accentColor:"#676FFF",walletList:["detected_wallets","metamask","coinbase_wallet","rainbow","wallet_connect"]},walletConnectCloudProjectId:Fc,rpcConfig:{rpcUrls:{},rpcTimeouts:{}},captchaEnabled:!1,_render:{inDialog:!0,inParentNodeId:null},fiatOnRamp:{useSandbox:!1}};var m2=new Set(["metamask","coinbase_wallet","rainbow","zerion","phantom","wallet_connect","detected_wallets"]),f2=e=>m2.has(e),h2=(e,t,o)=>o.indexOf(e)===t,Hf=({input:e})=>e?e.filter(f2).filter(h2):Pt.appearance.walletList;var Gf={id:43114,name:"Avalanche",network:"avalanche",nativeCurrency:{decimals:18,name:"Avalanche",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax.network/ext/bc/C/rpc"]},public:{http:["https://api.avax.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://snowtrace.io"},default:{name:"SnowTrace",url:"https://snowtrace.io"}}};var zf={id:43113,name:"Avalanche Fuji",network:"avalanche-fuji",nativeCurrency:{decimals:18,name:"Avalanche Fuji",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax-test.network/ext/bc/C/rpc"]},public:{http:["https://api.avax-test.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://testnet.snowtrace.io"},default:{name:"SnowTrace",url:"https://testnet.snowtrace.io"}},testnet:!0};var Vf={id:42220,name:"Celo Mainnet",network:"celo",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://forno.celo.org"]},infura:{http:["https://celo-mainnet.infura.io/v3"]},public:{http:["https://forno.celo.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/mainnet"},etherscan:{name:"CeloScan",url:"https://celoscan.io"}},testnet:!1};var $f={id:44787,name:"Celo Alfajores Testnet",network:"celo-alfajores",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://alfajores-forno.celo-testnet.org"]},infura:{http:["https://celo-alfajores.infura.io/v3"]},public:{http:["https://alfajores-forno.celo-testnet.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/alfajores"},etherscan:{name:"CeloScan",url:"https://alfajores.celoscan.io/"}},testnet:!0};var jf={id:314,name:"Filecoin - Mainnet",network:"filecoin-mainnet",nativeCurrency:{decimals:18,name:"filecoin",symbol:"FIL"},rpcUrls:{default:{http:["https://api.node.glif.io/rpc/v1"]},public:{http:["https://api.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filfox",url:"https://filfox.info/en"},filscan:{name:"Filscan",url:"https://filscan.io"},filscout:{name:"Filscout",url:"https://filscout.io/en"},glif:{name:"Glif",url:"https://explorer.glif.io"}}};var qf={id:314159,name:"Filecoin - Calibration testnet",network:"filecoin-calibration",nativeCurrency:{decimals:18,name:"testnet filecoin",symbol:"tFIL"},rpcUrls:{default:{http:["https://api.calibration.node.glif.io/rpc/v1"]},public:{http:["https://api.calibration.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filscan",url:"https://calibration.filscan.io"}}};var Kf={id:5,network:"goerli",name:"Goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-goerli.g.alchemy.com/v2"],webSocket:["wss://eth-goerli.g.alchemy.com/v2"]},infura:{http:["https://goerli.infura.io/v3"],webSocket:["wss://goerli.infura.io/ws/v3"]},default:{http:["https://rpc.ankr.com/eth_goerli"]},public:{http:["https://rpc.ankr.com/eth_goerli"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli.etherscan.io"},default:{name:"Etherscan",url:"https://goerli.etherscan.io"}},testnet:!0};var Yf={id:17e3,name:"Holesky",network:"holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://ethereum-holesky.publicnode.com"]},public:{http:["https://ethereum-holesky.publicnode.com"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://holesky.etherscan.io"},default:{name:"EtherScan",url:"https://holesky.etherscan.io"}}};var Jf={id:59144,network:"linea-mainnet",name:"Linea Mainnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-mainnet.infura.io/v3"],webSocket:["wss://linea-mainnet.infura.io/ws/v3"]},default:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]},public:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://lineascan.build"},etherscan:{name:"Etherscan",url:"https://lineascan.build"}},testnet:!1};var Qf={id:59140,network:"linea-testnet",name:"Linea Goerli Testnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-goerli.infura.io/v3"],webSocket:["wss://linea-goerli.infura.io/ws/v3"]},default:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]},public:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://goerli.lineascan.build"},etherscan:{name:"Etherscan",url:"https://goerli.lineascan.build"}},testnet:!0};var is={id:1,network:"homestead",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-mainnet.g.alchemy.com/v2"],webSocket:["wss://eth-mainnet.g.alchemy.com/v2"]},infura:{http:["https://mainnet.infura.io/v3"],webSocket:["wss://mainnet.infura.io/ws/v3"]},default:{http:["https://cloudflare-eth.com"]},public:{http:["https://cloudflare-eth.com"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://etherscan.io"},default:{name:"Etherscan",url:"https://etherscan.io"}}};var Zf={id:17001,name:"Redstone Holesky",network:"redstone-holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.holesky.redstone.xyz"]},public:{http:["https://rpc.holesky.redstone.xyz"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"},default:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"}}};var Xf={id:11155111,network:"sepolia",name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"SEP",decimals:18},rpcUrls:{alchemy:{http:["https://eth-sepolia.g.alchemy.com/v2"],webSocket:["wss://eth-sepolia.g.alchemy.com/v2"]},infura:{http:["https://sepolia.infura.io/v3"],webSocket:["wss://sepolia.infura.io/ws/v3"]},default:{http:["https://rpc.sepolia.org"]},public:{http:["https://rpc.sepolia.org"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://sepolia.etherscan.io"},default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}},testnet:!0};var ai=[Ba,Ha,Ga,Kf,Xf,is,ja,qa,Ka,oi,ri,Vf,$f,jf,qf,za,Va,$a,Jf,Qf,Gf,zf,Ya,Qa,Ja,Yf,Zf],QD=new Set(ai.map(e=>e.id));import vr from"tinycolor2";var eh="#FFFFFF",y2="#000000",g2=eh,v2="#1E1E1D";function w2(e){return e<.8&&e>.2&&console.warn("Background color is not light or dark enough, which could lead to accessibility issues."),e>.5?"light":"dark"}function qo(e,t){let o=Math.max(0,Math.min(1,e.toHsl().l+t));return vr({...e.toHsl(),l:o})}function th({backgroundTheme:e,accentHex:t,successHex:o="#51BA81",warnHex:r="#FFB74D",errorHex:n="#EC6351",whiteHex:i=eh,blackHex:a=y2}){let s;switch(e){case"light":s=g2;break;case"dark":s=v2;break;default:s=e;break}let l=vr(s),c=vr(t),u=vr(o),f=vr(r),y=vr(n),v=w2(l.getLuminance()),g=qo(l,v==="light"?-.04:.11),E=qo(l,v==="light"?-.88:.87),P=qo(l,v==="light"?-.77:.75),C=qo(l,v==="light"?-.43:.45).desaturate(v==="light"?60:20),_=qo(l,v==="light"?-.08:.25).desaturate(v==="light"?60:20),R=qo(c,.15),W=qo(c,-.06),N=vr(c.getLuminance()>.5?a:i),M=qo(u,-.16);return{colorScheme:v,background:l.toHslString(),background2:g.toHslString(),foreground:E.toHslString(),foreground2:P.toHslString(),foreground3:C.toHslString(),foreground4:_.toHslString(),accent:c.toHslString(),accentLight:R.toHslString(),accentDark:W.toHslString(),foregroundAccent:N.toHslString(),success:u.toHslString(),successDark:M.toHslString(),error:y.toHslString(),warn:f.toHslString()}}function as(e,t){let o=["google","twitter","discord","tiktok","linkedin","github","apple","farcaster"],r=t?.loginMethods?.filter(Z=>o.includes(Z)),n,i,a,s,l,c,u,f,y,v,g;t?.loginMethods?(n=t.loginMethods.includes("email"),i=t.loginMethods.includes("sms"),a=t.loginMethods.includes("wallet"),s=r?.includes("google"),l=r?.includes("twitter"),c=r?.includes("discord"),u=r?.includes("tiktok"),y=r?.includes("github"),f=r?.includes("linkedin"),v=r?.includes("apple"),g=r?.includes("farcaster")):(n=e.emailAuth,i=e.smsAuth,a=e.walletAuth,s=e.googleOAuth,l=e.twitterOAuth,c=e.discordOAuth,y=e.githubOAuth,u=e.tiktokOAuth,f=e.linkedinOAuth,v=e.appleOAuth,g=e.farcasterAuth);let E=[n,i].filter(Boolean),P=[s,l,c,y,u,f,v,g].filter(Boolean),C=[a].filter(Boolean);if(E.length+P.length+C.length===0)throw new Error("You must enable at least one login method");let _=t?.appearance?.showWalletLoginFirst!==void 0?t?.appearance?.showWalletLoginFirst:e.showWalletLoginFirst;_&&C.length===0?(console.warn("You should only enable `showWalletLoginFirst` when `wallet` logins are also enabled. `showWalletLoginFirst` has been set to false"),_=!1):!_&&P.length+E.length===0&&(console.warn("You should only disable `showWalletLoginFirst` when `email`, `sms`, or social logins are also enabled. `showWalletLoginFirst` has been set to true"),_=!0);let R=Hf({isWalletLoginEnabled:a,input:t?.appearance?.walletList});if(t?.embeddedWallets?.waitForTransactionConfirmation===!1&&t.embeddedWallets.noPromptOnSignature!==!0)throw new Error("Overriding `config.embeddedWallets.waitForTransactionConfirmation` requires that you also enable `config.embeddedWallets.noPromptOnSignature`");let W=t?.intl?.defaultCountry??"US",{chains:N,defaultChain:M}=C2({additionalChains:t?.additionalChains,supportedChains:t?.supportedChains,defaultChainFromConfig:t?.defaultChain,hasRpcConfigDefined:Object.keys(t?.rpcConfig?.rpcUrls??{}).length>0}),L=!!t?.defaultChain||!!t?.supportedChains,U=t?.customAuth?.getCustomAccessToken&&t?.customAuth?.enabled!==!1;return{id:e.id,name:e.name,allowlistConfig:e.allowlistConfig,appearance:{logo:t?.appearance?.logo??e.logoUrl,palette:th({backgroundTheme:t?.appearance?.theme??Pt.appearance.theme,accentHex:t?.appearance?.accentColor??e.accentColor??Pt.appearance.accentColor}),loginGroupPriority:_?"web3-first":"web2-first",hideDirectWeb2Inputs:!!t?.appearance?.hideDirectWeb2Inputs,walletList:R},loginMethods:{wallet:a,email:n,sms:i,google:s,twitter:l,discord:c,github:y,tiktok:u,linkedin:f,apple:v,farcaster:g},legal:{termsAndConditionsUrl:t?.legal?.termsAndConditionsUrl??e.termsAndConditionsUrl,privacyPolicyUrl:t?.legal?.privacyPolicyUrl??e.privacyPolicyUrl},walletConnectCloudProjectId:t?.walletConnectCloudProjectId??e.walletConnectCloudProjectId??Pt.walletConnectCloudProjectId,rpcConfig:{rpcUrls:t?.rpcConfig?.rpcUrls??Pt.rpcConfig.rpcUrls,rpcTimeouts:t?.rpcConfig?.rpcTimeouts??Pt.rpcConfig.rpcTimeouts},chains:N,defaultChain:M,intl:{defaultCountry:W},shouldSwitchChainOnConnect:L,captchaEnabled:e.captchaEnabled??Pt.captchaEnabled,captchaSiteKey:e.captchaSiteKey,embeddedWallets:{...e.embeddedWalletConfig,...U?{createOnLogin:"all-users",requireUserPasswordOnCreate:!1,noPromptOnSignature:!0}:{},waitForTransactionConfirmation:!0,priceDisplay:{primary:"fiat-currency",secondary:"native-token"},...t?.embeddedWallets},mfa:{methods:e.mfaMethods??[],noPromptOnMfaRequired:t?.mfa?.noPromptOnMfaRequired??!1},customAuth:U?{enabled:!0,...t.customAuth}:void 0,fiatOnRamp:{enabled:e.fiatOnRampEnabled,useSandbox:t?.fiatOnRamp?.useSandbox??Pt.fiatOnRamp.useSandbox},loginConfig:{twitterOAuthOnMobileEnabled:e.twitterOAuthOnMobileEnabled??!1},render:{inDialog:t?._render?.inDialog??Pt._render.inDialog,inParentNodeId:t?._render?.inParentNodeId??Pt._render.inParentNodeId}}}function oh(e,t){if(!e)return{legacyCreateEmbeddedWalletFlag:t};let{appearance:o,additionalChains:r,supportedChains:n,defaultChain:i,...a}=e;return{...a,...r?{additionalChains:r.map(l=>l.id)}:void 0,...n?{supportedChains:n.map(l=>l.id)}:void 0,...i?{defaultChain:i.id}:void 0,...o?{...o,...o.logo&&typeof o.logo?{logo:"component"}:void 0}:void 0,legacyCreateEmbeddedWalletFlag:t}}function C2({additionalChains:e,supportedChains:t,defaultChainFromConfig:o,hasRpcConfigDefined:r}){let n;if(e&&t&&console.warn("You should only specify one of `additionalChains` or `supportedChains`. Using `supportedChains`."),t){if(t.length===0)throw new Error("`supportedChains` must contain at least one chain");t.filter(l=>l.rpcUrls.privyWalletOverride).length>0&&r&&console.warn("You have specified at least one `supportedChain` with `privyWalletOverride` but also have `rpcConfig` defined. The `rpcConfig` will be ignored. `rpcConfig` is deprecated and you should use `privyWalletOverride` in a `supportedChain`."),n=t.map(l=>l.rpcUrls.privyWalletOverride?l:ai.find(u=>u.id===l.id)??l)}else n=ai.concat(e??[]);let i=t?n[0]:is,a=o??i;if(!n.find(s=>s.id===a.id))throw new Error("`defaultChain` must be included in `supportedChains`");return{chains:n,defaultChain:a}}import{useRef as b2,useEffect as E2}from"react";var ss=class{constructor(){this.callbacks={}}enqueue(t,o){this.callbacks[t]=o}dequeue(t,o){let r=this.callbacks[o];if(!r)throw new Error(`cannot dequeue ${t} event: no event found for id ${o}`);switch(delete this.callbacks[o],t){case"privy:iframe:ready":return r;case"privy:wallet:create":return r;case"privy:wallet:connect":return r;case"privy:wallet:recover":return r;case"privy:wallet:rpc":return r;case"privy:wallet:set-recovery-password":return r;case"privy:mfa:verify":return r;case"privy:mfa:init-enrollment":return r;case"privy:mfa:submit-enrollment":return r;case"privy:mfa:unenroll":return r;default:throw new Error(`invalid wallet event type ${t}`)}}};async function wr(e,t,o,r,n,i=!1){let a=i,s=async u=>{if(a&&t&&t.length>0){u===(i?0:1)?n("configureMfa","onMfaRequired",t):r.current?.reject(new Te("missing_or_invalid_mfa","MFA verification failed, retry."));let f=await new Promise((y,v)=>{o.current={resolve:y,reject:v};let g=1e3*60*5;setTimeout(()=>{let E=new Te("mfa_timeout","Timed out waiting for MFA code");r.current?.reject(E),v(E)},g)});return await e(f)}return await e()},l=4,c=null;for(let u=0;u<l;u++)try{c=await s(u),r.current?.resolve(void 0);break}catch(f){if(f.type==="missing_or_invalid_mfa")a=!0;else throw r.current?.resolve(void 0),f}if(c===null){let u=new Te("mfa_verification_max_attempts_reached","Max MFA verification attempts reached");throw r.current?.reject(u),u}return c}import{jsx as k2}from"react/jsx-runtime";var P2=function(e){return()=>`id-${e++}`}(0);function T2(e){return typeof e.event=="string"&&/^privy:.+/.test(e.event)}function eo(e){return e.error!==void 0}var Dt=new ss,ec=new Map,x2=(e,t)=>typeof t=="bigint"?t.toString():t,S2=(e,t)=>`${e}${JSON.stringify(t,x2)}`;function to(e,t,o){let r=o.contentWindow;if(!r)throw new Error("iframe not initialized");let n=S2(e,t);if(e==="privy:wallet:create"){let a=ec.get(n);if(a)return a}let i=new Promise((a,s)=>{let l=P2();Dt.enqueue(l,{resolve:a,reject:s}),r.postMessage({id:l,event:e,data:t},"*")}).finally(()=>{ec.delete(n)});return ec.set(n,i),i}function _2(e){switch(e.event){case"privy:iframe:ready":let t=Dt.dequeue(e.event,e.id);return eo(e)?t.reject(new Te(e.error.type,e.error.message)):t.resolve(e.data);case"privy:wallet:create":let o=Dt.dequeue(e.event,e.id);return eo(e)?o.reject(new Te(e.error.type,e.error.message)):o.resolve(e.data);case"privy:wallet:connect":let r=Dt.dequeue(e.event,e.id);return eo(e)?r.reject(new Te(e.error.type,e.error.message)):r.resolve(e.data);case"privy:wallet:recover":let n=Dt.dequeue(e.event,e.id);return eo(e)?n.reject(new Te(e.error.type,e.error.message)):n.resolve(e.data);case"privy:wallet:rpc":let i=Dt.dequeue(e.event,e.id);return eo(e)?i.reject(new Te(e.error.type,e.error.message)):i.resolve(e.data);case"privy:wallet:set-recovery-password":let a=Dt.dequeue(e.event,e.id);return eo(e)?a.reject(new Te(e.error.type,e.error.message)):a.resolve(e.data);case"privy:mfa:verify":let s=Dt.dequeue(e.event,e.id);return eo(e)?s.reject(new Te(e.error.type,e.error.message)):s.resolve(e.data);case"privy:mfa:init-enrollment":{let l=Dt.dequeue(e.event,e.id);return eo(e)?l.reject(new Te(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:submit-enrollment":{let l=Dt.dequeue(e.event,e.id);return eo(e)?l.reject(new Te(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:unenroll":{let l=Dt.dequeue(e.event,e.id);return eo(e)?l.reject(new Te(e.error.type,e.error.message)):l.resolve(e.data)}default:console.warn("Unsupported wallet proxy method:",e)}}function rh(e){let t=b2(null),o=Ud();return E2(()=>{let r=t.current;if(!r)return;function n(c){c&&c.origin===e.origin&&T2(c.data)&&_2(c.data)}let i={create(c){return to("privy:wallet:create",c,r)},connect(c){return to("privy:wallet:connect",c,r)},recover(c){return wr(u=>to("privy:wallet:recover",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},rpc(c){return wr(u=>to("privy:wallet:rpc",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},setRecoveryPassword(c){return wr(u=>to("privy:wallet:set-recovery-password",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},verifyMfa(c){return wr(u=>to("privy:mfa:verify",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},initEnrollMfa(c){return wr(u=>to("privy:mfa:init-enrollment",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},submitEnrollMfa(c){return to("privy:mfa:submit-enrollment",c,r)},unenrollMfa(c){return wr(u=>to("privy:mfa:unenroll",{...c,...u},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)}};window.addEventListener("message",n);let a=()=>e.onLoad(i),s=(...c)=>{console.warn("Privy iframe failed to load: ",...c),e.onLoadFailed()},l=new AbortController;return rd(()=>to("privy:iframe:ready",{},r),{abortSignal:l.signal}).then(a,s),()=>{window.removeEventListener("message",n),l.abort()}},[t.current,e.mfaMethods]),k2("iframe",{ref:t,width:"0",height:"0",style:{display:"none",height:"0px",width:"0px"},src:Ti(e.origin,`/apps/${e.appId}/embedded-wallets`,{caid:e.clientAnalyticsId})})}var ls=class{constructor(t,o){this.meta={action:t,phoneNumber:o}}async init(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Auth flow has no API instance");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set when initialzing authentication.");try{let t=Lc();await this.api.post(t,{action:this.meta.action,phoneNumber:this.meta.phoneNumber})}catch(t){throw oe(t)}}async authenticate(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Mfa flow has no API instance");if(!this.meta.smsCode)throw new w("sms code must be set prior to calling authenticate.");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set prior to calling authenticate.");try{let t=Oc(),o=await this.api.post(t,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return ut(o)}catch(t){throw oe(t)}}};import{jsx as vo,jsxs as nh}from"react/jsx-runtime";var li;function N2(e){return typeof e=="string"&&e.length===25}function De(){if(!li){let e=ee.get(Jo);return Promise.resolve(e||null)}return li.getAccessToken()}var ih,cd=(e,t)=>ih(e,t),ah,dd=(e,t)=>ah(e,t),sh,pd=()=>sh(),L2=()=>{let t=new URLSearchParams(window.location.search).get("privy_token");if(!t)return;ee.put(vn,t);let o=new URL(window.location.href);o.searchParams.delete("privy_token"),window.history.pushState({},"",o)},O2=({config:e,...t})=>{if(!N2(t.appId))throw new w("Cannot initialize the Privy provider with an invalid Privy app ID");li||(li=new Pn({appId:t.appId,apiUrl:t.apiUrl||vi}));let o=Object.assign({},e);return t.createPrivyWalletOnLogin!==void 0&&o.embeddedWallets?.createOnLogin===void 0&&(o.embeddedWallets||(o.embeddedWallets={}),o.embeddedWallets.createOnLogin=t.createPrivyWalletOnLogin?"users-without-wallets":"off"),t.createPrivyWalletOnLogin!==void 0&&e?.embeddedWallets?.createOnLogin&&console.warn("Both `createPrivyWalletOnLogin` and `config.embeddedWallets.createOnLogin` are set. `createPrivyWalletOnLogin` is deprecated and should be removed."),vo(D2,{...t,config:o,client:li})},D2=e=>{let t=e.client,[o,r]=ye(!1),[n,i]=ye(!1),[a,s]=ye(!1),[l,c]=ye(null),[u,f]=ye(!1),[y,v]=ye([]),g=si(y),[E,P]=ye(!1),[C,_]=ye(null),[R,W]=ye(!1),[N,M]=ye({status:"disconnected",connectedWallet:null,connectError:null,connector:null,connectRetry:T}),[L,U]=ye(null),[Y,Z]=ye(null),[A,H]=ye(null),[V,we]=ye({showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,linkedinOAuth:!1,appleOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null,embeddedWalletConfig:{createOnLogin:"off",requireUserPasswordOnCreate:!1},fiatOnRampEnabled:!1,captchaEnabled:!1,captchaSiteKey:""}),[O,ge]=ye(()=>{let p=oh(e.config,e.createPrivyWalletOnLogin);return t.createAnalyticsEvent("sdk_initialize",p),as(V,e.config)}),[Tt,ve]=ye(!0),[_e,Le]=ye({}),[ne,wo]=ye(null),[Co,Ko]=ye(null),[Ye,ke]=ye(!1),[bo,Cr]=ye(!1),X=si(null),Ut=si(null),te=si(Od);t.onStoreToken=p=>{p&&ie(te,"accessToken","onAccessTokenGranted",p)},t.onDeleteToken=()=>{ie(te,"accessToken","onAccessTokenRemoved")};let Ce=si(),ds=I2(p=>{let d=t.connectors?.walletsReady||!1;return a&&l?.linkedAccounts?.some(b=>b.type==="wallet"&&b.walletClientType==="privy")?d&&p?.some(b=>b?.walletClientType==="privy"):d},[a,l?.linkedAccounts,t?.connectors?.walletsReady]),ae=p=>{_(p),setTimeout(()=>{r(!0)},15),t.createAnalyticsEvent("modal_open",{initialScreen:p})},ro=p=>{O.embeddedWallets.createOnLogin!=="off"&&ve(!0),ae(p)};oo(()=>{if(!A||!l){t.connectors?.removeEmbeddedWalletConnector();return}let p=l?.linkedAccounts.filter(d=>d.type==="wallet"&&d.walletClient==="privy");if(p&&p.length>0){let d=p[0].address;t.connectors?.addEmbeddedWalletConnector(A,d,O.defaultChain)}},[A,l]),oo(()=>{A&&Co?.(A)},[A]),oo(()=>{(async()=>{if(!O.customAuth?.enabled)return;ve(!0);let{getCustomAccessToken:d,isLoading:m}=O.customAuth;if(!(!n||m))try{let b=await d();if(!b){await hn.logout();return}if(a)return;t.startAuthFlow(new Tr(b));let{user:I,isNewUser:$}=await t.authenticate();I||await hn.logout(),c(I||null),P($||!1),s(!0),Cr(!0)}catch(b){console.warn(b),a&&await hn.logout()}})()},[O.customAuth?.enabled,O.customAuth?.getCustomAccessToken,O.customAuth?.isLoading,n,a]),oo(()=>{bo&&A&&l&&xo(l,e.config?.embeddedWallets?.createOnLogin)&&(Cr(!1),rc(l,_r).catch(console.error))},[bo&&A&&l]),oo(()=>{async function p(){let d=await t.getServerConfig();we(d);let m=as(d,e.config);ge(m),d.customApiUrl&&t.updateApiUrl(d.customApiUrl);let b=ps();L2();let I=R2();U(I),t.initializeConnectorManager(m.walletConnectCloudProjectId,m.rpcConfig,m.chains,m.defaultChain,I,m.appearance.walletList),await t.connectors?.initialize();let $=await t.getAuthenticatedUser();e.config?.customAuth?.enabled||(s(!!$),$&&ie(te,"login","onComplete",$,!1,!0,null),c($)),b||be.setReadyToTrue(),b&&$&&f(!0),tt()}n||p()},[t,ne,n]),oo(()=>{let p=as(V,e.config);ge(p)},[e.config,V]);let ps=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_oauth_code"),m=p.get("privy_oauth_state"),b=p.get("privy_oauth_provider");return d&&m&&b?(t.startAuthFlow(new To(b,d,m)),ro("AWAITING_OAUTH_SCREEN"),!0):!1},fn=async(p,d,m,b)=>{let I=await t.connectors?.createWalletConnector(p,d)||null;Eo(I,d,m,b)};async function Eo(p,d,m,b){if(!p)return M({status:"disconnected",connectedWallet:null,connectError:new z("Unable to connect to wallet."),connector:null,connectRetry:T}),b?.(null,m);p instanceof $t&&d&&p.resetConnection(d),M({connector:p,status:"connecting",connectedWallet:null,connectError:null,connectRetry:()=>Eo(p,d,m,b)});try{let I=await p.connect({showPrompt:!0});if(O.shouldSwitchChainOnConnect&&!O.chains.find($=>$.id===Number(I?.chainId))&&!(I?.connectorType==="wallet_connect_v2"&&I?.walletClientType==="metamask")){M($=>({...$,connector:p,status:"switching_to_supported_chain",connectedWallet:null,connectError:null,connectRetry:T}));try{await I?.switchChain(O.defaultChain.id),I&&(I.chainId=kr(er(O.defaultChain.id)))}catch{console.warn(`Unable to switch to default chain: ${O.defaultChain.id}`)}}return M($=>({...$,status:"connected",connectedWallet:I,connectError:null,connectRetry:T})),I&&!R&&ie(te,"connectWallet","onSuccess",I),b?.(I,m)}catch(I){return I instanceof Oe?(console.warn(I.cause?I.cause:I.message),R||ie(te,"connectWallet","onError",I.privyErrorCode||"generic_connect_wallet_error")):(console.warn(I),R||ie(te,"connectWallet","onError","unknown_connect_wallet_error")),M($=>({...$,status:"disconnected",connectedWallet:null,connectError:I})),b?.(null,m)}}let Ae=async(p,d)=>{if(p===null)return;let m=new Zo(p,d);t.startAuthFlow(m)},tt=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_connector"),m=p.get("privy_wallet_client");if(!d||!m)return;if(m==="phantom"&&!So()&&ro("LOGIN_FAILED_SCREEN"),!t.connectors)throw new w("Connector not initialized");ae("AWAITING_CONNECTION");let b=new URL(window.location.href);b.searchParams.delete("privy_connector"),b.searchParams.delete("privy_wallet_client"),window.history.pushState({},"",b),fn(d,m,void 0,Ae)};oo(()=>{n&&a&&l===null&&t.getAuthenticatedUser().then(c)},[n,a,l,t]);let ot=()=>{if(!a)throw new w("User must be authenticated before linking a wallet.");f(!0),ae("LINK_WALLET_SCREEN")},oc=p=>{if(!a||!l)return!1;for(let d of l.linkedAccounts)if(d.type==="wallet"&&d.address===p.address)return!0;return!1},xt=async p=>{if(!t.connectors)throw new w("Connector not initialized");let d=t.connectors.findWalletConnector(p.connectorType,p.walletClientType)||null;if(M(m=>({...m,connector:d,status:"connected",connectedWallet:p,connectError:null,connectRetry:T})),O.captchaEnabled&&!a){let m={callback:b=>Ae(p,b),userIntentRequired:!1,onSuccessNavigateTo:"AWAITING_CONNECTION",onErrorNavigateTo:"ERROR_SCREEN"};Le({captchaModalData:m}),ro("CAPTCHA_SCREEN")}else await Ae(p),ro("AWAITING_CONNECTION")},br=async(p,d)=>{if(!O.fiatOnRamp.enabled)throw new w("Fiat on-ramp is not enabled");if(!d||!d.provider||d.provider==="moonpay"){let{signedUrl:m,externalTransactionId:b}=await Nu(t,p,d?.config??{},O.appearance.palette,O.fiatOnRamp.useSandbox);return{signedUrl:m,externalTransactionId:b}}else throw new w("Unsupported fund provider. Currently supported option is `moonpay`.")},ci=()=>{v(p=>{let d=t.connectors?.wallets.map(m=>({...m,linked:oc(m),loginOrLink:async()=>{if(!await m.isConnected())throw new w("Wallet is not connected");if(m.connectorType==="embedded"&&m.walletClientType==="privy")throw new w("Cannot link or login with embedded wallet");xt(m)},fund:async b=>{let{signedUrl:I,externalTransactionId:$}=await br(m.address,b);Le({fiatOnRampPrompt:{signedUrl:I},fiatOnRampStatus:{externalTransactionId:$}}),ae("FIAT_ON_RAMP_PROMPT_SCREEN")},unlink:async()=>{if(!a)throw new w("User is not authenticated.");if(m.connectorType==="embedded"&&m.walletClientType==="privy")throw new w("Cannot unlink an embedded wallet");let b=await t.unlinkWallet(m.address);c(b)}}))||[];return ke(ds(d)),Si(p,d)?p:d})};oo(()=>{ci()},[l?.linkedAccounts,a,n]),oo(()=>{if(n){if(!t.connectors)throw new w("Connector not initialized");ci(),t.connectors.on("walletsUpdated",ci)}},[n]);let dh=()=>{ae(a?"CONNECT_ONLY_AUTHENTICATED_SCREEN":"CONNECT_ONLY_LANDING_SCREEN")};oo(()=>{if(!y[0])return;let p=y[0],d=g.current.find(b=>b.address===p.address),m=l?.linkedAccounts.find(b=>b.type==="wallet"&&b.address===p.address);if(!d&&m){let b=Object.assign({},l);b.wallet=m&&{address:m.address,chainType:m.chainType,chainId:m.chainId,walletClient:m.walletClient,walletClientType:m.walletClientType,connectorType:m.connectorType},c(b)}g.current=y},[y]);let rc=async(p,d)=>{if(le(p))throw ie(te,"createWallet","onError","embedded_wallet_already_exists"),new Error("Only one Privy wallet per user is currently allowed");let[b,I]=await Promise.all([be.initializeWalletProxy(d),De()]);if(!b&&e.config?.customAuth?.enabled)throw ie(te,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to connect to wallet proxy");if(!b||!I||e.config?.embeddedWallets?.requireUserPasswordOnCreate)return new Promise(($,de)=>{ve(!0),Le({createWallet:{onSuccess:pt=>{ie(te,"createWallet","onSuccess",pt),$(pt)},onFailure:pt=>{ie(te,"createWallet","onError","unknown_embedded_wallet_error"),de(pt)},callAuthOnSuccessOnClose:!1}}),ae("EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN")});{await b.create({accessToken:I});let $=await be.refreshUser(),de=le($);if(!de)throw ie(te,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to create wallet");return ie(te,"createWallet","onSuccess",de),de}},ph=p=>{if(!O.chains.map(d=>d.id).includes(p))throw new z(`Chain ID ${p} is not supported. It must be added to the config.supportedChains property of the PrivyProvider.`,"unsupported_chain_id")},nc=(p,d,m)=>new Promise(async(b,I)=>{if(!a||!l){I(new Error("User must be authenticated before signing with a Privy wallet"));return}let $=le(l);if(!$){I(new Error("Must have a Privy wallet before signing"));return}ve(!0);let de=t.connectors?.findWalletConnector("embedded","privy")?.proxyProvider,Er=p.chainId?Number(p.chainId):de.chainId;ph(Er);let pt=Object.assign({},p,{chainId:Er}),yn=async()=>{let Po=await De();if(!Po||!A){I(new Error("Must have valid access token and Privy wallet to send transaction"));return}try{if(!await be.recoverEmbeddedWallet()){I(new Error("Unable to connect to wallet"));return}let sc=new A2(kt(pt.chainId,O.chains,O.rpcConfig)),mh=await pn($.address,pt,sc),fh=await Za(Po,$.address,A,mh,sc);b(fh)}catch(di){I(di)}};if(O.embeddedWallets.noPromptOnSignature)d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config"),yn();else{let Po={transactionRequest:pt,onSuccess:b,onFailure:I,uiOptions:d||{},fundWalletConfig:m},di={onCompleteNavigateTo:"EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN",onFailure:I};Le({connectWallet:di,sendTransaction:Po}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}});function ic(){return new Promise(async(p,d)=>{let m=await De();if(!m||!A)throw new Error("Must have valid access token to enroll in MFA");try{await A.verifyMfa({accessToken:m}),p()}catch(b){d(b)}})}let hn={ready:n,authenticated:a,user:l,walletConnectors:t.connectors||null,connectWallet:dh,linkWallet:ot,linkEmail:()=>{if(!a)throw new w("User must be authenticated before linking an email address.");if(l?.email)throw new w("User already has an email linked to their account.");f(!0),ae("LINK_EMAIL_SCREEN")},linkPhone:()=>{if(!a)throw new w("User must be authenticated before linking a phone number.");if(l?.phone)throw new w("User already has a phone number linked to their account.");f(!0),ae("LINK_PHONE_SCREEN")},linkGoogle:async()=>{if(!a)throw new w("User must be authenticated before linking a Google account.");if(l?.google)throw new w("User already has a Google account linked to their account.");await be.initLoginWithOAuth("google")},linkTwitter:async()=>{if(!a)throw new w("User must be authenticated before linking a Twitter account.");if(l?.twitter)throw new w("User already has a Twitter account linked to their account.");await be.initLoginWithOAuth("twitter")},linkDiscord:async()=>{if(!a)throw new w("User must be authenticated before linking a Discord account.");if(l?.discord)throw new w("User already has a Discord account linked to their account.");await be.initLoginWithOAuth("discord")},linkGithub:async()=>{if(!a)throw new w("User must be authenticated before linking a GitHub account.");if(l?.github)throw new w("User already has a Github account linked to their account.");await be.initLoginWithOAuth("github")},linkTiktok:async()=>{if(!a)throw new w("User must be authenticated before linking a TikTok account.");if(l?.tiktok)throw new w("User already has a Tiktok account linked to their account.");await be.initLoginWithOAuth("tiktok")},linkLinkedIn:async()=>{if(!a)throw new w("User must be authenticated before linking a LinkedIn account.");if(l?.linkedin)throw new w("User already has a LinkedIn account linked to their account.");await be.initLoginWithOAuth("linkedin")},linkApple:async()=>{if(!a)throw new w("User must be authenticated before linking an Apple account.");await be.initLoginWithOAuth("apple")},linkFarcaster:async()=>{if(!a)throw new w("User must be authenticated before linking a Farcaster account.");await be.initLoginWithFarcaster(),f(!0),ae("AWAITING_FARCASTER_CONNECTION")},login:async()=>{if(n||(await new Promise(p=>{wo(()=>p)}),wo(null)),a){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}W(!0),ro("LANDING")},logout:async()=>{await t.logout(),c(null),s(!1),_(null),ie(te,"logout","onSuccess"),f(!1),r(!1),ee.del(wn)},getAccessToken:()=>t.getAccessToken(),getEthereumProvider:()=>{if(!l||!l.wallet)return new se;let p=y.find(m=>l.wallet&&m.address===l.wallet.address),d=t.connectors?.walletConnectors.find(m=>m.wallets.find(b=>b.address===p?.address));return!p||!d?new se:d.proxyProvider},getEthersProvider:()=>{if(!l||!l.wallet)return new tc(new Gt(new se));let p=y.find(m=>l.wallet&&m.address===l.wallet.address),d=t.connectors?.walletConnectors.find(m=>m.wallets.find(b=>b.address===p?.address));return!p||!d?new tc(new Gt(new se)):new tc(new Gt(d.proxyProvider))},getWeb3jsProvider:()=>{if(!l||!l.wallet)return new Ao(new se);let p=y.find(m=>l.wallet&&m.address===l.wallet.address),d=t.connectors?.walletConnectors.find(m=>m.wallets.find(b=>b.address===p?.address));return!p||!d?new Ao(new se):new Ao(d.proxyProvider)},unlinkWallet:async p=>{let d=await t.unlinkWallet(p);return c(d),d},unlinkEmail:async p=>{let d=await t.unlinkEmail(p);return c(d),d},unlinkPhone:async p=>{let d=await t.unlinkPhone(p);return c(d),d},unlinkGoogle:async p=>{let d=await t.unlinkOAuth("google",p);return c(d),d},unlinkTwitter:async p=>{let d=await t.unlinkOAuth("twitter",p);return c(d),d},unlinkDiscord:async p=>{let d=await t.unlinkOAuth("discord",p);return c(d),d},unlinkGithub:async p=>{let d=await t.unlinkOAuth("github",p);return c(d),d},unlinkTiktok:async p=>{let d=await t.unlinkOAuth("tiktok",p);return c(d),d},unlinkLinkedIn:async p=>{let d=await t.unlinkOAuth("linkedin",p);return c(d),d},unlinkApple:async p=>{let d=await t.unlinkOAuth("apple",p);return c(d),d},unlinkFarcaster:async p=>{let d=await t.unlinkFarcaster(p);return c(d),d},setActiveWallet:async p=>{let d=y.find(b=>cs(b.address)===cs(p)),m=l?.linkedAccounts.find(b=>b.type==="wallet"&&cs(b.address)===cs(p));if(!d||!await d.isConnected())Z(p),ot();else if(!d.linked)d.loginOrLink();else{let b=Object.assign({},l);b.wallet=m&&{address:m.address,chainType:m.chainType,chainId:m.chainId,walletClient:m.walletClient,walletClientType:m.walletClientType,connectorType:m.connectorType},c(b)}},forkSession:()=>t.forkSession(),createWallet:async()=>{if(!a||!l)throw ie(te,"createWallet","onError","must_be_authenticated"),new Error("User must be authenticated before creating a Privy wallet");return rc(l,15e3)},setWalletPassword:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before adding password to Privy wallet"));return}let m=le(l);if(!m||!A){d(new Error("Must have a Privy wallet to add a password"));return}if(m.recoveryMethod==="user-passcode"){d(new Error("Cannot set password. Embedded wallet already has a password."));return}await ic(),ve(!0);let b={onSuccess:p,onFailure:d,callAuthOnSuccessOnClose:!1},I={onCompleteNavigateTo:"EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN",onFailure:d};Le({setWalletPassword:b,connectWallet:I}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}),signMessage:(p,d)=>new Promise(async(m,b)=>{if(!a||!l){b(new Error("User must be authenticated before signing with a Privy wallet"));return}let I=le(l);if(!I){b(new Error("Must have a Privy wallet before signing"));return}if(typeof p!="string"||p.length<1){b(new Error("Message must be a non-empty string"));return}ve(!0);let $=async()=>{if(!a)throw new Error("User must be authenticated before signing with a Privy wallet");let de=await De();if(!A||!de)throw new Error("Unable to connect to wallet");if(!await be.recoverEmbeddedWallet())throw new Error("Unable to connect to wallet");t.createAnalyticsEvent("embedded_wallet_sign_message_started",{walletAddress:I.address});let{response:pt}=await A.rpc({accessToken:de,address:I.address,request:{method:"personal_sign",params:[p,I.address]}}),yn=pt.data;return t.createAnalyticsEvent("embedded_wallet_sign_message_completed",{walletAddress:I.address}),yn};if(O.embeddedWallets.noPromptOnSignature){d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config");try{let de=await $();m(de)}catch(de){b(de??new ze("Unable to sign message"))}}else{let pt={message:p,confirmAndSignMessage:$,onSuccess:Po=>{m(Po)},onFailure:Po=>{b(Po)},uiOptions:d||{}},yn={onCompleteNavigateTo:"EMBEDDED_WALLET_SIGN_REQUEST_SCREEN",onFailure:b};Le({signMessage:pt,connectWallet:yn}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}}),sendTransaction:async(p,d,m)=>{let I=await(await nc(p,d,m)).wait();return es(I)},exportWallet:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before exporting their Privy wallet"));return}let m=le(l);if(!m){d(new Error("Must have a Privy wallet before exporting"));return}ve(!0);let b={onCompleteNavigateTo:"EMBEDDED_WALLET_KEY_EXPORT_SCREEN",onFailure:d},I=await De();if(!I||!A){d(new Error("Must have valid access token to enroll in MFA"));return}if(!A){d(new Error("Must have a Privy wallet before exporting"));return}try{try{await A.connect({accessToken:I,address:m.address}),await A.verifyMfa({accessToken:I})}catch(de){if(ar(de)&&m.recoveryMethod==="privy")await A.recover({accessToken:I,address:m.address});else throw de}}catch(de){d(de);return}let $={appId:e.appId,origin:t.apiUrl,onSuccess:p,onFailure:d};Le({keyExport:$,connectWallet:b}),ae("EMBEDDED_WALLET_CONNECTING_SCREEN")}),promptMfa:ic,async init(p){let d;switch(p){case"sms":d=new ls("verify");break;case"totp":return;default:throw new Error(`Unsupported MFA method: ${p}`)}t.startMfaFlow(d),await d.init()},async submit(p,d){switch(p){case"totp":case"sms":X.current?.resolve({mfaMethod:p,mfaCode:d}),await new Promise((m,b)=>{Ut.current={resolve:m,reject:b}});break;default:throw X.current?.reject(new w("Unsupported MFA method")),new w(`Unsupported MFA method: ${p}`)}},cancel(){X.current?.reject(new w("MFA canceled"))},async initEnrollmentWithSms(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to enroll in MFA");await A.initEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber})},enrollInMfa(p){return new Promise((d,m)=>{if(!p){be.closePrivyModal(),d();return}O.mfa.noPromptOnMfaRequired&&console.warn("[Privy Warning] Triggering the 'showMfaEnrollmentModal' function when 'noPromptOnMfaRequired' is set to true is unexpected. If this is intentional, ensure that you are building custom UIs for MFA verification."),Le({mfaEnrollmentFlow:{mfaMethods:O.mfa.methods,onSuccess:d,onFailure:m}}),ae("MFA_ENROLLMENT_FLOW_SCREEN")})},async initEnrollmentWithTotp(){let p=await De();if(!p||!A)throw new Error("Must have valid access token to enroll in MFA");let d=await A.initEnrollMfa({method:"totp",accessToken:p});return{secret:d.secret,authUrl:d.authUrl}},async submitEnrollmentWithSms(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to enroll in MFA");await A.submitEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber,code:p.mfaCode});let m=await t.getAuthenticatedUser();c(m)},async submitEnrollmentWithTotp(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to enroll in MFA");await A.submitEnrollMfa({method:"totp",accessToken:d,code:p.mfaCode});let m=await t.getAuthenticatedUser();c(m)},async unenroll(p){let d=await De();if(!d||!A)throw new Error("Must have valid access token to remove MFA");await A.unenrollMfa({method:p,accessToken:d});let m=await t.getAuthenticatedUser();c(m)},loginWithCode(p){return be.loginWithCode(p)},initLoginWithEmail(p){return be.initLoginWithEmail(p)},initLoginWithSms(p){return be.initLoginWithSms(p)},isModalOpen:o};ih=hn.signMessage,ah=async(...p)=>{let d=await nc(...p);return O.embeddedWallets.waitForTransactionConfirmation&&await d.wait(),d};let ac=!!e.config?.headless,be=(()=>({headless:ac,isNewUserThisSession:E,isLinking:u,linkingHint:Y,pendingTransaction:null,walletConnectionStatus:N,mipdStore:L,connectors:t.connectors?.walletConnectors??[],rpcConfig:O.rpcConfig,chains:O.chains,showFiatPrices:O.embeddedWallets.priceDisplay.primary!=="native-token",clientAnalyticsId:t.clientAnalyticsId,nativeTokenSymbolForChainId:p=>O.chains.find(d=>d.id===Number(p))?.nativeCurrency.symbol,initializeWalletProxy:async p=>{if(A)return A;let d=new Promise(I=>{Ko(()=>$=>I($))}),m=new Promise(I=>setTimeout(()=>I(null),p)),b=await Promise.race([d,m]);return Ko(null),b},getAuthFlow:()=>t.authFlow,getAuthMeta:()=>t.authFlow?.meta,closePrivyModal:(p={shouldCallAuthOnSuccess:!0})=>{let d=n&&a&&l;p.shouldCallAuthOnSuccess&&d?(ie(te,"login","onComplete",l,E,!1,Ce.current??null),e.onSuccess?.(l,E)):R&&ie(te,"login","onError","exited_auth_flow"),Z(null),W(!1),f(!1),P(!1),r(!1),setTimeout(()=>{t.authFlow=void 0},200),t.createAnalyticsEvent("modal_closed")},openPrivyModal:ae,connectWallet:Eo,initLoginWithWallet:async(p,d)=>{Ce.current="siwe",Ae(p,d)},loginWithWallet:async()=>{if(!n)throw new Pr;if(!(t.authFlow instanceof Zo))throw new w("Must initialize SIWE flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(m){throw ie(te,"login","onError",m.privyErrorCode||"generic_connect_wallet_error"),m}c(p||l||null),P(d||!1),s(!0)},initLoginWithFarcaster:async p=>{let d=new gn(p);t.startAuthFlow(d);try{Ce.current="farcaster",await d.initializeFarcasterConnect(),M2&&d.meta.connectUri&&window.open(d.meta.connectUri,"_blank","noopener noreferrer")}catch(m){throw ie(te,"login","onError",m.privyErrorCode||"unknown_auth_error"),m}},loginWithFarcaster:async()=>{if(!n)throw new Pr;if(!(t.authFlow instanceof gn))throw new w("Must initialize Farcaster flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(m){throw ie(te,"login","onError",m.privyErrorCode||"generic_connect_wallet_error"),m}c(p||null),P(d||!1),s(!0)},initLoginWithOAuth:async(p,d)=>{if(!Jc()){ro("IN_APP_BROWSER_LOGIN_NOT_POSSIBLE");return}let m=new To(p);d&&m.addCaptchaToken(d),t.startAuthFlow(m);let b=await t.authFlow.getAuthorizationUrl();b&&b.url&&window.location.assign(b.url)},loginWithOAuth:async p=>{if(!(t.authFlow instanceof To))throw new w("Must initialize OAuth flow before calling loginWithOAuth");let d=St.get(xr),m=t.authFlow.meta.stateCode;if(d!==m)throw t.createAnalyticsEvent("possible_phishing_attempt",{provider:p,storedStateCode:d??"",returnedStateCode:m??""}),new w("Unexpected auth flow. This may be a phishing attempt.");let b,I;if(a)b=await t.link();else try{({user:b,isNewUser:I}=await t.authenticate()),Ce.current=p}catch($){throw ie(te,"login","onError",$.privyErrorCode||"unknown_auth_error"),$}c(b),P(I||!1),s(!0)},initLoginWithEmail:async(p,d)=>{let m=new Yo(p,d);t.startAuthFlow(m);try{Ce.current="email",await m.sendCodeEmail()}catch(b){throw ie(te,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},initLoginWithSms:async(p,d)=>{let m=new Xo(p,d);t.startAuthFlow(m);try{Ce.current="sms",await m.sendSmsCode()}catch(b){throw ie(te,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},resendEmailCode:async()=>{await t.authFlow?.sendCodeEmail()},resendSmsCode:async()=>{await t.authFlow?.sendSmsCode()},loginWithCode:async p=>{if(!n)throw new Pr;if(t.authFlow instanceof Yo)t.authFlow.meta.emailCode=p.trim();else if(t.authFlow instanceof Xo)t.authFlow.meta.smsCode=p.trim();else throw new w("Must initialize a passwordless code flow first");let d,m;a?d=await t.link():{user:d,isNewUser:m}=await t.authenticate(),c(d||l||null),P(m||!1),s(!0)},refreshUser:async()=>{let p=await t.getAuthenticatedUser();return c(p),p},walletProxy:A,createAnalyticsEvent:(p,d,m)=>t.createAnalyticsEvent(p,d,m),getUsdTokenPrice:p=>t.getUsdTokenPrice(p),recoverEmbeddedWallet:async()=>new Promise(async(p,d)=>{let m=l?.linkedAccounts.find(I=>I.type==="wallet"&&I.walletClientType==="privy"),b=await De();if(!b||!A||!m){d(new Error("Must have valid access token and Privy wallet to recover wallet"));return}ve(!0);try{await A.connect({accessToken:b,address:m.address}),p(!0)}catch(I){ar(I)&&m.recoveryMethod==="privy"?(t.createAnalyticsEvent("embedded_wallet_pinless_recovery_started",{walletAddress:m.address}),(await A.recover({address:m.address,accessToken:b})).address||d(new Error("Unable to recover wallet")),t.createAnalyticsEvent("embedded_wallet_recovery_completed",{walletAddress:m.address}),p(!0)):ar(I)?(Le({recoverWallet:{privyWallet:m,onFailure:d,onSuccess:()=>p(!0)}}),ae("EMBEDDED_WALLET_RECOVERY_SCREEN")):d(I)}}),getFiatOnRampConfig:br,setReadyToTrue:()=>{i(!0),ne?.()},updateWallets:()=>ci()}))();sh=be.recoverEmbeddedWallet;let uh=W2(()=>({wallets:y,ready:Ye}),[y,Ye]);return vo(Ee.Provider,{value:hn,children:vo(Rs.Provider,{value:te,children:vo($l.Provider,{value:uh,children:nh(Md,{...O,children:[e.children,nh(As.Provider,{value:be,children:[!ac&&O.captchaEnabled&&vo(ks,{delayedExecution:!1}),vo(Of,{theme:{...O.appearance.palette||{}}}),vo(gd,{appConfig:O,data:_e,setModalData:Le,setInitialScreen:_,initialScreen:C,authenticated:a,children:vo(Bf,{open:o})}),Tt&&V.id?vo(rh,{appId:e.appId,clientAnalyticsId:t.clientAnalyticsId,origin:t.apiUrl,mfaMethods:l?.mfaMethods,mfaPromise:X,mfaSubmitPromise:Ut,onLoad:H,onLoadFailed:()=>null}):null]})]})})})})};import{useContext as U2}from"react";function F2(e){let{login:t}=U2(Ee);return mt("login",e),{login:t}}import{useContext as B2}from"react";function H2(e){let{logout:t}=B2(Ee);return mt("logout",e),{logout:t}}import{useCallback as lh}from"react";var G2=()=>{let e=ce(),{initLoginWithEmail:t,loginWithCode:o}=F(),r=lh(async({email:i})=>{if(!i)throw new Error("Email required to send OTP code");return e.status==="disabled",t(i)},[t]),n=lh(async({code:i})=>{if(e.enabled&&e.status==="error")throw new ao(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};import{useCallback as ch}from"react";var z2=()=>{let e=ce(),{initLoginWithSms:t,loginWithCode:o}=F(),r=ch(async({phoneNumber:i})=>{if(!i)throw new Error("SMS required to send OTP code");return e.status==="disabled",t(i)},[t]),n=ch(async({code:i})=>{if(e.enabled&&e.status!=="success")throw new ao(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};import{useContext as V2}from"react";function $2(e){let{connectWallet:t}=V2(Ee);return mt("connectWallet",e),{connectWallet:t}}import{useContext as j2}from"react";function q2(e){let{createWallet:t}=j2(Ee);return mt("createWallet",e),{createWallet:t}}import{useContext as K2}from"react";var Y2=()=>{let{isModalOpen:e}=K2(Ee);return{isOpen:e}};import{useContext as J2}from"react";function Q2(e){let{getAccessToken:t}=J2(Ee);return mt("accessToken",e),{getAccessToken:t}}function Z2(e,t){return{...e,rpcUrls:{...e.rpcUrls,privyWalletOverride:{http:[t]}}}}export{Gt as AsExternalProvider,ks as Captcha,En as ConnectorManager,Pn as PrivyClient,O2 as PrivyProvider,se as PrivyProxyProvider,ai as SUPPORTED_CHAINS,fs as VERSION,Xe as WalletConnector,Z2 as addRpcUrlOverrideToChain,Zs as errorIndicatesMaxMfaRetries,qr as errorIndicatesMfaTimeout,Kr as errorIndicatesMfaVerificationFailed,De as getAccessToken,$2 as useConnectWallet,q2 as useCreateWallet,F2 as useLogin,G2 as useLoginWithEmail,z2 as useLoginWithSms,H2 as useLogout,ln as useMfa,Jn as useMfaEnrollment,Y2 as useModalStatus,F as usePrivy,Is as useRegisterMfaListener,Q2 as useToken,ni as useWallets};
package/dist/index.js CHANGED
@@ -2608,4 +2608,4 @@ You will need this password to access your ${e} wallet on a new device. Please k
2608
2608
  opacity: 1;
2609
2609
  }
2610
2610
  }
2611
- `;var Ie=require("react/jsx-runtime"),_w={["LANDING"]:wf,["AWAITING_PASSWORDLESS_CODE"]:zp,["AWAITING_CONNECTION"]:uu,["AWAITING_CONNECT_ONLY_CONNECTION"]:hu,["AWAITING_FARCASTER_CONNECTION"]:Im,["PHANTOM_INTERSTITIAL_SCREEN"]:Eh,["LOGIN_FAILED_SCREEN"]:Sf,["AWAITING_OAUTH_SCREEN"]:vh,["ALLOWLIST_REJECTION_SCREEN"]:Np,["INSTALL_PHANTOM_SCREEN"]:qm,["LINK_EMAIL_SCREEN"]:bf,["LINK_PHONE_SCREEN"]:Pf,["LINK_WALLET_SCREEN"]:Tf,["CONNECT_ONLY_LANDING_SCREEN"]:cu,["CONNECT_ONLY_AUTHENTICATED_SCREEN"]:ru,["EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN"]:am,["EMBEDDED_WALLET_CREATED_SCREEN"]:xu,["EMBEDDED_WALLET_CONNECTING_SCREEN"]:Eu,["EMBEDDED_WALLET_RECOVERY_SCREEN"]:mm,["EMBEDDED_WALLET_KEY_EXPORT_SCREEN"]:Ru,["EMBEDDED_WALLET_SIGN_REQUEST_SCREEN"]:Ih,["EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN"]:kh,["FIAT_ON_RAMP_PROMPT_SCREEN"]:Dm,["FIAT_ON_RAMP_STATUS_SCREEN"]:Fm,["EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN"]:pm,["EMBEDDED_WALLET_PASSWORD_UPDATE_SCREEN"]:sm,["MFA_ENROLLMENT_FLOW_SCREEN"]:Uf,["CAPTCHA_SCREEN"]:Yp,["ERROR_SCREEN"]:fm,["IN_APP_BROWSER_LOGIN_NOT_POSSIBLE"]:Gm},kw=["LANDING","AWAITING_CONNECTION"],Aw=({isMfaVerifying:e,onMfaVerificationComplete:t})=>{let{ready:o,isModalOpen:r}=G(),{headless:n}=A(),{ready:i,currentScreen:a}=S(),{status:s,execute:l,reset:c,enabled:m}=Pe(),h=(0,rr.useRef)(null),y=Sp(h),v=r&&a&&kw.includes(a)&&!n&&s==="ready";if((0,rr.useEffect)(()=>{v&&l()},[v]),(0,rr.useEffect)(()=>{!r&&m&&c()},[r,m]),(!o||!i)&&a!=="AWAITING_OAUTH_SCREEN")return(0,Ie.jsxs)(ri,{children:[(0,Ie.jsx)(x,{}),(0,Ie.jsx)(Y,{}),(0,Ie.jsx)(kf,{children:(0,Ie.jsx)(Bt,{})}),(0,Ie.jsx)(te,{}),(0,Ie.jsx)(J,{})]});if(!a&&e)return(0,Ie.jsx)(ri,{style:{height:y},children:(0,Ie.jsx)("div",{ref:h,children:(0,Ie.jsx)(Oc,{open:e,onClose:t})})});if(!a)return null;let g=_w[a];return(0,Ie.jsx)(ri,{style:{height:y},children:(0,Ie.jsxs)("div",{ref:h,children:[(0,Ie.jsx)(qo,{if:!!e,children:(0,Ie.jsx)(g,{})}),(0,Ie.jsx)(qo,{if:!e,children:(0,Ie.jsx)(Oc,{open:e,onClose:t})})]})})},Rw=()=>{let{closePrivyModal:e}=A(),{onUserCloseViaDialogOrKeybindRef:t}=S();return{gracefulClosePrivyModal:(0,rr.useCallback)(()=>{if(t?.current)t.current(),t.current=null;else return e({shouldCallAuthOnSuccess:!1})},[e])}},Oh=({open:e})=>{let{app:t}=S(),{gracefulClosePrivyModal:o}=Rw(),[r,n]=(0,rr.useState)(!1);Da({onMfaRequired:()=>{t?.mfa.noPromptOnMfaRequired||n(!0)}});let i=(0,Ie.jsx)(Nh,{children:(0,Ie.jsx)(Aw,{isMfaVerifying:r,onMfaVerificationComplete:()=>n(!1)})}),a=e||r,s=t?.render.inDialog?(0,Ie.jsx)(_f,{open:a,id:"privy-dialog",onClick:()=>o(),children:i}):i;if(typeof window<"u"&&t?.render.inParentNodeId){let l=document.getElementById(t.render.inParentNodeId);if(l)return Lh.default.createPortal(s,l)}return s};var Yt={appearance:{theme:"light",accentColor:"#676FFF",walletList:["detected_wallets","metamask","coinbase_wallet","rainbow","wallet_connect"]},walletConnectCloudProjectId:_d,rpcConfig:{rpcUrls:{},rpcTimeouts:{}},captchaEnabled:!1,_render:{inDialog:!0,inParentNodeId:null},fiatOnRamp:{useSandbox:!1}};var Iw=new Set(["metamask","coinbase_wallet","rainbow","zerion","phantom","wallet_connect","detected_wallets"]),Ww=e=>Iw.has(e),Mw=(e,t,o)=>o.indexOf(e)===t,Dh=({input:e})=>e?e.filter(Ww).filter(Mw):Yt.appearance.walletList;var Uh={id:43114,name:"Avalanche",network:"avalanche",nativeCurrency:{decimals:18,name:"Avalanche",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax.network/ext/bc/C/rpc"]},public:{http:["https://api.avax.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://snowtrace.io"},default:{name:"SnowTrace",url:"https://snowtrace.io"}}};var Fh={id:43113,name:"Avalanche Fuji",network:"avalanche-fuji",nativeCurrency:{decimals:18,name:"Avalanche Fuji",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax-test.network/ext/bc/C/rpc"]},public:{http:["https://api.avax-test.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://testnet.snowtrace.io"},default:{name:"SnowTrace",url:"https://testnet.snowtrace.io"}},testnet:!0};var Bh={id:42220,name:"Celo Mainnet",network:"celo",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://forno.celo.org"]},infura:{http:["https://celo-mainnet.infura.io/v3"]},public:{http:["https://forno.celo.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/mainnet"},etherscan:{name:"CeloScan",url:"https://celoscan.io"}},testnet:!1};var Hh={id:44787,name:"Celo Alfajores Testnet",network:"celo-alfajores",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://alfajores-forno.celo-testnet.org"]},infura:{http:["https://celo-alfajores.infura.io/v3"]},public:{http:["https://alfajores-forno.celo-testnet.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/alfajores"},etherscan:{name:"CeloScan",url:"https://alfajores.celoscan.io/"}},testnet:!0};var Gh={id:314,name:"Filecoin - Mainnet",network:"filecoin-mainnet",nativeCurrency:{decimals:18,name:"filecoin",symbol:"FIL"},rpcUrls:{default:{http:["https://api.node.glif.io/rpc/v1"]},public:{http:["https://api.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filfox",url:"https://filfox.info/en"},filscan:{name:"Filscan",url:"https://filscan.io"},filscout:{name:"Filscout",url:"https://filscout.io/en"},glif:{name:"Glif",url:"https://explorer.glif.io"}}};var zh={id:314159,name:"Filecoin - Calibration testnet",network:"filecoin-calibration",nativeCurrency:{decimals:18,name:"testnet filecoin",symbol:"tFIL"},rpcUrls:{default:{http:["https://api.calibration.node.glif.io/rpc/v1"]},public:{http:["https://api.calibration.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filscan",url:"https://calibration.filscan.io"}}};var Vh={id:5,network:"goerli",name:"Goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-goerli.g.alchemy.com/v2"],webSocket:["wss://eth-goerli.g.alchemy.com/v2"]},infura:{http:["https://goerli.infura.io/v3"],webSocket:["wss://goerli.infura.io/ws/v3"]},default:{http:["https://rpc.ankr.com/eth_goerli"]},public:{http:["https://rpc.ankr.com/eth_goerli"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli.etherscan.io"},default:{name:"Etherscan",url:"https://goerli.etherscan.io"}},testnet:!0};var $h={id:17e3,name:"Holesky",network:"holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://ethereum-holesky.publicnode.com"]},public:{http:["https://ethereum-holesky.publicnode.com"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://holesky.etherscan.io"},default:{name:"EtherScan",url:"https://holesky.etherscan.io"}}};var jh={id:59144,network:"linea-mainnet",name:"Linea Mainnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-mainnet.infura.io/v3"],webSocket:["wss://linea-mainnet.infura.io/ws/v3"]},default:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]},public:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://lineascan.build"},etherscan:{name:"Etherscan",url:"https://lineascan.build"}},testnet:!1};var qh={id:59140,network:"linea-testnet",name:"Linea Goerli Testnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-goerli.infura.io/v3"],webSocket:["wss://linea-goerli.infura.io/ws/v3"]},default:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]},public:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://goerli.lineascan.build"},etherscan:{name:"Etherscan",url:"https://goerli.lineascan.build"}},testnet:!0};var ll={id:1,network:"homestead",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-mainnet.g.alchemy.com/v2"],webSocket:["wss://eth-mainnet.g.alchemy.com/v2"]},infura:{http:["https://mainnet.infura.io/v3"],webSocket:["wss://mainnet.infura.io/ws/v3"]},default:{http:["https://cloudflare-eth.com"]},public:{http:["https://cloudflare-eth.com"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://etherscan.io"},default:{name:"Etherscan",url:"https://etherscan.io"}}};var Kh={id:17001,name:"Redstone Holesky",network:"redstone-holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.holesky.redstone.xyz"]},public:{http:["https://rpc.holesky.redstone.xyz"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"},default:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"}}};var Yh={id:11155111,network:"sepolia",name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"SEP",decimals:18},rpcUrls:{alchemy:{http:["https://eth-sepolia.g.alchemy.com/v2"],webSocket:["wss://eth-sepolia.g.alchemy.com/v2"]},infura:{http:["https://sepolia.infura.io/v3"],webSocket:["wss://sepolia.infura.io/ws/v3"]},default:{http:["https://rpc.sepolia.org"]},public:{http:["https://rpc.sepolia.org"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://sepolia.etherscan.io"},default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}},testnet:!0};var fi=[Bs,Hs,Gs,Vh,Yh,ll,js,qs,Ks,Ki,Yi,Bh,Hh,Gh,zh,zs,Vs,$s,jh,qh,Uh,Fh,Ys,Qs,Js,$h,Kh],Q8=new Set(fi.map(e=>e.id));var Lr=k(require("tinycolor2")),Jh="#FFFFFF",Nw="#000000",Lw=Jh,Ow="#1E1E1D";function Dw(e){return e<.8&&e>.2&&console.warn("Background color is not light or dark enough, which could lead to accessibility issues."),e>.5?"light":"dark"}function Nr(e,t){let o=Math.max(0,Math.min(1,e.toHsl().l+t));return(0,Lr.default)({...e.toHsl(),l:o})}function Qh({backgroundTheme:e,accentHex:t,successHex:o="#51BA81",warnHex:r="#FFB74D",errorHex:n="#EC6351",whiteHex:i=Jh,blackHex:a=Nw}){let s;switch(e){case"light":s=Lw;break;case"dark":s=Ow;break;default:s=e;break}let l=(0,Lr.default)(s),c=(0,Lr.default)(t),m=(0,Lr.default)(o),h=(0,Lr.default)(r),y=(0,Lr.default)(n),v=Dw(l.getLuminance()),g=Nr(l,v==="light"?-.04:.11),E=Nr(l,v==="light"?-.88:.87),P=Nr(l,v==="light"?-.77:.75),C=Nr(l,v==="light"?-.43:.45).desaturate(v==="light"?60:20),_=Nr(l,v==="light"?-.08:.25).desaturate(v==="light"?60:20),I=Nr(c,.15),M=Nr(c,-.06),L=(0,Lr.default)(c.getLuminance()>.5?a:i),N=Nr(m,-.16);return{colorScheme:v,background:l.toHslString(),background2:g.toHslString(),foreground:E.toHslString(),foreground2:P.toHslString(),foreground3:C.toHslString(),foreground4:_.toHslString(),accent:c.toHslString(),accentLight:I.toHslString(),accentDark:M.toHslString(),foregroundAccent:L.toHslString(),success:m.toHslString(),successDark:N.toHslString(),error:y.toHslString(),warn:h.toHslString()}}function cl(e,t){let o=["google","twitter","discord","tiktok","linkedin","github","apple","farcaster"],r=t?.loginMethods?.filter(oe=>o.includes(oe)),n,i,a,s,l,c,m,h,y,v,g;t?.loginMethods?(n=t.loginMethods.includes("email"),i=t.loginMethods.includes("sms"),a=t.loginMethods.includes("wallet"),s=r?.includes("google"),l=r?.includes("twitter"),c=r?.includes("discord"),m=r?.includes("tiktok"),y=r?.includes("github"),h=r?.includes("linkedin"),v=r?.includes("apple"),g=r?.includes("farcaster")):(n=e.emailAuth,i=e.smsAuth,a=e.walletAuth,s=e.googleOAuth,l=e.twitterOAuth,c=e.discordOAuth,y=e.githubOAuth,m=e.tiktokOAuth,h=e.linkedinOAuth,v=e.appleOAuth,g=e.farcasterAuth);let E=[n,i].filter(Boolean),P=[s,l,c,y,m,h,v,g].filter(Boolean),C=[a].filter(Boolean);if(E.length+P.length+C.length===0)throw new Error("You must enable at least one login method");let _=t?.appearance?.showWalletLoginFirst!==void 0?t?.appearance?.showWalletLoginFirst:e.showWalletLoginFirst;_&&C.length===0?(console.warn("You should only enable `showWalletLoginFirst` when `wallet` logins are also enabled. `showWalletLoginFirst` has been set to false"),_=!1):!_&&P.length+E.length===0&&(console.warn("You should only disable `showWalletLoginFirst` when `email`, `sms`, or social logins are also enabled. `showWalletLoginFirst` has been set to true"),_=!0);let I=Dh({isWalletLoginEnabled:a,input:t?.appearance?.walletList});if(t?.embeddedWallets?.waitForTransactionConfirmation===!1&&t.embeddedWallets.noPromptOnSignature!==!0)throw new Error("Overriding `config.embeddedWallets.waitForTransactionConfirmation` requires that you also enable `config.embeddedWallets.noPromptOnSignature`");let M=t?.intl?.defaultCountry??"US",{chains:L,defaultChain:N}=Uw({additionalChains:t?.additionalChains,supportedChains:t?.supportedChains,defaultChainFromConfig:t?.defaultChain,hasRpcConfigDefined:Object.keys(t?.rpcConfig?.rpcUrls??{}).length>0}),O=!!t?.defaultChain||!!t?.supportedChains,H=t?.customAuth?.getCustomAccessToken&&t?.customAuth?.enabled!==!1;return{id:e.id,name:e.name,allowlistConfig:e.allowlistConfig,appearance:{logo:t?.appearance?.logo??e.logoUrl,palette:Qh({backgroundTheme:t?.appearance?.theme??Yt.appearance.theme,accentHex:t?.appearance?.accentColor??e.accentColor??Yt.appearance.accentColor}),loginGroupPriority:_?"web3-first":"web2-first",hideDirectWeb2Inputs:!!t?.appearance?.hideDirectWeb2Inputs,walletList:I},loginMethods:{wallet:a,email:n,sms:i,google:s,twitter:l,discord:c,github:y,tiktok:m,linkedin:h,apple:v,farcaster:g},legal:{termsAndConditionsUrl:t?.legal?.termsAndConditionsUrl??e.termsAndConditionsUrl,privacyPolicyUrl:t?.legal?.privacyPolicyUrl??e.privacyPolicyUrl},walletConnectCloudProjectId:t?.walletConnectCloudProjectId??e.walletConnectCloudProjectId??Yt.walletConnectCloudProjectId,rpcConfig:{rpcUrls:t?.rpcConfig?.rpcUrls??Yt.rpcConfig.rpcUrls,rpcTimeouts:t?.rpcConfig?.rpcTimeouts??Yt.rpcConfig.rpcTimeouts},chains:L,defaultChain:N,intl:{defaultCountry:M},shouldSwitchChainOnConnect:O,captchaEnabled:e.captchaEnabled??Yt.captchaEnabled,captchaSiteKey:e.captchaSiteKey,embeddedWallets:{...e.embeddedWalletConfig,...H?{createOnLogin:"all-users",requireUserPasswordOnCreate:!1,noPromptOnSignature:!0}:{},waitForTransactionConfirmation:!0,priceDisplay:{primary:"fiat-currency",secondary:"native-token"},...t?.embeddedWallets},mfa:{methods:e.mfaMethods??[],noPromptOnMfaRequired:t?.mfa?.noPromptOnMfaRequired??!1},customAuth:H?{enabled:!0,...t.customAuth}:void 0,fiatOnRamp:{enabled:e.fiatOnRampEnabled,useSandbox:t?.fiatOnRamp?.useSandbox??Yt.fiatOnRamp.useSandbox},loginConfig:{twitterOAuthOnMobileEnabled:e.twitterOAuthOnMobileEnabled??!1},render:{inDialog:t?._render?.inDialog??Yt._render.inDialog,inParentNodeId:t?._render?.inParentNodeId??Yt._render.inParentNodeId}}}function Zh(e,t){if(!e)return{legacyCreateEmbeddedWalletFlag:t};let{appearance:o,additionalChains:r,supportedChains:n,defaultChain:i,...a}=e;return{...a,...r?{additionalChains:r.map(l=>l.id)}:void 0,...n?{supportedChains:n.map(l=>l.id)}:void 0,...i?{defaultChain:i.id}:void 0,...o?{...o,...o.logo&&typeof o.logo?{logo:"component"}:void 0}:void 0,legacyCreateEmbeddedWalletFlag:t}}function Uw({additionalChains:e,supportedChains:t,defaultChainFromConfig:o,hasRpcConfigDefined:r}){let n;if(e&&t&&console.warn("You should only specify one of `additionalChains` or `supportedChains`. Using `supportedChains`."),t){if(t.length===0)throw new Error("`supportedChains` must contain at least one chain");t.filter(l=>l.rpcUrls.privyWalletOverride).length>0&&r&&console.warn("You have specified at least one `supportedChain` with `privyWalletOverride` but also have `rpcConfig` defined. The `rpcConfig` will be ignored. `rpcConfig` is deprecated and you should use `privyWalletOverride` in a `supportedChain`."),n=t.map(l=>l.rpcUrls.privyWalletOverride?l:fi.find(m=>m.id===l.id)??l)}else n=fi.concat(e??[]);let i=t?n[0]:ll,a=o??i;if(!n.find(s=>s.id===a.id))throw new Error("`defaultChain` must be included in `supportedChains`");return{chains:n,defaultChain:a}}var pl=require("react");var dl=class{constructor(){this.callbacks={}}enqueue(t,o){this.callbacks[t]=o}dequeue(t,o){let r=this.callbacks[o];if(!r)throw new Error(`cannot dequeue ${t} event: no event found for id ${o}`);switch(delete this.callbacks[o],t){case"privy:iframe:ready":return r;case"privy:wallet:create":return r;case"privy:wallet:connect":return r;case"privy:wallet:recover":return r;case"privy:wallet:rpc":return r;case"privy:wallet:set-recovery-password":return r;case"privy:mfa:verify":return r;case"privy:mfa:init-enrollment":return r;case"privy:mfa:submit-enrollment":return r;case"privy:mfa:unenroll":return r;default:throw new Error(`invalid wallet event type ${t}`)}}};async function ln(e,t,o,r,n,i=!1){let a=i,s=async m=>{if(a&&t&&t.length>0){m===(i?0:1)?n("configureMfa","onMfaRequired",t):r.current?.reject(new He("missing_or_invalid_mfa","MFA verification failed, retry."));let h=await new Promise((y,v)=>{o.current={resolve:y,reject:v};let g=1e3*60*5;setTimeout(()=>{let E=new He("mfa_timeout","Timed out waiting for MFA code");r.current?.reject(E),v(E)},g)});return await e(h)}return await e()},l=4,c=null;for(let m=0;m<l;m++)try{c=await s(m),r.current?.resolve(void 0);break}catch(h){if(h.type==="missing_or_invalid_mfa")a=!0;else throw r.current?.resolve(void 0),h}if(c===null){let m=new He("mfa_verification_max_attempts_reached","Max MFA verification attempts reached");throw r.current?.reject(m),m}return c}var ey=require("react/jsx-runtime"),Fw=function(e){return()=>`id-${e++}`}(0);function Bw(e){return typeof e.event=="string"&&/^privy:.+/.test(e.event)}function Uo(e){return e.error!==void 0}var mo=new dl,Fc=new Map,Hw=(e,t)=>typeof t=="bigint"?t.toString():t,Gw=(e,t)=>`${e}${JSON.stringify(t,Hw)}`;function Fo(e,t,o){let r=o.contentWindow;if(!r)throw new Error("iframe not initialized");let n=Gw(e,t);if(e==="privy:wallet:create"){let a=Fc.get(n);if(a)return a}let i=new Promise((a,s)=>{let l=Fw();mo.enqueue(l,{resolve:a,reject:s}),r.postMessage({id:l,event:e,data:t},"*")}).finally(()=>{Fc.delete(n)});return Fc.set(n,i),i}function zw(e){switch(e.event){case"privy:iframe:ready":let t=mo.dequeue(e.event,e.id);return Uo(e)?t.reject(new He(e.error.type,e.error.message)):t.resolve(e.data);case"privy:wallet:create":let o=mo.dequeue(e.event,e.id);return Uo(e)?o.reject(new He(e.error.type,e.error.message)):o.resolve(e.data);case"privy:wallet:connect":let r=mo.dequeue(e.event,e.id);return Uo(e)?r.reject(new He(e.error.type,e.error.message)):r.resolve(e.data);case"privy:wallet:recover":let n=mo.dequeue(e.event,e.id);return Uo(e)?n.reject(new He(e.error.type,e.error.message)):n.resolve(e.data);case"privy:wallet:rpc":let i=mo.dequeue(e.event,e.id);return Uo(e)?i.reject(new He(e.error.type,e.error.message)):i.resolve(e.data);case"privy:wallet:set-recovery-password":let a=mo.dequeue(e.event,e.id);return Uo(e)?a.reject(new He(e.error.type,e.error.message)):a.resolve(e.data);case"privy:mfa:verify":let s=mo.dequeue(e.event,e.id);return Uo(e)?s.reject(new He(e.error.type,e.error.message)):s.resolve(e.data);case"privy:mfa:init-enrollment":{let l=mo.dequeue(e.event,e.id);return Uo(e)?l.reject(new He(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:submit-enrollment":{let l=mo.dequeue(e.event,e.id);return Uo(e)?l.reject(new He(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:unenroll":{let l=mo.dequeue(e.event,e.id);return Uo(e)?l.reject(new He(e.error.type,e.error.message)):l.resolve(e.data)}default:console.warn("Unsupported wallet proxy method:",e)}}function Xh(e){let t=(0,pl.useRef)(null),o=Ap();return(0,pl.useEffect)(()=>{let r=t.current;if(!r)return;function n(c){c&&c.origin===e.origin&&Bw(c.data)&&zw(c.data)}let i={create(c){return Fo("privy:wallet:create",c,r)},connect(c){return Fo("privy:wallet:connect",c,r)},recover(c){return ln(m=>Fo("privy:wallet:recover",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},rpc(c){return ln(m=>Fo("privy:wallet:rpc",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},setRecoveryPassword(c){return ln(m=>Fo("privy:wallet:set-recovery-password",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},verifyMfa(c){return ln(m=>Fo("privy:mfa:verify",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},initEnrollMfa(c){return ln(m=>Fo("privy:mfa:init-enrollment",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},submitEnrollMfa(c){return Fo("privy:mfa:submit-enrollment",c,r)},unenrollMfa(c){return ln(m=>Fo("privy:mfa:unenroll",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)}};window.addEventListener("message",n);let a=()=>e.onLoad(i),s=(...c)=>{console.warn("Privy iframe failed to load: ",...c),e.onLoadFailed()},l=new AbortController;return Vd(()=>Fo("privy:iframe:ready",{},r),{abortSignal:l.signal}).then(a,s),()=>{window.removeEventListener("message",n),l.abort()}},[t.current,e.mfaMethods]),(0,ey.jsx)("iframe",{ref:t,width:"0",height:"0",style:{display:"none",height:"0px",width:"0px"},src:ya(e.origin,`/apps/${e.appId}/embedded-wallets`,{caid:e.clientAnalyticsId})})}var ul=class{constructor(t,o){this.meta={action:t,phoneNumber:o}}async init(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Auth flow has no API instance");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set when initialzing authentication.");try{let t=Pd();await this.api.post(t,{action:this.meta.action,phoneNumber:this.meta.phoneNumber})}catch(t){throw de(t)}}async authenticate(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Mfa flow has no API instance");if(!this.meta.smsCode)throw new w("sms code must be set prior to calling authenticate.");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set prior to calling authenticate.");try{let t=Td(),o=await this.api.post(t,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return Dt(o)}catch(t){throw de(t)}}};var Lt=require("react/jsx-runtime"),Zi;function Vw(e){return typeof e=="string"&&e.length===25}function Ze(){if(!Zi){let e=ae.get(Ur);return Promise.resolve(e||null)}return Zi.getAccessToken()}var ry,Jd=(e,t)=>ry(e,t),ny,Qd=(e,t)=>ny(e,t),iy,Zd=()=>iy(),$w=()=>{let t=new URLSearchParams(window.location.search).get("privy_token");if(!t)return;ae.put(Ci,t);let o=new URL(window.location.href);o.searchParams.delete("privy_token"),window.history.pushState({},"",o)},ay=({config:e,...t})=>{if(!Vw(t.appId))throw new w("Cannot initialize the Privy provider with an invalid Privy app ID");Zi||(Zi=new An({appId:t.appId,apiUrl:t.apiUrl||ca}));let o=Object.assign({},e);return t.createPrivyWalletOnLogin!==void 0&&o.embeddedWallets?.createOnLogin===void 0&&(o.embeddedWallets||(o.embeddedWallets={}),o.embeddedWallets.createOnLogin=t.createPrivyWalletOnLogin?"users-without-wallets":"off"),t.createPrivyWalletOnLogin!==void 0&&e?.embeddedWallets?.createOnLogin&&console.warn("Both `createPrivyWalletOnLogin` and `config.embeddedWallets.createOnLogin` are set. `createPrivyWalletOnLogin` is deprecated and should be removed."),(0,Lt.jsx)(jw,{...t,config:o,client:Zi})},jw=e=>{let t=e.client,[o,r]=(0,V.useState)(!1),[n,i]=(0,V.useState)(!1),[a,s]=(0,V.useState)(!1),[l,c]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),[y,v]=(0,V.useState)([]),g=(0,V.useRef)(y),[E,P]=(0,V.useState)(!1),[C,_]=(0,V.useState)(null),[I,M]=(0,V.useState)(!1),[L,N]=(0,V.useState)({status:"disconnected",connectedWallet:null,connectError:null,connector:null,connectRetry:T}),[O,H]=(0,V.useState)(null),[Z,oe]=(0,V.useState)(null),[R,$]=(0,V.useState)(null),[q,Oe]=(0,V.useState)({showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,linkedinOAuth:!1,appleOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null,embeddedWalletConfig:{createOnLogin:"off",requireUserPasswordOnCreate:!1},fiatOnRampEnabled:!1,captchaEnabled:!1,captchaSiteKey:""}),[D,We]=(0,V.useState)(()=>{let p=Zh(e.config,e.createPrivyWalletOnLogin);return t.createAnalyticsEvent("sdk_initialize",p),cl(q,e.config)}),[Jt,Me]=(0,V.useState)(!0),[Ve,ot]=(0,V.useState)({}),[ve,nr]=(0,V.useState)(null),[ir,Or]=(0,V.useState)(null),[ht,Je]=(0,V.useState)(!1),[ar,cn]=(0,V.useState)(!1),re=(0,V.useRef)(null),fo=(0,V.useRef)(null),ce=(0,V.useRef)(_p);t.onStoreToken=p=>{p&&Ce(ce,"accessToken","onAccessTokenGranted",p)},t.onDeleteToken=()=>{Ce(ce,"accessToken","onAccessTokenRemoved")};let De=(0,V.useRef)(),ml=(0,V.useCallback)(p=>{let d=t.connectors?.walletsReady||!1;return a&&l?.linkedAccounts?.some(b=>b.type==="wallet"&&b.walletClientType==="privy")?d&&p?.some(b=>b?.walletClientType==="privy"):d},[a,l?.linkedAccounts,t?.connectors?.walletsReady]),be=p=>{_("CAPTCHA_SCREEN"),setTimeout(()=>{r(!0)},15),t.createAnalyticsEvent("modal_open",{initialScreen:p})},Bo=p=>{D.embeddedWallets.createOnLogin!=="off"&&Me(!0),be(p)};(0,V.useEffect)(()=>{if(!R||!l){t.connectors?.removeEmbeddedWalletConnector();return}let p=l?.linkedAccounts.filter(d=>d.type==="wallet"&&d.walletClient==="privy");if(p&&p.length>0){let d=p[0].address;t.connectors?.addEmbeddedWalletConnector(R,d,D.defaultChain)}},[R,l]),(0,V.useEffect)(()=>{R&&ir?.(R)},[R]),(0,V.useEffect)(()=>{(async()=>{if(!D.customAuth?.enabled)return;Me(!0);let{getCustomAccessToken:d,isLoading:f}=D.customAuth;if(!(!n||f))try{let b=await d();if(!b){await gi.logout();return}if(a)return;t.startAuthFlow(new mn(b));let{user:W,isNewUser:K}=await t.authenticate();W||await gi.logout(),c(W||null),P(K||!1),s(!0),cn(!0)}catch(b){console.warn(b),a&&await gi.logout()}})()},[D.customAuth?.enabled,D.customAuth?.getCustomAccessToken,D.customAuth?.isLoading,n,a]),(0,V.useEffect)(()=>{ar&&R&&l&&dr(l,e.config?.embeddedWallets?.createOnLogin)&&(cn(!1),zc(l,yn).catch(console.error))},[ar&&R&&l]),(0,V.useEffect)(()=>{async function p(){let d=await t.getServerConfig();Oe(d);let f=cl(d,e.config);We(f),d.customApiUrl&&t.updateApiUrl(d.customApiUrl);let b=fl();$w();let W=(0,ty.createStore)();H(W),t.initializeConnectorManager(f.walletConnectCloudProjectId,f.rpcConfig,f.chains,f.defaultChain,W,f.appearance.walletList),await t.connectors?.initialize();let K=await t.getAuthenticatedUser();e.config?.customAuth?.enabled||(s(!!K),K&&Ce(ce,"login","onComplete",K,!1,!0,null),c(K)),b||Ue.setReadyToTrue(),b&&K&&h(!0),Pt()}n||p()},[t,ve,n]),(0,V.useEffect)(()=>{let p=cl(q,e.config);We(p)},[e.config,q]);let fl=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_oauth_code"),f=p.get("privy_oauth_state"),b=p.get("privy_oauth_provider");return d&&f&&b?(t.startAuthFlow(new cr(b,d,f)),Bo("AWAITING_OAUTH_SCREEN"),!0):!1},yi=async(p,d,f,b)=>{let W=await t.connectors?.createWalletConnector(p,d)||null;sr(W,d,f,b)};async function sr(p,d,f,b){if(!p)return N({status:"disconnected",connectedWallet:null,connectError:new j("Unable to connect to wallet."),connector:null,connectRetry:T}),b?.(null,f);p instanceof Co&&d&&p.resetConnection(d),N({connector:p,status:"connecting",connectedWallet:null,connectError:null,connectRetry:()=>sr(p,d,f,b)});try{let W=await p.connect({showPrompt:!0});if(D.shouldSwitchChainOnConnect&&!D.chains.find(K=>K.id===Number(W?.chainId))&&!(W?.connectorType==="wallet_connect_v2"&&W?.walletClientType==="metamask")){N(K=>({...K,connector:p,status:"switching_to_supported_chain",connectedWallet:null,connectError:null,connectRetry:T}));try{await W?.switchChain(D.defaultChain.id),W&&(W.chainId=gn(Gr(D.defaultChain.id)))}catch{console.warn(`Unable to switch to default chain: ${D.defaultChain.id}`)}}return N(K=>({...K,status:"connected",connectedWallet:W,connectError:null,connectRetry:T})),W&&!I&&Ce(ce,"connectWallet","onSuccess",W),b?.(W,f)}catch(W){return W instanceof rt?(console.warn(W.cause?W.cause:W.message),I||Ce(ce,"connectWallet","onError",W.privyErrorCode||"generic_connect_wallet_error")):(console.warn(W),I||Ce(ce,"connectWallet","onError","unknown_connect_wallet_error")),N(K=>({...K,status:"disconnected",connectedWallet:null,connectError:W})),b?.(null,f)}}let Qe=async(p,d)=>{if(p===null)return;let f=new Br(p,d);t.startAuthFlow(f)},Pt=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_connector"),f=p.get("privy_wallet_client");if(!d||!f)return;if(f==="phantom"&&!pr()&&Bo("LOGIN_FAILED_SCREEN"),!t.connectors)throw new w("Connector not initialized");be("AWAITING_CONNECTION");let b=new URL(window.location.href);b.searchParams.delete("privy_connector"),b.searchParams.delete("privy_wallet_client"),window.history.pushState({},"",b),yi(d,f,void 0,Qe)};(0,V.useEffect)(()=>{n&&a&&l===null&&t.getAuthenticatedUser().then(c)},[n,a,l,t]);let Tt=()=>{if(!a)throw new w("User must be authenticated before linking a wallet.");h(!0),be("LINK_WALLET_SCREEN")},Gc=p=>{if(!a||!l)return!1;for(let d of l.linkedAccounts)if(d.type==="wallet"&&d.address===p.address)return!0;return!1},Qt=async p=>{if(!t.connectors)throw new w("Connector not initialized");let d=t.connectors.findWalletConnector(p.connectorType,p.walletClientType)||null;if(N(f=>({...f,connector:d,status:"connected",connectedWallet:p,connectError:null,connectRetry:T})),D.captchaEnabled&&!a){let f={callback:b=>Qe(p,b),userIntentRequired:!1,onSuccessNavigateTo:"AWAITING_CONNECTION",onErrorNavigateTo:"ERROR_SCREEN"};ot({captchaModalData:f}),Bo("CAPTCHA_SCREEN")}else await Qe(p),Bo("AWAITING_CONNECTION")},dn=async(p,d)=>{if(!D.fiatOnRamp.enabled)throw new w("Fiat on-ramp is not enabled");if(!d||!d.provider||d.provider==="moonpay"){let{signedUrl:f,externalTransactionId:b}=await Lm(t,p,d?.config??{},D.appearance.palette,D.fiatOnRamp.useSandbox);return{signedUrl:f,externalTransactionId:b}}else throw new w("Unsupported fund provider. Currently supported option is `moonpay`.")},Xi=()=>{v(p=>{let d=t.connectors?.wallets.map(f=>({...f,linked:Gc(f),loginOrLink:async()=>{if(!await f.isConnected())throw new w("Wallet is not connected");if(f.connectorType==="embedded"&&f.walletClientType==="privy")throw new w("Cannot link or login with embedded wallet");Qt(f)},fund:async b=>{let{signedUrl:W,externalTransactionId:K}=await dn(f.address,b);ot({fiatOnRampPrompt:{signedUrl:W},fiatOnRampStatus:{externalTransactionId:K}}),be("FIAT_ON_RAMP_PROMPT_SCREEN")},unlink:async()=>{if(!a)throw new w("User is not authenticated.");if(f.connectorType==="embedded"&&f.walletClientType==="privy")throw new w("Cannot unlink an embedded wallet");let b=await t.unlinkWallet(f.address);c(b)}}))||[];return Je(ml(d)),va(p,d)?p:d})};(0,V.useEffect)(()=>{Xi()},[l?.linkedAccounts,a,n]),(0,V.useEffect)(()=>{if(n){if(!t.connectors)throw new w("Connector not initialized");Xi(),t.connectors.on("walletsUpdated",Xi)}},[n]);let Ey=()=>{be(a?"CONNECT_ONLY_AUTHENTICATED_SCREEN":"CONNECT_ONLY_LANDING_SCREEN")};(0,V.useEffect)(()=>{if(!y[0])return;let p=y[0],d=g.current.find(b=>b.address===p.address),f=l?.linkedAccounts.find(b=>b.type==="wallet"&&b.address===p.address);if(!d&&f){let b=Object.assign({},l);b.wallet=f&&{address:f.address,chainType:f.chainType,chainId:f.chainId,walletClient:f.walletClient,walletClientType:f.walletClientType,connectorType:f.connectorType},c(b)}g.current=y},[y]);let zc=async(p,d)=>{if(Ee(p))throw Ce(ce,"createWallet","onError","embedded_wallet_already_exists"),new Error("Only one Privy wallet per user is currently allowed");let[b,W]=await Promise.all([Ue.initializeWalletProxy(d),Ze()]);if(!b&&e.config?.customAuth?.enabled)throw Ce(ce,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to connect to wallet proxy");if(!b||!W||e.config?.embeddedWallets?.requireUserPasswordOnCreate)return new Promise((K,xe)=>{Me(!0),ot({createWallet:{onSuccess:Ot=>{Ce(ce,"createWallet","onSuccess",Ot),K(Ot)},onFailure:Ot=>{Ce(ce,"createWallet","onError","unknown_embedded_wallet_error"),xe(Ot)},callAuthOnSuccessOnClose:!1}}),be("EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN")});{await b.create({accessToken:W});let K=await Ue.refreshUser(),xe=Ee(K);if(!xe)throw Ce(ce,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to create wallet");return Ce(ce,"createWallet","onSuccess",xe),xe}},Py=p=>{if(!D.chains.map(d=>d.id).includes(p))throw new j(`Chain ID ${p} is not supported. It must be added to the config.supportedChains property of the PrivyProvider.`,"unsupported_chain_id")},Vc=(p,d,f)=>new Promise(async(b,W)=>{if(!a||!l){W(new Error("User must be authenticated before signing with a Privy wallet"));return}let K=Ee(l);if(!K){W(new Error("Must have a Privy wallet before signing"));return}Me(!0);let xe=t.connectors?.findWalletConnector("embedded","privy")?.proxyProvider,pn=p.chainId?Number(p.chainId):xe.chainId;Py(pn);let Ot=Object.assign({},p,{chainId:pn}),vi=async()=>{let lr=await Ze();if(!lr||!R){W(new Error("Must have valid access token and Privy wallet to send transaction"));return}try{if(!await Ue.recoverEmbeddedWallet()){W(new Error("Unable to connect to wallet"));return}let qc=new hi.StaticJsonRpcProvider(eo(Ot.chainId,D.chains,D.rpcConfig)),xy=await ci(K.address,Ot,qc),Sy=await Zs(lr,K.address,R,xy,qc);b(Sy)}catch(ea){W(ea)}};if(D.embeddedWallets.noPromptOnSignature)d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config"),vi();else{let lr={transactionRequest:Ot,onSuccess:b,onFailure:W,uiOptions:d||{},fundWalletConfig:f},ea={onCompleteNavigateTo:"EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN",onFailure:W};ot({connectWallet:ea,sendTransaction:lr}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}});function $c(){return new Promise(async(p,d)=>{let f=await Ze();if(!f||!R)throw new Error("Must have valid access token to enroll in MFA");try{await R.verifyMfa({accessToken:f}),p()}catch(b){d(b)}})}let gi={ready:n,authenticated:a,user:l,walletConnectors:t.connectors||null,connectWallet:Ey,linkWallet:Tt,linkEmail:()=>{if(!a)throw new w("User must be authenticated before linking an email address.");if(l?.email)throw new w("User already has an email linked to their account.");h(!0),be("LINK_EMAIL_SCREEN")},linkPhone:()=>{if(!a)throw new w("User must be authenticated before linking a phone number.");if(l?.phone)throw new w("User already has a phone number linked to their account.");h(!0),be("LINK_PHONE_SCREEN")},linkGoogle:async()=>{if(!a)throw new w("User must be authenticated before linking a Google account.");if(l?.google)throw new w("User already has a Google account linked to their account.");await Ue.initLoginWithOAuth("google")},linkTwitter:async()=>{if(!a)throw new w("User must be authenticated before linking a Twitter account.");if(l?.twitter)throw new w("User already has a Twitter account linked to their account.");await Ue.initLoginWithOAuth("twitter")},linkDiscord:async()=>{if(!a)throw new w("User must be authenticated before linking a Discord account.");if(l?.discord)throw new w("User already has a Discord account linked to their account.");await Ue.initLoginWithOAuth("discord")},linkGithub:async()=>{if(!a)throw new w("User must be authenticated before linking a GitHub account.");if(l?.github)throw new w("User already has a Github account linked to their account.");await Ue.initLoginWithOAuth("github")},linkTiktok:async()=>{if(!a)throw new w("User must be authenticated before linking a TikTok account.");if(l?.tiktok)throw new w("User already has a Tiktok account linked to their account.");await Ue.initLoginWithOAuth("tiktok")},linkLinkedIn:async()=>{if(!a)throw new w("User must be authenticated before linking a LinkedIn account.");if(l?.linkedin)throw new w("User already has a LinkedIn account linked to their account.");await Ue.initLoginWithOAuth("linkedin")},linkApple:async()=>{if(!a)throw new w("User must be authenticated before linking an Apple account.");await Ue.initLoginWithOAuth("apple")},linkFarcaster:async()=>{if(!a)throw new w("User must be authenticated before linking a Farcaster account.");await Ue.initLoginWithFarcaster(),h(!0),be("AWAITING_FARCASTER_CONNECTION")},login:async()=>{if(n||(await new Promise(p=>{nr(()=>p)}),nr(null)),a){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}M(!0),Bo("LANDING")},logout:async()=>{await t.logout(),c(null),s(!1),_(null),Ce(ce,"logout","onSuccess"),h(!1),r(!1),ae.del(bi)},getAccessToken:()=>t.getAccessToken(),getEthereumProvider:()=>{if(!l||!l.wallet)return new we;let p=y.find(f=>l.wallet&&f.address===l.wallet.address),d=t.connectors?.walletConnectors.find(f=>f.wallets.find(b=>b.address===p?.address));return!p||!d?new we:d.proxyProvider},getEthersProvider:()=>{if(!l||!l.wallet)return new hi.Web3Provider(new oo(new we));let p=y.find(f=>l.wallet&&f.address===l.wallet.address),d=t.connectors?.walletConnectors.find(f=>f.wallets.find(b=>b.address===p?.address));return!p||!d?new hi.Web3Provider(new oo(new we)):new hi.Web3Provider(new oo(d.proxyProvider))},getWeb3jsProvider:()=>{if(!l||!l.wallet)return new fr(new we);let p=y.find(f=>l.wallet&&f.address===l.wallet.address),d=t.connectors?.walletConnectors.find(f=>f.wallets.find(b=>b.address===p?.address));return!p||!d?new fr(new we):new fr(d.proxyProvider)},unlinkWallet:async p=>{let d=await t.unlinkWallet(p);return c(d),d},unlinkEmail:async p=>{let d=await t.unlinkEmail(p);return c(d),d},unlinkPhone:async p=>{let d=await t.unlinkPhone(p);return c(d),d},unlinkGoogle:async p=>{let d=await t.unlinkOAuth("google",p);return c(d),d},unlinkTwitter:async p=>{let d=await t.unlinkOAuth("twitter",p);return c(d),d},unlinkDiscord:async p=>{let d=await t.unlinkOAuth("discord",p);return c(d),d},unlinkGithub:async p=>{let d=await t.unlinkOAuth("github",p);return c(d),d},unlinkTiktok:async p=>{let d=await t.unlinkOAuth("tiktok",p);return c(d),d},unlinkLinkedIn:async p=>{let d=await t.unlinkOAuth("linkedin",p);return c(d),d},unlinkApple:async p=>{let d=await t.unlinkOAuth("apple",p);return c(d),d},unlinkFarcaster:async p=>{let d=await t.unlinkFarcaster(p);return c(d),d},setActiveWallet:async p=>{let d=y.find(b=>(0,Qi.getAddress)(b.address)===(0,Qi.getAddress)(p)),f=l?.linkedAccounts.find(b=>b.type==="wallet"&&(0,Qi.getAddress)(b.address)===(0,Qi.getAddress)(p));if(!d||!await d.isConnected())oe(p),Tt();else if(!d.linked)d.loginOrLink();else{let b=Object.assign({},l);b.wallet=f&&{address:f.address,chainType:f.chainType,chainId:f.chainId,walletClient:f.walletClient,walletClientType:f.walletClientType,connectorType:f.connectorType},c(b)}},forkSession:()=>t.forkSession(),createWallet:async()=>{if(!a||!l)throw Ce(ce,"createWallet","onError","must_be_authenticated"),new Error("User must be authenticated before creating a Privy wallet");return zc(l,15e3)},setWalletPassword:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before adding password to Privy wallet"));return}let f=Ee(l);if(!f||!R){d(new Error("Must have a Privy wallet to add a password"));return}if(f.recoveryMethod==="user-passcode"){d(new Error("Cannot set password. Embedded wallet already has a password."));return}await $c(),Me(!0);let b={onSuccess:p,onFailure:d,callAuthOnSuccessOnClose:!1},W={onCompleteNavigateTo:"EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN",onFailure:d};ot({setWalletPassword:b,connectWallet:W}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}),signMessage:(p,d)=>new Promise(async(f,b)=>{if(!a||!l){b(new Error("User must be authenticated before signing with a Privy wallet"));return}let W=Ee(l);if(!W){b(new Error("Must have a Privy wallet before signing"));return}if(typeof p!="string"||p.length<1){b(new Error("Message must be a non-empty string"));return}Me(!0);let K=async()=>{if(!a)throw new Error("User must be authenticated before signing with a Privy wallet");let xe=await Ze();if(!R||!xe)throw new Error("Unable to connect to wallet");if(!await Ue.recoverEmbeddedWallet())throw new Error("Unable to connect to wallet");t.createAnalyticsEvent("embedded_wallet_sign_message_started",{walletAddress:W.address});let{response:Ot}=await R.rpc({accessToken:xe,address:W.address,request:{method:"personal_sign",params:[p,W.address]}}),vi=Ot.data;return t.createAnalyticsEvent("embedded_wallet_sign_message_completed",{walletAddress:W.address}),vi};if(D.embeddedWallets.noPromptOnSignature){d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config");try{let xe=await K();f(xe)}catch(xe){b(xe??new ct("Unable to sign message"))}}else{let Ot={message:p,confirmAndSignMessage:K,onSuccess:lr=>{f(lr)},onFailure:lr=>{b(lr)},uiOptions:d||{}},vi={onCompleteNavigateTo:"EMBEDDED_WALLET_SIGN_REQUEST_SCREEN",onFailure:b};ot({signMessage:Ot,connectWallet:vi}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}}),sendTransaction:async(p,d,f)=>{let W=await(await Vc(p,d,f)).wait();return el(W)},exportWallet:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before exporting their Privy wallet"));return}let f=Ee(l);if(!f){d(new Error("Must have a Privy wallet before exporting"));return}Me(!0);let b={onCompleteNavigateTo:"EMBEDDED_WALLET_KEY_EXPORT_SCREEN",onFailure:d},W=await Ze();if(!W||!R){d(new Error("Must have valid access token to enroll in MFA"));return}if(!R){d(new Error("Must have a Privy wallet before exporting"));return}try{try{await R.connect({accessToken:W,address:f.address}),await R.verifyMfa({accessToken:W})}catch(xe){if($r(xe)&&f.recoveryMethod==="privy")await R.recover({accessToken:W,address:f.address});else throw xe}}catch(xe){d(xe);return}let K={appId:e.appId,origin:t.apiUrl,onSuccess:p,onFailure:d};ot({keyExport:K,connectWallet:b}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}),promptMfa:$c,async init(p){let d;switch(p){case"sms":d=new ul("verify");break;case"totp":return;default:throw new Error(`Unsupported MFA method: ${p}`)}t.startMfaFlow(d),await d.init()},async submit(p,d){switch(p){case"totp":case"sms":re.current?.resolve({mfaMethod:p,mfaCode:d}),await new Promise((f,b)=>{fo.current={resolve:f,reject:b}});break;default:throw re.current?.reject(new w("Unsupported MFA method")),new w(`Unsupported MFA method: ${p}`)}},cancel(){re.current?.reject(new w("MFA canceled"))},async initEnrollmentWithSms(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to enroll in MFA");await R.initEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber})},enrollInMfa(p){return new Promise((d,f)=>{if(!p){Ue.closePrivyModal(),d();return}D.mfa.noPromptOnMfaRequired&&console.warn("[Privy Warning] Triggering the 'showMfaEnrollmentModal' function when 'noPromptOnMfaRequired' is set to true is unexpected. If this is intentional, ensure that you are building custom UIs for MFA verification."),ot({mfaEnrollmentFlow:{mfaMethods:D.mfa.methods,onSuccess:d,onFailure:f}}),be("MFA_ENROLLMENT_FLOW_SCREEN")})},async initEnrollmentWithTotp(){let p=await Ze();if(!p||!R)throw new Error("Must have valid access token to enroll in MFA");let d=await R.initEnrollMfa({method:"totp",accessToken:p});return{secret:d.secret,authUrl:d.authUrl}},async submitEnrollmentWithSms(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to enroll in MFA");await R.submitEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber,code:p.mfaCode});let f=await t.getAuthenticatedUser();c(f)},async submitEnrollmentWithTotp(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to enroll in MFA");await R.submitEnrollMfa({method:"totp",accessToken:d,code:p.mfaCode});let f=await t.getAuthenticatedUser();c(f)},async unenroll(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to remove MFA");await R.unenrollMfa({method:p,accessToken:d});let f=await t.getAuthenticatedUser();c(f)},loginWithCode(p){return Ue.loginWithCode(p)},initLoginWithEmail(p){return Ue.initLoginWithEmail(p)},initLoginWithSms(p){return Ue.initLoginWithSms(p)},isModalOpen:o};ry=gi.signMessage,ny=async(...p)=>{let d=await Vc(...p);return D.embeddedWallets.waitForTransactionConfirmation&&await d.wait(),d};let jc=!!e.config?.headless,Ue=(()=>({headless:jc,isNewUserThisSession:E,isLinking:m,linkingHint:Z,pendingTransaction:null,walletConnectionStatus:L,mipdStore:O,connectors:t.connectors?.walletConnectors??[],rpcConfig:D.rpcConfig,chains:D.chains,showFiatPrices:D.embeddedWallets.priceDisplay.primary!=="native-token",clientAnalyticsId:t.clientAnalyticsId,nativeTokenSymbolForChainId:p=>D.chains.find(d=>d.id===Number(p))?.nativeCurrency.symbol,initializeWalletProxy:async p=>{if(R)return R;let d=new Promise(W=>{Or(()=>K=>W(K))}),f=new Promise(W=>setTimeout(()=>W(null),p)),b=await Promise.race([d,f]);return Or(null),b},getAuthFlow:()=>t.authFlow,getAuthMeta:()=>t.authFlow?.meta,closePrivyModal:(p={shouldCallAuthOnSuccess:!0})=>{let d=n&&a&&l;p.shouldCallAuthOnSuccess&&d?(Ce(ce,"login","onComplete",l,E,!1,De.current??null),e.onSuccess?.(l,E)):I&&Ce(ce,"login","onError","exited_auth_flow"),oe(null),M(!1),h(!1),P(!1),r(!1),setTimeout(()=>{t.authFlow=void 0},200),t.createAnalyticsEvent("modal_closed")},openPrivyModal:be,connectWallet:sr,initLoginWithWallet:async(p,d)=>{De.current="siwe",Qe(p,d)},loginWithWallet:async()=>{if(!n)throw new un;if(!(t.authFlow instanceof Br))throw new w("Must initialize SIWE flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(f){throw Ce(ce,"login","onError",f.privyErrorCode||"generic_connect_wallet_error"),f}c(p||l||null),P(d||!1),s(!0)},initLoginWithFarcaster:async p=>{let d=new wi(p);t.startAuthFlow(d);try{De.current="farcaster",await d.initializeFarcasterConnect(),oy.isMobile&&d.meta.connectUri&&window.open(d.meta.connectUri,"_blank","noopener noreferrer")}catch(f){throw Ce(ce,"login","onError",f.privyErrorCode||"unknown_auth_error"),f}},loginWithFarcaster:async()=>{if(!n)throw new un;if(!(t.authFlow instanceof wi))throw new w("Must initialize Farcaster flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(f){throw Ce(ce,"login","onError",f.privyErrorCode||"generic_connect_wallet_error"),f}c(p||null),P(d||!1),s(!0)},initLoginWithOAuth:async(p,d)=>{if(!Ud()){Bo("IN_APP_BROWSER_LOGIN_NOT_POSSIBLE");return}let f=new cr(p);d&&f.addCaptchaToken(d),t.startAuthFlow(f);let b=await t.authFlow.getAuthorizationUrl();b&&b.url&&window.location.assign(b.url)},loginWithOAuth:async p=>{if(!(t.authFlow instanceof cr))throw new w("Must initialize OAuth flow before calling loginWithOAuth");let d=Zt.get(fn),f=t.authFlow.meta.stateCode;if(d!==f)throw t.createAnalyticsEvent("possible_phishing_attempt",{provider:p,storedStateCode:d??"",returnedStateCode:f??""}),new w("Unexpected auth flow. This may be a phishing attempt.");let b,W;if(a)b=await t.link();else try{({user:b,isNewUser:W}=await t.authenticate()),De.current=p}catch(K){throw Ce(ce,"login","onError",K.privyErrorCode||"unknown_auth_error"),K}c(b),P(W||!1),s(!0)},initLoginWithEmail:async(p,d)=>{let f=new Dr(p,d);t.startAuthFlow(f);try{De.current="email",await f.sendCodeEmail()}catch(b){throw Ce(ce,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},initLoginWithSms:async(p,d)=>{let f=new Hr(p,d);t.startAuthFlow(f);try{De.current="sms",await f.sendSmsCode()}catch(b){throw Ce(ce,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},resendEmailCode:async()=>{await t.authFlow?.sendCodeEmail()},resendSmsCode:async()=>{await t.authFlow?.sendSmsCode()},loginWithCode:async p=>{if(!n)throw new un;if(t.authFlow instanceof Dr)t.authFlow.meta.emailCode=p.trim();else if(t.authFlow instanceof Hr)t.authFlow.meta.smsCode=p.trim();else throw new w("Must initialize a passwordless code flow first");let d,f;a?d=await t.link():{user:d,isNewUser:f}=await t.authenticate(),c(d||l||null),P(f||!1),s(!0)},refreshUser:async()=>{let p=await t.getAuthenticatedUser();return c(p),p},walletProxy:R,createAnalyticsEvent:(p,d,f)=>t.createAnalyticsEvent(p,d,f),getUsdTokenPrice:p=>t.getUsdTokenPrice(p),recoverEmbeddedWallet:async()=>new Promise(async(p,d)=>{let f=l?.linkedAccounts.find(W=>W.type==="wallet"&&W.walletClientType==="privy"),b=await Ze();if(!b||!R||!f){d(new Error("Must have valid access token and Privy wallet to recover wallet"));return}Me(!0);try{await R.connect({accessToken:b,address:f.address}),p(!0)}catch(W){$r(W)&&f.recoveryMethod==="privy"?(t.createAnalyticsEvent("embedded_wallet_pinless_recovery_started",{walletAddress:f.address}),(await R.recover({address:f.address,accessToken:b})).address||d(new Error("Unable to recover wallet")),t.createAnalyticsEvent("embedded_wallet_recovery_completed",{walletAddress:f.address}),p(!0)):$r(W)?(ot({recoverWallet:{privyWallet:f,onFailure:d,onSuccess:()=>p(!0)}}),be("EMBEDDED_WALLET_RECOVERY_SCREEN")):d(W)}}),getFiatOnRampConfig:dn,setReadyToTrue:()=>{i(!0),ve?.()},updateWallets:()=>Xi()}))();iy=Ue.recoverEmbeddedWallet;let Ty=(0,V.useMemo)(()=>({wallets:y,ready:ht}),[y,ht]);return(0,Lt.jsx)(Fe.Provider,{value:gi,children:(0,Lt.jsx)(Dl.Provider,{value:ce,children:(0,Lt.jsx)(Mc.Provider,{value:Ty,children:(0,Lt.jsxs)(Pp,{...D,children:[e.children,(0,Lt.jsxs)(Ol.Provider,{value:Ue,children:[!jc&&D.captchaEnabled&&(0,Lt.jsx)(Ma,{delayedExecution:!1}),(0,Lt.jsx)(Mh,{theme:{...D.appearance.palette||{}}}),(0,Lt.jsx)(np,{appConfig:D,data:Ve,setModalData:ot,setInitialScreen:_,initialScreen:C,authenticated:a,children:(0,Lt.jsx)(Oh,{open:o})}),Jt&&q.id?(0,Lt.jsx)(Xh,{appId:e.appId,clientAnalyticsId:t.clientAnalyticsId,origin:t.apiUrl,mfaMethods:l?.mfaMethods,mfaPromise:re,mfaSubmitPromise:fo,onLoad:$,onLoadFailed:()=>null}):null]})]})})})})};var sy=require("react");function ly(e){let{login:t}=(0,sy.useContext)(Fe);return Ft("login",e),{login:t}}var cy=require("react");function dy(e){let{logout:t}=(0,cy.useContext)(Fe);return Ft("logout",e),{logout:t}}var Bc=require("react");var py=()=>{let e=Pe(),{initLoginWithEmail:t,loginWithCode:o}=G(),r=(0,Bc.useCallback)(async({email:i})=>{if(!i)throw new Error("Email required to send OTP code");return e.status==="disabled",t(i)},[t]),n=(0,Bc.useCallback)(async({code:i})=>{if(e.enabled&&e.status==="error")throw new Vo(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};var Hc=require("react");var uy=()=>{let e=Pe(),{initLoginWithSms:t,loginWithCode:o}=G(),r=(0,Hc.useCallback)(async({phoneNumber:i})=>{if(!i)throw new Error("SMS required to send OTP code");return e.status==="disabled",t(i)},[t]),n=(0,Hc.useCallback)(async({code:i})=>{if(e.enabled&&e.status!=="success")throw new Vo(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};var my=require("react");function fy(e){let{connectWallet:t}=(0,my.useContext)(Fe);return Ft("connectWallet",e),{connectWallet:t}}var hy=require("react");function yy(e){let{createWallet:t}=(0,hy.useContext)(Fe);return Ft("createWallet",e),{createWallet:t}}var gy=require("react");var vy=()=>{let{isModalOpen:e}=(0,gy.useContext)(Fe);return{isOpen:e}};var wy=require("react");function Cy(e){let{getAccessToken:t}=(0,wy.useContext)(Fe);return Ft("accessToken",e),{getAccessToken:t}}function by(e,t){return{...e,rpcUrls:{...e.rpcUrls,privyWalletOverride:{http:[t]}}}}0&&(module.exports={AsExternalProvider,Captcha,ConnectorManager,PrivyClient,PrivyProvider,PrivyProxyProvider,SUPPORTED_CHAINS,VERSION,WalletConnector,addRpcUrlOverrideToChain,errorIndicatesMaxMfaRetries,errorIndicatesMfaTimeout,errorIndicatesMfaVerificationFailed,getAccessToken,useConnectWallet,useCreateWallet,useLogin,useLoginWithEmail,useLoginWithSms,useLogout,useMfa,useMfaEnrollment,useModalStatus,usePrivy,useRegisterMfaListener,useToken,useWallets});
2611
+ `;var Ie=require("react/jsx-runtime"),_w={["LANDING"]:wf,["AWAITING_PASSWORDLESS_CODE"]:zp,["AWAITING_CONNECTION"]:uu,["AWAITING_CONNECT_ONLY_CONNECTION"]:hu,["AWAITING_FARCASTER_CONNECTION"]:Im,["PHANTOM_INTERSTITIAL_SCREEN"]:Eh,["LOGIN_FAILED_SCREEN"]:Sf,["AWAITING_OAUTH_SCREEN"]:vh,["ALLOWLIST_REJECTION_SCREEN"]:Np,["INSTALL_PHANTOM_SCREEN"]:qm,["LINK_EMAIL_SCREEN"]:bf,["LINK_PHONE_SCREEN"]:Pf,["LINK_WALLET_SCREEN"]:Tf,["CONNECT_ONLY_LANDING_SCREEN"]:cu,["CONNECT_ONLY_AUTHENTICATED_SCREEN"]:ru,["EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN"]:am,["EMBEDDED_WALLET_CREATED_SCREEN"]:xu,["EMBEDDED_WALLET_CONNECTING_SCREEN"]:Eu,["EMBEDDED_WALLET_RECOVERY_SCREEN"]:mm,["EMBEDDED_WALLET_KEY_EXPORT_SCREEN"]:Ru,["EMBEDDED_WALLET_SIGN_REQUEST_SCREEN"]:Ih,["EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN"]:kh,["FIAT_ON_RAMP_PROMPT_SCREEN"]:Dm,["FIAT_ON_RAMP_STATUS_SCREEN"]:Fm,["EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN"]:pm,["EMBEDDED_WALLET_PASSWORD_UPDATE_SCREEN"]:sm,["MFA_ENROLLMENT_FLOW_SCREEN"]:Uf,["CAPTCHA_SCREEN"]:Yp,["ERROR_SCREEN"]:fm,["IN_APP_BROWSER_LOGIN_NOT_POSSIBLE"]:Gm},kw=["LANDING","AWAITING_CONNECTION"],Aw=({isMfaVerifying:e,onMfaVerificationComplete:t})=>{let{ready:o,isModalOpen:r}=G(),{headless:n}=A(),{ready:i,currentScreen:a}=S(),{status:s,execute:l,reset:c,enabled:m}=Pe(),h=(0,rr.useRef)(null),y=Sp(h),v=r&&a&&kw.includes(a)&&!n&&s==="ready";if((0,rr.useEffect)(()=>{v&&l()},[v]),(0,rr.useEffect)(()=>{!r&&m&&c()},[r,m]),(!o||!i)&&a!=="AWAITING_OAUTH_SCREEN")return(0,Ie.jsxs)(ri,{children:[(0,Ie.jsx)(x,{}),(0,Ie.jsx)(Y,{}),(0,Ie.jsx)(kf,{children:(0,Ie.jsx)(Bt,{})}),(0,Ie.jsx)(te,{}),(0,Ie.jsx)(J,{})]});if(!a&&e)return(0,Ie.jsx)(ri,{style:{height:y},children:(0,Ie.jsx)("div",{ref:h,children:(0,Ie.jsx)(Oc,{open:e,onClose:t})})});if(!a)return null;let g=_w[a];return(0,Ie.jsx)(ri,{style:{height:y},children:(0,Ie.jsxs)("div",{ref:h,children:[(0,Ie.jsx)(qo,{if:!!e,children:(0,Ie.jsx)(g,{})}),(0,Ie.jsx)(qo,{if:!e,children:(0,Ie.jsx)(Oc,{open:e,onClose:t})})]})})},Rw=()=>{let{closePrivyModal:e}=A(),{onUserCloseViaDialogOrKeybindRef:t}=S();return{gracefulClosePrivyModal:(0,rr.useCallback)(()=>{if(t?.current)t.current(),t.current=null;else return e({shouldCallAuthOnSuccess:!1})},[e])}},Oh=({open:e})=>{let{app:t}=S(),{gracefulClosePrivyModal:o}=Rw(),[r,n]=(0,rr.useState)(!1);Da({onMfaRequired:()=>{t?.mfa.noPromptOnMfaRequired||n(!0)}});let i=(0,Ie.jsx)(Nh,{children:(0,Ie.jsx)(Aw,{isMfaVerifying:r,onMfaVerificationComplete:()=>n(!1)})}),a=e||r,s=t?.render.inDialog?(0,Ie.jsx)(_f,{open:a,id:"privy-dialog",onClick:()=>o(),children:i}):i;if(typeof window<"u"&&t?.render.inParentNodeId){let l=document.getElementById(t.render.inParentNodeId);if(l)return Lh.default.createPortal(s,l)}return s};var Yt={appearance:{theme:"light",accentColor:"#676FFF",walletList:["detected_wallets","metamask","coinbase_wallet","rainbow","wallet_connect"]},walletConnectCloudProjectId:_d,rpcConfig:{rpcUrls:{},rpcTimeouts:{}},captchaEnabled:!1,_render:{inDialog:!0,inParentNodeId:null},fiatOnRamp:{useSandbox:!1}};var Iw=new Set(["metamask","coinbase_wallet","rainbow","zerion","phantom","wallet_connect","detected_wallets"]),Ww=e=>Iw.has(e),Mw=(e,t,o)=>o.indexOf(e)===t,Dh=({input:e})=>e?e.filter(Ww).filter(Mw):Yt.appearance.walletList;var Uh={id:43114,name:"Avalanche",network:"avalanche",nativeCurrency:{decimals:18,name:"Avalanche",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax.network/ext/bc/C/rpc"]},public:{http:["https://api.avax.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://snowtrace.io"},default:{name:"SnowTrace",url:"https://snowtrace.io"}}};var Fh={id:43113,name:"Avalanche Fuji",network:"avalanche-fuji",nativeCurrency:{decimals:18,name:"Avalanche Fuji",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax-test.network/ext/bc/C/rpc"]},public:{http:["https://api.avax-test.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://testnet.snowtrace.io"},default:{name:"SnowTrace",url:"https://testnet.snowtrace.io"}},testnet:!0};var Bh={id:42220,name:"Celo Mainnet",network:"celo",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://forno.celo.org"]},infura:{http:["https://celo-mainnet.infura.io/v3"]},public:{http:["https://forno.celo.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/mainnet"},etherscan:{name:"CeloScan",url:"https://celoscan.io"}},testnet:!1};var Hh={id:44787,name:"Celo Alfajores Testnet",network:"celo-alfajores",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://alfajores-forno.celo-testnet.org"]},infura:{http:["https://celo-alfajores.infura.io/v3"]},public:{http:["https://alfajores-forno.celo-testnet.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/alfajores"},etherscan:{name:"CeloScan",url:"https://alfajores.celoscan.io/"}},testnet:!0};var Gh={id:314,name:"Filecoin - Mainnet",network:"filecoin-mainnet",nativeCurrency:{decimals:18,name:"filecoin",symbol:"FIL"},rpcUrls:{default:{http:["https://api.node.glif.io/rpc/v1"]},public:{http:["https://api.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filfox",url:"https://filfox.info/en"},filscan:{name:"Filscan",url:"https://filscan.io"},filscout:{name:"Filscout",url:"https://filscout.io/en"},glif:{name:"Glif",url:"https://explorer.glif.io"}}};var zh={id:314159,name:"Filecoin - Calibration testnet",network:"filecoin-calibration",nativeCurrency:{decimals:18,name:"testnet filecoin",symbol:"tFIL"},rpcUrls:{default:{http:["https://api.calibration.node.glif.io/rpc/v1"]},public:{http:["https://api.calibration.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filscan",url:"https://calibration.filscan.io"}}};var Vh={id:5,network:"goerli",name:"Goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-goerli.g.alchemy.com/v2"],webSocket:["wss://eth-goerli.g.alchemy.com/v2"]},infura:{http:["https://goerli.infura.io/v3"],webSocket:["wss://goerli.infura.io/ws/v3"]},default:{http:["https://rpc.ankr.com/eth_goerli"]},public:{http:["https://rpc.ankr.com/eth_goerli"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli.etherscan.io"},default:{name:"Etherscan",url:"https://goerli.etherscan.io"}},testnet:!0};var $h={id:17e3,name:"Holesky",network:"holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://ethereum-holesky.publicnode.com"]},public:{http:["https://ethereum-holesky.publicnode.com"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://holesky.etherscan.io"},default:{name:"EtherScan",url:"https://holesky.etherscan.io"}}};var jh={id:59144,network:"linea-mainnet",name:"Linea Mainnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-mainnet.infura.io/v3"],webSocket:["wss://linea-mainnet.infura.io/ws/v3"]},default:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]},public:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://lineascan.build"},etherscan:{name:"Etherscan",url:"https://lineascan.build"}},testnet:!1};var qh={id:59140,network:"linea-testnet",name:"Linea Goerli Testnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-goerli.infura.io/v3"],webSocket:["wss://linea-goerli.infura.io/ws/v3"]},default:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]},public:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://goerli.lineascan.build"},etherscan:{name:"Etherscan",url:"https://goerli.lineascan.build"}},testnet:!0};var ll={id:1,network:"homestead",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-mainnet.g.alchemy.com/v2"],webSocket:["wss://eth-mainnet.g.alchemy.com/v2"]},infura:{http:["https://mainnet.infura.io/v3"],webSocket:["wss://mainnet.infura.io/ws/v3"]},default:{http:["https://cloudflare-eth.com"]},public:{http:["https://cloudflare-eth.com"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://etherscan.io"},default:{name:"Etherscan",url:"https://etherscan.io"}}};var Kh={id:17001,name:"Redstone Holesky",network:"redstone-holesky",nativeCurrency:{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.holesky.redstone.xyz"]},public:{http:["https://rpc.holesky.redstone.xyz"]}},blockExplorers:{etherscan:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"},default:{name:"EtherScan",url:"https://explorer.holesky.redstone.xyz"}}};var Yh={id:11155111,network:"sepolia",name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"SEP",decimals:18},rpcUrls:{alchemy:{http:["https://eth-sepolia.g.alchemy.com/v2"],webSocket:["wss://eth-sepolia.g.alchemy.com/v2"]},infura:{http:["https://sepolia.infura.io/v3"],webSocket:["wss://sepolia.infura.io/ws/v3"]},default:{http:["https://rpc.sepolia.org"]},public:{http:["https://rpc.sepolia.org"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://sepolia.etherscan.io"},default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}},testnet:!0};var fi=[Bs,Hs,Gs,Vh,Yh,ll,js,qs,Ks,Ki,Yi,Bh,Hh,Gh,zh,zs,Vs,$s,jh,qh,Uh,Fh,Ys,Qs,Js,$h,Kh],Q8=new Set(fi.map(e=>e.id));var Lr=k(require("tinycolor2")),Jh="#FFFFFF",Nw="#000000",Lw=Jh,Ow="#1E1E1D";function Dw(e){return e<.8&&e>.2&&console.warn("Background color is not light or dark enough, which could lead to accessibility issues."),e>.5?"light":"dark"}function Nr(e,t){let o=Math.max(0,Math.min(1,e.toHsl().l+t));return(0,Lr.default)({...e.toHsl(),l:o})}function Qh({backgroundTheme:e,accentHex:t,successHex:o="#51BA81",warnHex:r="#FFB74D",errorHex:n="#EC6351",whiteHex:i=Jh,blackHex:a=Nw}){let s;switch(e){case"light":s=Lw;break;case"dark":s=Ow;break;default:s=e;break}let l=(0,Lr.default)(s),c=(0,Lr.default)(t),m=(0,Lr.default)(o),h=(0,Lr.default)(r),y=(0,Lr.default)(n),v=Dw(l.getLuminance()),g=Nr(l,v==="light"?-.04:.11),E=Nr(l,v==="light"?-.88:.87),P=Nr(l,v==="light"?-.77:.75),C=Nr(l,v==="light"?-.43:.45).desaturate(v==="light"?60:20),_=Nr(l,v==="light"?-.08:.25).desaturate(v==="light"?60:20),I=Nr(c,.15),M=Nr(c,-.06),L=(0,Lr.default)(c.getLuminance()>.5?a:i),N=Nr(m,-.16);return{colorScheme:v,background:l.toHslString(),background2:g.toHslString(),foreground:E.toHslString(),foreground2:P.toHslString(),foreground3:C.toHslString(),foreground4:_.toHslString(),accent:c.toHslString(),accentLight:I.toHslString(),accentDark:M.toHslString(),foregroundAccent:L.toHslString(),success:m.toHslString(),successDark:N.toHslString(),error:y.toHslString(),warn:h.toHslString()}}function cl(e,t){let o=["google","twitter","discord","tiktok","linkedin","github","apple","farcaster"],r=t?.loginMethods?.filter(oe=>o.includes(oe)),n,i,a,s,l,c,m,h,y,v,g;t?.loginMethods?(n=t.loginMethods.includes("email"),i=t.loginMethods.includes("sms"),a=t.loginMethods.includes("wallet"),s=r?.includes("google"),l=r?.includes("twitter"),c=r?.includes("discord"),m=r?.includes("tiktok"),y=r?.includes("github"),h=r?.includes("linkedin"),v=r?.includes("apple"),g=r?.includes("farcaster")):(n=e.emailAuth,i=e.smsAuth,a=e.walletAuth,s=e.googleOAuth,l=e.twitterOAuth,c=e.discordOAuth,y=e.githubOAuth,m=e.tiktokOAuth,h=e.linkedinOAuth,v=e.appleOAuth,g=e.farcasterAuth);let E=[n,i].filter(Boolean),P=[s,l,c,y,m,h,v,g].filter(Boolean),C=[a].filter(Boolean);if(E.length+P.length+C.length===0)throw new Error("You must enable at least one login method");let _=t?.appearance?.showWalletLoginFirst!==void 0?t?.appearance?.showWalletLoginFirst:e.showWalletLoginFirst;_&&C.length===0?(console.warn("You should only enable `showWalletLoginFirst` when `wallet` logins are also enabled. `showWalletLoginFirst` has been set to false"),_=!1):!_&&P.length+E.length===0&&(console.warn("You should only disable `showWalletLoginFirst` when `email`, `sms`, or social logins are also enabled. `showWalletLoginFirst` has been set to true"),_=!0);let I=Dh({isWalletLoginEnabled:a,input:t?.appearance?.walletList});if(t?.embeddedWallets?.waitForTransactionConfirmation===!1&&t.embeddedWallets.noPromptOnSignature!==!0)throw new Error("Overriding `config.embeddedWallets.waitForTransactionConfirmation` requires that you also enable `config.embeddedWallets.noPromptOnSignature`");let M=t?.intl?.defaultCountry??"US",{chains:L,defaultChain:N}=Uw({additionalChains:t?.additionalChains,supportedChains:t?.supportedChains,defaultChainFromConfig:t?.defaultChain,hasRpcConfigDefined:Object.keys(t?.rpcConfig?.rpcUrls??{}).length>0}),O=!!t?.defaultChain||!!t?.supportedChains,H=t?.customAuth?.getCustomAccessToken&&t?.customAuth?.enabled!==!1;return{id:e.id,name:e.name,allowlistConfig:e.allowlistConfig,appearance:{logo:t?.appearance?.logo??e.logoUrl,palette:Qh({backgroundTheme:t?.appearance?.theme??Yt.appearance.theme,accentHex:t?.appearance?.accentColor??e.accentColor??Yt.appearance.accentColor}),loginGroupPriority:_?"web3-first":"web2-first",hideDirectWeb2Inputs:!!t?.appearance?.hideDirectWeb2Inputs,walletList:I},loginMethods:{wallet:a,email:n,sms:i,google:s,twitter:l,discord:c,github:y,tiktok:m,linkedin:h,apple:v,farcaster:g},legal:{termsAndConditionsUrl:t?.legal?.termsAndConditionsUrl??e.termsAndConditionsUrl,privacyPolicyUrl:t?.legal?.privacyPolicyUrl??e.privacyPolicyUrl},walletConnectCloudProjectId:t?.walletConnectCloudProjectId??e.walletConnectCloudProjectId??Yt.walletConnectCloudProjectId,rpcConfig:{rpcUrls:t?.rpcConfig?.rpcUrls??Yt.rpcConfig.rpcUrls,rpcTimeouts:t?.rpcConfig?.rpcTimeouts??Yt.rpcConfig.rpcTimeouts},chains:L,defaultChain:N,intl:{defaultCountry:M},shouldSwitchChainOnConnect:O,captchaEnabled:e.captchaEnabled??Yt.captchaEnabled,captchaSiteKey:e.captchaSiteKey,embeddedWallets:{...e.embeddedWalletConfig,...H?{createOnLogin:"all-users",requireUserPasswordOnCreate:!1,noPromptOnSignature:!0}:{},waitForTransactionConfirmation:!0,priceDisplay:{primary:"fiat-currency",secondary:"native-token"},...t?.embeddedWallets},mfa:{methods:e.mfaMethods??[],noPromptOnMfaRequired:t?.mfa?.noPromptOnMfaRequired??!1},customAuth:H?{enabled:!0,...t.customAuth}:void 0,fiatOnRamp:{enabled:e.fiatOnRampEnabled,useSandbox:t?.fiatOnRamp?.useSandbox??Yt.fiatOnRamp.useSandbox},loginConfig:{twitterOAuthOnMobileEnabled:e.twitterOAuthOnMobileEnabled??!1},render:{inDialog:t?._render?.inDialog??Yt._render.inDialog,inParentNodeId:t?._render?.inParentNodeId??Yt._render.inParentNodeId}}}function Zh(e,t){if(!e)return{legacyCreateEmbeddedWalletFlag:t};let{appearance:o,additionalChains:r,supportedChains:n,defaultChain:i,...a}=e;return{...a,...r?{additionalChains:r.map(l=>l.id)}:void 0,...n?{supportedChains:n.map(l=>l.id)}:void 0,...i?{defaultChain:i.id}:void 0,...o?{...o,...o.logo&&typeof o.logo?{logo:"component"}:void 0}:void 0,legacyCreateEmbeddedWalletFlag:t}}function Uw({additionalChains:e,supportedChains:t,defaultChainFromConfig:o,hasRpcConfigDefined:r}){let n;if(e&&t&&console.warn("You should only specify one of `additionalChains` or `supportedChains`. Using `supportedChains`."),t){if(t.length===0)throw new Error("`supportedChains` must contain at least one chain");t.filter(l=>l.rpcUrls.privyWalletOverride).length>0&&r&&console.warn("You have specified at least one `supportedChain` with `privyWalletOverride` but also have `rpcConfig` defined. The `rpcConfig` will be ignored. `rpcConfig` is deprecated and you should use `privyWalletOverride` in a `supportedChain`."),n=t.map(l=>l.rpcUrls.privyWalletOverride?l:fi.find(m=>m.id===l.id)??l)}else n=fi.concat(e??[]);let i=t?n[0]:ll,a=o??i;if(!n.find(s=>s.id===a.id))throw new Error("`defaultChain` must be included in `supportedChains`");return{chains:n,defaultChain:a}}var pl=require("react");var dl=class{constructor(){this.callbacks={}}enqueue(t,o){this.callbacks[t]=o}dequeue(t,o){let r=this.callbacks[o];if(!r)throw new Error(`cannot dequeue ${t} event: no event found for id ${o}`);switch(delete this.callbacks[o],t){case"privy:iframe:ready":return r;case"privy:wallet:create":return r;case"privy:wallet:connect":return r;case"privy:wallet:recover":return r;case"privy:wallet:rpc":return r;case"privy:wallet:set-recovery-password":return r;case"privy:mfa:verify":return r;case"privy:mfa:init-enrollment":return r;case"privy:mfa:submit-enrollment":return r;case"privy:mfa:unenroll":return r;default:throw new Error(`invalid wallet event type ${t}`)}}};async function ln(e,t,o,r,n,i=!1){let a=i,s=async m=>{if(a&&t&&t.length>0){m===(i?0:1)?n("configureMfa","onMfaRequired",t):r.current?.reject(new He("missing_or_invalid_mfa","MFA verification failed, retry."));let h=await new Promise((y,v)=>{o.current={resolve:y,reject:v};let g=1e3*60*5;setTimeout(()=>{let E=new He("mfa_timeout","Timed out waiting for MFA code");r.current?.reject(E),v(E)},g)});return await e(h)}return await e()},l=4,c=null;for(let m=0;m<l;m++)try{c=await s(m),r.current?.resolve(void 0);break}catch(h){if(h.type==="missing_or_invalid_mfa")a=!0;else throw r.current?.resolve(void 0),h}if(c===null){let m=new He("mfa_verification_max_attempts_reached","Max MFA verification attempts reached");throw r.current?.reject(m),m}return c}var ey=require("react/jsx-runtime"),Fw=function(e){return()=>`id-${e++}`}(0);function Bw(e){return typeof e.event=="string"&&/^privy:.+/.test(e.event)}function Uo(e){return e.error!==void 0}var mo=new dl,Fc=new Map,Hw=(e,t)=>typeof t=="bigint"?t.toString():t,Gw=(e,t)=>`${e}${JSON.stringify(t,Hw)}`;function Fo(e,t,o){let r=o.contentWindow;if(!r)throw new Error("iframe not initialized");let n=Gw(e,t);if(e==="privy:wallet:create"){let a=Fc.get(n);if(a)return a}let i=new Promise((a,s)=>{let l=Fw();mo.enqueue(l,{resolve:a,reject:s}),r.postMessage({id:l,event:e,data:t},"*")}).finally(()=>{Fc.delete(n)});return Fc.set(n,i),i}function zw(e){switch(e.event){case"privy:iframe:ready":let t=mo.dequeue(e.event,e.id);return Uo(e)?t.reject(new He(e.error.type,e.error.message)):t.resolve(e.data);case"privy:wallet:create":let o=mo.dequeue(e.event,e.id);return Uo(e)?o.reject(new He(e.error.type,e.error.message)):o.resolve(e.data);case"privy:wallet:connect":let r=mo.dequeue(e.event,e.id);return Uo(e)?r.reject(new He(e.error.type,e.error.message)):r.resolve(e.data);case"privy:wallet:recover":let n=mo.dequeue(e.event,e.id);return Uo(e)?n.reject(new He(e.error.type,e.error.message)):n.resolve(e.data);case"privy:wallet:rpc":let i=mo.dequeue(e.event,e.id);return Uo(e)?i.reject(new He(e.error.type,e.error.message)):i.resolve(e.data);case"privy:wallet:set-recovery-password":let a=mo.dequeue(e.event,e.id);return Uo(e)?a.reject(new He(e.error.type,e.error.message)):a.resolve(e.data);case"privy:mfa:verify":let s=mo.dequeue(e.event,e.id);return Uo(e)?s.reject(new He(e.error.type,e.error.message)):s.resolve(e.data);case"privy:mfa:init-enrollment":{let l=mo.dequeue(e.event,e.id);return Uo(e)?l.reject(new He(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:submit-enrollment":{let l=mo.dequeue(e.event,e.id);return Uo(e)?l.reject(new He(e.error.type,e.error.message)):l.resolve(e.data)}case"privy:mfa:unenroll":{let l=mo.dequeue(e.event,e.id);return Uo(e)?l.reject(new He(e.error.type,e.error.message)):l.resolve(e.data)}default:console.warn("Unsupported wallet proxy method:",e)}}function Xh(e){let t=(0,pl.useRef)(null),o=Ap();return(0,pl.useEffect)(()=>{let r=t.current;if(!r)return;function n(c){c&&c.origin===e.origin&&Bw(c.data)&&zw(c.data)}let i={create(c){return Fo("privy:wallet:create",c,r)},connect(c){return Fo("privy:wallet:connect",c,r)},recover(c){return ln(m=>Fo("privy:wallet:recover",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},rpc(c){return ln(m=>Fo("privy:wallet:rpc",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},setRecoveryPassword(c){return ln(m=>Fo("privy:wallet:set-recovery-password",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},verifyMfa(c){return ln(m=>Fo("privy:mfa:verify",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)},initEnrollMfa(c){return ln(m=>Fo("privy:mfa:init-enrollment",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o)},submitEnrollMfa(c){return Fo("privy:mfa:submit-enrollment",c,r)},unenrollMfa(c){return ln(m=>Fo("privy:mfa:unenroll",{...c,...m},r),e.mfaMethods,e.mfaPromise,e.mfaSubmitPromise,o,!0)}};window.addEventListener("message",n);let a=()=>e.onLoad(i),s=(...c)=>{console.warn("Privy iframe failed to load: ",...c),e.onLoadFailed()},l=new AbortController;return Vd(()=>Fo("privy:iframe:ready",{},r),{abortSignal:l.signal}).then(a,s),()=>{window.removeEventListener("message",n),l.abort()}},[t.current,e.mfaMethods]),(0,ey.jsx)("iframe",{ref:t,width:"0",height:"0",style:{display:"none",height:"0px",width:"0px"},src:ya(e.origin,`/apps/${e.appId}/embedded-wallets`,{caid:e.clientAnalyticsId})})}var ul=class{constructor(t,o){this.meta={action:t,phoneNumber:o}}async init(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Auth flow has no API instance");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set when initialzing authentication.");try{let t=Pd();await this.api.post(t,{action:this.meta.action,phoneNumber:this.meta.phoneNumber})}catch(t){throw de(t)}}async authenticate(){if(!this.meta.action)throw new w("action required");if(!this.api)throw new w("Mfa flow has no API instance");if(!this.meta.smsCode)throw new w("sms code must be set prior to calling authenticate.");if(this.meta.action==="enroll"&&!this.meta.phoneNumber)throw new w("phone number must be set prior to calling authenticate.");try{let t=Td(),o=await this.api.post(t,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return Dt(o)}catch(t){throw de(t)}}};var Lt=require("react/jsx-runtime"),Zi;function Vw(e){return typeof e=="string"&&e.length===25}function Ze(){if(!Zi){let e=ae.get(Ur);return Promise.resolve(e||null)}return Zi.getAccessToken()}var ry,Jd=(e,t)=>ry(e,t),ny,Qd=(e,t)=>ny(e,t),iy,Zd=()=>iy(),$w=()=>{let t=new URLSearchParams(window.location.search).get("privy_token");if(!t)return;ae.put(Ci,t);let o=new URL(window.location.href);o.searchParams.delete("privy_token"),window.history.pushState({},"",o)},ay=({config:e,...t})=>{if(!Vw(t.appId))throw new w("Cannot initialize the Privy provider with an invalid Privy app ID");Zi||(Zi=new An({appId:t.appId,apiUrl:t.apiUrl||ca}));let o=Object.assign({},e);return t.createPrivyWalletOnLogin!==void 0&&o.embeddedWallets?.createOnLogin===void 0&&(o.embeddedWallets||(o.embeddedWallets={}),o.embeddedWallets.createOnLogin=t.createPrivyWalletOnLogin?"users-without-wallets":"off"),t.createPrivyWalletOnLogin!==void 0&&e?.embeddedWallets?.createOnLogin&&console.warn("Both `createPrivyWalletOnLogin` and `config.embeddedWallets.createOnLogin` are set. `createPrivyWalletOnLogin` is deprecated and should be removed."),(0,Lt.jsx)(jw,{...t,config:o,client:Zi})},jw=e=>{let t=e.client,[o,r]=(0,V.useState)(!1),[n,i]=(0,V.useState)(!1),[a,s]=(0,V.useState)(!1),[l,c]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),[y,v]=(0,V.useState)([]),g=(0,V.useRef)(y),[E,P]=(0,V.useState)(!1),[C,_]=(0,V.useState)(null),[I,M]=(0,V.useState)(!1),[L,N]=(0,V.useState)({status:"disconnected",connectedWallet:null,connectError:null,connector:null,connectRetry:T}),[O,H]=(0,V.useState)(null),[Z,oe]=(0,V.useState)(null),[R,$]=(0,V.useState)(null),[q,Oe]=(0,V.useState)({showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,linkedinOAuth:!1,appleOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null,embeddedWalletConfig:{createOnLogin:"off",requireUserPasswordOnCreate:!1},fiatOnRampEnabled:!1,captchaEnabled:!1,captchaSiteKey:""}),[D,We]=(0,V.useState)(()=>{let p=Zh(e.config,e.createPrivyWalletOnLogin);return t.createAnalyticsEvent("sdk_initialize",p),cl(q,e.config)}),[Jt,Me]=(0,V.useState)(!0),[Ve,ot]=(0,V.useState)({}),[ve,nr]=(0,V.useState)(null),[ir,Or]=(0,V.useState)(null),[ht,Je]=(0,V.useState)(!1),[ar,cn]=(0,V.useState)(!1),re=(0,V.useRef)(null),fo=(0,V.useRef)(null),ce=(0,V.useRef)(_p);t.onStoreToken=p=>{p&&Ce(ce,"accessToken","onAccessTokenGranted",p)},t.onDeleteToken=()=>{Ce(ce,"accessToken","onAccessTokenRemoved")};let De=(0,V.useRef)(),ml=(0,V.useCallback)(p=>{let d=t.connectors?.walletsReady||!1;return a&&l?.linkedAccounts?.some(b=>b.type==="wallet"&&b.walletClientType==="privy")?d&&p?.some(b=>b?.walletClientType==="privy"):d},[a,l?.linkedAccounts,t?.connectors?.walletsReady]),be=p=>{_(p),setTimeout(()=>{r(!0)},15),t.createAnalyticsEvent("modal_open",{initialScreen:p})},Bo=p=>{D.embeddedWallets.createOnLogin!=="off"&&Me(!0),be(p)};(0,V.useEffect)(()=>{if(!R||!l){t.connectors?.removeEmbeddedWalletConnector();return}let p=l?.linkedAccounts.filter(d=>d.type==="wallet"&&d.walletClient==="privy");if(p&&p.length>0){let d=p[0].address;t.connectors?.addEmbeddedWalletConnector(R,d,D.defaultChain)}},[R,l]),(0,V.useEffect)(()=>{R&&ir?.(R)},[R]),(0,V.useEffect)(()=>{(async()=>{if(!D.customAuth?.enabled)return;Me(!0);let{getCustomAccessToken:d,isLoading:f}=D.customAuth;if(!(!n||f))try{let b=await d();if(!b){await gi.logout();return}if(a)return;t.startAuthFlow(new mn(b));let{user:W,isNewUser:K}=await t.authenticate();W||await gi.logout(),c(W||null),P(K||!1),s(!0),cn(!0)}catch(b){console.warn(b),a&&await gi.logout()}})()},[D.customAuth?.enabled,D.customAuth?.getCustomAccessToken,D.customAuth?.isLoading,n,a]),(0,V.useEffect)(()=>{ar&&R&&l&&dr(l,e.config?.embeddedWallets?.createOnLogin)&&(cn(!1),zc(l,yn).catch(console.error))},[ar&&R&&l]),(0,V.useEffect)(()=>{async function p(){let d=await t.getServerConfig();Oe(d);let f=cl(d,e.config);We(f),d.customApiUrl&&t.updateApiUrl(d.customApiUrl);let b=fl();$w();let W=(0,ty.createStore)();H(W),t.initializeConnectorManager(f.walletConnectCloudProjectId,f.rpcConfig,f.chains,f.defaultChain,W,f.appearance.walletList),await t.connectors?.initialize();let K=await t.getAuthenticatedUser();e.config?.customAuth?.enabled||(s(!!K),K&&Ce(ce,"login","onComplete",K,!1,!0,null),c(K)),b||Ue.setReadyToTrue(),b&&K&&h(!0),Pt()}n||p()},[t,ve,n]),(0,V.useEffect)(()=>{let p=cl(q,e.config);We(p)},[e.config,q]);let fl=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_oauth_code"),f=p.get("privy_oauth_state"),b=p.get("privy_oauth_provider");return d&&f&&b?(t.startAuthFlow(new cr(b,d,f)),Bo("AWAITING_OAUTH_SCREEN"),!0):!1},yi=async(p,d,f,b)=>{let W=await t.connectors?.createWalletConnector(p,d)||null;sr(W,d,f,b)};async function sr(p,d,f,b){if(!p)return N({status:"disconnected",connectedWallet:null,connectError:new j("Unable to connect to wallet."),connector:null,connectRetry:T}),b?.(null,f);p instanceof Co&&d&&p.resetConnection(d),N({connector:p,status:"connecting",connectedWallet:null,connectError:null,connectRetry:()=>sr(p,d,f,b)});try{let W=await p.connect({showPrompt:!0});if(D.shouldSwitchChainOnConnect&&!D.chains.find(K=>K.id===Number(W?.chainId))&&!(W?.connectorType==="wallet_connect_v2"&&W?.walletClientType==="metamask")){N(K=>({...K,connector:p,status:"switching_to_supported_chain",connectedWallet:null,connectError:null,connectRetry:T}));try{await W?.switchChain(D.defaultChain.id),W&&(W.chainId=gn(Gr(D.defaultChain.id)))}catch{console.warn(`Unable to switch to default chain: ${D.defaultChain.id}`)}}return N(K=>({...K,status:"connected",connectedWallet:W,connectError:null,connectRetry:T})),W&&!I&&Ce(ce,"connectWallet","onSuccess",W),b?.(W,f)}catch(W){return W instanceof rt?(console.warn(W.cause?W.cause:W.message),I||Ce(ce,"connectWallet","onError",W.privyErrorCode||"generic_connect_wallet_error")):(console.warn(W),I||Ce(ce,"connectWallet","onError","unknown_connect_wallet_error")),N(K=>({...K,status:"disconnected",connectedWallet:null,connectError:W})),b?.(null,f)}}let Qe=async(p,d)=>{if(p===null)return;let f=new Br(p,d);t.startAuthFlow(f)},Pt=()=>{let p=new URLSearchParams(window.location.search),d=p.get("privy_connector"),f=p.get("privy_wallet_client");if(!d||!f)return;if(f==="phantom"&&!pr()&&Bo("LOGIN_FAILED_SCREEN"),!t.connectors)throw new w("Connector not initialized");be("AWAITING_CONNECTION");let b=new URL(window.location.href);b.searchParams.delete("privy_connector"),b.searchParams.delete("privy_wallet_client"),window.history.pushState({},"",b),yi(d,f,void 0,Qe)};(0,V.useEffect)(()=>{n&&a&&l===null&&t.getAuthenticatedUser().then(c)},[n,a,l,t]);let Tt=()=>{if(!a)throw new w("User must be authenticated before linking a wallet.");h(!0),be("LINK_WALLET_SCREEN")},Gc=p=>{if(!a||!l)return!1;for(let d of l.linkedAccounts)if(d.type==="wallet"&&d.address===p.address)return!0;return!1},Qt=async p=>{if(!t.connectors)throw new w("Connector not initialized");let d=t.connectors.findWalletConnector(p.connectorType,p.walletClientType)||null;if(N(f=>({...f,connector:d,status:"connected",connectedWallet:p,connectError:null,connectRetry:T})),D.captchaEnabled&&!a){let f={callback:b=>Qe(p,b),userIntentRequired:!1,onSuccessNavigateTo:"AWAITING_CONNECTION",onErrorNavigateTo:"ERROR_SCREEN"};ot({captchaModalData:f}),Bo("CAPTCHA_SCREEN")}else await Qe(p),Bo("AWAITING_CONNECTION")},dn=async(p,d)=>{if(!D.fiatOnRamp.enabled)throw new w("Fiat on-ramp is not enabled");if(!d||!d.provider||d.provider==="moonpay"){let{signedUrl:f,externalTransactionId:b}=await Lm(t,p,d?.config??{},D.appearance.palette,D.fiatOnRamp.useSandbox);return{signedUrl:f,externalTransactionId:b}}else throw new w("Unsupported fund provider. Currently supported option is `moonpay`.")},Xi=()=>{v(p=>{let d=t.connectors?.wallets.map(f=>({...f,linked:Gc(f),loginOrLink:async()=>{if(!await f.isConnected())throw new w("Wallet is not connected");if(f.connectorType==="embedded"&&f.walletClientType==="privy")throw new w("Cannot link or login with embedded wallet");Qt(f)},fund:async b=>{let{signedUrl:W,externalTransactionId:K}=await dn(f.address,b);ot({fiatOnRampPrompt:{signedUrl:W},fiatOnRampStatus:{externalTransactionId:K}}),be("FIAT_ON_RAMP_PROMPT_SCREEN")},unlink:async()=>{if(!a)throw new w("User is not authenticated.");if(f.connectorType==="embedded"&&f.walletClientType==="privy")throw new w("Cannot unlink an embedded wallet");let b=await t.unlinkWallet(f.address);c(b)}}))||[];return Je(ml(d)),va(p,d)?p:d})};(0,V.useEffect)(()=>{Xi()},[l?.linkedAccounts,a,n]),(0,V.useEffect)(()=>{if(n){if(!t.connectors)throw new w("Connector not initialized");Xi(),t.connectors.on("walletsUpdated",Xi)}},[n]);let Ey=()=>{be(a?"CONNECT_ONLY_AUTHENTICATED_SCREEN":"CONNECT_ONLY_LANDING_SCREEN")};(0,V.useEffect)(()=>{if(!y[0])return;let p=y[0],d=g.current.find(b=>b.address===p.address),f=l?.linkedAccounts.find(b=>b.type==="wallet"&&b.address===p.address);if(!d&&f){let b=Object.assign({},l);b.wallet=f&&{address:f.address,chainType:f.chainType,chainId:f.chainId,walletClient:f.walletClient,walletClientType:f.walletClientType,connectorType:f.connectorType},c(b)}g.current=y},[y]);let zc=async(p,d)=>{if(Ee(p))throw Ce(ce,"createWallet","onError","embedded_wallet_already_exists"),new Error("Only one Privy wallet per user is currently allowed");let[b,W]=await Promise.all([Ue.initializeWalletProxy(d),Ze()]);if(!b&&e.config?.customAuth?.enabled)throw Ce(ce,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to connect to wallet proxy");if(!b||!W||e.config?.embeddedWallets?.requireUserPasswordOnCreate)return new Promise((K,xe)=>{Me(!0),ot({createWallet:{onSuccess:Ot=>{Ce(ce,"createWallet","onSuccess",Ot),K(Ot)},onFailure:Ot=>{Ce(ce,"createWallet","onError","unknown_embedded_wallet_error"),xe(Ot)},callAuthOnSuccessOnClose:!1}}),be("EMBEDDED_WALLET_ON_ACCOUNT_CREATE_SCREEN")});{await b.create({accessToken:W});let K=await Ue.refreshUser(),xe=Ee(K);if(!xe)throw Ce(ce,"createWallet","onError","unknown_embedded_wallet_error"),new Error("Failed to create wallet");return Ce(ce,"createWallet","onSuccess",xe),xe}},Py=p=>{if(!D.chains.map(d=>d.id).includes(p))throw new j(`Chain ID ${p} is not supported. It must be added to the config.supportedChains property of the PrivyProvider.`,"unsupported_chain_id")},Vc=(p,d,f)=>new Promise(async(b,W)=>{if(!a||!l){W(new Error("User must be authenticated before signing with a Privy wallet"));return}let K=Ee(l);if(!K){W(new Error("Must have a Privy wallet before signing"));return}Me(!0);let xe=t.connectors?.findWalletConnector("embedded","privy")?.proxyProvider,pn=p.chainId?Number(p.chainId):xe.chainId;Py(pn);let Ot=Object.assign({},p,{chainId:pn}),vi=async()=>{let lr=await Ze();if(!lr||!R){W(new Error("Must have valid access token and Privy wallet to send transaction"));return}try{if(!await Ue.recoverEmbeddedWallet()){W(new Error("Unable to connect to wallet"));return}let qc=new hi.StaticJsonRpcProvider(eo(Ot.chainId,D.chains,D.rpcConfig)),xy=await ci(K.address,Ot,qc),Sy=await Zs(lr,K.address,R,xy,qc);b(Sy)}catch(ea){W(ea)}};if(D.embeddedWallets.noPromptOnSignature)d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config"),vi();else{let lr={transactionRequest:Ot,onSuccess:b,onFailure:W,uiOptions:d||{},fundWalletConfig:f},ea={onCompleteNavigateTo:"EMBEDDED_WALLET_SEND_TRANSACTION_SCREEN",onFailure:W};ot({connectWallet:ea,sendTransaction:lr}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}});function $c(){return new Promise(async(p,d)=>{let f=await Ze();if(!f||!R)throw new Error("Must have valid access token to enroll in MFA");try{await R.verifyMfa({accessToken:f}),p()}catch(b){d(b)}})}let gi={ready:n,authenticated:a,user:l,walletConnectors:t.connectors||null,connectWallet:Ey,linkWallet:Tt,linkEmail:()=>{if(!a)throw new w("User must be authenticated before linking an email address.");if(l?.email)throw new w("User already has an email linked to their account.");h(!0),be("LINK_EMAIL_SCREEN")},linkPhone:()=>{if(!a)throw new w("User must be authenticated before linking a phone number.");if(l?.phone)throw new w("User already has a phone number linked to their account.");h(!0),be("LINK_PHONE_SCREEN")},linkGoogle:async()=>{if(!a)throw new w("User must be authenticated before linking a Google account.");if(l?.google)throw new w("User already has a Google account linked to their account.");await Ue.initLoginWithOAuth("google")},linkTwitter:async()=>{if(!a)throw new w("User must be authenticated before linking a Twitter account.");if(l?.twitter)throw new w("User already has a Twitter account linked to their account.");await Ue.initLoginWithOAuth("twitter")},linkDiscord:async()=>{if(!a)throw new w("User must be authenticated before linking a Discord account.");if(l?.discord)throw new w("User already has a Discord account linked to their account.");await Ue.initLoginWithOAuth("discord")},linkGithub:async()=>{if(!a)throw new w("User must be authenticated before linking a GitHub account.");if(l?.github)throw new w("User already has a Github account linked to their account.");await Ue.initLoginWithOAuth("github")},linkTiktok:async()=>{if(!a)throw new w("User must be authenticated before linking a TikTok account.");if(l?.tiktok)throw new w("User already has a Tiktok account linked to their account.");await Ue.initLoginWithOAuth("tiktok")},linkLinkedIn:async()=>{if(!a)throw new w("User must be authenticated before linking a LinkedIn account.");if(l?.linkedin)throw new w("User already has a LinkedIn account linked to their account.");await Ue.initLoginWithOAuth("linkedin")},linkApple:async()=>{if(!a)throw new w("User must be authenticated before linking an Apple account.");await Ue.initLoginWithOAuth("apple")},linkFarcaster:async()=>{if(!a)throw new w("User must be authenticated before linking a Farcaster account.");await Ue.initLoginWithFarcaster(),h(!0),be("AWAITING_FARCASTER_CONNECTION")},login:async()=>{if(n||(await new Promise(p=>{nr(()=>p)}),nr(null)),a){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}M(!0),Bo("LANDING")},logout:async()=>{await t.logout(),c(null),s(!1),_(null),Ce(ce,"logout","onSuccess"),h(!1),r(!1),ae.del(bi)},getAccessToken:()=>t.getAccessToken(),getEthereumProvider:()=>{if(!l||!l.wallet)return new we;let p=y.find(f=>l.wallet&&f.address===l.wallet.address),d=t.connectors?.walletConnectors.find(f=>f.wallets.find(b=>b.address===p?.address));return!p||!d?new we:d.proxyProvider},getEthersProvider:()=>{if(!l||!l.wallet)return new hi.Web3Provider(new oo(new we));let p=y.find(f=>l.wallet&&f.address===l.wallet.address),d=t.connectors?.walletConnectors.find(f=>f.wallets.find(b=>b.address===p?.address));return!p||!d?new hi.Web3Provider(new oo(new we)):new hi.Web3Provider(new oo(d.proxyProvider))},getWeb3jsProvider:()=>{if(!l||!l.wallet)return new fr(new we);let p=y.find(f=>l.wallet&&f.address===l.wallet.address),d=t.connectors?.walletConnectors.find(f=>f.wallets.find(b=>b.address===p?.address));return!p||!d?new fr(new we):new fr(d.proxyProvider)},unlinkWallet:async p=>{let d=await t.unlinkWallet(p);return c(d),d},unlinkEmail:async p=>{let d=await t.unlinkEmail(p);return c(d),d},unlinkPhone:async p=>{let d=await t.unlinkPhone(p);return c(d),d},unlinkGoogle:async p=>{let d=await t.unlinkOAuth("google",p);return c(d),d},unlinkTwitter:async p=>{let d=await t.unlinkOAuth("twitter",p);return c(d),d},unlinkDiscord:async p=>{let d=await t.unlinkOAuth("discord",p);return c(d),d},unlinkGithub:async p=>{let d=await t.unlinkOAuth("github",p);return c(d),d},unlinkTiktok:async p=>{let d=await t.unlinkOAuth("tiktok",p);return c(d),d},unlinkLinkedIn:async p=>{let d=await t.unlinkOAuth("linkedin",p);return c(d),d},unlinkApple:async p=>{let d=await t.unlinkOAuth("apple",p);return c(d),d},unlinkFarcaster:async p=>{let d=await t.unlinkFarcaster(p);return c(d),d},setActiveWallet:async p=>{let d=y.find(b=>(0,Qi.getAddress)(b.address)===(0,Qi.getAddress)(p)),f=l?.linkedAccounts.find(b=>b.type==="wallet"&&(0,Qi.getAddress)(b.address)===(0,Qi.getAddress)(p));if(!d||!await d.isConnected())oe(p),Tt();else if(!d.linked)d.loginOrLink();else{let b=Object.assign({},l);b.wallet=f&&{address:f.address,chainType:f.chainType,chainId:f.chainId,walletClient:f.walletClient,walletClientType:f.walletClientType,connectorType:f.connectorType},c(b)}},forkSession:()=>t.forkSession(),createWallet:async()=>{if(!a||!l)throw Ce(ce,"createWallet","onError","must_be_authenticated"),new Error("User must be authenticated before creating a Privy wallet");return zc(l,15e3)},setWalletPassword:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before adding password to Privy wallet"));return}let f=Ee(l);if(!f||!R){d(new Error("Must have a Privy wallet to add a password"));return}if(f.recoveryMethod==="user-passcode"){d(new Error("Cannot set password. Embedded wallet already has a password."));return}await $c(),Me(!0);let b={onSuccess:p,onFailure:d,callAuthOnSuccessOnClose:!1},W={onCompleteNavigateTo:"EMBEDDED_WALLET_PASSWORD_UPDATE_SPLASH_SCREEN",onFailure:d};ot({setWalletPassword:b,connectWallet:W}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}),signMessage:(p,d)=>new Promise(async(f,b)=>{if(!a||!l){b(new Error("User must be authenticated before signing with a Privy wallet"));return}let W=Ee(l);if(!W){b(new Error("Must have a Privy wallet before signing"));return}if(typeof p!="string"||p.length<1){b(new Error("Message must be a non-empty string"));return}Me(!0);let K=async()=>{if(!a)throw new Error("User must be authenticated before signing with a Privy wallet");let xe=await Ze();if(!R||!xe)throw new Error("Unable to connect to wallet");if(!await Ue.recoverEmbeddedWallet())throw new Error("Unable to connect to wallet");t.createAnalyticsEvent("embedded_wallet_sign_message_started",{walletAddress:W.address});let{response:Ot}=await R.rpc({accessToken:xe,address:W.address,request:{method:"personal_sign",params:[p,W.address]}}),vi=Ot.data;return t.createAnalyticsEvent("embedded_wallet_sign_message_completed",{walletAddress:W.address}),vi};if(D.embeddedWallets.noPromptOnSignature){d&&console.warn("uiOptions defined with `noPromptOnSignature` set to true in app config");try{let xe=await K();f(xe)}catch(xe){b(xe??new ct("Unable to sign message"))}}else{let Ot={message:p,confirmAndSignMessage:K,onSuccess:lr=>{f(lr)},onFailure:lr=>{b(lr)},uiOptions:d||{}},vi={onCompleteNavigateTo:"EMBEDDED_WALLET_SIGN_REQUEST_SCREEN",onFailure:b};ot({signMessage:Ot,connectWallet:vi}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}}),sendTransaction:async(p,d,f)=>{let W=await(await Vc(p,d,f)).wait();return el(W)},exportWallet:()=>new Promise(async(p,d)=>{if(!a||!l){d(new Error("User must be authenticated before exporting their Privy wallet"));return}let f=Ee(l);if(!f){d(new Error("Must have a Privy wallet before exporting"));return}Me(!0);let b={onCompleteNavigateTo:"EMBEDDED_WALLET_KEY_EXPORT_SCREEN",onFailure:d},W=await Ze();if(!W||!R){d(new Error("Must have valid access token to enroll in MFA"));return}if(!R){d(new Error("Must have a Privy wallet before exporting"));return}try{try{await R.connect({accessToken:W,address:f.address}),await R.verifyMfa({accessToken:W})}catch(xe){if($r(xe)&&f.recoveryMethod==="privy")await R.recover({accessToken:W,address:f.address});else throw xe}}catch(xe){d(xe);return}let K={appId:e.appId,origin:t.apiUrl,onSuccess:p,onFailure:d};ot({keyExport:K,connectWallet:b}),be("EMBEDDED_WALLET_CONNECTING_SCREEN")}),promptMfa:$c,async init(p){let d;switch(p){case"sms":d=new ul("verify");break;case"totp":return;default:throw new Error(`Unsupported MFA method: ${p}`)}t.startMfaFlow(d),await d.init()},async submit(p,d){switch(p){case"totp":case"sms":re.current?.resolve({mfaMethod:p,mfaCode:d}),await new Promise((f,b)=>{fo.current={resolve:f,reject:b}});break;default:throw re.current?.reject(new w("Unsupported MFA method")),new w(`Unsupported MFA method: ${p}`)}},cancel(){re.current?.reject(new w("MFA canceled"))},async initEnrollmentWithSms(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to enroll in MFA");await R.initEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber})},enrollInMfa(p){return new Promise((d,f)=>{if(!p){Ue.closePrivyModal(),d();return}D.mfa.noPromptOnMfaRequired&&console.warn("[Privy Warning] Triggering the 'showMfaEnrollmentModal' function when 'noPromptOnMfaRequired' is set to true is unexpected. If this is intentional, ensure that you are building custom UIs for MFA verification."),ot({mfaEnrollmentFlow:{mfaMethods:D.mfa.methods,onSuccess:d,onFailure:f}}),be("MFA_ENROLLMENT_FLOW_SCREEN")})},async initEnrollmentWithTotp(){let p=await Ze();if(!p||!R)throw new Error("Must have valid access token to enroll in MFA");let d=await R.initEnrollMfa({method:"totp",accessToken:p});return{secret:d.secret,authUrl:d.authUrl}},async submitEnrollmentWithSms(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to enroll in MFA");await R.submitEnrollMfa({method:"sms",accessToken:d,phoneNumber:p.phoneNumber,code:p.mfaCode});let f=await t.getAuthenticatedUser();c(f)},async submitEnrollmentWithTotp(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to enroll in MFA");await R.submitEnrollMfa({method:"totp",accessToken:d,code:p.mfaCode});let f=await t.getAuthenticatedUser();c(f)},async unenroll(p){let d=await Ze();if(!d||!R)throw new Error("Must have valid access token to remove MFA");await R.unenrollMfa({method:p,accessToken:d});let f=await t.getAuthenticatedUser();c(f)},loginWithCode(p){return Ue.loginWithCode(p)},initLoginWithEmail(p){return Ue.initLoginWithEmail(p)},initLoginWithSms(p){return Ue.initLoginWithSms(p)},isModalOpen:o};ry=gi.signMessage,ny=async(...p)=>{let d=await Vc(...p);return D.embeddedWallets.waitForTransactionConfirmation&&await d.wait(),d};let jc=!!e.config?.headless,Ue=(()=>({headless:jc,isNewUserThisSession:E,isLinking:m,linkingHint:Z,pendingTransaction:null,walletConnectionStatus:L,mipdStore:O,connectors:t.connectors?.walletConnectors??[],rpcConfig:D.rpcConfig,chains:D.chains,showFiatPrices:D.embeddedWallets.priceDisplay.primary!=="native-token",clientAnalyticsId:t.clientAnalyticsId,nativeTokenSymbolForChainId:p=>D.chains.find(d=>d.id===Number(p))?.nativeCurrency.symbol,initializeWalletProxy:async p=>{if(R)return R;let d=new Promise(W=>{Or(()=>K=>W(K))}),f=new Promise(W=>setTimeout(()=>W(null),p)),b=await Promise.race([d,f]);return Or(null),b},getAuthFlow:()=>t.authFlow,getAuthMeta:()=>t.authFlow?.meta,closePrivyModal:(p={shouldCallAuthOnSuccess:!0})=>{let d=n&&a&&l;p.shouldCallAuthOnSuccess&&d?(Ce(ce,"login","onComplete",l,E,!1,De.current??null),e.onSuccess?.(l,E)):I&&Ce(ce,"login","onError","exited_auth_flow"),oe(null),M(!1),h(!1),P(!1),r(!1),setTimeout(()=>{t.authFlow=void 0},200),t.createAnalyticsEvent("modal_closed")},openPrivyModal:be,connectWallet:sr,initLoginWithWallet:async(p,d)=>{De.current="siwe",Qe(p,d)},loginWithWallet:async()=>{if(!n)throw new un;if(!(t.authFlow instanceof Br))throw new w("Must initialize SIWE flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(f){throw Ce(ce,"login","onError",f.privyErrorCode||"generic_connect_wallet_error"),f}c(p||l||null),P(d||!1),s(!0)},initLoginWithFarcaster:async p=>{let d=new wi(p);t.startAuthFlow(d);try{De.current="farcaster",await d.initializeFarcasterConnect(),oy.isMobile&&d.meta.connectUri&&window.open(d.meta.connectUri,"_blank","noopener noreferrer")}catch(f){throw Ce(ce,"login","onError",f.privyErrorCode||"unknown_auth_error"),f}},loginWithFarcaster:async()=>{if(!n)throw new un;if(!(t.authFlow instanceof wi))throw new w("Must initialize Farcaster flow first.");let p,d;if(a)p=await t.link();else try{({user:p,isNewUser:d}=await t.authenticate())}catch(f){throw Ce(ce,"login","onError",f.privyErrorCode||"generic_connect_wallet_error"),f}c(p||null),P(d||!1),s(!0)},initLoginWithOAuth:async(p,d)=>{if(!Ud()){Bo("IN_APP_BROWSER_LOGIN_NOT_POSSIBLE");return}let f=new cr(p);d&&f.addCaptchaToken(d),t.startAuthFlow(f);let b=await t.authFlow.getAuthorizationUrl();b&&b.url&&window.location.assign(b.url)},loginWithOAuth:async p=>{if(!(t.authFlow instanceof cr))throw new w("Must initialize OAuth flow before calling loginWithOAuth");let d=Zt.get(fn),f=t.authFlow.meta.stateCode;if(d!==f)throw t.createAnalyticsEvent("possible_phishing_attempt",{provider:p,storedStateCode:d??"",returnedStateCode:f??""}),new w("Unexpected auth flow. This may be a phishing attempt.");let b,W;if(a)b=await t.link();else try{({user:b,isNewUser:W}=await t.authenticate()),De.current=p}catch(K){throw Ce(ce,"login","onError",K.privyErrorCode||"unknown_auth_error"),K}c(b),P(W||!1),s(!0)},initLoginWithEmail:async(p,d)=>{let f=new Dr(p,d);t.startAuthFlow(f);try{De.current="email",await f.sendCodeEmail()}catch(b){throw Ce(ce,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},initLoginWithSms:async(p,d)=>{let f=new Hr(p,d);t.startAuthFlow(f);try{De.current="sms",await f.sendSmsCode()}catch(b){throw Ce(ce,"login","onError",b.privyErrorCode||"unknown_auth_error"),b}},resendEmailCode:async()=>{await t.authFlow?.sendCodeEmail()},resendSmsCode:async()=>{await t.authFlow?.sendSmsCode()},loginWithCode:async p=>{if(!n)throw new un;if(t.authFlow instanceof Dr)t.authFlow.meta.emailCode=p.trim();else if(t.authFlow instanceof Hr)t.authFlow.meta.smsCode=p.trim();else throw new w("Must initialize a passwordless code flow first");let d,f;a?d=await t.link():{user:d,isNewUser:f}=await t.authenticate(),c(d||l||null),P(f||!1),s(!0)},refreshUser:async()=>{let p=await t.getAuthenticatedUser();return c(p),p},walletProxy:R,createAnalyticsEvent:(p,d,f)=>t.createAnalyticsEvent(p,d,f),getUsdTokenPrice:p=>t.getUsdTokenPrice(p),recoverEmbeddedWallet:async()=>new Promise(async(p,d)=>{let f=l?.linkedAccounts.find(W=>W.type==="wallet"&&W.walletClientType==="privy"),b=await Ze();if(!b||!R||!f){d(new Error("Must have valid access token and Privy wallet to recover wallet"));return}Me(!0);try{await R.connect({accessToken:b,address:f.address}),p(!0)}catch(W){$r(W)&&f.recoveryMethod==="privy"?(t.createAnalyticsEvent("embedded_wallet_pinless_recovery_started",{walletAddress:f.address}),(await R.recover({address:f.address,accessToken:b})).address||d(new Error("Unable to recover wallet")),t.createAnalyticsEvent("embedded_wallet_recovery_completed",{walletAddress:f.address}),p(!0)):$r(W)?(ot({recoverWallet:{privyWallet:f,onFailure:d,onSuccess:()=>p(!0)}}),be("EMBEDDED_WALLET_RECOVERY_SCREEN")):d(W)}}),getFiatOnRampConfig:dn,setReadyToTrue:()=>{i(!0),ve?.()},updateWallets:()=>Xi()}))();iy=Ue.recoverEmbeddedWallet;let Ty=(0,V.useMemo)(()=>({wallets:y,ready:ht}),[y,ht]);return(0,Lt.jsx)(Fe.Provider,{value:gi,children:(0,Lt.jsx)(Dl.Provider,{value:ce,children:(0,Lt.jsx)(Mc.Provider,{value:Ty,children:(0,Lt.jsxs)(Pp,{...D,children:[e.children,(0,Lt.jsxs)(Ol.Provider,{value:Ue,children:[!jc&&D.captchaEnabled&&(0,Lt.jsx)(Ma,{delayedExecution:!1}),(0,Lt.jsx)(Mh,{theme:{...D.appearance.palette||{}}}),(0,Lt.jsx)(np,{appConfig:D,data:Ve,setModalData:ot,setInitialScreen:_,initialScreen:C,authenticated:a,children:(0,Lt.jsx)(Oh,{open:o})}),Jt&&q.id?(0,Lt.jsx)(Xh,{appId:e.appId,clientAnalyticsId:t.clientAnalyticsId,origin:t.apiUrl,mfaMethods:l?.mfaMethods,mfaPromise:re,mfaSubmitPromise:fo,onLoad:$,onLoadFailed:()=>null}):null]})]})})})})};var sy=require("react");function ly(e){let{login:t}=(0,sy.useContext)(Fe);return Ft("login",e),{login:t}}var cy=require("react");function dy(e){let{logout:t}=(0,cy.useContext)(Fe);return Ft("logout",e),{logout:t}}var Bc=require("react");var py=()=>{let e=Pe(),{initLoginWithEmail:t,loginWithCode:o}=G(),r=(0,Bc.useCallback)(async({email:i})=>{if(!i)throw new Error("Email required to send OTP code");return e.status==="disabled",t(i)},[t]),n=(0,Bc.useCallback)(async({code:i})=>{if(e.enabled&&e.status==="error")throw new Vo(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};var Hc=require("react");var uy=()=>{let e=Pe(),{initLoginWithSms:t,loginWithCode:o}=G(),r=(0,Hc.useCallback)(async({phoneNumber:i})=>{if(!i)throw new Error("SMS required to send OTP code");return e.status==="disabled",t(i)},[t]),n=(0,Hc.useCallback)(async({code:i})=>{if(e.enabled&&e.status!=="success")throw new Vo(e.error,null,"captcha_failure");return o(i)},[o,e.status]);return{sendCode:r,loginWithCode:n}};var my=require("react");function fy(e){let{connectWallet:t}=(0,my.useContext)(Fe);return Ft("connectWallet",e),{connectWallet:t}}var hy=require("react");function yy(e){let{createWallet:t}=(0,hy.useContext)(Fe);return Ft("createWallet",e),{createWallet:t}}var gy=require("react");var vy=()=>{let{isModalOpen:e}=(0,gy.useContext)(Fe);return{isOpen:e}};var wy=require("react");function Cy(e){let{getAccessToken:t}=(0,wy.useContext)(Fe);return Ft("accessToken",e),{getAccessToken:t}}function by(e,t){return{...e,rpcUrls:{...e.rpcUrls,privyWalletOverride:{http:[t]}}}}0&&(module.exports={AsExternalProvider,Captcha,ConnectorManager,PrivyClient,PrivyProvider,PrivyProxyProvider,SUPPORTED_CHAINS,VERSION,WalletConnector,addRpcUrlOverrideToChain,errorIndicatesMaxMfaRetries,errorIndicatesMfaTimeout,errorIndicatesMfaVerificationFailed,getAccessToken,useConnectWallet,useCreateWallet,useLogin,useLoginWithEmail,useLoginWithSms,useLogout,useMfa,useMfaEnrollment,useModalStatus,usePrivy,useRegisterMfaListener,useToken,useWallets});
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.55.2-beta-20240201162656",
2
+ "version": "1.55.2-beta-20240201194530",
3
3
  "name": "@privy-io/react-auth",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [