UNPKG

@privy-io/expo

Version:

Expo client for the Privy Auth API

2 lines (1 loc) • 32.6 kB
import{M as m,Q as he,R as ge,S as fe,a as U,b as de,d as l,e as b,f as g,g as R,i as ue,k as me,l as pe,m as f,n as x,o as F,p as T,w as W}from"./chunk-BVELFONN.js";import{useCallback as q,useContext as ze}from"react";import{PrivyClientError as Je}from"@privy-io/js-sdk-core";var Lt=e=>{let{client:t,setSiweState:s,siweState:n}=ze(m),o=q(a=>{var d;let c=f(a);return s({status:"error",error:c}),(d=e==null?void 0:e.onError)==null||d.call(e,c),c},[e==null?void 0:e.onError]),r=q(h=>l(void 0,[h],function*({wallet:a,from:{domain:c,uri:d}}){var u;try{s({status:"generating-message"});let p=yield t.auth.siwe.init(a,c,d);return s({status:"awaiting-signature"}),(u=e==null?void 0:e.onGenerateMessage)==null||u.call(e,p.message),p.message}catch(p){throw o(p)}}),[t,o,e==null?void 0:e.onGenerateMessage]),i=q(d=>l(void 0,[d],function*({signature:a,messageOverride:c}){var h;try{if(!g())throw new Je({code:"attempted_link_siwe_before_logged_in",error:"Must be logged in to link a wallet, Use `useLoginWithSiwe` to login with a wallet"});s({status:"submitting-signature"});let{user:p}=yield t.auth.siwe.linkWithSiwe(a,void 0,c);return s({status:"done"}),(h=e==null?void 0:e.onSuccess)==null||h.call(e,p),p}catch(u){throw o(u)}}),[t,o,e==null?void 0:e.onSuccess]);return{generateSiweMessage:r,linkWithSiwe:i,state:n}};import{useCallback as $,useContext as Qe}from"react";import{PrivyClientError as Xe}from"@privy-io/js-sdk-core";var Dt=e=>{let{client:t,setSiweState:s,siweState:n}=Qe(m),o=$(a=>{var d;let c=f(a);return s({status:"error",error:c}),(d=e==null?void 0:e.onError)==null||d.call(e,c),c},[e==null?void 0:e.onError]),r=$(h=>l(void 0,[h],function*({wallet:a,from:{domain:c,uri:d}}){var u;try{s({status:"generating-message"});let p=yield t.auth.siwe.init(a,c,d);return s({status:"awaiting-signature"}),(u=e==null?void 0:e.onGenerateMessage)==null||u.call(e,p.message),p.message}catch(p){throw o(p)}}),[t,o,e==null?void 0:e.onGenerateMessage]);return{loginWithSiwe:$(h=>l(void 0,[h],function*({signature:a,messageOverride:c,disableSignup:d}){var u;try{if(g())throw new Xe({code:"attempted_login_with_siwe_while_already_logged_in",error:"Already logged in, use `useLinkWithSiwe` if you are trying to link a wallet to an existing account"});s({status:"submitting-signature"});let y=b(),w=yield t.auth.siwe.loginWithSiwe(a,void 0,c,d?"no-signup":"login-or-sign-up",{embedded:y==null?void 0:y.embedded});return s({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,w.user,w.is_new_user),w.user}catch(p){throw o(p)}}),[t,o,e==null?void 0:e.onSuccess]),generateSiweMessage:r,state:n}};import{useCallback as ye}from"react";import{createSiwsMessage as Ye,PrivyClientError as Ze}from"@privy-io/js-sdk-core";var zt=()=>{let e=W(),t=ye(i=>l(void 0,[i],function*({wallet:{address:n},from:{domain:o,uri:r}}){try{let{nonce:a}=yield e.auth.siws.fetchNonce({address:n});return{message:Ye({address:n,domain:o,uri:r,nonce:a})}}catch(a){throw f(a)}}),[e]),s=ye(a=>l(void 0,[a],function*({signature:n,message:o,wallet:{walletClientType:r,connectorType:i}={}}){try{if(!g())throw new Ze({code:"attempted_link_siws_before_logged_in",error:"Must be logged in to link a wallet, Use `useLoginWithSiws` to login with a wallet"});let{user:d}=yield e.auth.siws.link({signature:n,message:o,walletClientType:r,connectorType:i});return d}catch(c){throw f(c)}}),[e]);return{generateMessage:t,link:s}};import{useCallback as we}from"react";import{createSiwsMessage as er,PrivyClientError as rr}from"@privy-io/js-sdk-core";var to=()=>{let e=W(),t=we(i=>l(void 0,[i],function*({wallet:{address:n},from:{domain:o,uri:r}}){try{let{nonce:a}=yield e.auth.siws.fetchNonce({address:n});return{message:er({address:n,domain:o,uri:r,nonce:a})}}catch(a){throw f(a)}}),[e]),s=we(c=>l(void 0,[c],function*({signature:n,message:o,wallet:{walletClientType:r,connectorType:i}={},disableSignup:a}){try{if(g())throw new rr({code:"attempted_login_with_siws_while_already_logged_in",error:"Already logged in, use `useLinkWithSiws` if you are trying to link a wallet to an existing account"});return(yield e.auth.siws.login({signature:n,message:o,walletClientType:r,connectorType:i,mode:a?"no-signup":"login-or-sign-up"})).user}catch(d){throw f(d)}}),[e]);return{generateMessage:t,login:s}};import{useCallback as ve,useContext as tr}from"react";import{PrivyClientError as or}from"@privy-io/js-sdk-core";var uo=e=>{let{client:t}=tr(m),s=ve(o=>{var i;let r=f(o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkWallet:ve(r=>l(void 0,[r],function*({address:o}){var i;try{if(!g())throw new or({code:"attempted_unlink_siwe_before_logged_in",error:"Must be logged in to unlink a wallet, Use `useLoginWithSiwe` to login with a wallet"});let{user:c}=yield t.auth.siwe.unlinkWallet(o);return(i=e==null?void 0:e.onSuccess)==null||i.call(e,c),c}catch(a){throw s(a)}}),[t,s,e==null?void 0:e.onSuccess])}};import{useCallback as z,useContext as nr,useState as ir}from"react";import{PrivyClientError as ke}from"@privy-io/js-sdk-core";var vo=e=>{let[t,s]=ir(""),{client:n,otpState:o,setOtpState:r}=nr(m),i=z(d=>{var u;let h=f(d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=z(h=>l(void 0,[h],function*({email:d}){var u;s(d);try{r({status:"sending-code"});let p=yield n.auth.email.sendCode(d);return r({status:"awaiting-code-input"}),(u=e==null?void 0:e.onSendCodeSuccess)==null||u.call(e,{email:d}),p}catch(p){throw i(p)}}),[n,i,e,r]),c=z(u=>l(void 0,[u],function*({code:d,email:h}){var p;try{if(!g())throw new ke({code:"attempted_link_email_before_logged_in",error:"Must be logged in to link an email, Use `useLoginWithEmail` to login with email"});let w=h||t;if(!w)throw new ke({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});r({status:"submitting-code"});let{user:v}=yield n.auth.email.linkWithCode(w,d);return r({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,v),v}catch(y){throw i(y)}}),[t,r,n,e,i]);return{sendCode:a,linkWithCode:c,state:o}};import{useCallback as J,useContext as sr,useState as ar}from"react";import{PrivyClientError as Ce}from"@privy-io/js-sdk-core";var Uo=e=>{let[t,s]=ar(""),{client:n,otpState:o,setOtpState:r}=sr(m),i=J(d=>{var u;let h=f(d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=J(h=>l(void 0,[h],function*({email:d}){var u;s(d);try{r({status:"sending-code"});let p=yield n.auth.email.sendCode(d);return r({status:"awaiting-code-input"}),(u=e==null?void 0:e.onSendCodeSuccess)==null||u.call(e,{email:d}),p}catch(p){throw i(p)}}),[n,i,e,r]),c=J(p=>l(void 0,[p],function*({code:d,email:h,disableSignup:u}){var y;try{if(g())throw new Ce({code:"attempted_login_with_email_while_already_logged_in",error:"Already logged in, use `useLinkWithEmail` if you are trying to link an email to an existing account"});let v=h||t;if(!v)throw new Ce({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `loginWithCode`"});r({status:"submitting-code"});let C=b(),k=yield n.auth.email.loginWithCode(v,d,u?"no-signup":"login-or-sign-up",{embedded:C==null?void 0:C.embedded});return r({status:"done"}),(y=e==null?void 0:e.onLoginSuccess)==null||y.call(e,k.user,k.is_new_user),k==null?void 0:k.user}catch(w){throw i(w)}}),[t,r,n,e,i]);return{sendCode:a,loginWithCode:c,state:o}};import{useCallback as Q,useContext as cr,useState as lr}from"react";import{PrivyClientError as be}from"@privy-io/js-sdk-core";var Fo=e=>{let[t,s]=lr(""),{client:n,otpState:o,setOtpState:r}=cr(m),i=Q(d=>{var u;let h=f(d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=Q(h=>l(void 0,[h],function*({phone:d}){var u;s(d);try{r({status:"sending-code"});let p=yield n.auth.phone.sendCode(d);return r({status:"awaiting-code-input"}),(u=e==null?void 0:e.onSendCodeSuccess)==null||u.call(e,{phone:d}),p}catch(p){throw i(p)}}),[n,i,e,r]),c=Q(u=>l(void 0,[u],function*({code:d,phone:h}){var p;try{if(!g())throw new be({code:"attempted_link_sms_before_logged_in",error:"Must be logged in to link a phone number, Use `useLoginWithSMS` to login with a phone number"});if(!(h||t))throw new be({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});r({status:"submitting-code"});let{user:v}=yield n.auth.phone.linkWithCode(h||t,d);return r({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,v),v}catch(y){throw i(y)}}),[t,r,n,e,i]);return{sendCode:a,linkWithCode:c,state:o}};import{useCallback as X,useContext as dr,useState as ur}from"react";import{PrivyClientError as Se}from"@privy-io/js-sdk-core";var jo=e=>{let[t,s]=ur(""),{client:n,otpState:o,setOtpState:r}=dr(m),i=X(d=>{var u;let h=f(d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=X(h=>l(void 0,[h],function*({phone:d}){var u;s(d);try{r({status:"sending-code"});let p=yield n.auth.phone.sendCode(d);return r({status:"awaiting-code-input"}),(u=e==null?void 0:e.onSendCodeSuccess)==null||u.call(e,{phone:d}),p}catch(p){throw i(p)}}),[n,i,e,r]),c=X(p=>l(void 0,[p],function*({code:d,phone:h,disableSignup:u}){var y;try{if(g())throw new Se({code:"attempted_login_with_sms_while_already_logged_in",error:"Already logged in, use `useLinkWithSMS` if you are trying to link a phone number to an existing account"});if(!(h||t))throw new Se({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});r({status:"submitting-code"});let C=b(),k=yield n.auth.phone.loginWithCode(h||t,d,u?"no-signup":"login-or-sign-up",{embedded:C==null?void 0:C.embedded});return r({status:"done"}),(y=e==null?void 0:e.onLoginSuccess)==null||y.call(e,k.user,k.is_new_user),k==null?void 0:k.user}catch(w){throw i(w)}}),[t,r,n,e,i]);return{sendCode:a,loginWithCode:c,state:o}};import*as H from"expo-linking";import{useCallback as Y,useContext as mr,useRef as pr}from"react";import{PrivyClientError as M}from"@privy-io/js-sdk-core";var Zo=e=>{let{appState:t,getCurrentAppState:s}=F(),{client:n,farcasterState:o,setFarcasterState:r}=mr(m),i=pr(!1),a=Y(h=>{var p;let u=f(h);return r({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e==null?void 0:e.onError,r]),c=Y(()=>{i.current=!0},[]);return{linkWithFarcaster:Y((y,...w)=>l(void 0,[y,...w],function*({relyingParty:h,redirectUrl:u},p={pollAttempts:10,pollIntervalMs:1e3}){var v;try{let C=g();if(i.current=!1,!C)throw new M({code:"attempted_link_farcaster_before_logged_in",error:"Must be logged in to link a Farcaster account."});r({status:"generating-uri"});let{connect_uri:k,channel_token:P}=yield n.auth.farcaster.initializeAuth({relyingParty:h,redirectUrl:H.createURL(u!=null?u:"/")});if(!k)throw new M({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!P)throw new M({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield H.openURL(k),r({status:"polling-status"});let _=0;for(;_<p.pollAttempts;){if(i.current)throw new M({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&s()!=="active"){yield x(p.pollIntervalMs);continue}let A=yield n.auth.farcaster.getFarcasterStatus({channel_token:P});if(A.state==="completed"){r({status:"submitting-token"});let{user:L}=yield n.auth.farcaster.link(U({channel_token:P},A));return r({status:"done"}),(v=e==null?void 0:e.onSuccess)==null||v.call(e,L),L}_++,yield x(p.pollIntervalMs)}throw new M({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(C){throw a(C)}}),[n,e==null?void 0:e.onSuccess,a,r]),state:o,cancel:c}};import{useCallback as We,useContext as hr}from"react";var sn=e=>{let{client:t}=hr(m),s=We(o=>{var i;let r=f(o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkFarcaster:We(r=>l(void 0,[r],function*({fid:o}){var i;try{let{user:a}=yield t.auth.farcaster.unlink({fid:o});return(i=e==null?void 0:e.onSuccess)==null||i.call(e,a),a}catch(a){throw s(a)}}),[t,e==null?void 0:e.onSuccess,s])}};import*as N from"expo-linking";import{useCallback as re,useContext as gr,useRef as fr}from"react";import{PrivyClientError as O}from"@privy-io/js-sdk-core";var gn=e=>{let{appState:t,getCurrentAppState:s}=F(),{client:n,farcasterState:o,setFarcasterState:r}=gr(m),i=fr(!1),a=re(h=>{var p;let u=f(h);return r({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e==null?void 0:e.onError,r]),c=re(()=>{i.current=!0},[]);return{loginWithFarcaster:re((w,...v)=>l(void 0,[w,...v],function*({relyingParty:h,redirectUrl:u,disableSignup:p},y={pollAttempts:10,pollIntervalMs:1e3}){var C;try{if(i.current=!1,g())throw new O({code:"attempted_login_with_farcaster_while_already_logged_in",error:"Already logged in, use `useLinkWithFarcaster` if you are trying to link farcaster to an existing account"});r({status:"generating-uri"});let{connect_uri:P,channel_token:_}=yield n.auth.farcaster.initializeAuth({relyingParty:h,redirectUrl:N.createURL(u!=null?u:"/")});if(!P)throw new O({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!_)throw new O({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield N.openURL(P),r({status:"polling-status"});let A=0;for(;A<y.pollAttempts;){if(i.current)throw new O({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&s()!=="active"){yield x(y.pollIntervalMs);continue}let L=yield n.auth.farcaster.getFarcasterStatus({channel_token:_});if(L.state==="completed"){r({status:"submitting-token"});let K=b(),j=yield n.auth.farcaster.authenticate(U({channel_token:_,mode:p?"no-signup":"login-or-sign-up"},L),{embedded:K==null?void 0:K.embedded});return r({status:"done"}),(C=e==null?void 0:e.onSuccess)==null||C.call(e,j.user,j.is_new_user),j.user}A++,yield x(y.pollIntervalMs)}throw new O({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(k){throw a(k)}}),[n,a,e==null?void 0:e.onSuccess,r,t]),state:o,cancel:c}};import{useCallback as Ee,useContext as yr}from"react";import{create as wr}from"zustand";import{PrivyClientError as vr}from"@privy-io/js-sdk-core";var te=wr(()=>({status:"initial"})),E=e=>te.setState(e,!0),kr=te.getState,En=()=>{let{client:e}=yr(m),t=te(),s=Ee(()=>l(void 0,null,function*(){try{E({status:"fetching-nonce"});let o=yield e.auth.farcasterV2.initializeAuth();return E({status:"awaiting-signature"}),o}catch(o){let r=f(o);throw E({status:"initial",error:r}),r}}),[e]),n=Ee(o=>l(void 0,null,function*(){let r=kr().status;try{if(g()){let d=new vr({code:"attempted_login_with_farcaster_while_already_logged_in",error:"Already logged in, use a link helper if you are trying to link farcaster to an existing account"});throw E({status:r,error:d}),d}E({status:"submitting-signature"});let a=b(),c=yield e.auth.farcasterV2.authenticate(o,{embedded:a==null?void 0:a.embedded});return E({status:"done"}),setTimeout(()=>E({status:"initial"}),1500),{user:c.user}}catch(i){let a=f(i);throw E({status:r,error:a}),a}}),[e]);return{init:s,login:n,state:t}};import{useCallback as Pe,useContext as Cr}from"react";var Ln=e=>{let{client:t}=Cr(m),s=Pe(o=>{var i;let r=f(o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkOAuth:Pe(i=>l(void 0,[i],function*({provider:o,subject:r}){var a;try{let{user:c}=yield t.auth.oauth.unlink(o,r);return(a=e==null?void 0:e.onSuccess)==null||a.call(e,c),c}catch(c){throw s(c)}}),[t,e==null?void 0:e.onSuccess,s])}};import{useContext as br,useEffect as Sr,useRef as Wr}from"react";var Fn=e=>{let{client:t}=br(m),s=Wr(e.onOAuthTokenGrant);s.current=e.onOAuthTokenGrant,Sr(()=>{let{unsubscribe:n}=t.addOAuthTokensListener(o=>{s.current(o)});return n},[t])};import{useContext as Er,useMemo as Pr}from"react";import{delegatedActions as _e}from"@privy-io/js-sdk-core";var Bn=()=>{let{client:e}=Er(m);return Pr(()=>({delegateWallet:_e.delegateWallet(e),revokeWallets:_e.revokeWallets(e)}),[e])};import{useContext as _r,useMemo as Ur}from"react";import{PrivyClientError as xe}from"@privy-io/js-sdk-core";var $n=()=>{let{client:e}=_r(m);return Ur(()=>({sendCode(n){return l(this,arguments,function*({newEmailAddress:s}){Ue(),yield e.auth.email.sendCode(s)})},updateEmail(o){return l(this,arguments,function*({newEmailAddress:s,code:n}){let{address:r}=Ue(),{user:i}=yield e.auth.email.updateEmail({oldEmailAddress:r,newEmailAddress:s,code:n});return i})}}),[e])};function Ue(){let t=xr().linked_accounts.find(s=>s.type==="email");if(!t)throw new xe({code:"attempted_update_email_without_a_linked_email",error:"Must have a linked email account already to update an email address. Use `useLinkEmail` to link an email account."});return t}function xr(){let e=g();if(!e)throw new xe({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import{useContext as Ar,useMemo as Lr}from"react";import{PrivyClientError as Le}from"@privy-io/js-sdk-core";var ei=()=>{let{client:e}=Ar(m);return Lr(()=>({sendCode(n){return l(this,arguments,function*({newPhoneNumber:s}){Ae(),yield e.auth.phone.sendCode(s)})},updatePhone(o){return l(this,arguments,function*({newPhoneNumber:s,code:n}){let{phoneNumber:r}=Ae(),{user:i}=yield e.auth.phone.updatePhone({oldPhoneNumber:r,newPhoneNumber:s,code:n});return i})}}),[e])};function Ae(){let t=Mr().linked_accounts.find(s=>s.type==="phone");if(!t)throw new Le({code:"attempted_update_phone_without_a_linked_phone",error:"Must have a linked phone account already to update a phone number. Use `useLinkSMS` to link a phone number."});return t}function Mr(){let e=g();if(!e)throw new Le({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import*as Re from"expo-linking";import{useCallback as Fr,useContext as Tr,useMemo as Hr}from"react";import{crossApp as Nr,PrivyClientError as Dr}from"@privy-io/js-sdk-core";import*as D from"expo-linking";import*as Oe from"expo-web-browser";import{Platform as Me}from"react-native";import{PrivyClientError as Ie}from"@privy-io/js-sdk-core";var S=e=>l(void 0,null,function*(){let t;Me.OS==="android"&&(t=Or());let s=yield Oe.openAuthSessionAsync(e),n;if(Me.OS==="android")n=yield t;else{if(s.type!=="success")throw new Ie({code:"oauth_session_failed",error:"OAuth session failed"});n=s.url}return Ir(n)});function Or(){let e;return new Promise((t,s)=>{e=D.addEventListener("url",({url:n})=>{n&&t(n)}),setTimeout(()=>{s(new Ie({code:"oauth_session_timeout",error:"OAuth session timed out"}))},Rr)}).finally(()=>{e==null||e.remove()})}function Ir(e){let{queryParams:t}=D.parse(e);return t}var Rr=2*60*1e3;var mi=()=>{let{client:e}=Tr(m),t=Hr(()=>Nr.loginWithCrossAppAuth({client:e,openAuthSession:S}),[e]);return{loginWithCrossApp:Fr(r=>l(void 0,[r],function*({appId:n,redirectUri:o}){if(g())throw new Dr({code:"attempted_login_with_cross_app_while_already_logged_in",error:"Already logged in, use `linkCrossAppAccount` if you are trying to link a cross app account to an existing account"});let{user:a}=yield t({providerAppId:n,redirectUrl:Re.createURL(o||"/")});return{user:a}}),[t])}};import*as Fe from"expo-linking";import{useCallback as Br,useContext as Gr,useMemo as Vr}from"react";import{crossApp as Kr,PrivyClientError as jr}from"@privy-io/js-sdk-core";var ki=()=>{let{client:e}=Gr(m),t=Vr(()=>Kr.linkWithCrossAppAuth({client:e,openAuthSession:S}),[e]);return{linkWithCrossApp:Br(r=>l(void 0,[r],function*({appId:n,redirectUri:o}){if(!g())throw new jr({code:"attempted_link_cross_app_before_logged_in",error:"Must be logged in to link a cross app account, Use `loginWithCrossAppAccount` to login with cross app"});return{user:yield t({providerAppId:n,redirectUrl:Fe.createURL(o||"/")})}}),[t])}};import*as He from"expo-linking";import{useContext as qr,useMemo as Te}from"react";import{crossApp as $r}from"@privy-io/js-sdk-core";var Ui=()=>{let{client:e}=qr(m),t=Te(()=>$r.wallet.signMessage({client:e,openAuthSession:S}),[e]);return Te(()=>({signMessage:({address:s,message:n,redirectUri:o="/"})=>t({user:g(),address:s,message:n,redirectUrl:He.createURL(o)})}),[t])};import*as De from"expo-linking";import{useContext as zr,useMemo as Ne}from"react";import{crossApp as Jr}from"@privy-io/js-sdk-core";var Ri=()=>{let{client:e}=zr(m),t=Ne(()=>Jr.wallet.signTypedData({client:e,openAuthSession:S}),[e]);return Ne(()=>({signTypedData:({address:s,typedData:n,redirectUri:o="/"})=>t({user:g(),address:s,typedData:n,redirectUrl:De.createURL(o)})}),[t])};import*as Ge from"expo-linking";import{useContext as Qr,useMemo as Be}from"react";import{crossApp as Xr}from"@privy-io/js-sdk-core";var Gi=()=>{let{client:e}=Qr(m),t=Be(()=>Xr.wallet.sendTransaction({client:e,openAuthSession:S}),[e]);return Be(()=>({sendTransaction:({address:s,transaction:n,redirectUri:o="/"})=>t({user:g(),address:s,transaction:n,redirectUrl:Ge.createURL(o)})}),[t])};import{useCallback as Yr,useContext as Zr}from"react";import{getUserEmbeddedEthereumWallet as et,getUserEmbeddedSolanaWallet as rt,PrivyClientError as I,throwIfInvalidRecoveryUpgradePath as tt}from"@privy-io/js-sdk-core";var Qi=()=>{let{client:e}=Zr(m);return{setRecovery:Yr(s=>l(void 0,null,function*(){var a;let n=g(),o=e.app.appId;if(!n)throw new I({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let r=(a=et(n))!=null?a:rt(n);if(!r)throw new I({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});try{r.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(r):r.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(r,r.address,"solana-address-verifier"))}catch(c){throw new I({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}tt({currentRecoveryMethod:r.recovery_method,upgradeToRecoveryMethod:s.recoveryMethod});let i=yield ot({appId:o,client:e,user:n,primaryAccount:r,recoveryParams:s});try{let{user:c}=yield e.embeddedWallet.setRecovery(i);return{user:c}}catch(c){throw new I({code:"embedded_wallet_set_recovery_error",error:c instanceof Error?c.message:"Error setting password on embedded wallet"})}}),[e])}},ot=r=>l(void 0,[r],function*({appId:e,client:t,user:s,primaryAccount:n,recoveryParams:o}){switch(o.recoveryMethod){case"privy":return{recoveryMethod:"privy",wallet:n};case"user-passcode":return de(U({},o),{wallet:n});case"google-drive":{let i=yield T(t);return{recoveryMethod:"google-drive",wallet:n,recoveryAccessToken:i}}case"icloud":{let{recoverySecret:i,iCloudRecordName:a}=yield me({appId:e,client:t,user:s});return{recoveryMethod:"icloud-native",recoverySecretOverride:i,iCloudRecordNameOverride:a,wallet:n}}case"recovery-encryption-key":return{recoveryMethod:"recovery-encryption-key",wallet:n,recoveryKey:o.recoveryKey};default:throw new I({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}});import{useCallback as nt,useContext as it}from"react";import{getUserEmbeddedEthereumWallet as st,getUserEmbeddedSolanaWallet as at,PrivyClientError as B}from"@privy-io/js-sdk-core";var is=()=>{let{client:e}=it(m);return{recover:nt(s=>l(void 0,null,function*(){var d;let n=g();if(!n)throw new B({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let o=(d=st(n))!=null?d:at(n);if(!o)throw new B({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let r,i,a,c;switch(s.recoveryMethod){case"user-passcode":i=s.password;break;case"google-drive":a=yield T(e);break;case"icloud":let{recoverySecret:h}=yield pe({client:e,walletAddress:o.address,chainType:o.chain_type});c=h;break;case"recovery-encryption-key":r=s.recoveryKey;break;case"privy":break;default:throw new B({code:"unsupported_recovery_method",error:`Unsupported recovery options ${s}`})}try{o.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(o,i,a,c,r):o.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(o,o.address,"solana-address-verifier",i,a,c))}catch(h){throw new B({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};import{useContext as ct,useEffect as oe}from"react";var ne=(e={})=>{let{wallet:t,createWalletCallbacks:s,recoverWalletCallbacks:n,setWalletRecoveryCallbacks:o}=ct(m),{onCreateWalletSuccess:r,onCreateWalletError:i,onRecoverWalletError:a,onRecoverWalletSuccess:c,onSetWalletRecoverySuccess:d,onSetWalletRecoveryError:h}=e;return oe(()=>{s.current={onSuccess:r,onError:i}},[r,i]),oe(()=>{n.current={onSuccess:c,onError:a}},[c,a]),oe(()=>{o.current={onSuccess:d,onError:h}},[c,a]),t};import{useEffect as lt}from"react";var ps=({onStateChange:e})=>{let t=ne();return lt(()=>{e(t)},[t])};import{useContext as dt}from"react";var ys=()=>{let{getIdentityToken:e}=dt(m);return{getIdentityToken:e}};import{useCallback as Ve,useContext as ut}from"react";import{PrivyClientError as mt}from"@privy-io/js-sdk-core";var Es=e=>{let{client:t}=ut(m),s=Ve(o=>{var i;let r=f(o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{create:Ve(()=>l(void 0,null,function*(){var o;try{if(g())throw new mt({code:"attempted_to_create_guest_account_for_logged_in_user",error:"Already logged in, you cannot create a guest account"});let i=b(),a=yield t.auth.guest.create({embedded:i==null?void 0:i.embedded});return(o=e==null?void 0:e.onSuccess)==null||o.call(e,a.user,a.is_new_user),a.user}catch(r){throw s(r)}}),[t,s,e==null?void 0:e.onSuccess])}};import{useContext as pt,useEffect as ht}from"react";function Ls({onMfaRequired:e}){let{client:t}=pt(m);ht(()=>{function s(){return l(this,null,function*(){var o;let n=g();yield e((o=n==null?void 0:n.mfa_methods.map(({type:r})=>r))!=null?o:[])})}return t.mfaPromises.on("mfaRequired",s),()=>{t.mfaPromises.off("mfaRequired",s)}},[t,e])}import{useCallback as G,useContext as gt}from"react";import{PrivyClientError as V}from"@privy-io/js-sdk-core";function Ns(){let{client:e}=gt(m),t=G(r=>l(this,null,function*(){var i,a;switch(r.method){case"sms":yield e.mfa.sms.sendCode({action:"verify"});return;case"passkey":let{options:c}=yield e.mfa.passkey.generateAuthenticationOptions({relying_party:r.relyingParty||((a=(i=b())==null?void 0:i.mfa)==null?void 0:a.relyingParty)});return fe(c);case"totp":return;default:throw new Error(`Unsupported MFA method: ${r.mfaMethod}`)}}),[e]),s=G(r=>l(this,null,function*(){var i,a,c,d,h,u,p;switch(r.method){case"totp":case"sms":if(typeof r.mfaCode!="string")throw new V({code:"invalid_mfa_code",error:"Invalid MFA code"});(c=e.mfaPromises.rootPromise.current)==null||c.resolve({mfaMethod:r.method,mfaCode:r.mfaCode,relyingParty:r.relyingParty||((a=(i=b())==null?void 0:i.mfa)==null?void 0:a.relyingParty)||""}),yield new Promise((C,k)=>{e.mfaPromises.submitPromise.current={resolve:C,reject:k}});break;case"passkey":if(typeof r.mfaCode=="string")throw new V({code:"invalid_passkey_response",error:"Invalid authenticator response"});let y=yield he(r.mfaCode),w=ge(y);(u=e.mfaPromises.rootPromise.current)==null||u.resolve({mfaMethod:r.method,relyingParty:r.relyingParty||((h=(d=b())==null?void 0:d.mfa)==null?void 0:h.relyingParty)||"",mfaCode:w}),yield new Promise((C,k)=>{e.mfaPromises.submitPromise.current={resolve:C,reject:k}});break;default:let v=new V({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(p=e.mfaPromises.rootPromise.current)==null||p.reject(v),v}}),[e]),n=G(()=>l(this,null,function*(){yield e.mfa.verifyMfa()}),[e]),o=G(()=>{var r;(r=e.mfaPromises.rootPromise.current)==null||r.reject(new V({code:"mfa_canceled",error:"MFA canceled"}))},[e]);return{init:t,submit:s,prompt:n,cancel:o}}import{useCallback as ie,useContext as ft}from"react";function Ks(){let{client:e}=ft(m),t=ie(o=>l(this,null,function*(){switch(o.method){case"sms":case"totp":return yield e.mfa.initEnrollMfa(o);case"passkey":return;default:throw new Error(`Unsupported MFA method: ${o.method}`)}}),[e]),s=ie(o=>l(this,null,function*(){switch(o.method){case"sms":case"totp":case"passkey":yield e.mfa.submitEnrollMfa(o);return;default:throw new Error(`Unsupported MFA method: ${o.method}`)}}),[e]),n=ie(o=>l(this,null,function*(){switch(o.method){case"sms":case"totp":yield e.mfa.unenrollMfa(o.method);return;case"passkey":yield e.mfa.submitEnrollMfa({method:"passkey",credentialIds:[],removeForLogin:o.removeForLogin});return;default:throw new Error(`Unsupported MFA method: ${o.method}`)}}),[e]);return{initMfaEnrollment:t,submitMfaEnrollment:s,unenrollMfa:n}}import{useCallback as yt,useMemo as wt}from"react";import{getAllUserEmbeddedEthereumWallets as ae,getEntropyDetailsFromUser as Ke,getUserEmbeddedSolanaWallet as vt,PrivyClientError as je}from"@privy-io/js-sdk-core";var kt=()=>{let e=R(),t=W(),s=wt(()=>{let r=ae(e).map(i=>{let a=Ke(e,i);return a?{account:i,entropy:a}:null});return r.some(i=>i===null)?[]:r.filter(i=>i!==null).map(({account:i,entropy:{entropyId:a,entropyIdVerifier:c}})=>({address:i.address,walletIndex:i.wallet_index,chainType:i.chain_type,getProvider:()=>t.embeddedWallet.getEthereumProvider({wallet:i,entropyId:a,entropyIdVerifier:c,onNeedsRecovery:d=>l(void 0,null,function*(){var h;yield(h=ue())==null?void 0:h(d)})})}))},[t,e]),n=yt((...r)=>l(void 0,[...r],function*({createAdditional:o=!1}={}){let{user:i}=yield t.user.get(),a=ae(i);if(!o&&a.length>0)throw new je({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let c=Ke(i);if(!c){let w=yield t.embeddedWallet.create({});return se(w.user,0),{user:w.user}}let{entropyId:d,entropyIdVerifier:h}=c;if(h==="solana-address-verifier"){let w=vt(i),v=yield t.embeddedWallet.create({solanaAccount:w});return se(v.user,0),{user:v.user}}let p=a.map(w=>w.wallet_index).reduce((w,v)=>Math.max(w,v),0)+1,y=yield t.embeddedWallet.add({chainType:"ethereum",hdWalletIndex:p,entropyId:d,entropyIdVerifier:h});return se(y.user,p),{user:y.user}}),[t]);return{wallets:s,create:n}};function se(e,t){let s=ae(e).find(n=>n.wallet_index===t);if(!e||!s)throw new je({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}import{useContext as Ct,useEffect as qe}from"react";var bt=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:s,recoverSolanaWalletCallbacks:n}=Ct(m),{onCreateWalletSuccess:o,onCreateWalletError:r,onRecoverWalletError:i,onRecoverWalletSuccess:a}=e;return qe(()=>{s.current={onSuccess:o,onError:r}},[o,r]),qe(()=>{n.current={onSuccess:a,onError:i}},[a,i]),t};import{useCallback as St,useMemo as Wt}from"react";import{getAllUserEmbeddedBitcoinWallets as ce,getEntropyDetailsFromUser as $e,PrivyClientError as le}from"@privy-io/js-sdk-core";var Et=()=>{let e=R(),t=W(),s=Wt(()=>{let o=$e(e);if(!o)return[];let r=ce(e),{entropyId:i,entropyIdVerifier:a}=o;return r.map(c=>({address:c.address,walletIndex:c.wallet_index,publicKey:c.public_key,chainType:c.chain_type,getProvider:()=>t.embeddedWallet.getBitcoinProvider({wallet:c,entropyId:i,entropyIdVerifier:a})}))},[t,e]),n=St(i=>l(void 0,[i],function*({chainType:o,createAdditional:r=!1}){let{user:a}=yield t.user.get(),c=$e(a);if(!c)throw new le({code:"embedded_wallet_creation_error",error:"No existing wallet for this user, create an Ethereum walet first to add a Bitcoin wallet"});let{entropyId:d,entropyIdVerifier:h}=c,u=ce(a).filter(v=>v.chain_type===o);if(!r&&u.length>0)throw new le({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let p=u.length===0?0:Math.max(...u.map(v=>v.wallet_index),0)+1,y=yield t.embeddedWallet.add({chainType:o,hdWalletIndex:p,entropyId:d,entropyIdVerifier:h}),w=ce(y.user).find(v=>v.chain_type===o&&v.wallet_index===p);if(!y.user||!w)throw new le({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"});return{user:y.user,provider:yield t.embeddedWallet.getBitcoinProvider({wallet:w,entropyId:d,entropyIdVerifier:h})}}),[t]);return{wallets:s,create:n}};export{Lt as a,Dt as b,zt as c,to as d,uo as e,vo as f,Uo as g,Fo as h,jo as i,Zo as j,sn as k,gn as l,En as m,Ln as n,Fn as o,Bn as p,$n as q,ei as r,mi as s,ki as t,Ui as u,Ri as v,Gi as w,Qi as x,is as y,ne as z,ps as A,ys as B,Es as C,Ls as D,Ns as E,Ks as F,kt as G,bt as H,Et as I};