@privy-io/expo
Version:
Expo client for the Privy Auth API
2 lines (1 loc) • 41.7 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 _chunkVCDHJV7Cjs = require('./chunk-VCDHJV7C.js');var _chunkOWCFWPALjs = require('./chunk-OWCFWPAL.js');var _react = require('react');var _jssdkcore = require('@privy-io/js-sdk-core');var $t=e=>{let{client:t,setSiweState:i,siweState:n}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),o=_react.useCallback.call(void 0, a=>{var d;let c=_chunkVCDHJV7Cjs.j.call(void 0, a);return i({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, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({wallet:a,from:{domain:c,uri:d}}){var m;try{i({status:"generating-message"});let p=yield t.auth.siwe.init(a,c,d);return i({status:"awaiting-signature"}),(m=e==null?void 0:e.onGenerateMessage)==null||m.call(e,p.message),p.message}catch(p){throw o(p)}}),[t,o,e==null?void 0:e.onGenerateMessage]),s=_react.useCallback.call(void 0, d=>_chunkOWCFWPALjs.d.call(void 0, void 0,[d],function*({signature:a,messageOverride:c}){var g;try{if(!_chunkVCDHJV7Cjs.b.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"});i({status:"submitting-signature"});let{user:p}=yield t.auth.siwe.linkWithSiwe(a,void 0,c);return i({status:"done"}),(g=e==null?void 0:e.onSuccess)==null||g.call(e,p),p}catch(m){throw o(m)}}),[t,o,e==null?void 0:e.onSuccess]);return{generateSiweMessage:r,linkWithSiwe:s,state:n}};var oo=e=>{let{client:t,setSiweState:i,siweState:n}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),o=_react.useCallback.call(void 0, a=>{var d;let c=_chunkVCDHJV7Cjs.j.call(void 0, a);return i({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, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({wallet:a,from:{domain:c,uri:d}}){var m;try{i({status:"generating-message"});let p=yield t.auth.siwe.init(a,c,d);return i({status:"awaiting-signature"}),(m=e==null?void 0:e.onGenerateMessage)==null||m.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, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({signature:a,messageOverride:c,disableSignup:d}){var m;try{if(_chunkVCDHJV7Cjs.b.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"});i({status:"submitting-signature"});let v=_chunkVCDHJV7Cjs.a.call(void 0, ),y=yield t.auth.siwe.loginWithSiwe(a,void 0,c,d?"no-signup":"login-or-sign-up",{embedded:v==null?void 0:v.embedded});return i({status:"done"}),(m=e==null?void 0:e.onSuccess)==null||m.call(e,y.user,y.is_new_user),y.user}catch(p){throw o(p)}}),[t,o,e==null?void 0:e.onSuccess]),generateSiweMessage:r,state:n}};var C=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return e};var fo=()=>{let e=C(),t=_react.useCallback.call(void 0, s=>_chunkOWCFWPALjs.d.call(void 0, void 0,[s],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 _chunkVCDHJV7Cjs.j.call(void 0, a)}}),[e]),i=_react.useCallback.call(void 0, a=>_chunkOWCFWPALjs.d.call(void 0, void 0,[a],function*({signature:n,message:o,wallet:{walletClientType:r,connectorType:s}={}}){try{if(!_chunkVCDHJV7Cjs.b.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:s});return d}catch(c){throw _chunkVCDHJV7Cjs.j.call(void 0, c)}}),[e]);return{generateMessage:t,link:i}};var Co=()=>{let e=C(),t=_react.useCallback.call(void 0, s=>_chunkOWCFWPALjs.d.call(void 0, void 0,[s],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 _chunkVCDHJV7Cjs.j.call(void 0, a)}}),[e]),i=_react.useCallback.call(void 0, c=>_chunkOWCFWPALjs.d.call(void 0, void 0,[c],function*({signature:n,message:o,wallet:{walletClientType:r,connectorType:s}={},disableSignup:a}){try{if(_chunkVCDHJV7Cjs.b.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:s,mode:a?"no-signup":"login-or-sign-up"})).user}catch(d){throw _chunkVCDHJV7Cjs.j.call(void 0, d)}}),[e]);return{generateMessage:t,login:i}};var Lo=e=>{let{client:t}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),i=_react.useCallback.call(void 0, o=>{var s;let r=_chunkVCDHJV7Cjs.j.call(void 0, o);return(s=e==null?void 0:e.onError)==null||s.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkWallet:_react.useCallback.call(void 0, r=>_chunkOWCFWPALjs.d.call(void 0, void 0,[r],function*({address:o}){var s;try{if(!_chunkVCDHJV7Cjs.b.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(s=e==null?void 0:e.onSuccess)==null||s.call(e,c),c}catch(a){throw i(a)}}),[t,i,e==null?void 0:e.onSuccess])}};var Go=e=>{let[t,i]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),s=_react.useCallback.call(void 0, d=>{var m;let g=_chunkVCDHJV7Cjs.j.call(void 0, d);return r({status:"error",error:g}),(m=e==null?void 0:e.onError)==null||m.call(e,g),g},[e,r]),a=_react.useCallback.call(void 0, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({email:d}){var m;i(d);try{r({status:"sending-code"});let p=yield n.auth.email.sendCode(d);return r({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{email:d}),p}catch(p){throw s(p)}}),[n,s,e,r]),c=_react.useCallback.call(void 0, m=>_chunkOWCFWPALjs.d.call(void 0, void 0,[m],function*({code:d,email:g}){var p;try{if(!_chunkVCDHJV7Cjs.b.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 y=g||t;if(!y)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:S}=yield n.auth.email.linkWithCode(y,d);return r({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,S),S}catch(v){throw s(v)}}),[t,r,n,e,s]);return{sendCode:a,linkWithCode:c,state:o}};var $o=e=>{let[t,i]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),s=_react.useCallback.call(void 0, d=>{var m;let g=_chunkVCDHJV7Cjs.j.call(void 0, d);return r({status:"error",error:g}),(m=e==null?void 0:e.onError)==null||m.call(e,g),g},[e,r]),a=_react.useCallback.call(void 0, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({email:d}){var m;i(d);try{r({status:"sending-code"});let p=yield n.auth.email.sendCode(d);return r({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{email:d}),p}catch(p){throw s(p)}}),[n,s,e,r]),c=_react.useCallback.call(void 0, p=>_chunkOWCFWPALjs.d.call(void 0, void 0,[p],function*({code:d,email:g,disableSignup:m}){var v;try{if(_chunkVCDHJV7Cjs.b.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 S=g||t;if(!S)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 k=_chunkVCDHJV7Cjs.a.call(void 0, ),w=yield n.auth.email.loginWithCode(S,d,m?"no-signup":"login-or-sign-up",{embedded:k==null?void 0:k.embedded});return r({status:"done"}),(v=e==null?void 0:e.onLoginSuccess)==null||v.call(e,w.user,w.is_new_user),w==null?void 0:w.user}catch(y){throw s(y)}}),[t,r,n,e,s]);return{sendCode:a,loginWithCode:c,state:o}};var tn=e=>{let[t,i]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),s=_react.useCallback.call(void 0, d=>{var m;let g=_chunkVCDHJV7Cjs.j.call(void 0, d);return r({status:"error",error:g}),(m=e==null?void 0:e.onError)==null||m.call(e,g),g},[e,r]),a=_react.useCallback.call(void 0, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({phone:d}){var m;i(d);try{r({status:"sending-code"});let p=yield n.auth.phone.sendCode(d);return r({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{phone:d}),p}catch(p){throw s(p)}}),[n,s,e,r]),c=_react.useCallback.call(void 0, m=>_chunkOWCFWPALjs.d.call(void 0, void 0,[m],function*({code:d,phone:g}){var p;try{if(!_chunkVCDHJV7Cjs.b.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(!(g||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:S}=yield n.auth.phone.linkWithCode(g||t,d);return r({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,S),S}catch(v){throw s(v)}}),[t,r,n,e,s]);return{sendCode:a,linkWithCode:c,state:o}};var mn=e=>{let[t,i]=_react.useState.call(void 0, ""),{client:n,otpState:o,setOtpState:r}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),s=_react.useCallback.call(void 0, d=>{var m;let g=_chunkVCDHJV7Cjs.j.call(void 0, d);return r({status:"error",error:g}),(m=e==null?void 0:e.onError)==null||m.call(e,g),g},[e,r]),a=_react.useCallback.call(void 0, g=>_chunkOWCFWPALjs.d.call(void 0, void 0,[g],function*({phone:d}){var m;i(d);try{r({status:"sending-code"});let p=yield n.auth.phone.sendCode(d);return r({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{phone:d}),p}catch(p){throw s(p)}}),[n,s,e,r]),c=_react.useCallback.call(void 0, p=>_chunkOWCFWPALjs.d.call(void 0, void 0,[p],function*({code:d,phone:g,disableSignup:m}){var v;try{if(_chunkVCDHJV7Cjs.b.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(!(g||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 k=_chunkVCDHJV7Cjs.a.call(void 0, ),w=yield n.auth.phone.loginWithCode(g||t,d,m?"no-signup":"login-or-sign-up",{embedded:k==null?void 0:k.embedded});return r({status:"done"}),(v=e==null?void 0:e.onLoginSuccess)==null||v.call(e,w.user,w.is_new_user),w==null?void 0:w.user}catch(y){throw s(y)}}),[t,r,n,e,s]);return{sendCode:a,loginWithCode:c,state:o}};var _expolinking = require('expo-linking'); var G = _interopRequireWildcard(_expolinking); var N = _interopRequireWildcard(_expolinking); var Fe = _interopRequireWildcard(_expolinking); var B = _interopRequireWildcard(_expolinking); var Te = _interopRequireWildcard(_expolinking); var Ge = _interopRequireWildcard(_expolinking); var Be = _interopRequireWildcard(_expolinking); var Ve = _interopRequireWildcard(_expolinking);var Sn=e=>{let{appState:t,getCurrentAppState:i}=_chunkVCDHJV7Cjs.l.call(void 0, ),{client:n,farcasterState:o,setFarcasterState:r}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),s=_react.useRef.call(void 0, !1),a=_react.useCallback.call(void 0, g=>{var p;let m=_chunkVCDHJV7Cjs.j.call(void 0, g);return r({status:"error",error:m}),(p=e==null?void 0:e.onError)==null||p.call(e,m),m},[e==null?void 0:e.onError,r]),c=_react.useCallback.call(void 0, ()=>{s.current=!0},[]);return{linkWithFarcaster:_react.useCallback.call(void 0, (v,...y)=>_chunkOWCFWPALjs.d.call(void 0, void 0,[v,...y],function*({relyingParty:g,redirectUrl:m},p={pollAttempts:10,pollIntervalMs:1e3}){var S;try{let k=_chunkVCDHJV7Cjs.b.call(void 0, );if(s.current=!1,!k)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:w,channel_token:P}=yield n.auth.farcaster.initializeAuth({relyingParty:g,redirectUrl:G.createURL(m!=null?m:"/")});if(!w)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 G.openURL(w),r({status:"polling-status"});let U=0;for(;U<p.pollAttempts;){if(s.current)throw new (0, _jssdkcore.PrivyClientError)({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&i()!=="active"){yield _chunkVCDHJV7Cjs.k.call(void 0, p.pollIntervalMs);continue}let M=yield n.auth.farcaster.getFarcasterStatus({channel_token:P});if(M.state==="completed"){r({status:"submitting-token"});let{user:O}=yield n.auth.farcaster.link(_chunkOWCFWPALjs.a.call(void 0, {channel_token:P},M));return r({status:"done"}),(S=e==null?void 0:e.onSuccess)==null||S.call(e,O),O}U++,yield _chunkVCDHJV7Cjs.k.call(void 0, p.pollIntervalMs)}throw new (0, _jssdkcore.PrivyClientError)({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(k){throw a(k)}}),[n,e==null?void 0:e.onSuccess,a,r]),state:o,cancel:c}};var Pn=e=>{let{client:t}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),i=_react.useCallback.call(void 0, o=>{var s;let r=_chunkVCDHJV7Cjs.j.call(void 0, o);return(s=e==null?void 0:e.onError)==null||s.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkFarcaster:_react.useCallback.call(void 0, r=>_chunkOWCFWPALjs.d.call(void 0, void 0,[r],function*({fid:o}){var s;try{let{user:a}=yield t.auth.farcaster.unlink({fid:o});return(s=e==null?void 0:e.onSuccess)==null||s.call(e,a),a}catch(a){throw i(a)}}),[t,e==null?void 0:e.onSuccess,i])}};var Rn=e=>{let{appState:t,getCurrentAppState:i}=_chunkVCDHJV7Cjs.l.call(void 0, ),{client:n,farcasterState:o,setFarcasterState:r}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),s=_react.useRef.call(void 0, !1),a=_react.useCallback.call(void 0, g=>{var p;let m=_chunkVCDHJV7Cjs.j.call(void 0, g);return r({status:"error",error:m}),(p=e==null?void 0:e.onError)==null||p.call(e,m),m},[e==null?void 0:e.onError,r]),c=_react.useCallback.call(void 0, ()=>{s.current=!0},[]);return{loginWithFarcaster:_react.useCallback.call(void 0, (y,...S)=>_chunkOWCFWPALjs.d.call(void 0, void 0,[y,...S],function*({relyingParty:g,redirectUrl:m,disableSignup:p},v={pollAttempts:10,pollIntervalMs:1e3}){var k;try{if(s.current=!1,_chunkVCDHJV7Cjs.b.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:U}=yield n.auth.farcaster.initializeAuth({relyingParty:g,redirectUrl:N.createURL(m!=null?m:"/")});if(!P)throw new (0, _jssdkcore.PrivyClientError)({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!U)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 M=0;for(;M<v.pollAttempts;){if(s.current)throw new (0, _jssdkcore.PrivyClientError)({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&i()!=="active"){yield _chunkVCDHJV7Cjs.k.call(void 0, v.pollIntervalMs);continue}let O=yield n.auth.farcaster.getFarcasterStatus({channel_token:U});if(O.state==="completed"){r({status:"submitting-token"});let K=_chunkVCDHJV7Cjs.a.call(void 0, ),j=yield n.auth.farcaster.authenticate(_chunkOWCFWPALjs.a.call(void 0, {channel_token:U,mode:p?"no-signup":"login-or-sign-up"},O),{embedded:K==null?void 0:K.embedded});return r({status:"done"}),(k=e==null?void 0:e.onSuccess)==null||k.call(e,j.user,j.is_new_user),j.user}M++,yield _chunkVCDHJV7Cjs.k.call(void 0, v.pollIntervalMs)}throw new (0, _jssdkcore.PrivyClientError)({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(w){throw a(w)}}),[n,a,e==null?void 0:e.onSuccess,r,t]),state:o,cancel:c}};var _zustand = require('zustand');var oe=_zustand.create.call(void 0, ()=>({status:"initial"})),E=e=>oe.setState(e,!0),br=oe.getState,Kn= exports.n =()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=oe(),i=_react.useCallback.call(void 0, ()=>_chunkOWCFWPALjs.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=_chunkVCDHJV7Cjs.j.call(void 0, o);throw E({status:"initial",error:r}),r}}),[e]),n=_react.useCallback.call(void 0, o=>_chunkOWCFWPALjs.d.call(void 0, void 0,null,function*(){let r=br().status;try{if(_chunkVCDHJV7Cjs.b.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=_chunkVCDHJV7Cjs.a.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(s){let a=_chunkVCDHJV7Cjs.j.call(void 0, s);throw E({status:r,error:a}),a}}),[e]);return{init:i,login:n,state:t}};var Xn=e=>{let{client:t}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),i=_react.useCallback.call(void 0, o=>{var s;let r=_chunkVCDHJV7Cjs.j.call(void 0, o);return(s=e==null?void 0:e.onError)==null||s.call(e,r),r},[e==null?void 0:e.onError]);return{unlinkOAuth:_react.useCallback.call(void 0, s=>_chunkOWCFWPALjs.d.call(void 0, void 0,[s],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 i(c)}}),[t,e==null?void 0:e.onSuccess,i])}};var ti=e=>{let{client:t}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),i=_react.useRef.call(void 0, e.onOAuthTokenGrant);i.current=e.onOAuthTokenGrant,_react.useEffect.call(void 0, ()=>{let{unsubscribe:n}=t.addOAuthTokensListener(o=>{i.current(o)});return n},[t])};var ai=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return _react.useMemo.call(void 0, ()=>({delegateWallet:_jssdkcore.delegatedActions.delegateWallet(e),revokeWallets:_jssdkcore.delegatedActions.revokeWallets(e)}),[e])};function Mr(e,t){return[..._jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, e),..._jssdkcore.getAllUserEmbeddedSolanaWallets.call(void 0, e),..._jssdkcore.getAllUserEmbeddedBitcoinWallets.call(void 0, e)].find(n=>n.address===t)}function ne(e){let t=_chunkVCDHJV7Cjs.b.call(void 0, );if(!t)throw new Error("User must be authenticated to perform this operation");let i=Mr(t,e);if(!i)throw new Error(`No wallet found with address ${e}`);return i}var hi=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return _react.useMemo.call(void 0, ()=>({addSessionSigners:({address:t,signers:i})=>_jssdkcore.addSessionSigners.call(void 0, {client:e,wallet:ne(t),signers:i.map(n=>({signer_id:n.signerId,override_policy_ids:n.policyIds}))}),removeSessionSigners:({address:t})=>_jssdkcore.removeSessionSigners.call(void 0, {client:e,wallet:ne(t)})}),[e])};var bi=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return _react.useMemo.call(void 0, ()=>({sendCode(n){return _chunkOWCFWPALjs.d.call(void 0, this,arguments,function*({newEmailAddress:i}){xe(),yield e.auth.email.sendCode(i)})},updateEmail(o){return _chunkOWCFWPALjs.d.call(void 0, this,arguments,function*({newEmailAddress:i,code:n}){let{address:r}=xe(),{user:s}=yield e.auth.email.updateEmail({oldEmailAddress:r,newEmailAddress:i,code:n});return s})}}),[e])};function xe(){let t=Gr().linked_accounts.find(i=>i.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 Gr(){let e=_chunkVCDHJV7Cjs.b.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 xi=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return _react.useMemo.call(void 0, ()=>({sendCode(n){return _chunkOWCFWPALjs.d.call(void 0, this,arguments,function*({newPhoneNumber:i}){Le(),yield e.auth.phone.sendCode(i)})},updatePhone(o){return _chunkOWCFWPALjs.d.call(void 0, this,arguments,function*({newPhoneNumber:i,code:n}){let{phoneNumber:r}=Le(),{user:s}=yield e.auth.phone.updatePhone({oldPhoneNumber:r,newPhoneNumber:i,code:n});return s})}}),[e])};function Le(){let t=Dr().linked_accounts.find(i=>i.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 Dr(){let e=_chunkVCDHJV7Cjs.b.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 Ie = _interopRequireWildcard(_expowebbrowser);var _reactnative = require('react-native');var W=e=>_chunkOWCFWPALjs.d.call(void 0, void 0,null,function*(){let t;_reactnative.Platform.OS==="android"&&(t=Vr());let i=yield Ie.openAuthSessionAsync(e),n;if(_reactnative.Platform.OS==="android")n=yield t;else{if(i.type!=="success")throw new (0, _jssdkcore.PrivyClientError)({code:"oauth_session_failed",error:"OAuth session failed"});n=i.url}return zr(n)});function Vr(){let e;return new Promise((t,i)=>{e=B.addEventListener("url",({url:n})=>{n&&t(n)}),setTimeout(()=>{i(new (0, _jssdkcore.PrivyClientError)({code:"oauth_session_timeout",error:"OAuth session timed out"}))},Kr)}).finally(()=>{e==null||e.remove()})}function zr(e){let{queryParams:t}=B.parse(e);return t}var Kr=2*60*1e3;var Bi=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.loginWithCrossAppAuth({client:e,openAuthSession:W}),[e]);return{loginWithCrossApp:_react.useCallback.call(void 0, r=>_chunkOWCFWPALjs.d.call(void 0, void 0,[r],function*({appId:n,redirectUri:o}){if(_chunkVCDHJV7Cjs.b.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:Fe.createURL(o||"/")});return{user:a}}),[t])}};var Ji=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.linkWithCrossAppAuth({client:e,openAuthSession:W}),[e]);return{linkWithCrossApp:_react.useCallback.call(void 0, r=>_chunkOWCFWPALjs.d.call(void 0, void 0,[r],function*({appId:n,redirectUri:o}){if(!_chunkVCDHJV7Cjs.b.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:Te.createURL(o||"/")})}}),[t])}};var os=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.wallet.signMessage({client:e,openAuthSession:W}),[e]);return _react.useMemo.call(void 0, ()=>({signMessage:({address:i,message:n,redirectUri:o="/"})=>t({user:_chunkVCDHJV7Cjs.b.call(void 0, ),address:i,message:n,redirectUrl:Ge.createURL(o)})}),[t])};var ds=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.wallet.signTypedData({client:e,openAuthSession:W}),[e]);return _react.useMemo.call(void 0, ()=>({signTypedData:({address:i,typedData:n,redirectUri:o="/"})=>t({user:_chunkVCDHJV7Cjs.b.call(void 0, ),address:i,typedData:n,redirectUrl:Be.createURL(o)})}),[t])};var ys=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useMemo.call(void 0, ()=>_jssdkcore.crossApp.wallet.sendTransaction({client:e,openAuthSession:W}),[e]);return _react.useMemo.call(void 0, ()=>({sendTransaction:({address:i,transaction:n,redirectUri:o="/"})=>t({user:_chunkVCDHJV7Cjs.b.call(void 0, ),address:i,transaction:n,redirectUrl:Ve.createURL(o)})}),[t])};var Es=()=>{let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return{setRecovery:_react.useCallback.call(void 0, i=>_chunkOWCFWPALjs.d.call(void 0, void 0,null,function*(){var a;let n=_chunkVCDHJV7Cjs.b.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"});if(_jssdkcore.isUnifiedWallet.call(void 0, r))throw new (0, _jssdkcore.PrivyClientError)({code:"unsupported_wallet_type",error:"Embedded wallet recovery is only supported for on-device execution and this app uses TEE execution. Learn more https://docs.privy.io/recipes/tee-wallet-migration-guide"});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:i.recoveryMethod});let s=yield gt({appId:o,client:e,user:n,primaryAccount:r,recoveryParams:i});try{let{user:c}=yield e.embeddedWallet.setRecovery(s);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])}},gt=r=>_chunkOWCFWPALjs.d.call(void 0, void 0,[r],function*({appId:e,client:t,user:i,primaryAccount:n,recoveryParams:o}){switch(o.recoveryMethod){case"privy":return{recoveryMethod:"privy",wallet:n};case"user-passcode":return _chunkOWCFWPALjs.b.call(void 0, _chunkOWCFWPALjs.a.call(void 0, {},o),{wallet:n});case"google-drive":{let s=yield _chunkVCDHJV7Cjs.m.call(void 0, t);return{recoveryMethod:"google-drive",wallet:n,recoveryAccessToken:s}}case"icloud":{let{recoverySecret:s,iCloudRecordName:a}=yield _chunkVCDHJV7Cjs.h.call(void 0, {appId:e,client:t,user:i});return{recoveryMethod:"icloud-native",recoverySecretOverride:s,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, _chunkVCDHJV7Cjs.s);return{recover:_react.useCallback.call(void 0, i=>_chunkOWCFWPALjs.d.call(void 0, void 0,null,function*(){var d;let n=_chunkVCDHJV7Cjs.b.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"});if(_jssdkcore.isUnifiedWallet.call(void 0, o))throw new (0, _jssdkcore.PrivyClientError)({code:"unsupported_wallet_type",error:"User owned wallet recovery is only supported for on-device execution and this app uses TEE execution. Learn more https://docs.privy.io/recipes/tee-wallet-migration-guide"});let r,s,a,c;switch(i.recoveryMethod){case"user-passcode":s=i.password;break;case"google-drive":a=yield _chunkVCDHJV7Cjs.m.call(void 0, e);break;case"icloud":let{recoverySecret:g}=yield _chunkVCDHJV7Cjs.i.call(void 0, {client:e,walletAddress:o.address,chainType:o.chain_type});c=g;break;case"recovery-encryption-key":r=i.recoveryKey;break;case"privy":break;default:throw new (0, _jssdkcore.PrivyClientError)({code:"unsupported_recovery_method",error:`Unsupported recovery options ${i}`})}try{o.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(o,s,a,c,r):o.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(o,o.address,"solana-address-verifier",s,a,c))}catch(g){throw new (0, _jssdkcore.PrivyClientError)({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};var se=(e={})=>{let{wallet:t,createWalletCallbacks:i,recoverWalletCallbacks:n,setWalletRecoveryCallbacks:o}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),{onCreateWalletSuccess:r,onCreateWalletError:s,onRecoverWalletError:a,onRecoverWalletSuccess:c,onSetWalletRecoverySuccess:d,onSetWalletRecoveryError:g}=e;return _react.useEffect.call(void 0, ()=>{i.current={onSuccess:r,onError:s}},[r,s]),_react.useEffect.call(void 0, ()=>{n.current={onSuccess:c,onError:a}},[c,a]),_react.useEffect.call(void 0, ()=>{o.current={onSuccess:d,onError:g}},[c,a]),t};var Ds=({onStateChange:e})=>{let t=se();return _react.useEffect.call(void 0, ()=>{e(t)},[t])};var js=()=>{let{getIdentityToken:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return{getIdentityToken:e}};var ea=e=>{let{client:t}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),i=_react.useCallback.call(void 0, o=>{var s;let r=_chunkVCDHJV7Cjs.j.call(void 0, o);return(s=e==null?void 0:e.onError)==null||s.call(e,r),r},[e==null?void 0:e.onError]);return{create:_react.useCallback.call(void 0, ()=>_chunkOWCFWPALjs.d.call(void 0, void 0,null,function*(){var o;try{if(_chunkVCDHJV7Cjs.b.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 s=_chunkVCDHJV7Cjs.a.call(void 0, ),a=yield t.auth.guest.create({embedded:s==null?void 0:s.embedded});return(o=e==null?void 0:e.onSuccess)==null||o.call(e,a.user,a.is_new_user),a.user}catch(r){throw i(r)}}),[t,i,e==null?void 0:e.onSuccess])}};function sa({onMfaRequired:e}){let{client:t}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);_react.useEffect.call(void 0, ()=>{function i(){return _chunkOWCFWPALjs.d.call(void 0, this,null,function*(){var o;let n=_chunkVCDHJV7Cjs.b.call(void 0, );yield e((o=n==null?void 0:n.mfa_methods.map(({type:r})=>r))!=null?o:[])})}return t.mfaPromises.on("mfaRequired",i),()=>{t.mfaPromises.off("mfaRequired",i)}},[t,e])}function ga(){let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useCallback.call(void 0, r=>_chunkOWCFWPALjs.d.call(void 0, this,null,function*(){var s,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=(s=_chunkVCDHJV7Cjs.a.call(void 0, ))==null?void 0:s.mfa)==null?void 0:a.relyingParty)});return _chunkVCDHJV7Cjs.y.call(void 0, c);case"totp":return;default:throw new Error(`Unsupported MFA method: ${r.mfaMethod}`)}}),[e]),i=_react.useCallback.call(void 0, r=>_chunkOWCFWPALjs.d.call(void 0, this,null,function*(){var s,a,c,d,g,m,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=(s=_chunkVCDHJV7Cjs.a.call(void 0, ))==null?void 0:s.mfa)==null?void 0:a.relyingParty)||""}),yield new Promise((k,w)=>{e.mfaPromises.submitPromise.current={resolve:k,reject:w}});break;case"passkey":if(typeof r.mfaCode=="string")throw new (0, _jssdkcore.PrivyClientError)({code:"invalid_passkey_response",error:"Invalid authenticator response"});let v=yield _chunkVCDHJV7Cjs.w.call(void 0, r.mfaCode),y=_chunkVCDHJV7Cjs.x.call(void 0, v);(m=e.mfaPromises.rootPromise.current)==null||m.resolve({mfaMethod:r.method,relyingParty:r.relyingParty||((g=(d=_chunkVCDHJV7Cjs.a.call(void 0, ))==null?void 0:d.mfa)==null?void 0:g.relyingParty)||"",mfaCode:y}),yield new Promise((k,w)=>{e.mfaPromises.submitPromise.current={resolve:k,reject:w}});break;default:let S=new (0, _jssdkcore.PrivyClientError)({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(p=e.mfaPromises.rootPromise.current)==null||p.reject(S),S}}),[e]),n=_react.useCallback.call(void 0, ()=>_chunkOWCFWPALjs.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:i,prompt:n,cancel:o}}function va(){let{client:e}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),t=_react.useCallback.call(void 0, o=>_chunkOWCFWPALjs.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]),i=_react.useCallback.call(void 0, o=>_chunkOWCFWPALjs.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=>_chunkOWCFWPALjs.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:i,unenrollMfa:n}}var Mt=()=>{let e=_chunkVCDHJV7Cjs.d.call(void 0, ),t=C(),i=_react.useMemo.call(void 0, ()=>{let r=_jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, e).map(s=>{let a=_jssdkcore.getEntropyDetailsFromUser.call(void 0, e,s);return a?{account:s,entropy:a}:null});return r.some(s=>s===null)?[]:r.filter(s=>s!==null).map(({account:s,entropy:{entropyId:a,entropyIdVerifier:c}})=>({address:s.address,walletIndex:s.wallet_index,chainType:s.chain_type,getProvider:()=>t.embeddedWallet.getEthereumProvider({wallet:s,entropyId:a,entropyIdVerifier:c,onNeedsRecovery:d=>_chunkOWCFWPALjs.d.call(void 0, void 0,null,function*(){var g;yield(g=_chunkVCDHJV7Cjs.f.call(void 0, ))==null?void 0:g(d)})})}))},[t,e]),n=_react.useCallback.call(void 0, (...r)=>_chunkOWCFWPALjs.d.call(void 0, void 0,[...r],function*({createAdditional:o=!1}={}){let{user:s}=yield t.user.get(),a=_jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, s);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, s);if(!c){let y=yield t.embeddedWallet.create({});return ce(y.user,0),{user:y.user}}let{entropyId:d,entropyIdVerifier:g}=c;if(g==="solana-address-verifier"){let y=_jssdkcore.getUserEmbeddedSolanaWallet.call(void 0, s),S=yield t.embeddedWallet.create({solanaAccount:y});return ce(S.user,0),{user:S.user}}let p=a.map(y=>y.wallet_index).reduce((y,S)=>Math.max(y,S),0)+1,v=yield t.embeddedWallet.add({chainType:"ethereum",hdWalletIndex:p,entropyId:d,entropyIdVerifier:g});return ce(v.user,p),{user:v.user}}),[t]);return{wallets:i,create:n}};function ce(e,t){let i=_jssdkcore.getAllUserEmbeddedEthereumWallets.call(void 0, e).find(n=>n.wallet_index===t);if(!e||!i)throw new (0, _jssdkcore.PrivyClientError)({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}var It=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:i,recoverSolanaWalletCallbacks:n}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s),{onCreateWalletSuccess:o,onCreateWalletError:r,onRecoverWalletError:s,onRecoverWalletSuccess:a}=e;return _react.useEffect.call(void 0, ()=>{i.current={onSuccess:o,onError:r}},[o,r]),_react.useEffect.call(void 0, ()=>{n.current={onSuccess:a,onError:s}},[a,s]),t};var Tt=()=>{let e=_chunkVCDHJV7Cjs.d.call(void 0, ),t=C(),i=_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:s,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:s,entropyIdVerifier:a})}))},[t,e]),n=_react.useCallback.call(void 0, s=>_chunkOWCFWPALjs.d.call(void 0, void 0,[s],function*({chainType:o,createAdditional:r=!1}){var k;let a=t.app.getConfig();if(((k=a==null?void 0:a.embedded_wallet_config)==null?void 0:k.mode)==="user-controlled-server-wallets-only")throw new (0, _jssdkcore.PrivyClientError)({code:"unsupported_wallet_type",error:"Bitcoin wallets are only supported for on-device execution and this app uses TEE execution. Learn more https://docs.privy.io/recipes/tee-wallet-migration-guide"});let{user:c}=yield t.user.get(),d=_jssdkcore.getEntropyDetailsFromUser.call(void 0, c);if(!d)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:g,entropyIdVerifier:m}=d,p=_jssdkcore.getAllUserEmbeddedBitcoinWallets.call(void 0, c).filter(w=>w.chain_type===o);if(!r&&p.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 v=p.length===0?0:Math.max(...p.map(w=>w.wallet_index),0)+1,y=yield t.embeddedWallet.add({chainType:o,hdWalletIndex:v,entropyId:g,entropyIdVerifier:m}),S=_jssdkcore.getAllUserEmbeddedBitcoinWallets.call(void 0, y.user).find(w=>w.chain_type===o&&w.wallet_index===v);if(!y.user||!S)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:S,entropyId:g,entropyIdVerifier:m})}}),[t]);return{wallets:i,create:n}};var Gt=()=>{let{isReady:e,logout:t,getAccessToken:i,error:n}=_react.useContext.call(void 0, _chunkVCDHJV7Cjs.s);return{user:_chunkVCDHJV7Cjs.d.call(void 0, ),isReady:e,error:n,logout:t,getAccessToken:i}};var Dt=()=>{let e=C();return _react.useMemo.call(void 0, ()=>({generateAuthorizationSignature(i){return _chunkOWCFWPALjs.d.call(void 0, this,null,function*(){let{signature:n}=yield _jssdkcore.generateAuthorizationSignature.call(void 0, (...o)=>e.embeddedWallet.signWithUserSigner(...o),i);return{signature:n}})}}),[e])};exports.a = $t; exports.b = oo; exports.c = C; exports.d = fo; exports.e = Co; exports.f = Lo; exports.g = Go; exports.h = $o; exports.i = tn; exports.j = mn; exports.k = Sn; exports.l = Pn; exports.m = Rn; exports.n = Kn; exports.o = Xn; exports.p = ti; exports.q = ai; exports.r = hi; exports.s = bi; exports.t = xi; exports.u = Bi; exports.v = Ji; exports.w = os; exports.x = ds; exports.y = ys; exports.z = Es; exports.A = Is; exports.B = se; exports.C = Ds; exports.D = js; exports.E = ea; exports.F = sa; exports.G = ga; exports.H = va; exports.I = Mt; exports.J = It; exports.K = Tt; exports.L = Gt; exports.M = Dt;