@privy-io/expo
Version:
Expo client for the Privy Auth API
2 lines (1 loc) • 39.3 kB
JavaScript
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _chunkBVELFONNjs = require('./chunk-BVELFONN.js');var _react = require('react');var _jssdkcore = require('@privy-io/js-sdk-core');var Lt=e=>{let{client:t,setSiweState:s,siweState:n}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),o=_react.useCallback.call(void 0, a=>{var d;let c=_chunkBVELFONNjs.m.call(void 0, 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=_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, d=>_chunkBVELFONNjs.d.call(void 0, void 0,[d],function*({signature:a,messageOverride:c}){var h;try{if(!_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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}};var Dt=e=>{let{client:t,setSiweState:s,siweState:n}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),o=_react.useCallback.call(void 0, a=>{var d;let c=_chunkBVELFONNjs.m.call(void 0, 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=_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, 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:_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, void 0,[h],function*({signature:a,messageOverride:c,disableSignup:d}){var u;try{if(_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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=_chunkBVELFONNjs.e.call(void 0, ),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}};var zt=()=>{let e=_chunkBVELFONNjs.w.call(void 0, ),t=_react.useCallback.call(void 0, i=>_chunkBVELFONNjs.d.call(void 0, 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:_jssdkcore.createSiwsMessage.call(void 0, {address:n,domain:o,uri:r,nonce:a})}}catch(a){throw _chunkBVELFONNjs.m.call(void 0, a)}}),[e]),s=_react.useCallback.call(void 0, a=>_chunkBVELFONNjs.d.call(void 0, void 0,[a],function*({signature:n,message:o,wallet:{walletClientType:r,connectorType:i}={}}){try{if(!_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 _chunkBVELFONNjs.m.call(void 0, c)}}),[e]);return{generateMessage:t,link:s}};var to=()=>{let e=_chunkBVELFONNjs.w.call(void 0, ),t=_react.useCallback.call(void 0, i=>_chunkBVELFONNjs.d.call(void 0, 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:_jssdkcore.createSiwsMessage.call(void 0, {address:n,domain:o,uri:r,nonce:a})}}catch(a){throw _chunkBVELFONNjs.m.call(void 0, a)}}),[e]),s=_react.useCallback.call(void 0, c=>_chunkBVELFONNjs.d.call(void 0, void 0,[c],function*({signature:n,message:o,wallet:{walletClientType:r,connectorType:i}={},disableSignup:a}){try{if(_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 _chunkBVELFONNjs.m.call(void 0, d)}}),[e]);return{generateMessage:t,login:s}};var uo=e=>{let{client:t}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),s=_react.useCallback.call(void 0, o=>{var i;let r=_chunkBVELFONNjs.m.call(void 0, o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkWallet:_react.useCallback.call(void 0, r=>_chunkBVELFONNjs.d.call(void 0, void 0,[r],function*({address:o}){var i;try{if(!_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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])}};var vo=e=>{let[t,s]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),i=_react.useCallback.call(void 0, d=>{var u;let h=_chunkBVELFONNjs.m.call(void 0, d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, u=>_chunkBVELFONNjs.d.call(void 0, void 0,[u],function*({code:d,email:h}){var p;try{if(!_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({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}};var Uo=e=>{let[t,s]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),i=_react.useCallback.call(void 0, d=>{var u;let h=_chunkBVELFONNjs.m.call(void 0, d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, p=>_chunkBVELFONNjs.d.call(void 0, void 0,[p],function*({code:d,email:h,disableSignup:u}){var y;try{if(_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `loginWithCode`"});r({status:"submitting-code"});let C=_chunkBVELFONNjs.e.call(void 0, ),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}};var Fo=e=>{let[t,s]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),i=_react.useCallback.call(void 0, d=>{var u;let h=_chunkBVELFONNjs.m.call(void 0, d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, u=>_chunkBVELFONNjs.d.call(void 0, void 0,[u],function*({code:d,phone:h}){var p;try{if(!_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({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}};var jo=e=>{let[t,s]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),i=_react.useCallback.call(void 0, d=>{var u;let h=_chunkBVELFONNjs.m.call(void 0, d);return r({status:"error",error:h}),(u=e==null?void 0:e.onError)==null||u.call(e,h),h},[e,r]),a=_react.useCallback.call(void 0, h=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, p=>_chunkBVELFONNjs.d.call(void 0, void 0,[p],function*({code:d,phone:h,disableSignup:u}){var y;try{if(_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});r({status:"submitting-code"});let C=_chunkBVELFONNjs.e.call(void 0, ),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}};var _expolinking = require('expo-linking'); var H = _interopRequireWildcard(_expolinking); var N = _interopRequireWildcard(_expolinking); var Re = _interopRequireWildcard(_expolinking); var D = _interopRequireWildcard(_expolinking); var Fe = _interopRequireWildcard(_expolinking); var He = _interopRequireWildcard(_expolinking); var De = _interopRequireWildcard(_expolinking); var Ge = _interopRequireWildcard(_expolinking);var Zo=e=>{let{appState:t,getCurrentAppState:s}=_chunkBVELFONNjs.o.call(void 0, ),{client:n,farcasterState:o,setFarcasterState:r}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),i=_react.useRef.call(void 0, !1),a=_react.useCallback.call(void 0, h=>{var p;let u=_chunkBVELFONNjs.m.call(void 0, 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=_react.useCallback.call(void 0, ()=>{i.current=!0},[]);return{linkWithFarcaster:_react.useCallback.call(void 0, (y,...w)=>_chunkBVELFONNjs.d.call(void 0, void 0,[y,...w],function*({relyingParty:h,redirectUrl:u},p={pollAttempts:10,pollIntervalMs:1e3}){var v;try{let C=_chunkBVELFONNjs.f.call(void 0, );if(i.current=!1,!C)throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!P)throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&s()!=="active"){yield _chunkBVELFONNjs.n.call(void 0, 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(_chunkBVELFONNjs.a.call(void 0, {channel_token:P},A));return r({status:"done"}),(v=e==null?void 0:e.onSuccess)==null||v.call(e,L),L}_++,yield _chunkBVELFONNjs.n.call(void 0, p.pollIntervalMs)}throw new (0, _jssdkcore.PrivyClientError)({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}};var sn=e=>{let{client:t}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),s=_react.useCallback.call(void 0, o=>{var i;let r=_chunkBVELFONNjs.m.call(void 0, o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkFarcaster:_react.useCallback.call(void 0, r=>_chunkBVELFONNjs.d.call(void 0, 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])}};var gn=e=>{let{appState:t,getCurrentAppState:s}=_chunkBVELFONNjs.o.call(void 0, ),{client:n,farcasterState:o,setFarcasterState:r}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),i=_react.useRef.call(void 0, !1),a=_react.useCallback.call(void 0, h=>{var p;let u=_chunkBVELFONNjs.m.call(void 0, 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=_react.useCallback.call(void 0, ()=>{i.current=!0},[]);return{loginWithFarcaster:_react.useCallback.call(void 0, (w,...v)=>_chunkBVELFONNjs.d.call(void 0, void 0,[w,...v],function*({relyingParty:h,redirectUrl:u,disableSignup:p},y={pollAttempts:10,pollIntervalMs:1e3}){var C;try{if(i.current=!1,_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!_)throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&s()!=="active"){yield _chunkBVELFONNjs.n.call(void 0, y.pollIntervalMs);continue}let L=yield n.auth.farcaster.getFarcasterStatus({channel_token:_});if(L.state==="completed"){r({status:"submitting-token"});let K=_chunkBVELFONNjs.e.call(void 0, ),j=yield n.auth.farcaster.authenticate(_chunkBVELFONNjs.a.call(void 0, {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 _chunkBVELFONNjs.n.call(void 0, y.pollIntervalMs)}throw new (0, _jssdkcore.PrivyClientError)({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}};var _zustand = require('zustand');var te=_zustand.create.call(void 0, ()=>({status:"initial"})),E=e=>te.setState(e,!0),kr=te.getState,En= exports.m =()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=te(),s=_react.useCallback.call(void 0, ()=>_chunkBVELFONNjs.d.call(void 0, 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=_chunkBVELFONNjs.m.call(void 0, o);throw E({status:"initial",error:r}),r}}),[e]),n=_react.useCallback.call(void 0, o=>_chunkBVELFONNjs.d.call(void 0, void 0,null,function*(){let r=kr().status;try{if(_chunkBVELFONNjs.f.call(void 0, )){let d=new (0, _jssdkcore.PrivyClientError)({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=_chunkBVELFONNjs.e.call(void 0, ),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=_chunkBVELFONNjs.m.call(void 0, i);throw E({status:r,error:a}),a}}),[e]);return{init:s,login:n,state:t}};var Ln=e=>{let{client:t}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),s=_react.useCallback.call(void 0, o=>{var i;let r=_chunkBVELFONNjs.m.call(void 0, o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkOAuth:_react.useCallback.call(void 0, i=>_chunkBVELFONNjs.d.call(void 0, 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])}};var Fn=e=>{let{client:t}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),s=_react.useRef.call(void 0, e.onOAuthTokenGrant);s.current=e.onOAuthTokenGrant,_react.useEffect.call(void 0, ()=>{let{unsubscribe:n}=t.addOAuthTokensListener(o=>{s.current(o)});return n},[t])};var Bn=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);return _react.useMemo.call(void 0, ()=>({delegateWallet:_jssdkcore.delegatedActions.delegateWallet(e),revokeWallets:_jssdkcore.delegatedActions.revokeWallets(e)}),[e])};var $n=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);return _react.useMemo.call(void 0, ()=>({sendCode(n){return _chunkBVELFONNjs.d.call(void 0, this,arguments,function*({newEmailAddress:s}){Ue(),yield e.auth.email.sendCode(s)})},updateEmail(o){return _chunkBVELFONNjs.d.call(void 0, 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 (0, _jssdkcore.PrivyClientError)({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=_chunkBVELFONNjs.f.call(void 0, );if(!e)throw new (0, _jssdkcore.PrivyClientError)({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}var ei=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);return _react.useMemo.call(void 0, ()=>({sendCode(n){return _chunkBVELFONNjs.d.call(void 0, this,arguments,function*({newPhoneNumber:s}){Ae(),yield e.auth.phone.sendCode(s)})},updatePhone(o){return _chunkBVELFONNjs.d.call(void 0, 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 (0, _jssdkcore.PrivyClientError)({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=_chunkBVELFONNjs.f.call(void 0, );if(!e)throw new (0, _jssdkcore.PrivyClientError)({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}var _expowebbrowser = require('expo-web-browser'); var Oe = _interopRequireWildcard(_expowebbrowser);var _reactnative = require('react-native');var S=e=>_chunkBVELFONNjs.d.call(void 0, void 0,null,function*(){let t;_reactnative.Platform.OS==="android"&&(t=Or());let s=yield Oe.openAuthSessionAsync(e),n;if(_reactnative.Platform.OS==="android")n=yield t;else{if(s.type!=="success")throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({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}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.loginWithCrossAppAuth({client:e,openAuthSession:S}),[e]);return{loginWithCrossApp:_react.useCallback.call(void 0, r=>_chunkBVELFONNjs.d.call(void 0, void 0,[r],function*({appId:n,redirectUri:o}){if(_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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])}};var ki=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.linkWithCrossAppAuth({client:e,openAuthSession:S}),[e]);return{linkWithCrossApp:_react.useCallback.call(void 0, r=>_chunkBVELFONNjs.d.call(void 0, void 0,[r],function*({appId:n,redirectUri:o}){if(!_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({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])}};var Ui=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.wallet.signMessage({client:e,openAuthSession:S}),[e]);return _react.useMemo.call(void 0, ()=>({signMessage:({address:s,message:n,redirectUri:o="/"})=>t({user:_chunkBVELFONNjs.f.call(void 0, ),address:s,message:n,redirectUrl:He.createURL(o)})}),[t])};var Ri=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.wallet.signTypedData({client:e,openAuthSession:S}),[e]);return _react.useMemo.call(void 0, ()=>({signTypedData:({address:s,typedData:n,redirectUri:o="/"})=>t({user:_chunkBVELFONNjs.f.call(void 0, ),address:s,typedData:n,redirectUrl:De.createURL(o)})}),[t])};var Gi=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.wallet.sendTransaction({client:e,openAuthSession:S}),[e]);return _react.useMemo.call(void 0, ()=>({sendTransaction:({address:s,transaction:n,redirectUri:o="/"})=>t({user:_chunkBVELFONNjs.f.call(void 0, ),address:s,transaction:n,redirectUrl:Ge.createURL(o)})}),[t])};var Qi=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);return{setRecovery:_react.useCallback.call(void 0, s=>_chunkBVELFONNjs.d.call(void 0, void 0,null,function*(){var a;let n=_chunkBVELFONNjs.f.call(void 0, ),o=e.app.appId;if(!n)throw new (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let r=(a=_jssdkcore.getUserEmbeddedEthereumWallet.call(void 0, n))!=null?a:_jssdkcore.getUserEmbeddedSolanaWallet.call(void 0, n);if(!r)throw new (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}_jssdkcore.throwIfInvalidRecoveryUpgradePath.call(void 0, {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 (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_set_recovery_error",error:c instanceof Error?c.message:"Error setting password on embedded wallet"})}}),[e])}},ot=r=>_chunkBVELFONNjs.d.call(void 0, 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 _chunkBVELFONNjs.b.call(void 0, _chunkBVELFONNjs.a.call(void 0, {},o),{wallet:n});case"google-drive":{let i=yield _chunkBVELFONNjs.p.call(void 0, t);return{recoveryMethod:"google-drive",wallet:n,recoveryAccessToken:i}}case"icloud":{let{recoverySecret:i,iCloudRecordName:a}=yield _chunkBVELFONNjs.k.call(void 0, {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 (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}});var is=()=>{let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);return{recover:_react.useCallback.call(void 0, s=>_chunkBVELFONNjs.d.call(void 0, void 0,null,function*(){var d;let n=_chunkBVELFONNjs.f.call(void 0, );if(!n)throw new (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let o=(d=_jssdkcore.getUserEmbeddedEthereumWallet.call(void 0, n))!=null?d:_jssdkcore.getUserEmbeddedSolanaWallet.call(void 0, n);if(!o)throw new (0, _jssdkcore.PrivyClientError)({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 _chunkBVELFONNjs.p.call(void 0, e);break;case"icloud":let{recoverySecret:h}=yield _chunkBVELFONNjs.l.call(void 0, {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 (0, _jssdkcore.PrivyClientError)({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 (0, _jssdkcore.PrivyClientError)({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};var ne=(e={})=>{let{wallet:t,createWalletCallbacks:s,recoverWalletCallbacks:n,setWalletRecoveryCallbacks:o}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),{onCreateWalletSuccess:r,onCreateWalletError:i,onRecoverWalletError:a,onRecoverWalletSuccess:c,onSetWalletRecoverySuccess:d,onSetWalletRecoveryError:h}=e;return _react.useEffect.call(void 0, ()=>{s.current={onSuccess:r,onError:i}},[r,i]),_react.useEffect.call(void 0, ()=>{n.current={onSuccess:c,onError:a}},[c,a]),_react.useEffect.call(void 0, ()=>{o.current={onSuccess:d,onError:h}},[c,a]),t};var ps=({onStateChange:e})=>{let t=ne();return _react.useEffect.call(void 0, ()=>{e(t)},[t])};var ys=()=>{let{getIdentityToken:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);return{getIdentityToken:e}};var Es=e=>{let{client:t}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),s=_react.useCallback.call(void 0, o=>{var i;let r=_chunkBVELFONNjs.m.call(void 0, o);return(i=e==null?void 0:e.onError)==null||i.call(e,r),r},[e==null?void 0:e.onError]);return{create:_react.useCallback.call(void 0, ()=>_chunkBVELFONNjs.d.call(void 0, void 0,null,function*(){var o;try{if(_chunkBVELFONNjs.f.call(void 0, ))throw new (0, _jssdkcore.PrivyClientError)({code:"attempted_to_create_guest_account_for_logged_in_user",error:"Already logged in, you cannot create a guest account"});let i=_chunkBVELFONNjs.e.call(void 0, ),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])}};function Ls({onMfaRequired:e}){let{client:t}=_react.useContext.call(void 0, _chunkBVELFONNjs.M);_react.useEffect.call(void 0, ()=>{function s(){return _chunkBVELFONNjs.d.call(void 0, this,null,function*(){var o;let n=_chunkBVELFONNjs.f.call(void 0, );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])}function Ns(){let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useCallback.call(void 0, r=>_chunkBVELFONNjs.d.call(void 0, 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=_chunkBVELFONNjs.e.call(void 0, ))==null?void 0:i.mfa)==null?void 0:a.relyingParty)});return _chunkBVELFONNjs.S.call(void 0, c);case"totp":return;default:throw new Error(`Unsupported MFA method: ${r.mfaMethod}`)}}),[e]),s=_react.useCallback.call(void 0, r=>_chunkBVELFONNjs.d.call(void 0, 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 (0, _jssdkcore.PrivyClientError)({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=_chunkBVELFONNjs.e.call(void 0, ))==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 (0, _jssdkcore.PrivyClientError)({code:"invalid_passkey_response",error:"Invalid authenticator response"});let y=yield _chunkBVELFONNjs.Q.call(void 0, r.mfaCode),w=_chunkBVELFONNjs.R.call(void 0, y);(u=e.mfaPromises.rootPromise.current)==null||u.resolve({mfaMethod:r.method,relyingParty:r.relyingParty||((h=(d=_chunkBVELFONNjs.e.call(void 0, ))==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 (0, _jssdkcore.PrivyClientError)({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(p=e.mfaPromises.rootPromise.current)==null||p.reject(v),v}}),[e]),n=_react.useCallback.call(void 0, ()=>_chunkBVELFONNjs.d.call(void 0, this,null,function*(){yield e.mfa.verifyMfa()}),[e]),o=_react.useCallback.call(void 0, ()=>{var r;(r=e.mfaPromises.rootPromise.current)==null||r.reject(new (0, _jssdkcore.PrivyClientError)({code:"mfa_canceled",error:"MFA canceled"}))},[e]);return{init:t,submit:s,prompt:n,cancel:o}}function Ks(){let{client:e}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),t=_react.useCallback.call(void 0, o=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, o=>_chunkBVELFONNjs.d.call(void 0, 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=_react.useCallback.call(void 0, o=>_chunkBVELFONNjs.d.call(void 0, 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}}var kt=()=>{let e=_chunkBVELFONNjs.g.call(void 0, ),t=_chunkBVELFONNjs.w.call(void 0, ),s=_react.useMemo.call(void 0, ()=>{let r=_jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, e).map(i=>{let a=_jssdkcore.getEntropyDetailsFromUser.call(void 0, 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=>_chunkBVELFONNjs.d.call(void 0, void 0,null,function*(){var h;yield(h=_chunkBVELFONNjs.i.call(void 0, ))==null?void 0:h(d)})})}))},[t,e]),n=_react.useCallback.call(void 0, (...r)=>_chunkBVELFONNjs.d.call(void 0, void 0,[...r],function*({createAdditional:o=!1}={}){let{user:i}=yield t.user.get(),a=_jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, i);if(!o&&a.length>0)throw new (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let c=_jssdkcore.getEntropyDetailsFromUser.call(void 0, 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=_jssdkcore.getUserEmbeddedSolanaWallet.call(void 0, 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=_jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, e).find(n=>n.wallet_index===t);if(!e||!s)throw new (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}var bt=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:s,recoverSolanaWalletCallbacks:n}=_react.useContext.call(void 0, _chunkBVELFONNjs.M),{onCreateWalletSuccess:o,onCreateWalletError:r,onRecoverWalletError:i,onRecoverWalletSuccess:a}=e;return _react.useEffect.call(void 0, ()=>{s.current={onSuccess:o,onError:r}},[o,r]),_react.useEffect.call(void 0, ()=>{n.current={onSuccess:a,onError:i}},[a,i]),t};var Et=()=>{let e=_chunkBVELFONNjs.g.call(void 0, ),t=_chunkBVELFONNjs.w.call(void 0, ),s=_react.useMemo.call(void 0, ()=>{let o=_jssdkcore.getEntropyDetailsFromUser.call(void 0, e);if(!o)return[];let r=_jssdkcore.getAllUserEmbeddedBitcoinWallets.call(void 0, 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=_react.useCallback.call(void 0, i=>_chunkBVELFONNjs.d.call(void 0, void 0,[i],function*({chainType:o,createAdditional:r=!1}){let{user:a}=yield t.user.get(),c=_jssdkcore.getEntropyDetailsFromUser.call(void 0, a);if(!c)throw new (0, _jssdkcore.PrivyClientError)({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=_jssdkcore.getAllUserEmbeddedBitcoinWallets.call(void 0, a).filter(v=>v.chain_type===o);if(!r&&u.length>0)throw new (0, _jssdkcore.PrivyClientError)({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=_jssdkcore.getAllUserEmbeddedBitcoinWallets.call(void 0, y.user).find(v=>v.chain_type===o&&v.wallet_index===p);if(!y.user||!w)throw new (0, _jssdkcore.PrivyClientError)({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}};exports.a = Lt; exports.b = Dt; exports.c = zt; exports.d = to; exports.e = uo; exports.f = vo; exports.g = Uo; exports.h = Fo; exports.i = jo; exports.j = Zo; exports.k = sn; exports.l = gn; exports.m = En; exports.n = Ln; exports.o = Fn; exports.p = Bn; exports.q = $n; exports.r = ei; exports.s = mi; exports.t = ki; exports.u = Ui; exports.v = Ri; exports.w = Gi; exports.x = Qi; exports.y = is; exports.z = ne; exports.A = ps; exports.B = ys; exports.C = Es; exports.D = Ls; exports.E = Ns; exports.F = Ks; exports.G = kt; exports.H = bt; exports.I = Et;