@privy-io/expo 0.64.0 → 0.64.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{a as P,b as N,d as l,e as ut,f as mt,g as ye}from"./chunk-QTVIWU3N.js";import{useEffect as Rr}from"react";import{create as Ir}from"zustand";var pt=Ir(()=>({status:"disconnected"})),fe=()=>pt.getState().onNeedsRecovery,Or=e=>{Rr(()=>{pt.setState({onNeedsRecovery:e==null?void 0:e.onNeedsRecovery})},[e==null?void 0:e.onNeedsRecovery])};import{digest as Mr}from"expo-crypto";import Fr from"@privy-io/js-sdk-core";var yt={name:"@privy-io/expo",version:"0.64.0",description:"Expo client for the Privy Auth API",keywords:["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],homepage:"https://docs.privy.io",bugs:{url:"https://privy.io/slack"},license:"Apache-2.0",author:"privy.io",exports:{".":{require:"./dist/index.js",import:"./dist/esm/index.js",types:"./dist/index.d.ts"},"./passkey":{require:"./dist/passkey.js",import:"./dist/esm/passkey.js",types:"./dist/passkey.d.ts"},"./smart-wallets":{require:"./dist/smart-wallets.js",import:"./dist/esm/smart-wallets.js",types:"./dist/smart-wallets.d.ts"},"./extended-chains":{require:"./dist/extended-chains.js",import:"./dist/esm/extended-chains.js",types:"./dist/extended-chains.d.ts"},"./ui":{require:"./dist/ui.js",import:"./dist/esm/ui.js",types:"./dist/ui.d.ts"},"./connectors":{require:"./dist/connectors.js",import:"./dist/esm/connectors.js",types:"./dist/connectors.d.ts"}},main:"./dist/esm/index.js",source:"./src/index.ts",types:"./dist/index.d.ts",files:["dist/**/*","LICENSE","README.md"],scripts:{build:"tsup --clean --minify","check-types":"tsc --noEmit",clean:"rm -rf dist .turbo","clean:reset":"rm -rf dist .turbo node_modules",dev:"tsup --watch",format:'eslint "src/**/*.{ts,tsx,js,jsx}" --fix',"generate-types":"tsup --dts-only",lint:'eslint "src/**/*.{ts,tsx,js,jsx}"',test:"jest"},browserslist:["defaults","node >= 18","not op_mini all"],dependencies:{"@privy-io/api-types":"0.8.0","@privy-io/js-sdk-core":"workspace:*","@scure/base":"^1.2.4","react-fast-compare":"^3.2.2",tweetnacl:"^1.0.3",zustand:"^5.0.4"},devDependencies:{"@privy-io/eslint-config-custom":"workspace:*","@privy-io/eslint-plugin-privy-rules":"workspace:*","@privy-io/tsconfig":"workspace:*","@simplewebauthn/types":"9.0.1","@solana/web3.js":"^1.98.0","@svgr/core":"^8.1.0","@svgr/plugin-jsx":"^8.1.0","@svgr/plugin-svgo":"^8.1.0","@testing-library/react-native":"^13.1.0","@tsconfig/node16-strictest-esm":"^1.0.3","@types/jest":"^29.1.2","@types/react":"^18.3.18",buffer:"^5.4.3","eslint-plugin-react-hooks":"^5.0.0-canary-7118f5dd7-20230705","expo-apple-authentication":"7.1.3","expo-application":"6.0.2","expo-clipboard":"7.0.1","expo-crypto":"14.0.2","expo-linking":"5.0.2","expo-secure-store":"12.5.0","expo-web-browser":"15.0.9",jest:"^29.7.0","jest-expo":"52.0.5","lucide-react-native":"^0.474.0",react:"^18.3.1","react-native":"0.77.1","react-test-renderer":"^18.3.1",tsup:"^6.2.3",typescript:"~5.5.3"},peerDependencies:{"@privy-io/expo-native-extensions":"workspace:*","expo-apple-authentication":"*","expo-application":"*","expo-clipboard":"*","expo-crypto":"*","expo-linking":"*","expo-secure-store":"*","expo-web-browser":"*",permissionless:"^0.2.47",react:"*","react-native":"*","react-native-passkeys":"^0.4.0","react-native-qrcode-styled":"0.3.3","react-native-safe-area-context":"*","react-native-svg":"*","react-native-webview":"*",viem:"2.47.4"},peerDependenciesMeta:{permissionless:{optional:!0},viem:{optional:!0},"react-native-svg":{optional:!0},"expo-apple-authentication":{optional:!0},"expo-clipboard":{optional:!0},"expo-crypto":{optional:!0},"expo-linking":{optional:!0},"expo-secure-store":{optional:!0},"expo-web-browser":{optional:!0},"react-native-qrcode-styled":{optional:!0},"react-native-safe-area-context":{optional:!0}},publishConfig:{access:"public"}};var ft=({appId:e,clientId:t,storage:r=ye,supportedChains:n,baseUrl:i,logLevel:o,logger:a})=>new Fr({appId:e,clientId:t,supportedChains:n,storage:mt(r),sdkVersion:`expo:${yt.version}`,nativeAppIdentifier:ut(),crypto:{digest:Mr},baseUrl:i,logLevel:o,logger:a});import{useCallback as it,useContext as Ai}from"react";import{PrivyClientError as Ri}from"@privy-io/js-sdk-core";import Z,{useState as L,useMemo as ki,createContext as Wi,useCallback as Ue,useRef as le,useEffect as br,useContext as xi}from"react";import{AppState as Sr,View as Pi}from"react-native";import{PrivyClientError as Er}from"@privy-io/js-sdk-core";import Tr from"react-fast-compare";import{create as Nr}from"zustand";var ge=Nr(()=>{}),gt=e=>ge.setState(t=>Tr(t,e)?t:e),W=ge.getState;import Vr from"react";import{useCallback as Kr,useEffect as zr,useRef as Hr}from"react";import{AppState as Br}from"react-native";import qr from"react-native-webview";import*as F from"expo-secure-store";function ht(e){return typeof e!="object"||e===null||!("event"in e&&typeof e.event=="string")||!("id"in e&&typeof e.id=="string")||!("data"in e&&typeof e.data=="object")||e.data===null?!1:e.event.startsWith("app:secure-storage:")}function wt(e){return l(this,null,function*(){switch(e.event){case"app:secure-storage:get":{let{key:t}=e.data,r=yield F.getItemAsync(Oe(t),{keychainAccessible:F.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).catch(n=>(console.warn("Failed to get the value from secure store",n),null));return{event:e.event,id:e.id,data:{value:r}}}case"app:secure-storage:remove":{let{key:t}=e.data,r=yield F.deleteItemAsync(Oe(t),{keychainAccessible:F.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(n=>(console.warn("Failed to remove the value from secure store",n),!1));return{event:e.event,id:e.id,data:{success:r}}}case"app:secure-storage:set":{let{key:t,value:r}=e.data,n=yield F.setItemAsync(Oe(t),r,{keychainAccessible:F.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(i=>(console.warn("Failed to write the value to secure store",i),!1));return{event:e.event,id:e.id,data:{success:n}}}}})}var Oe=e=>e.replaceAll(":","-");import Dr from"react-fast-compare";import{createStore as jr,useStore as Le}from"zustand";var j=jr()(()=>({user:null,proxyStatus:"loading"}));function b(){return j.getState().user}var Ji=j.subscribe.bind(j);function Me(e){j.setState(({user:t})=>Dr(t,e)?{}:{user:e})}var Fe=e=>j.setState({proxyStatus:e});function U(){return Le(j,e=>e.user)}function $i(){return Le(j,e=>!!e.user)}function V(){return Le(j,e=>e.proxyStatus!=="loading")}var Gr={shouldUseAppBackedStorage:!0},vt=({client:e,isClientReady:t})=>{let r=Hr(null);zr(()=>Br.addEventListener("change",o=>l(void 0,null,function*(){o==="active"&&((yield e.embeddedWallet.ping(500))||(Fe("reloading"),e.embeddedWallet.reload()))})).remove,[e]);let n=Kr(i=>l(void 0,null,function*(){var s;let{data:o}=i.nativeEvent,a=JSON.parse(o);if(ht(a)){let d=yield wt(a);(s=r.current)==null||s.postMessage(JSON.stringify(d));return}e.embeddedWallet.onMessage(a)}),[e]);return t?Vr.createElement(qr,{style:{flex:1},ref:i=>{i&&(e.setMessagePoster(i),r.current=i)},cacheEnabled:!1,cacheMode:"LOAD_NO_CACHE",injectedJavaScriptObject:Gr,source:{uri:e.embeddedWallet.getURL()},webviewDebuggingEnabled:e.logger.level==="DEBUG",onLoad:()=>Fe("loaded"),onError:console.error,onMessage:n}):null};import{useCallback as Te,useEffect as _t,useMemo as Ne}from"react";import{errorIndicatesRecoveryIsNeeded as $r,getAllUserEmbeddedSolanaWallets as Yr,getEntropyDetailsFromUser as Ct,PrivyClientError as re}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedSolanaWallets as he,getEntropyDetailsFromAccount as bt,getUserEmbeddedEthereumWallet as Jr,PrivyClientError as B}from"@privy-io/js-sdk-core";function St(o){return l(this,arguments,function*({client:e,setSolanaWallet:t,createSolanaWalletCallbacks:r,setSolanaRecoveryFlowState:n,opts:i}){var a,s,d;t({status:"creating"});try{let{user:c}=yield e.user.get(),u=he(c),m=u[0],p=(a=Jr(c))!=null?a:void 0;if(i!=null&&i.recoveryMethod&&i.recoveryMethod!=="privy")throw new B({code:"embedded_wallet_creation_error",error:"Unsupported recovery method for solana wallet."});if(!(i!=null&&i.createAdditional)&&m)throw new B({code:"embedded_wallet_creation_error",error:"Solana wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let w,g;if(m){let y=p!=null?p:m,{entropyId:h,entropyIdVerifier:S}=bt(y),_=Math.max(...u.map(x=>x.wallet_index),0)+1,C=yield e.embeddedWallet.add({chainType:"solana",entropyId:h,entropyIdVerifier:S,hdWalletIndex:_}),k=he(C.user).find(x=>x.wallet_index===_);if(!k)throw new B({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});w=yield e.embeddedWallet.getSolanaProvider(k,h,S),g=C.user}else{let y=yield e.embeddedWallet.createSolana({ethereumAccount:p}),h=he(y.user).find(k=>k.wallet_index===0);if(!h)throw new B({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let S=p!=null?p:h,{entropyId:_,entropyIdVerifier:C}=bt(S);w=yield e.embeddedWallet.getSolanaProvider(h,_,C),g=y.user}let v=he(g)[0];if(!v)throw new B({code:"embedded_wallet_creation_error",error:"Unknown error creating solana wallet"});return(d=(s=r.current)==null?void 0:s.onSuccess)==null||d.call(s,w),t({status:"connected",publicKey:v.public_key}),n({status:"initial"}),w}catch(c){let u=c instanceof Error?c.message:"Error creating embedded wallet";throw t({status:"error",error:u}),n({status:"initial"}),new B({code:"embedded_wallet_creation_error",error:u})}})}import{PrivyClientError as z}from"@privy-io/js-sdk-core";function we(u){return l(this,arguments,function*({client:e,account:t,setWallet:r,recoverWalletCallbacks:n,recoveryMethod:i,setRecoveryFlowState:o,password:a,recoveryKey:s,recoveryToken:d,recoverySecretOverride:c}){var m,p,w,g;if(!t)throw new z({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});switch(i){case"user-passcode":if(!a)throw new z({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"google-drive":if(!d)throw new z({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!c)throw new z({code:"embedded_wallet_recovery_error",error:"Record name is required for icloud recovery method"});break;case"recovery-encryption-key":if(!s)throw new z({code:"embedded_wallet_recovery_error",error:"recoveryKey is required for recovery-encryption-key recovery method"});break}r({status:"connecting",account:t});try{let v=yield e.embeddedWallet.getProvider(t,a,d,c,s);return r({status:"connected",provider:v,account:t}),o({status:"initial"}),(p=(m=n.current)==null?void 0:m.onSuccess)==null||p.call(m,v),v}catch(v){r({status:"needs-recovery",account:t}),o({status:"initial"});let y=new z({code:"embedded_wallet_recovery_error",error:v instanceof Error?v.message:"Error recovering embedded wallet"});throw(g=(w=n.current)==null?void 0:w.onError)==null||g.call(w,y),y}})}function Et(s){return l(this,arguments,function*({client:e,account:t,entropyId:r,entropyIdVerifier:n,setSolanaWallet:i,recoverSolanaWalletCallbacks:o,setSolanaRecoveryFlowState:a}){var d,c,u,m;i({status:"connecting"});try{let p=yield e.embeddedWallet.getSolanaProvider(t,r,n);return i({status:"connected",publicKey:p._publicKey}),a({status:"initial"}),(c=(d=o.current)==null?void 0:d.onSuccess)==null||c.call(d,p),p}catch(p){i({status:"needs-recovery"}),a({status:"initial"});let w=new z({code:"embedded_wallet_recovery_error",error:p instanceof Error?p.message:"Error recovering embedded wallet"});throw(m=(u=o.current)==null?void 0:u.onError)==null||m.call(u,w),w}})}var kt=({client:e,solanaWallet:t,setSolanaWallet:r,setSolanaRecoveryFlowState:n,createSolanaWalletCallbacks:i,recoverSolanaWalletCallbacks:o})=>{let a=U(),s=Ne(()=>Yr(a),[a]),d=V(),c=Ne(()=>s.length===0?null:Ct(a),[a,s]),u=Ne(()=>{let g=s.map(S=>{let _=Ct(a,S);return _?{account:S,entropy:_}:null});if(g.some(S=>S===null))return[];let v=void 0,y=void 0,h=void 0;return g.filter(S=>S!==null).map(({account:S,entropy:{entropyId:_,entropyIdVerifier:C}})=>({address:S.address,publicKey:S.address,walletIndex:S.wallet_index,getProvider:()=>e.embeddedWallet.getSolanaProvider(S,_,C,v,y,h,k=>l(void 0,null,function*(){var x;yield(x=fe())==null?void 0:x(k)}))}))},[s,a,e]),m=Te(g=>l(void 0,null,function*(){return yield St({client:e,setSolanaWallet:r,createSolanaWalletCallbacks:i,setSolanaRecoveryFlowState:n,opts:g})}),[e,i]),p=Te(()=>l(void 0,null,function*(){if(!c)throw new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{entropyId:g,entropyIdVerifier:v}=c;return Et({client:e,account:s[0],entropyId:g,entropyIdVerifier:v,setSolanaWallet:r,recoverSolanaWalletCallbacks:o,setSolanaRecoveryFlowState:n})}),[e,c,s,o,n,r]),w=Te(()=>l(void 0,null,function*(){if(!c)throw r({status:"not-created"}),new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});r(g=>g.status==="connected"?{status:"reconnecting"}:{status:"connecting"});try{let{entropyId:g,entropyIdVerifier:v}=c,y=yield e.embeddedWallet.getSolanaProvider(s[0],g,v);return r({status:"connected",publicKey:s[0].public_key}),y}catch(g){throw $r(g)?(r({status:"needs-recovery"}),new re({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):g instanceof Error?(r({status:"error",error:g.message}),new re({code:"unknown_embedded_wallet_error",error:g.message})):(r({status:"error",error:"Error loading embedded wallet"}),new re({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[s,e,c,r]);return _t(()=>{if(!a&&t.status!=="disconnected")return r({status:"disconnected"});d&&w().catch(()=>{})},[d,a]),_t(()=>{t.status==="error"&&t.error.includes("User must be logged in")&&w()},[t.status]),{create:m,recover:p,getProvider:w,wallets:u}};import{useCallback as ie,useEffect as At,useMemo as ao}from"react";import{getUserEmbeddedEthereumWallet as so,getUserEmbeddedSolanaWallet as Rt,isUnifiedWallet as co,throwIfInvalidRecoveryUpgradePath as lo}from"@privy-io/js-sdk-core";import{errorIndicatesRecoveryIsNeeded as uo,PrivyClientError as A}from"@privy-io/js-sdk-core";import{getUserEmbeddedEthereumWallet as Qr}from"@privy-io/js-sdk-core";import{PrivyClientError as q}from"@privy-io/js-sdk-core";function ve(m){return l(this,arguments,function*({client:e,setWallet:t,createWalletCallbacks:r,recoveryMethod:n,setRecoveryFlowState:i,password:o,recoveryKey:a,recoveryToken:s,recoverySecretOverride:d,iCloudRecordNameOverride:c,solanaAccount:u}){var w,g;switch(n){case"user-passcode":if(!o)throw new q({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"recovery-encryption-key":if(!a)throw new q({code:"embedded_wallet_recovery_error",error:"key is required for recovery-encryption-key recovery method"});break;case"google-drive":if(!s)throw new q({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!d||!c)throw new q({code:"embedded_wallet_recovery_error",error:"iCloud recovery failed due to inability to store credentials"});break}t({status:"creating",account:null});let p=n==="icloud"?"icloud-native":n;try{let{user:v}=yield e.embeddedWallet.create({password:o,recoveryMethod:p,recoveryKey:a,recoveryToken:s,recoverySecretOverride:d,iCloudRecordNameOverride:c,solanaAccount:u}),y=Qr(v);if(!y)throw new q({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let h=yield e.embeddedWallet.getProvider(y);return(g=(w=r.current)==null?void 0:w.onSuccess)==null||g.call(w,h),t({status:"connected",provider:h,account:y}),i({status:"initial"}),h}catch(v){let y=v instanceof Error?v.message:"Error creating embedded wallet";throw t({status:"error",error:y,account:null}),i({status:"initial"}),new q({code:"embedded_wallet_creation_error",error:y})}})}import{Platform as Wt}from"react-native";import{PrivyClientError as D}from"@privy-io/js-sdk-core";function xt(){return l(this,null,function*(){try{return yield import("@privy-io/expo-native-extensions")}catch(e){throw new Error("@privy-io/expo-native-extensions not found. Ensure that you're explicitly including as a dependency, and running an Expo development build")}})}function oe(n){return l(this,arguments,function*({user:e,appId:t,client:r}){var s;if(Wt.OS==="android")throw new D({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let i=yield xt(),o=yield r.recovery.icloudAuth.getICloudConfiguration("expo-ios");if(!(o==null?void 0:o.container_identifier))throw new D({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:d,iCloudRecordName:c}=yield i.writeRecoverySecretToICloud({containerId:o.container_identifier,appId:t,userId:e.id});return{recoverySecret:d,iCloudRecordName:c}}catch(d){if(d instanceof Error){let c=(s=d.message.split("Caused by: ")[1])!=null?s:"Error writing to iCloud";throw new D({code:"embedded_wallet_recovery_error",error:c})}throw new D({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}function be(n){return l(this,arguments,function*({walletAddress:e,client:t,chainType:r}){var c;if(Wt.OS==="android")throw new D({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let i=yield xt(),a=(yield t.recovery.getRecoveryKeyMaterial(e,r)).icloud_record_name;if(!a)throw new D({code:"embedded_wallet_recovery_error",error:"iCloud recovery not properly backed up."});let s=yield t.recovery.icloudAuth.getICloudConfiguration("expo-ios"),d=s==null?void 0:s.container_identifier;if(!d)throw new D({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:u}=yield i.readRecoverySecretFromICloud({containerId:d,recordName:a});return{recoverySecret:u}}catch(u){if(u instanceof Error){let m=(c=u.message.split("Caused by: ")[1])!=null?c:"Error writing to iCloud";throw new D({code:"embedded_wallet_recovery_error",error:m})}throw new D({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}import*as H from"expo-linking";import*as Pt from"expo-web-browser";import{Platform as Ut}from"react-native";import{PrivyClientError as J}from"@privy-io/js-sdk-core";import Pa from"react-fast-compare";import{PrivyApiError as Xr,PrivyClientError as Zr}from"@privy-io/js-sdk-core";function E(e){return e instanceof Error||e instanceof Xr||e instanceof Zr?e:typeof e=="string"?new Error(e):new Error("Unknown error")}var G=e=>new Promise(t=>setTimeout(t,e));import{useEffect as eo,useRef as to}from"react";import{AppState as De}from"react-native";function Se(){let e=to(De.currentState);eo(()=>De.addEventListener("change",n=>{e.current=n}).remove,[]);function t(){return De.currentState}return{appState:e,getCurrentAppState:t}}function ne(i){return l(this,arguments,function*({provider:e,redirectUri:t,client:r,onError:n}){try{let o;switch(e){case"google-drive":{let{url:c}=yield r.recovery.auth.generateURL(H.createURL(t||"/"));o=c;break}default:throw new J({error:"OAuth invalid provider",code:"embedded_wallet_recovery_error"})}let a=yield Pt.openAuthSessionAsync(o);if(Ut.OS==="android")return;if(a.type!=="success")throw new J({error:"Recovery OAuth session failed",code:"embedded_wallet_recovery_error"});let{queryParams:s}=H.parse(a.url),d;switch(e){case"google-drive":{let{privy_oauth_state:c,privy_oauth_code:u}=s;if(!u||!c)throw new J({error:"Recovery OAuth invalid credentials",code:"embedded_wallet_recovery_error"});d=yield Ee({oAuthCode:u,oAuthState:c,client:r});break}default:throw new J({error:"Recovery OAuth invalid provider",code:"embedded_wallet_recovery_error"})}return d}catch(o){throw n==null||n(E(o)),o}})}function Ee(n){return l(this,arguments,function*({oAuthCode:e,oAuthState:t,client:r}){let{access_token:i}=yield r.recovery.auth.authorize(e,t);if(!i)throw new J({error:"OAuth invalid credentials",code:"login_with_oauth_returned_with_invalid_credentials"});return i})}var ro=2*60*1e3;function oo(e){let t;return new Promise((r,n)=>{t=H.addEventListener("url",o=>l(this,[o],function*({url:i}){if(!i)return;let{queryParams:a}=H.parse(i),{privy_oauth_state:s,privy_oauth_code:d}=a!=null?a:{};if(typeof d!="string"||typeof s!="string")return;let c=yield Ee({client:e,oAuthCode:d,oAuthState:s});r(c)})),setTimeout(()=>{n(new J({code:"embedded_wallet_set_recovery_error",error:"Failed to complete Google Drive recovery flow"}))},ro)}).finally(()=>{t==null||t.remove()})}function _e(e){return l(this,null,function*(){let t;Ut.OS==="android"&&(t=oo(e));let r=yield ne({provider:"google-drive",client:e});return r!=null?r:yield t})}import{getUserEmbeddedWallet as no,PrivyClientError as io}from"@privy-io/js-sdk-core";function Ce(o){return l(this,arguments,function*({client:e,recoveryInput:t,setWalletRecoveryCallbacks:r,setRecoveryFlowState:n,setWallet:i}){var a,s,d,c;try{let{provider:u,user:m}=yield e.embeddedWallet.setRecovery(t),p=u,w=no(m);return i({status:"connected",provider:p,account:w}),(s=(a=r.current)==null?void 0:a.onSuccess)==null||s.call(a,p),n({status:"initial"}),p}catch(u){let m=new io({code:"embedded_wallet_set_recovery_error",error:u instanceof Error?u.message:"Error setting password on embedded wallet"});throw(c=(d=r.current)==null?void 0:d.onError)==null||c.call(d,m),n({status:"initial"}),m}})}function It(e){return e===void 0?{recoveryMethod:"privy"}:typeof e=="string"?{recoveryMethod:"user-passcode",password:e}:e.recoveryMethod==="user-passcode"?{recoveryMethod:"user-passcode",password:e.password}:e.recoveryMethod==="recovery-encryption-key"?{recoveryMethod:"recovery-encryption-key",recoveryKey:e.recoveryKey}:{recoveryMethod:e.recoveryMethod}}var Ot=({client:e,appId:t,wallet:r,setWallet:n,setRecoveryFlowState:i,createWalletCallbacks:o,recoverWalletCallbacks:a,setWalletRecoveryCallbacks:s})=>{let d=U(),c=ao(()=>so(d),[d]),u=V(),m=ie(y=>l(void 0,null,function*(){var ue,me;if(c)throw new A({error:"This user already has an embedded wallet",code:"embedded_wallet_already_exists"});let{user:h}=yield e.user.get(),{password:S,recoveryMethod:_,recoveryKey:C}=It(y),k,x,M;if(_==="google-drive"&&(k=yield ne({provider:_,client:e,onError:(ue=o.current)==null?void 0:ue.onError}),i({status:"creating-wallet"}),!k))return null;if(_==="icloud"){if(!h)throw new A({code:"embedded_wallet_recovery_error",error:"User must be loaded before creating a wallet with iCloud."});let{recoverySecret:Ae,iCloudRecordName:te}=yield oe({user:h,appId:t,client:e});x=Ae,M=te}return yield ve({client:e,setWallet:n,createWalletCallbacks:o,recoveryMethod:_,recoveryKey:C,setRecoveryFlowState:i,password:S,recoverySecretOverride:x,iCloudRecordNameOverride:M,solanaAccount:(me=Rt(h))!=null?me:void 0})}),[e,c,d]),p=ie(y=>l(void 0,null,function*(){var _;if(r.status!=="connected")throw new A({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"});if(!c)throw new A({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(Rt(d))throw new A({code:"embedded_wallet_set_recovery_error",error:"Cannot set user-controlled recovery for a user with an embedded Solana wallet."});if(co(c))throw new A({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"});lo({currentRecoveryMethod:c.recovery_method,upgradeToRecoveryMethod:y.recoveryMethod});let h,S;switch(y.recoveryMethod){case"privy":S=N(P({},y),{wallet:c});break;case"user-passcode":S=N(P({},y),{wallet:c,password:y.password});break;case"google-drive":if(h=yield ne({provider:y.recoveryMethod,client:e,onError:(_=s.current)==null?void 0:_.onError}),i({status:"upgrading-recovery"}),!h)return null;S={recoveryMethod:"google-drive",wallet:c,recoveryAccessToken:h};break;case"icloud":if(!d)throw new A({code:"embedded_wallet_recovery_error",error:"User must be loaded before backing up to iCloud."});let{recoverySecret:C,iCloudRecordName:k}=yield oe({user:d,appId:t,client:e});S={recoveryMethod:"icloud-native",recoverySecretOverride:C,iCloudRecordNameOverride:k,wallet:c};break;default:throw new A({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}return Ce({client:e,recoveryInput:S,setWalletRecoveryCallbacks:s,setRecoveryFlowState:i,setWallet:n})}),[e,c,r.status,d]),w=ie(y=>l(void 0,null,function*(){return p({recoveryMethod:"user-passcode",password:y})}),[e,c,r.status]),g=ie(y=>l(void 0,null,function*(){var x;if(!c)throw new A({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{password:h,recoveryMethod:S,recoveryKey:_}=It(y),C,k;if(S==="google-drive"&&(C=yield ne({provider:S,client:e,onError:(x=a.current)==null?void 0:x.onError}),i({status:"recovering"}),!C))return null;if(S==="icloud"){if(!d)throw new A({code:"embedded_wallet_recovery_error",error:"User must be loaded before recovering via iCloud."});let{recoverySecret:M}=yield be({client:e,walletAddress:c.address});k=M}return we({client:e,account:c,setWallet:n,recoverWalletCallbacks:a,recoveryMethod:S,setRecoveryFlowState:i,recoveryKey:_,password:h,recoveryToken:C,recoverySecretOverride:k})}),[e,c]),v=ie(()=>l(void 0,null,function*(){if(!c)throw n({status:"not-created",account:null}),new A({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});n(y=>y.status==="connected"?{status:"reconnecting",account:c}:{status:"connecting",account:c});try{let y=yield e.embeddedWallet.getProvider(c);return n({status:"connected",provider:y,account:c}),y}catch(y){throw uo(y)?(n({status:"needs-recovery",account:c}),new A({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):y instanceof Error?(n({status:"error",error:y.message,account:c}),new A({code:"unknown_embedded_wallet_error",error:y.message})):(n({status:"error",error:"Error loading embedded wallet",account:c}),new A({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[e,c]);return At(()=>{if(!d&&r.status!=="disconnected")return n({status:"disconnected",account:null});u&&v().catch(()=>{})},[u,d,c]),At(()=>{r.status==="error"&&r.error.includes("User must be logged in")&&v()},[r.status]),{create:m,recover:g,setPassword:w,setRecovery:p,getProvider:v}};import{useEffect as mo,useState as po}from"react";import{PrivyClientError as Lt}from"@privy-io/js-sdk-core";var Mt=({client:e,isReady:t})=>{let r=U(),n=ge(a=>a==null?void 0:a.customAuth),[i,o]=po({status:"initial"});return mo(()=>{(()=>l(void 0,null,function*(){if(!(n!=null&&n.enabled)){o({status:"not-enabled"});return}o({status:"loading"});let{getCustomAccessToken:s,isLoading:d}=n;if(!(!t||d))try{let c=yield s();if(!c&&r){yield e.auth.logout(),o({status:"done"});return}if(!c){o({status:"done"});return}if(r){o({status:"done"});return}let u=W();if(!(yield e.auth.customProvider.syncWithToken(c,{embedded:u==null?void 0:u.embedded}))){yield e.auth.logout(),o({status:"error",error:new Lt({error:"Failed to sync with custom auth provider",code:"third_party_auth_error"})});return}o({status:"done"})}catch(c){if(console.log("Error syncing with custom auth provider",c),o({status:"error",error:c}),r)throw yield e.auth.logout(),new Lt({error:"Third-party auth failed",code:"third_party_auth_error"})}}))()},[e,r,t,n==null?void 0:n.enabled,n==null?void 0:n.getCustomAccessToken,n==null?void 0:n.isLoading]),{customAuthState:i,customAuthStateIsSettled:i.status!=="loading"&&i.status!=="initial"}};import*as $ from"expo-linking";import{useCallback as yo,useEffect as fo,useMemo as go}from"react";import{Platform as ho}from"react-native";import{getUserEmbeddedSolanaWallet as wo,getUserEmbeddedWallet as vo}from"@privy-io/js-sdk-core";var Ft=({client:e,createWalletCallbacks:t,recoverWalletCallbacks:r,setWalletRecoveryCallbacks:n,recoveryFlowState:i,oAuthState:o,setRecoveryFlowState:a,setWallet:s,appStateVisible:d})=>{let c=$.useURL(),u=U(),m=go(()=>vo(u),[u]),p=V(),w=yo(g=>{var y,h,S,_;let v=E(g);i.status==="creating-wallet"?(h=(y=t.current).onError)==null||h.call(y,E(v)):(_=(S=r.current).onError)==null||_.call(S,E(v)),a({status:"initial"})},[i]);return fo(()=>{function g(){return l(this,null,function*(){var S;if(!c&&i.status!=="initial"&&d&&w(new Error("Recovery OAuth session failed")),!c||i.status==="initial"||o.status!=="initial"||!d||!p)return;let{queryParams:v}=$.parse(c),{privy_oauth_state:y,privy_oauth_code:h}=v;if(!(!h||!y)){yield $.openURL(c.split("?")[0]);try{let _=yield Ee({oAuthCode:h,oAuthState:y,client:e});if(i.status==="creating-wallet"){let C=(S=wo(u))!=null?S:void 0;yield ve({client:e,setWallet:s,createWalletCallbacks:t,recoveryMethod:"google-drive",setRecoveryFlowState:a,recoveryToken:_,solanaAccount:C})}else if(i.status==="upgrading-recovery"){if(!m)throw new Error("Embedded wallet not found");yield Ce({client:e,recoveryInput:{recoveryMethod:"google-drive",wallet:m,recoveryAccessToken:_},setWalletRecoveryCallbacks:n,setRecoveryFlowState:a,setWallet:s})}else yield we({client:e,account:m,setWallet:s,recoverWalletCallbacks:r,recoveryMethod:"google-drive",setRecoveryFlowState:a,recoveryToken:_})}catch(_){w(_)}}})}ho.OS==="android"&&g()},[c,i.status,d,p])};import{useEffect as bo}from"react";var Tt=({client:e,isUserInitialized:t,setIsUserInitialized:r,setError:n})=>{bo(()=>{t||(()=>l(void 0,null,function*(){try{yield e.initialize()}catch(o){n(o instanceof Error?o:new Error(String(o)))}try{yield e.user.get()}catch(o){}finally{r(!0)}}))()},[e,t,n,r])};import{useEffect as _i,useRef as Ci}from"react";import{useCallback as je,useContext as So}from"react";import{PrivyClientError as Eo}from"@privy-io/js-sdk-core";var Ls=e=>{let{client:t,setSiweState:r,siweState:n}=So(f),i=je(s=>{var c;let d=E(s);return r({status:"error",error:d}),(c=e==null?void 0:e.onError)==null||c.call(e,d),d},[e==null?void 0:e.onError]),o=je(u=>l(void 0,[u],function*({wallet:s,from:{domain:d,uri:c}}){var m;try{r({status:"generating-message"});let p=yield t.auth.siwe.init(s,d,c);return r({status:"awaiting-signature"}),(m=e==null?void 0:e.onGenerateMessage)==null||m.call(e,p.message),p.message}catch(p){throw i(p)}}),[t,i,e==null?void 0:e.onGenerateMessage]);return{loginWithSiwe:je(u=>l(void 0,[u],function*({signature:s,messageOverride:d,disableSignup:c}){var m;try{if(b())throw new Eo({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"});r({status:"submitting-signature"});let w=W(),g=yield t.auth.siwe.loginWithSiwe(s,void 0,d,c?"no-signup":"login-or-sign-up",{embedded:w==null?void 0:w.embedded});return r({status:"done"}),(m=e==null?void 0:e.onSuccess)==null||m.call(e,g.user,g.is_new_user),g.user}catch(p){throw i(p)}}),[t,i,e==null?void 0:e.onSuccess]),generateSiweMessage:o,state:n}};import{useCallback as Nt}from"react";import{createSiwsMessage as Co,PrivyClientError as ko}from"@privy-io/js-sdk-core";import{useContext as _o}from"react";var O=()=>{let{client:e}=_o(f);return e};var Bs=()=>{let e=O(),t=Nt(a=>l(void 0,[a],function*({wallet:{address:n},from:{domain:i,uri:o}}){try{let{nonce:s}=yield e.auth.siws.fetchNonce({address:n});return{message:Co({address:n,domain:i,uri:o,nonce:s})}}catch(s){throw E(s)}}),[e]),r=Nt(s=>l(void 0,[s],function*({signature:n,message:i,wallet:{walletClientType:o,connectorType:a}={}}){try{if(!b())throw new ko({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:c}=yield e.auth.siws.link({signature:n,message:i,walletClientType:o,connectorType:a});return c}catch(d){throw E(d)}}),[e]);return{generateMessage:t,link:r}};import{useCallback as Dt}from"react";import{createSiwsMessage as Wo,PrivyClientError as xo}from"@privy-io/js-sdk-core";var ec=()=>{let e=O(),t=Dt(a=>l(void 0,[a],function*({wallet:{address:n},from:{domain:i,uri:o}}){try{let{nonce:s}=yield e.auth.siws.fetchNonce({address:n});return{message:Wo({address:n,domain:i,uri:o,nonce:s})}}catch(s){throw E(s)}}),[e]),r=Dt(d=>l(void 0,[d],function*({signature:n,message:i,wallet:{walletClientType:o,connectorType:a}={},disableSignup:s}){try{if(b())throw new xo({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"});let u=W();return(yield e.auth.siws.login({signature:n,message:i,walletClientType:o,connectorType:a,mode:s?"no-signup":"login-or-sign-up",opts:{embedded:u==null?void 0:u.embedded}})).user}catch(c){throw E(c)}}),[e]);return{generateMessage:t,login:r}};import{useCallback as jt,useContext as Po}from"react";import{PrivyClientError as Uo}from"@privy-io/js-sdk-core";var cc=e=>{let{client:t}=Po(f),r=jt(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{unlinkWallet:jt(o=>l(void 0,[o],function*({address:i}){var a;try{if(!b())throw new Uo({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:d}=yield t.auth.siwe.unlinkWallet(i);return(a=e==null?void 0:e.onSuccess)==null||a.call(e,d),d}catch(s){throw r(s)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useCallback as Ve,useContext as Ao,useState as Ro}from"react";import{PrivyClientError as Vt}from"@privy-io/js-sdk-core";var gc=e=>{let[t,r]=Ro(""),{client:n,otpState:i,setOtpState:o}=Ao(f),a=Ve(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=Ve(u=>l(void 0,[u],function*({email:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.email.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{email:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=Ve(m=>l(void 0,[m],function*({code:c,email:u}){var p;try{if(!b())throw new Vt({code:"attempted_link_email_before_logged_in",error:"Must be logged in to link an email, Use `useLoginWithEmail` to login with email"});let g=u||t;if(!g)throw new Vt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});o({status:"submitting-code"});let{user:v}=yield n.auth.email.linkWithCode(g,c);return o({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,v),v}catch(w){throw a(w)}}),[t,o,n,e,a]);return{sendCode:s,linkWithCode:d,state:i}};import{useCallback as Kt,useContext as Io}from"react";var Ec=e=>{let{client:t}=Io(f),r=Kt(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{unlinkEmail:Kt(o=>l(void 0,[o],function*({email:i}){var a;try{let{user:s}=yield t.auth.email.unlink(i);return(a=e==null?void 0:e.onSuccess)==null||a.call(e,s),s}catch(s){throw r(s)}}),[t,e==null?void 0:e.onSuccess,r])}};import{useCallback as Ke,useContext as Oo,useState as Lo}from"react";import{PrivyClientError as zt}from"@privy-io/js-sdk-core";var Rc=e=>{let[t,r]=Lo(""),{client:n,otpState:i,setOtpState:o}=Oo(f),a=Ke(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=Ke(u=>l(void 0,[u],function*({email:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.email.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{email:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=Ke(p=>l(void 0,[p],function*({code:c,email:u,disableSignup:m}){var w;try{if(b())throw new zt({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=u||t;if(!v)throw new zt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `loginWithCode`"});o({status:"submitting-code"});let y=W(),h=yield n.auth.email.loginWithCode(v,c,m?"no-signup":"login-or-sign-up",{embedded:y==null?void 0:y.embedded});return o({status:"done"}),(w=e==null?void 0:e.onLoginSuccess)==null||w.call(e,h.user,h.is_new_user),h==null?void 0:h.user}catch(g){throw a(g)}}),[t,o,n,e,a]);return{sendCode:s,loginWithCode:d,state:i}};import{useCallback as ze,useContext as Mo,useState as Fo}from"react";import{PrivyClientError as Ht}from"@privy-io/js-sdk-core";var Dc=e=>{let[t,r]=Fo(""),{client:n,otpState:i,setOtpState:o}=Mo(f),a=ze(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=ze(u=>l(void 0,[u],function*({phone:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.phone.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{phone:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=ze(m=>l(void 0,[m],function*({code:c,phone:u}){var p;try{if(!b())throw new Ht({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(!(u||t))throw new Ht({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});o({status:"submitting-code"});let{user:v}=yield n.auth.phone.linkWithCode(u||t,c);return o({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,v),v}catch(w){throw a(w)}}),[t,o,n,e,a]);return{sendCode:s,linkWithCode:d,state:i}};import{useCallback as He,useContext as To,useState as No}from"react";import{PrivyClientError as Bt}from"@privy-io/js-sdk-core";var Jc=e=>{let[t,r]=No(""),{client:n,otpState:i,setOtpState:o}=To(f),a=He(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=He(u=>l(void 0,[u],function*({phone:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.phone.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{phone:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=He(p=>l(void 0,[p],function*({code:c,phone:u,disableSignup:m}){var w;try{if(b())throw new Bt({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(!(u||t))throw new Bt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});o({status:"submitting-code"});let y=W(),h=yield n.auth.phone.loginWithCode(u||t,c,m?"no-signup":"login-or-sign-up",{embedded:y==null?void 0:y.embedded});return o({status:"done"}),(w=e==null?void 0:e.onLoginSuccess)==null||w.call(e,h.user,h.is_new_user),h==null?void 0:h.user}catch(g){throw a(g)}}),[t,o,n,e,a]);return{sendCode:s,loginWithCode:d,state:i}};import*as ke from"expo-linking";import{useCallback as Be,useContext as Do,useRef as jo}from"react";import{PrivyClientError as ae}from"@privy-io/js-sdk-core";var rd=e=>{let{appState:t,getCurrentAppState:r}=Se(),{client:n,farcasterState:i,setFarcasterState:o}=Do(f),a=jo(!1),s=Be(u=>{var p;let m=E(u);return o({status:"error",error:m}),(p=e==null?void 0:e.onError)==null||p.call(e,m),m},[e==null?void 0:e.onError,o]),d=Be(()=>{a.current=!0},[]);return{linkWithFarcaster:Be((w,...g)=>l(void 0,[w,...g],function*({relyingParty:u,redirectUrl:m},p={pollAttempts:10,pollIntervalMs:1e3}){var v;try{let y=b();if(a.current=!1,!y)throw new ae({code:"attempted_link_farcaster_before_logged_in",error:"Must be logged in to link a Farcaster account."});o({status:"generating-uri"});let{connect_uri:h,channel_token:S}=yield n.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:ke.createURL(m!=null?m:"/")});if(!h)throw new ae({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!S)throw new ae({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield ke.openURL(h),o({status:"polling-status"});let _=0;for(;_<p.pollAttempts;){if(a.current)throw new ae({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield G(p.pollIntervalMs);continue}let C=yield n.auth.farcaster.getFarcasterStatus({channel_token:S});if(C.state==="completed"){o({status:"submitting-token"});let{user:k}=yield n.auth.farcaster.link(P({channel_token:S},C));return o({status:"done"}),(v=e==null?void 0:e.onSuccess)==null||v.call(e,k),k}_++,yield G(p.pollIntervalMs)}throw new ae({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(y){throw s(y)}}),[n,e==null?void 0:e.onSuccess,s,o]),state:i,cancel:d}};import{useCallback as qt,useContext as Vo}from"react";var cd=e=>{let{client:t}=Vo(f),r=qt(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{unlinkFarcaster:qt(o=>l(void 0,[o],function*({fid:i}){var a;try{let{user:s}=yield t.auth.farcaster.unlink({fid:i});return(a=e==null?void 0:e.onSuccess)==null||a.call(e,s),s}catch(s){throw r(s)}}),[t,e==null?void 0:e.onSuccess,r])}};import*as We from"expo-linking";import{useCallback as Je,useContext as Ko,useRef as zo}from"react";import{PrivyClientError as se}from"@privy-io/js-sdk-core";var hd=e=>{let{appState:t,getCurrentAppState:r}=Se(),{client:n,farcasterState:i,setFarcasterState:o}=Ko(f),a=zo(!1),s=Je(u=>{var p;let m=E(u);return o({status:"error",error:m}),(p=e==null?void 0:e.onError)==null||p.call(e,m),m},[e==null?void 0:e.onError,o]),d=Je(()=>{a.current=!0},[]);return{loginWithFarcaster:Je((g,...v)=>l(void 0,[g,...v],function*({relyingParty:u,redirectUrl:m,disableSignup:p},w={pollAttempts:10,pollIntervalMs:1e3}){var y;try{if(a.current=!1,b())throw new se({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"});o({status:"generating-uri"});let{connect_uri:S,channel_token:_}=yield n.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:We.createURL(m!=null?m:"/")});if(!S)throw new se({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!_)throw new se({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield We.openURL(S),o({status:"polling-status"});let C=0;for(;C<w.pollAttempts;){if(a.current)throw new se({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield G(w.pollIntervalMs);continue}let k=yield n.auth.farcaster.getFarcasterStatus({channel_token:_});if(k.state==="completed"){o({status:"submitting-token"});let x=W(),M=yield n.auth.farcaster.authenticate(P({channel_token:_,mode:p?"no-signup":"login-or-sign-up"},k),{embedded:x==null?void 0:x.embedded});return o({status:"done"}),(y=e==null?void 0:e.onSuccess)==null||y.call(e,M.user,M.is_new_user),M.user}C++,yield G(w.pollIntervalMs)}throw new se({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(h){throw s(h)}}),[n,s,e==null?void 0:e.onSuccess,o,t]),state:i,cancel:d}};import{useCallback as Gt,useContext as Ho}from"react";import{create as Bo}from"zustand";import{PrivyClientError as qo}from"@privy-io/js-sdk-core";var $e=Bo(()=>({status:"initial"})),K=e=>$e.setState(e,!0),Go=$e.getState,xd=()=>{let{client:e}=Ho(f),t=$e(),r=Gt(()=>l(void 0,null,function*(){try{K({status:"fetching-nonce"});let i=yield e.auth.farcasterV2.initializeAuth();return K({status:"awaiting-signature"}),i}catch(i){let o=E(i);throw K({status:"initial",error:o}),o}}),[e]),n=Gt(i=>l(void 0,null,function*(){let o=Go().status;try{if(b()){let c=new qo({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 K({status:o,error:c}),c}K({status:"submitting-signature"});let s=W(),d=yield e.auth.farcasterV2.authenticate(i,{embedded:s==null?void 0:s.embedded});return K({status:"done"}),setTimeout(()=>K({status:"initial"}),1500),{user:d.user}}catch(a){let s=E(a);throw K({status:o,error:s}),s}}),[e]);return{init:r,login:n,state:t}};import{useContext as Jo,useMemo as $o}from"react";import{delegatedActions as Jt}from"@privy-io/js-sdk-core";var Od=()=>{let{client:e}=Jo(f);return $o(()=>({delegateWallet:Jt.delegateWallet(e),revokeWallets:Jt.revokeWallets(e)}),[e])};import{useContext as Xo,useMemo as Zo}from"react";import{addSessionSigners as en,removeSessionSigners as tn}from"@privy-io/js-sdk-core";import{isEmbeddedWalletAccount as Yo}from"@privy-io/js-sdk-core";function Qo(e,t){return e.linked_accounts.filter(Yo).find(r=>r.address===t)}function Y(e){let t=b();if(!t)throw new Error("User must be authenticated to perform this operation");let r=Qo(t,e);if(!r)throw new Error(`No wallet found with address ${e}`);return r}var Kd=()=>{let{client:e}=Xo(f);return Zo(()=>({addSessionSigners:({address:t,signers:r})=>en({client:e,wallet:Y(t),signers:r.map(n=>({signer_id:n.signerId,override_policy_ids:n.policyIds}))}),removeSessionSigners:({address:t})=>tn({client:e,wallet:Y(t)})}),[e])};import{useContext as rn,useMemo as on}from"react";import{addSessionSigners as nn,removeSessionSigners as an}from"@privy-io/js-sdk-core";var Jd=()=>{let{client:e}=rn(f);return on(()=>({addSigners:({address:t,signers:r})=>nn({client:e,wallet:Y(t),signers:r.map(n=>({signer_id:n.signerId,override_policy_ids:n.policyIds}))}),removeSigners:({address:t})=>an({client:e,wallet:Y(t)})}),[e])};import{useContext as sn,useMemo as cn}from"react";import{PrivyClientError as Yt}from"@privy-io/js-sdk-core";var el=()=>{let{client:e}=sn(f);return cn(()=>({sendCode(n){return l(this,arguments,function*({newEmailAddress:r}){$t(),yield e.auth.email.sendCode(r)})},updateEmail(i){return l(this,arguments,function*({newEmailAddress:r,code:n}){let{address:o}=$t(),{user:a}=yield e.auth.email.updateEmail({oldEmailAddress:o,newEmailAddress:r,code:n});return a})}}),[e])};function $t(){let t=dn().linked_accounts.find(r=>r.type==="email");if(!t)throw new Yt({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 dn(){let e=b();if(!e)throw new Yt({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import{useContext as ln,useMemo as un}from"react";import{PrivyClientError as Xt}from"@privy-io/js-sdk-core";var sl=()=>{let{client:e}=ln(f);return un(()=>({sendCode(n){return l(this,arguments,function*({newPhoneNumber:r}){Qt(),yield e.auth.phone.sendCode(r)})},updatePhone(i){return l(this,arguments,function*({newPhoneNumber:r,code:n}){let{phoneNumber:o}=Qt(),{user:a}=yield e.auth.phone.updatePhone({oldPhoneNumber:o,newPhoneNumber:r,code:n});return a})}}),[e])};function Qt(){let t=mn().linked_accounts.find(r=>r.type==="phone");if(!t)throw new Xt({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 mn(){let e=b();if(!e)throw new Xt({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import*as tr from"expo-linking";import{useCallback as yn,useContext as fn,useMemo as gn}from"react";import{crossApp as hn,PrivyClientError as wn}from"@privy-io/js-sdk-core";import*as er from"expo-linking";import*as ce from"expo-web-browser";import{PrivyClientError as Zt}from"@privy-io/js-sdk-core";var T=(e,t)=>l(void 0,null,function*(){let r=yield ce.openAuthSessionAsync(e,t,{createTask:!1});if(r.type!=="success")throw r.type===ce.WebBrowserResultType.CANCEL||r.type===ce.WebBrowserResultType.DISMISS?new Zt({error:"OAuth session was cancelled",code:"oauth_session_failed"}):new Zt({error:"OAuth session failed",code:"oauth_session_failed"});return pn(r.url)});function pn(e){let{queryParams:t}=er.parse(e);return t}var wl=()=>{let{client:e}=fn(f),t=gn(()=>hn.loginWithCrossAppAuth({client:e,openAuthSession:T}),[e]);return{loginWithCrossApp:yn(o=>l(void 0,[o],function*({appId:n,redirectUri:i}){if(b())throw new wn({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:s}=yield t({providerAppId:n,redirectUrl:tr.createURL(i||"/")});return{user:s}}),[t])}};import*as rr from"expo-linking";import{useCallback as vn,useContext as bn,useMemo as Sn}from"react";import{crossApp as En,PrivyClientError as _n}from"@privy-io/js-sdk-core";var Wl=()=>{let{client:e}=bn(f),t=Sn(()=>En.linkWithCrossAppAuth({client:e,openAuthSession:T}),[e]);return{linkWithCrossApp:vn(o=>l(void 0,[o],function*({appId:n,redirectUri:i}){if(!b())throw new _n({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:rr.createURL(i||"/")})}}),[t])}};import*as nr from"expo-linking";import{useContext as Cn,useMemo as or}from"react";import{crossApp as kn}from"@privy-io/js-sdk-core";var Ll=()=>{let{client:e}=Cn(f),t=or(()=>kn.wallet.signMessage({client:e,openAuthSession:T}),[e]);return or(()=>({signMessage:({address:r,message:n,redirectUri:i="/"})=>t({user:b(),address:r,message:n,redirectUrl:nr.createURL(i)})}),[t])};import*as ar from"expo-linking";import{useContext as Wn,useMemo as ir}from"react";import{crossApp as xn}from"@privy-io/js-sdk-core";var Vl=()=>{let{client:e}=Wn(f),t=ir(()=>xn.wallet.signTypedData({client:e,openAuthSession:T}),[e]);return ir(()=>({signTypedData:({address:r,typedData:n,redirectUri:i="/"})=>t({user:b(),address:r,typedData:n,redirectUrl:ar.createURL(i)})}),[t])};import*as cr from"expo-linking";import{useContext as Pn,useMemo as sr}from"react";import{crossApp as Un}from"@privy-io/js-sdk-core";var Jl=()=>{let{client:e}=Pn(f),t=sr(()=>Un.wallet.sendTransaction({client:e,openAuthSession:T}),[e]);return sr(()=>({sendTransaction:({address:r,transaction:n,redirectUri:i="/"})=>t({user:b(),address:r,transaction:n,redirectUrl:cr.createURL(i)})}),[t])};import{useCallback as An,useContext as Rn}from"react";import{getUserEmbeddedEthereumWallet as In,getUserEmbeddedSolanaWallet as On,isUnifiedWallet as Ln,PrivyClientError as Q,throwIfInvalidRecoveryUpgradePath as Mn}from"@privy-io/js-sdk-core";var ru=()=>{let{client:e}=Rn(f);return{setRecovery:An(r=>l(void 0,null,function*(){var s;let n=b(),i=e.app.appId;if(!n)throw new Q({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let o=(s=In(n))!=null?s:On(n);if(!o)throw new Q({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(Ln(o))throw new Q({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{o.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(o):o.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(o,o.address,"solana-address-verifier"))}catch(d){throw new Q({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}Mn({currentRecoveryMethod:o.recovery_method,upgradeToRecoveryMethod:r.recoveryMethod});let a=yield Fn({appId:i,client:e,user:n,primaryAccount:o,recoveryParams:r});try{let{user:d}=yield e.embeddedWallet.setRecovery(a);return{user:d}}catch(d){throw new Q({code:"embedded_wallet_set_recovery_error",error:d instanceof Error?d.message:"Error setting password on embedded wallet"})}}),[e])}},Fn=o=>l(void 0,[o],function*({appId:e,client:t,user:r,primaryAccount:n,recoveryParams:i}){switch(i.recoveryMethod){case"privy":return{recoveryMethod:"privy",wallet:n};case"user-passcode":return N(P({},i),{wallet:n});case"google-drive":{let a=yield _e(t);return{recoveryMethod:"google-drive",wallet:n,recoveryAccessToken:a}}case"icloud":{let{recoverySecret:a,iCloudRecordName:s}=yield oe({appId:e,client:t,user:r});return{recoveryMethod:"icloud-native",recoverySecretOverride:a,iCloudRecordNameOverride:s,wallet:n}}case"recovery-encryption-key":return{recoveryMethod:"recovery-encryption-key",wallet:n,recoveryKey:i.recoveryKey};default:throw new Q({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}});import{useCallback as Tn,useContext as Nn}from"react";import{getUserEmbeddedEthereumWallet as Dn,getUserEmbeddedSolanaWallet as jn,PrivyClientError as de,isUnifiedWallet as Vn}from"@privy-io/js-sdk-core";var uu=()=>{let{client:e}=Nn(f);return{recover:Tn(r=>l(void 0,null,function*(){var c;let n=b();if(!n)throw new de({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let i=(c=Dn(n))!=null?c:jn(n);if(!i)throw new de({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(Vn(i))throw new de({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 o,a,s,d;switch(r.recoveryMethod){case"user-passcode":a=r.password;break;case"google-drive":s=yield _e(e);break;case"icloud":let{recoverySecret:u}=yield be({client:e,walletAddress:i.address,chainType:i.chain_type});d=u;break;case"recovery-encryption-key":o=r.recoveryKey;break;case"privy":break;default:throw new de({code:"unsupported_recovery_method",error:`Unsupported recovery options ${r}`})}try{i.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(i,a,s,d,o):i.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(i,i.address,"solana-address-verifier",a,s,d))}catch(u){throw new de({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};import{useEffect as zn}from"react";import{useContext as Kn,useEffect as Ye}from"react";var Qe=(e={})=>{let{wallet:t,createWalletCallbacks:r,recoverWalletCallbacks:n,setWalletRecoveryCallbacks:i}=Kn(f),{onCreateWalletSuccess:o,onCreateWalletError:a,onRecoverWalletError:s,onRecoverWalletSuccess:d,onSetWalletRecoverySuccess:c,onSetWalletRecoveryError:u}=e;return Ye(()=>{r.current={onSuccess:o,onError:a}},[o,a]),Ye(()=>{n.current={onSuccess:d,onError:s}},[d,s]),Ye(()=>{i.current={onSuccess:c,onError:u}},[d,s]),t};var vu=({onStateChange:e})=>{let t=Qe();return zn(()=>{e(t)},[t])};import{useContext as Hn}from"react";var _u=()=>{let{getIdentityToken:e}=Hn(f);return{getIdentityToken:e}};import{useCallback as dr,useContext as Bn}from"react";import{PrivyClientError as qn}from"@privy-io/js-sdk-core";var Ru=e=>{let{client:t}=Bn(f),r=dr(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{create:dr(()=>l(void 0,null,function*(){var i;try{if(b())throw new qn({code:"attempted_to_create_guest_account_for_logged_in_user",error:"Already logged in, you cannot create a guest account"});let a=W(),s=yield t.auth.guest.create({embedded:a==null?void 0:a.embedded});return(i=e==null?void 0:e.onSuccess)==null||i.call(e,s.user,s.is_new_user),s.user}catch(o){throw r(o)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useContext as Gn,useEffect as Jn}from"react";function Tu({onMfaRequired:e}){let{client:t}=Gn(f);Jn(()=>{function r(){return l(this,null,function*(){var i;let n=b();yield e((i=n==null?void 0:n.mfa_methods.map(({type:o})=>o))!=null?i:[])})}return t.mfaPromises.on("mfaRequired",r),()=>{t.mfaPromises.off("mfaRequired",r)}},[t,e])}import{useCallback as xe,useContext as Zn}from"react";import{PrivyClientError as Pe}from"@privy-io/js-sdk-core";import{PrivyClientError as $n}from"@privy-io/js-sdk-core";var Yn=e=>l(void 0,null,function*(){var n;let r=yield(yield import("react-native-passkeys")).create({rp:e.rp,user:e.user,challenge:e.challenge,pubKeyCredParams:e.pubKeyCredParams,excludeCredentials:e.excludeCredentials,authenticatorSelection:e.authenticatorSelection,timeout:12e4});if(!r)throw new $n({code:"failed_to_create_passkey",error:"Could not create passkey"});return N(P({},r),{type:(n=r.type)!=null?n:"public-key",clientExtensionResults:{}})});import{PrivyClientError as Qn}from"@privy-io/js-sdk-core";var Ze=e=>l(void 0,null,function*(){var n;let r=yield(yield import("react-native-passkeys")).get({rpId:e.rpId,challenge:e.challenge,allowCredentials:e.allowCredentials,timeout:12e4});if(!r)throw new Qn({code:"no_passkey_found_for_challenge",error:"Could not find a matching passkey to login with"});return N(P({},r),{type:(n=r.type)!=null?n:"public-key",clientExtensionResults:{}})});function lr(e){var t;return{id:e.id,client_extension_results:{app_id:e.clientExtensionResults.appid,cred_props:e.clientExtensionResults.credProps,hmac_create_secret:e.clientExtensionResults.hmacCreateSecret},raw_id:e.rawId,type:e.type,authenticator_attachment:(t=e.authenticatorAttachment)!=null?t:"platform",response:{authenticator_data:e.response.authenticatorData,client_data_json:e.response.clientDataJSON,signature:e.response.signature,user_handle:e.response.userHandle}}}function ur(e){var t,r,n,i;return{challenge:e.challenge,rpId:e.rp_id,extensions:{appid:(t=e.extensions)==null?void 0:t.app_id,credProps:(r=e.extensions)==null?void 0:r.cred_props,hmacCreateSecret:(n=e.extensions)==null?void 0:n.hmac_create_secret},timeout:e.timeout,allowCredentials:(i=e.allow_credentials)==null?void 0:i.map(({id:o,type:a,transports:s})=>({id:o,type:a,transports:s})),userVerification:e.user_verification}}function Qu(e){var t,r,n,i,o,a,s,d;return{rp:e.rp,user:{id:e.user.id,name:e.user.name,displayName:e.user.display_name},challenge:e.challenge,pubKeyCredParams:e.pub_key_cred_params,extensions:{hmacCreateSecret:(t=e.extensions)==null?void 0:t.hmac_create_secret,credProps:(n=(r=e.extensions)==null?void 0:r.cred_props)==null?void 0:n.rk,appid:(i=e.extensions)==null?void 0:i.app_id},attestation:e.attestation,excludeCredentials:e.exclude_credentials,authenticatorSelection:{authenticatorAttachment:(o=e.authenticator_selection)==null?void 0:o.authenticator_attachment,residentKey:(a=e.authenticator_selection)==null?void 0:a.resident_key,userVerification:(s=e.authenticator_selection)==null?void 0:s.user_verification,requireResidentKey:(d=e.authenticator_selection)==null?void 0:d.require_resident_key}}}function om(){let{client:e}=Zn(f),t=xe(o=>l(this,null,function*(){var a,s;switch(o.method){case"sms":yield e.mfa.sms.sendCode({action:"verify"});return;case"passkey":let{options:d}=yield e.mfa.passkey.generateAuthenticationOptions({relying_party:o.relyingParty||((s=(a=W())==null?void 0:a.mfa)==null?void 0:s.relyingParty)});return ur(d);case"totp":return;default:throw new Error(`Unsupported MFA method: ${o.mfaMethod}`)}}),[e]),r=xe(o=>l(this,null,function*(){var a,s,d,c,u,m,p;switch(o.method){case"totp":case"sms":if(typeof o.mfaCode!="string")throw new Pe({code:"invalid_mfa_code",error:"Invalid MFA code"});(d=e.mfaPromises.rootPromise.current)==null||d.resolve({mfaMethod:o.method,mfaCode:o.mfaCode,relyingParty:o.relyingParty||((s=(a=W())==null?void 0:a.mfa)==null?void 0:s.relyingParty)||""}),yield new Promise((y,h)=>{e.mfaPromises.submitPromise.current={resolve:y,reject:h}});break;case"passkey":if(typeof o.mfaCode=="string")throw new Pe({code:"invalid_passkey_response",error:"Invalid authenticator response"});let w=yield Ze(o.mfaCode),g=lr(w);(m=e.mfaPromises.rootPromise.current)==null||m.resolve({mfaMethod:o.method,relyingParty:o.relyingParty||((u=(c=W())==null?void 0:c.mfa)==null?void 0:u.relyingParty)||"",mfaCode:g}),yield new Promise((y,h)=>{e.mfaPromises.submitPromise.current={resolve:y,reject:h}});break;default:let v=new Pe({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(p=e.mfaPromises.rootPromise.current)==null||p.reject(v),v}}),[e]),n=xe(()=>l(this,null,function*(){let o=b();!o||o.mfa_methods.length===0||(yield e.mfa.verifyMfa())}),[e]),i=xe(()=>{var o;(o=e.mfaPromises.rootPromise.current)==null||o.reject(new Pe({code:"mfa_canceled",error:"MFA canceled"}))},[e]);return{init:t,submit:r,prompt:n,cancel:i}}import{useCallback as et,useContext as ei}from"react";function cm(){let{client:e}=ei(f),t=et(i=>l(this,null,function*(){switch(i.method){case"sms":case"totp":return yield e.mfa.initEnrollMfa(i);case"passkey":return;default:throw new Error(`Unsupported MFA method: ${i.method}`)}}),[e]),r=et(i=>l(this,null,function*(){switch(i.method){case"sms":case"totp":case"passkey":yield e.mfa.submitEnrollMfa(i);return;default:throw new Error(`Unsupported MFA method: ${i.method}`)}}),[e]),n=et(i=>l(this,null,function*(){switch(i.method){case"sms":case"totp":yield e.mfa.unenrollMfa(i.method);return;case"passkey":yield e.mfa.submitEnrollMfa({method:"passkey",credentialIds:[],removeForLogin:i.removeForLogin});return;default:throw new Error(`Unsupported MFA method: ${i.method}`)}}),[e]);return{initMfaEnrollment:t,submitMfaEnrollment:r,unenrollMfa:n}}import{useCallback as ti,useMemo as mr}from"react";import{getAllUserEmbeddedEthereumWallets as rt,getEntropyDetailsFromUser as pr,getUserEmbeddedSolanaWallet as ri,PrivyClientError as yr}from"@privy-io/js-sdk-core";var oi=()=>{let e=U(),t=O(),r=mr(()=>{let o=rt(e).map(a=>{let s=pr(e,a);return s?{account:a,entropy:s}:null});return o.some(a=>a===null)?[]:o.filter(a=>a!==null).map(({account:a,entropy:{entropyId:s,entropyIdVerifier:d}})=>({address:a.address,walletIndex:a.wallet_index,chainType:a.chain_type,getProvider:()=>t.embeddedWallet.getEthereumProvider({wallet:a,entropyId:s,entropyIdVerifier:d,onNeedsRecovery:c=>l(void 0,null,function*(){var u;yield(u=fe())==null?void 0:u(c)})})}))},[t,e]),n=ti((...o)=>l(void 0,[...o],function*({createAdditional:i=!1}={}){let{user:a}=yield t.user.get(),s=rt(a);if(!i&&s.length>0)throw new yr({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let d=pr(a);if(!d){let g=yield t.embeddedWallet.create({});return tt(g.user,0),{user:g.user}}let{entropyId:c,entropyIdVerifier:u}=d;if(u==="solana-address-verifier"){let g=ri(a),v=yield t.embeddedWallet.create({solanaAccount:g});return tt(v.user,0),{user:v.user}}let p=s.map(g=>g.wallet_index).reduce((g,v)=>Math.max(g,v),0)+1,w=yield t.embeddedWallet.add({chainType:"ethereum",hdWalletIndex:p,entropyId:c,entropyIdVerifier:u});return tt(w.user,p),{user:w.user}}),[t]);return mr(()=>({wallets:r,create:n}),[r,n])};function tt(e,t){let r=rt(e).find(n=>n.wallet_index===t);if(!e||!r)throw new yr({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}import{useContext as ni,useEffect as fr}from"react";var ii=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:r,recoverSolanaWalletCallbacks:n}=ni(f),{onCreateWalletSuccess:i,onCreateWalletError:o,onRecoverWalletError:a,onRecoverWalletSuccess:s}=e;return fr(()=>{r.current={onSuccess:i,onError:o}},[i,o]),fr(()=>{n.current={onSuccess:s,onError:a}},[s,a]),t};import{useCallback as ai,useMemo as si}from"react";import{getAllUserEmbeddedBitcoinWallets as ot,getEntropyDetailsFromUser as gr,isUnifiedWallet as ci,PrivyClientError as X}from"@privy-io/js-sdk-core";var di=()=>{let e=U(),t=O(),r=si(()=>{let i=gr(e);if(!i)return[];let o=ot(e),{entropyId:a,entropyIdVerifier:s}=i;return o.map(d=>({address:d.address,walletIndex:d.wallet_index,publicKey:d.public_key,chainType:d.chain_type,getProvider:()=>ci(d)?Promise.reject(new X({code:"unsupported_wallet_type",error:"Bitcoin wallet providers are only supported for on-device execution and this app uses TEE execution. Use the useSignRawHash hook from @privy-io/expo/extended-chains to sign over a hash with this wallet. Learn more at https://docs.privy.io/recipes/tee-wallet-migration-guide"})):t.embeddedWallet.getBitcoinProvider({wallet:d,entropyId:a,entropyIdVerifier:s})}))},[t,e]),n=ai(a=>l(void 0,[a],function*({chainType:i,createAdditional:o=!1}){var y;let s=t.app.getConfig();if(((y=s==null?void 0:s.embedded_wallet_config)==null?void 0:y.mode)==="user-controlled-server-wallets-only")throw i==="bitcoin-segwit"?new X({code:"unsupported_wallet_type",error:"This app uses TEE execution. Use the useCreateWallet hook from @privy-io/expo/extended-chains to create the wallet instead. Learn more https://docs.privy.io/recipes/tee-wallet-migration-guide"}):new X({code:"unsupported_wallet_type",error:`Bitcoin (${i}) 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:d}=yield t.user.get(),c=gr(d);if(!c)throw new X({code:"embedded_wallet_creation_error",error:"No existing wallet for this user, create an Ethereum walet first to add a Bitcoin wallet"});let{entropyId:u,entropyIdVerifier:m}=c,p=ot(d).filter(h=>h.chain_type===i);if(!o&&p.length>0)throw new X({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let w=p.length===0?0:Math.max(...p.map(h=>h.wallet_index),0)+1,g=yield t.embeddedWallet.add({chainType:i,hdWalletIndex:w,entropyId:u,entropyIdVerifier:m}),v=ot(g.user).find(h=>h.chain_type===i&&h.wallet_index===w);if(!g.user||!v)throw new X({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"});return{user:g.user,provider:yield t.embeddedWallet.getBitcoinProvider({wallet:v,entropyId:u,entropyIdVerifier:m})}}),[t]);return{wallets:r,create:n}};import{useContext as li}from"react";var nt=()=>{let{isReady:e,logout:t,getAccessToken:r,error:n}=li(f);return{user:U(),isReady:e,error:n,logout:t,getAccessToken:r}};import{useContext as ui}from"react";function mi(){let{client:e}=ui(f);return{acceptTerms:()=>l(this,null,function*(){return e.user.acceptTerms()})}}import{useMemo as pi}from"react";import{generateAuthorizationSignature as yi}from"@privy-io/js-sdk-core";var fi=()=>{let e=O();return pi(()=>({generateAuthorizationSignature(r){return l(this,null,function*(){let{signature:n}=yield yi((...i)=>e.embeddedWallet.signWithUserSigner(...i),r);return{signature:n}})}}),[e])};import{useCallback as Si}from"react";import{PrivyClientError as Ei}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedBitcoinWallets as gi,getUserEmbeddedEthereumWallet as hi,getUserEmbeddedSolanaWallet as wi,isEmbeddedWalletAccount as vi,isUnifiedWallet as bi}from"@privy-io/js-sdk-core";function hr(e,t){return l(this,null,function*(){var i;let r=(i=hi(t))!=null?i:wi(t);if(!r||bi(r))return{success:!0,migrated:!1};if(r.imported)throw new Error("Imported wallets cannot be migrated");if(gi(t).length>0)throw new Error("Bitcoin wallets cannot be migrated");let n=t.linked_accounts.filter(vi).filter(o=>!o.imported).filter(o=>o.chain_type==="ethereum"||o.chain_type==="solana");return r.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(r):r.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(r,r.address,"solana-address-verifier")),yield e.embeddedWallet.delegateWallets({rootWallet:{address:r.address,chainType:r.chain_type,imported:r.imported},delegatedWallets:n.map(o=>({address:o.address,chainType:o.chain_type,walletIndex:o.wallet_index}))}),yield e.user.get(),{success:!0,migrated:!0}})}var wr=()=>{let e=O();return{migrate:Si(()=>l(void 0,null,function*(){var o;let r=b(),n=e.app.getConfig();if(((o=n==null?void 0:n.embedded_wallet_config)==null?void 0:o.mode)!=="user-controlled-server-wallets-only")return{success:!0};if(!r)throw new Ei({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before migrating wallets"});return hr(e,r)}),[e])}};var vr=({disabled:e})=>{let{migrate:t}=wr(),{user:r}=nt(),n=Ci(!1);return _i(()=>{e||r&&(n.current||(n.current=!0,t().then(i=>{i.migrated&&!n.current&&(console.info("Migrated wallets for user"),n.current=!0)}).catch(i=>{console.debug("Unable to migrate wallets: ",i)}).finally(()=>{n.current=!1})))},[t,r,e]),null};var f=Wi(null),ee;function ry(e){return ee?ee.getAccessToken():e!=null&&e.strict?Promise.reject(new Er({code:"attempted_to_read_storage_before_client_initialized",error:"Called `getAccessToken` before client initialized"})):(console.warn("Called `getAccessToken` before client initialized"),Promise.resolve(null))}var oy=e=>{var ct,dt,lt;Ui();let[t,r]=L(Sr.currentState==="active");br(()=>{let I=Sr.addEventListener("change",Ar=>{r(Ar==="active")});return()=>{I.remove()}},[]),br(()=>gt(e.config),[e.config]);let[n,i]=L(!1),[o,a]=L(null),[s,d]=L(!1),[c,u]=L({status:"disconnected",account:null}),[m,p]=L({status:"disconnected"}),[w,g]=L({status:"initial"}),[v,y]=L({status:"initial"}),[h,S]=L({status:"initial"}),[_,C]=L({status:"initial"}),[k,x]=L({status:"initial"}),[M,ue]=L({status:"initial"}),[me,Ae]=L({status:"initial"}),te=le({}),Re=le({}),Ie=le({}),at=le({}),st=le({}),pe=Ue(I=>{if(I){Me(I),a(null);return}Me(null),g({status:"initial"}),y({status:"initial"}),u({status:"disconnected",account:null})},[]),R=ki(()=>{let I=e.storage||ye;return e.client?ee=e.client:ee=ft({appId:e.appId,clientId:e.clientId,supportedChains:e.supportedChains,storage:I,baseUrl:e.baseUrl,logLevel:e.logLevel}),ee.setCallbacks({setUser:pe,setIsReady:d}),ee},[e.client,e.storage,e.appId,e.clientId,e.baseUrl,e.supportedChains,e.logLevel,pe]),_r=Ue(()=>l(void 0,null,function*(){let I=b();yield R.auth.logout(I?{userId:I==null?void 0:I.id}:void 0),pe(null)}),[pe,R]),Cr=Ue(()=>l(void 0,null,function*(){try{return yield R.getAccessToken()}catch(I){return console.debug(I),null}}),[R]),kr=Ue(()=>R.getIdentityToken(),[R]);Tt({client:R,isUserInitialized:n,setIsUserInitialized:i,setError:a});let Wr=Ot({client:R,appId:e.appId,createWalletCallbacks:te,recoverWalletCallbacks:Re,setWalletRecoveryCallbacks:Ie,setRecoveryFlowState:S,wallet:c,setWallet:u}),xr=kt({client:R,createSolanaWalletCallbacks:at,recoverSolanaWalletCallbacks:st,setSolanaRecoveryFlowState:C,solanaWallet:m,setSolanaWallet:p});Ft({client:R,createWalletCallbacks:te,recoverWalletCallbacks:Re,setWalletRecoveryCallbacks:Ie,recoveryFlowState:h,oAuthState:v,setRecoveryFlowState:S,setWallet:u,appStateVisible:t});let{customAuthStateIsSettled:Pr}=Mt({client:R,isReady:n}),Ur=V();return Z.createElement(Z.Fragment,null,Z.createElement(f.Provider,{value:{client:R,isReady:Ur&&n&&Pr,error:o,logout:_r,getAccessToken:Cr,getIdentityToken:kr,wallet:P(P({},c),Wr),solanaWallet:P(P({},m),xr),oAuthState:v,recoveryFlowState:h,setRecoveryFlowState:S,solanaRecoveryFlowState:_,setSolanaRecoveryFlowState:C,createWalletCallbacks:te,recoverWalletCallbacks:Re,setWalletRecoveryCallbacks:Ie,createSolanaWalletCallbacks:at,recoverSolanaWalletCallbacks:st,setOAuthState:y,siweState:k,setSiweState:x,otpState:w,setOtpState:g,passkeyState:M,setPasskeyState:ue,farcasterState:me,setFarcasterState:Ae}},e.children,Z.createElement(vr,{disabled:(lt=(dt=(ct=e.config)==null?void 0:ct.embedded)==null?void 0:dt.disableAutomaticMigration)!=null?lt:!1})),Z.createElement(Pi,{style:{width:0,height:0,overflow:"hidden"}},Z.createElement(vt,{client:R,isClientReady:s})))},Ui=()=>{if(xi(f))throw new Er({code:"configuration_error",error:"Found multiple instances of PrivyProvider, ensure there is only one mounted in your application tree."})};var uy=e=>{let{client:t,setSiweState:r,siweState:n}=Ai(f),i=it(s=>{var c;let d=E(s);return r({status:"error",error:d}),(c=e==null?void 0:e.onError)==null||c.call(e,d),d},[e==null?void 0:e.onError]),o=it(u=>l(void 0,[u],function*({wallet:s,from:{domain:d,uri:c}}){var m;try{r({status:"generating-message"});let p=yield t.auth.siwe.init(s,d,c);return r({status:"awaiting-signature"}),(m=e==null?void 0:e.onGenerateMessage)==null||m.call(e,p.message),p.message}catch(p){throw i(p)}}),[t,i,e==null?void 0:e.onGenerateMessage]),a=it(c=>l(void 0,[c],function*({signature:s,messageOverride:d}){var u;try{if(!b())throw new Ri({code:"attempted_link_siwe_before_logged_in",error:"Must be logged in to link a wallet, Use `useLoginWithSiwe` to login with a wallet"});r({status:"submitting-signature"});let{user:p}=yield t.auth.siwe.linkWithSiwe(s,void 0,d);return r({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,p),p}catch(m){throw i(m)}}),[t,i,e==null?void 0:e.onSuccess]);return{generateSiweMessage:o,linkWithSiwe:a,state:n}};export{W as a,b,Ji as c,U as d,$i as e,Or as f,E as g,G as h,ft as i,uy as j,Ls as k,O as l,Bs as m,ec as n,cc as o,gc as p,Ec as q,Rc as r,Dc as s,Jc as t,rd as u,cd as v,hd as w,xd as x,Od as y,Kd as z,Jd as A,el as B,sl as C,wl as D,Wl as E,Ll as F,Vl as G,Jl as H,ru as I,uu as J,Qe as K,vu as L,_u as M,Ru as N,Tu as O,Yn as P,Ze as Q,Qu as R,om as S,cm as T,oi as U,ii as V,di as W,nt as X,mi as Y,fi as Z,wr as _,f as $,ry as aa,oy as ba};
1
+ import{a as P,b as N,d as l,e as ut,f as mt,g as ye}from"./chunk-QTVIWU3N.js";import{useEffect as Rr}from"react";import{create as Ir}from"zustand";var pt=Ir(()=>({status:"disconnected"})),fe=()=>pt.getState().onNeedsRecovery,Or=e=>{Rr(()=>{pt.setState({onNeedsRecovery:e==null?void 0:e.onNeedsRecovery})},[e==null?void 0:e.onNeedsRecovery])};import{digest as Mr}from"expo-crypto";import Fr from"@privy-io/js-sdk-core";var yt={name:"@privy-io/expo",version:"0.64.1",description:"Expo client for the Privy Auth API",keywords:["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],homepage:"https://docs.privy.io",bugs:{url:"https://privy.io/slack"},license:"Apache-2.0",author:"privy.io",exports:{".":{require:"./dist/index.js",import:"./dist/esm/index.js",types:"./dist/index.d.ts"},"./passkey":{require:"./dist/passkey.js",import:"./dist/esm/passkey.js",types:"./dist/passkey.d.ts"},"./smart-wallets":{require:"./dist/smart-wallets.js",import:"./dist/esm/smart-wallets.js",types:"./dist/smart-wallets.d.ts"},"./extended-chains":{require:"./dist/extended-chains.js",import:"./dist/esm/extended-chains.js",types:"./dist/extended-chains.d.ts"},"./ui":{require:"./dist/ui.js",import:"./dist/esm/ui.js",types:"./dist/ui.d.ts"},"./connectors":{require:"./dist/connectors.js",import:"./dist/esm/connectors.js",types:"./dist/connectors.d.ts"}},main:"./dist/esm/index.js",source:"./src/index.ts",types:"./dist/index.d.ts",files:["dist/**/*","LICENSE","README.md"],scripts:{build:"tsup --clean --minify","check-types":"tsc --noEmit",clean:"rm -rf dist .turbo","clean:reset":"rm -rf dist .turbo node_modules",dev:"tsup --watch",format:'eslint "src/**/*.{ts,tsx,js,jsx}" --fix',"generate-types":"tsup --dts-only",lint:'eslint "src/**/*.{ts,tsx,js,jsx}"',test:"jest"},browserslist:["defaults","node >= 18","not op_mini all"],dependencies:{"@privy-io/api-types":"0.8.0","@privy-io/js-sdk-core":"workspace:*","@scure/base":"^1.2.4","react-fast-compare":"^3.2.2",tweetnacl:"^1.0.3",zustand:"^5.0.4"},devDependencies:{"@privy-io/eslint-config-custom":"workspace:*","@privy-io/eslint-plugin-privy-rules":"workspace:*","@privy-io/tsconfig":"workspace:*","@simplewebauthn/types":"9.0.1","@solana/web3.js":"^1.98.0","@svgr/core":"^8.1.0","@svgr/plugin-jsx":"^8.1.0","@svgr/plugin-svgo":"^8.1.0","@testing-library/react-native":"^13.1.0","@tsconfig/node16-strictest-esm":"^1.0.3","@types/jest":"^29.1.2","@types/react":"^18.3.18",buffer:"^5.4.3","eslint-plugin-react-hooks":"^5.0.0-canary-7118f5dd7-20230705","expo-apple-authentication":"7.1.3","expo-application":"6.0.2","expo-clipboard":"7.0.1","expo-crypto":"14.0.2","expo-linking":"5.0.2","expo-secure-store":"12.5.0","expo-web-browser":"15.0.9",jest:"^29.7.0","jest-expo":"52.0.5","lucide-react-native":"^0.474.0",react:"^18.3.1","react-native":"0.77.1","react-test-renderer":"^18.3.1",tsup:"^6.2.3",typescript:"~5.5.3"},peerDependencies:{"@privy-io/expo-native-extensions":"workspace:*","expo-apple-authentication":"*","expo-application":"*","expo-clipboard":"*","expo-crypto":"*","expo-linking":"*","expo-secure-store":"*","expo-web-browser":"*",permissionless:"^0.2.47",react:"*","react-native":"*","react-native-passkeys":"^0.4.0","react-native-qrcode-styled":"0.3.3","react-native-safe-area-context":"*","react-native-svg":"*","react-native-webview":"*",viem:"2.47.4"},peerDependenciesMeta:{permissionless:{optional:!0},viem:{optional:!0},"react-native-svg":{optional:!0},"expo-apple-authentication":{optional:!0},"expo-clipboard":{optional:!0},"expo-crypto":{optional:!0},"expo-linking":{optional:!0},"expo-secure-store":{optional:!0},"expo-web-browser":{optional:!0},"react-native-qrcode-styled":{optional:!0},"react-native-safe-area-context":{optional:!0}},publishConfig:{access:"public"}};var ft=({appId:e,clientId:t,storage:r=ye,supportedChains:n,baseUrl:i,logLevel:o,logger:a})=>new Fr({appId:e,clientId:t,supportedChains:n,storage:mt(r),sdkVersion:`expo:${yt.version}`,nativeAppIdentifier:ut(),crypto:{digest:Mr},baseUrl:i,logLevel:o,logger:a});import{useCallback as it,useContext as Ai}from"react";import{PrivyClientError as Ri}from"@privy-io/js-sdk-core";import Z,{useState as L,useMemo as ki,createContext as Wi,useCallback as Ue,useRef as le,useEffect as br,useContext as xi}from"react";import{AppState as Sr,View as Pi}from"react-native";import{PrivyClientError as Er}from"@privy-io/js-sdk-core";import Tr from"react-fast-compare";import{create as Nr}from"zustand";var ge=Nr(()=>{}),gt=e=>ge.setState(t=>Tr(t,e)?t:e),W=ge.getState;import Vr from"react";import{useCallback as Kr,useEffect as zr,useRef as Hr}from"react";import{AppState as Br}from"react-native";import qr from"react-native-webview";import*as F from"expo-secure-store";function ht(e){return typeof e!="object"||e===null||!("event"in e&&typeof e.event=="string")||!("id"in e&&typeof e.id=="string")||!("data"in e&&typeof e.data=="object")||e.data===null?!1:e.event.startsWith("app:secure-storage:")}function wt(e){return l(this,null,function*(){switch(e.event){case"app:secure-storage:get":{let{key:t}=e.data,r=yield F.getItemAsync(Oe(t),{keychainAccessible:F.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).catch(n=>(console.warn("Failed to get the value from secure store",n),null));return{event:e.event,id:e.id,data:{value:r}}}case"app:secure-storage:remove":{let{key:t}=e.data,r=yield F.deleteItemAsync(Oe(t),{keychainAccessible:F.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(n=>(console.warn("Failed to remove the value from secure store",n),!1));return{event:e.event,id:e.id,data:{success:r}}}case"app:secure-storage:set":{let{key:t,value:r}=e.data,n=yield F.setItemAsync(Oe(t),r,{keychainAccessible:F.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(i=>(console.warn("Failed to write the value to secure store",i),!1));return{event:e.event,id:e.id,data:{success:n}}}}})}var Oe=e=>e.replaceAll(":","-");import Dr from"react-fast-compare";import{createStore as jr,useStore as Le}from"zustand";var j=jr()(()=>({user:null,proxyStatus:"loading"}));function b(){return j.getState().user}var Ji=j.subscribe.bind(j);function Me(e){j.setState(({user:t})=>Dr(t,e)?{}:{user:e})}var Fe=e=>j.setState({proxyStatus:e});function U(){return Le(j,e=>e.user)}function $i(){return Le(j,e=>!!e.user)}function V(){return Le(j,e=>e.proxyStatus!=="loading")}var Gr={shouldUseAppBackedStorage:!0},vt=({client:e,isClientReady:t})=>{let r=Hr(null);zr(()=>Br.addEventListener("change",o=>l(void 0,null,function*(){o==="active"&&((yield e.embeddedWallet.ping(500))||(Fe("reloading"),e.embeddedWallet.reload()))})).remove,[e]);let n=Kr(i=>l(void 0,null,function*(){var s;let{data:o}=i.nativeEvent,a=JSON.parse(o);if(ht(a)){let d=yield wt(a);(s=r.current)==null||s.postMessage(JSON.stringify(d));return}e.embeddedWallet.onMessage(a)}),[e]);return t?Vr.createElement(qr,{style:{flex:1},ref:i=>{i&&(e.setMessagePoster(i),r.current=i)},cacheEnabled:!1,cacheMode:"LOAD_NO_CACHE",injectedJavaScriptObject:Gr,source:{uri:e.embeddedWallet.getURL()},webviewDebuggingEnabled:e.logger.level==="DEBUG",onLoad:()=>Fe("loaded"),onError:console.error,onMessage:n}):null};import{useCallback as Te,useEffect as _t,useMemo as Ne}from"react";import{errorIndicatesRecoveryIsNeeded as $r,getAllUserEmbeddedSolanaWallets as Yr,getEntropyDetailsFromUser as Ct,PrivyClientError as re}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedSolanaWallets as he,getEntropyDetailsFromAccount as bt,getUserEmbeddedEthereumWallet as Jr,PrivyClientError as B}from"@privy-io/js-sdk-core";function St(o){return l(this,arguments,function*({client:e,setSolanaWallet:t,createSolanaWalletCallbacks:r,setSolanaRecoveryFlowState:n,opts:i}){var a,s,d;t({status:"creating"});try{let{user:c}=yield e.user.get(),u=he(c),m=u[0],p=(a=Jr(c))!=null?a:void 0;if(i!=null&&i.recoveryMethod&&i.recoveryMethod!=="privy")throw new B({code:"embedded_wallet_creation_error",error:"Unsupported recovery method for solana wallet."});if(!(i!=null&&i.createAdditional)&&m)throw new B({code:"embedded_wallet_creation_error",error:"Solana wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let w,g;if(m){let y=p!=null?p:m,{entropyId:h,entropyIdVerifier:S}=bt(y),_=Math.max(...u.map(x=>x.wallet_index),0)+1,C=yield e.embeddedWallet.add({chainType:"solana",entropyId:h,entropyIdVerifier:S,hdWalletIndex:_}),k=he(C.user).find(x=>x.wallet_index===_);if(!k)throw new B({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});w=yield e.embeddedWallet.getSolanaProvider(k,h,S),g=C.user}else{let y=yield e.embeddedWallet.createSolana({ethereumAccount:p}),h=he(y.user).find(k=>k.wallet_index===0);if(!h)throw new B({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let S=p!=null?p:h,{entropyId:_,entropyIdVerifier:C}=bt(S);w=yield e.embeddedWallet.getSolanaProvider(h,_,C),g=y.user}let v=he(g)[0];if(!v)throw new B({code:"embedded_wallet_creation_error",error:"Unknown error creating solana wallet"});return(d=(s=r.current)==null?void 0:s.onSuccess)==null||d.call(s,w),t({status:"connected",publicKey:v.public_key}),n({status:"initial"}),w}catch(c){let u=c instanceof Error?c.message:"Error creating embedded wallet";throw t({status:"error",error:u}),n({status:"initial"}),new B({code:"embedded_wallet_creation_error",error:u})}})}import{PrivyClientError as z}from"@privy-io/js-sdk-core";function we(u){return l(this,arguments,function*({client:e,account:t,setWallet:r,recoverWalletCallbacks:n,recoveryMethod:i,setRecoveryFlowState:o,password:a,recoveryKey:s,recoveryToken:d,recoverySecretOverride:c}){var m,p,w,g;if(!t)throw new z({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});switch(i){case"user-passcode":if(!a)throw new z({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"google-drive":if(!d)throw new z({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!c)throw new z({code:"embedded_wallet_recovery_error",error:"Record name is required for icloud recovery method"});break;case"recovery-encryption-key":if(!s)throw new z({code:"embedded_wallet_recovery_error",error:"recoveryKey is required for recovery-encryption-key recovery method"});break}r({status:"connecting",account:t});try{let v=yield e.embeddedWallet.getProvider(t,a,d,c,s);return r({status:"connected",provider:v,account:t}),o({status:"initial"}),(p=(m=n.current)==null?void 0:m.onSuccess)==null||p.call(m,v),v}catch(v){r({status:"needs-recovery",account:t}),o({status:"initial"});let y=new z({code:"embedded_wallet_recovery_error",error:v instanceof Error?v.message:"Error recovering embedded wallet"});throw(g=(w=n.current)==null?void 0:w.onError)==null||g.call(w,y),y}})}function Et(s){return l(this,arguments,function*({client:e,account:t,entropyId:r,entropyIdVerifier:n,setSolanaWallet:i,recoverSolanaWalletCallbacks:o,setSolanaRecoveryFlowState:a}){var d,c,u,m;i({status:"connecting"});try{let p=yield e.embeddedWallet.getSolanaProvider(t,r,n);return i({status:"connected",publicKey:p._publicKey}),a({status:"initial"}),(c=(d=o.current)==null?void 0:d.onSuccess)==null||c.call(d,p),p}catch(p){i({status:"needs-recovery"}),a({status:"initial"});let w=new z({code:"embedded_wallet_recovery_error",error:p instanceof Error?p.message:"Error recovering embedded wallet"});throw(m=(u=o.current)==null?void 0:u.onError)==null||m.call(u,w),w}})}var kt=({client:e,solanaWallet:t,setSolanaWallet:r,setSolanaRecoveryFlowState:n,createSolanaWalletCallbacks:i,recoverSolanaWalletCallbacks:o})=>{let a=U(),s=Ne(()=>Yr(a),[a]),d=V(),c=Ne(()=>s.length===0?null:Ct(a),[a,s]),u=Ne(()=>{let g=s.map(S=>{let _=Ct(a,S);return _?{account:S,entropy:_}:null});if(g.some(S=>S===null))return[];let v=void 0,y=void 0,h=void 0;return g.filter(S=>S!==null).map(({account:S,entropy:{entropyId:_,entropyIdVerifier:C}})=>({address:S.address,publicKey:S.address,walletIndex:S.wallet_index,getProvider:()=>e.embeddedWallet.getSolanaProvider(S,_,C,v,y,h,k=>l(void 0,null,function*(){var x;yield(x=fe())==null?void 0:x(k)}))}))},[s,a,e]),m=Te(g=>l(void 0,null,function*(){return yield St({client:e,setSolanaWallet:r,createSolanaWalletCallbacks:i,setSolanaRecoveryFlowState:n,opts:g})}),[e,i]),p=Te(()=>l(void 0,null,function*(){if(!c)throw new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{entropyId:g,entropyIdVerifier:v}=c;return Et({client:e,account:s[0],entropyId:g,entropyIdVerifier:v,setSolanaWallet:r,recoverSolanaWalletCallbacks:o,setSolanaRecoveryFlowState:n})}),[e,c,s,o,n,r]),w=Te(()=>l(void 0,null,function*(){if(!c)throw r({status:"not-created"}),new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});r(g=>g.status==="connected"?{status:"reconnecting"}:{status:"connecting"});try{let{entropyId:g,entropyIdVerifier:v}=c,y=yield e.embeddedWallet.getSolanaProvider(s[0],g,v);return r({status:"connected",publicKey:s[0].public_key}),y}catch(g){throw $r(g)?(r({status:"needs-recovery"}),new re({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):g instanceof Error?(r({status:"error",error:g.message}),new re({code:"unknown_embedded_wallet_error",error:g.message})):(r({status:"error",error:"Error loading embedded wallet"}),new re({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[s,e,c,r]);return _t(()=>{if(!a&&t.status!=="disconnected")return r({status:"disconnected"});d&&w().catch(()=>{})},[d,a]),_t(()=>{t.status==="error"&&t.error.includes("User must be logged in")&&w()},[t.status]),{create:m,recover:p,getProvider:w,wallets:u}};import{useCallback as ie,useEffect as At,useMemo as ao}from"react";import{getUserEmbeddedEthereumWallet as so,getUserEmbeddedSolanaWallet as Rt,isUnifiedWallet as co,throwIfInvalidRecoveryUpgradePath as lo}from"@privy-io/js-sdk-core";import{errorIndicatesRecoveryIsNeeded as uo,PrivyClientError as A}from"@privy-io/js-sdk-core";import{getUserEmbeddedEthereumWallet as Qr}from"@privy-io/js-sdk-core";import{PrivyClientError as q}from"@privy-io/js-sdk-core";function ve(m){return l(this,arguments,function*({client:e,setWallet:t,createWalletCallbacks:r,recoveryMethod:n,setRecoveryFlowState:i,password:o,recoveryKey:a,recoveryToken:s,recoverySecretOverride:d,iCloudRecordNameOverride:c,solanaAccount:u}){var w,g;switch(n){case"user-passcode":if(!o)throw new q({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"recovery-encryption-key":if(!a)throw new q({code:"embedded_wallet_recovery_error",error:"key is required for recovery-encryption-key recovery method"});break;case"google-drive":if(!s)throw new q({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!d||!c)throw new q({code:"embedded_wallet_recovery_error",error:"iCloud recovery failed due to inability to store credentials"});break}t({status:"creating",account:null});let p=n==="icloud"?"icloud-native":n;try{let{user:v}=yield e.embeddedWallet.create({password:o,recoveryMethod:p,recoveryKey:a,recoveryToken:s,recoverySecretOverride:d,iCloudRecordNameOverride:c,solanaAccount:u}),y=Qr(v);if(!y)throw new q({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let h=yield e.embeddedWallet.getProvider(y);return(g=(w=r.current)==null?void 0:w.onSuccess)==null||g.call(w,h),t({status:"connected",provider:h,account:y}),i({status:"initial"}),h}catch(v){let y=v instanceof Error?v.message:"Error creating embedded wallet";throw t({status:"error",error:y,account:null}),i({status:"initial"}),new q({code:"embedded_wallet_creation_error",error:y})}})}import{Platform as Wt}from"react-native";import{PrivyClientError as D}from"@privy-io/js-sdk-core";function xt(){return l(this,null,function*(){try{return yield import("@privy-io/expo-native-extensions")}catch(e){throw new Error("@privy-io/expo-native-extensions not found. Ensure that you're explicitly including as a dependency, and running an Expo development build")}})}function oe(n){return l(this,arguments,function*({user:e,appId:t,client:r}){var s;if(Wt.OS==="android")throw new D({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let i=yield xt(),o=yield r.recovery.icloudAuth.getICloudConfiguration("expo-ios");if(!(o==null?void 0:o.container_identifier))throw new D({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:d,iCloudRecordName:c}=yield i.writeRecoverySecretToICloud({containerId:o.container_identifier,appId:t,userId:e.id});return{recoverySecret:d,iCloudRecordName:c}}catch(d){if(d instanceof Error){let c=(s=d.message.split("Caused by: ")[1])!=null?s:"Error writing to iCloud";throw new D({code:"embedded_wallet_recovery_error",error:c})}throw new D({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}function be(n){return l(this,arguments,function*({walletAddress:e,client:t,chainType:r}){var c;if(Wt.OS==="android")throw new D({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let i=yield xt(),a=(yield t.recovery.getRecoveryKeyMaterial(e,r)).icloud_record_name;if(!a)throw new D({code:"embedded_wallet_recovery_error",error:"iCloud recovery not properly backed up."});let s=yield t.recovery.icloudAuth.getICloudConfiguration("expo-ios"),d=s==null?void 0:s.container_identifier;if(!d)throw new D({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:u}=yield i.readRecoverySecretFromICloud({containerId:d,recordName:a});return{recoverySecret:u}}catch(u){if(u instanceof Error){let m=(c=u.message.split("Caused by: ")[1])!=null?c:"Error writing to iCloud";throw new D({code:"embedded_wallet_recovery_error",error:m})}throw new D({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}import*as H from"expo-linking";import*as Pt from"expo-web-browser";import{Platform as Ut}from"react-native";import{PrivyClientError as J}from"@privy-io/js-sdk-core";import Pa from"react-fast-compare";import{PrivyApiError as Xr,PrivyClientError as Zr}from"@privy-io/js-sdk-core";function E(e){return e instanceof Error||e instanceof Xr||e instanceof Zr?e:typeof e=="string"?new Error(e):new Error("Unknown error")}var G=e=>new Promise(t=>setTimeout(t,e));import{useEffect as eo,useRef as to}from"react";import{AppState as De}from"react-native";function Se(){let e=to(De.currentState);eo(()=>De.addEventListener("change",n=>{e.current=n}).remove,[]);function t(){return De.currentState}return{appState:e,getCurrentAppState:t}}function ne(i){return l(this,arguments,function*({provider:e,redirectUri:t,client:r,onError:n}){try{let o;switch(e){case"google-drive":{let{url:c}=yield r.recovery.auth.generateURL(H.createURL(t||"/"));o=c;break}default:throw new J({error:"OAuth invalid provider",code:"embedded_wallet_recovery_error"})}let a=yield Pt.openAuthSessionAsync(o);if(Ut.OS==="android")return;if(a.type!=="success")throw new J({error:"Recovery OAuth session failed",code:"embedded_wallet_recovery_error"});let{queryParams:s}=H.parse(a.url),d;switch(e){case"google-drive":{let{privy_oauth_state:c,privy_oauth_code:u}=s;if(!u||!c)throw new J({error:"Recovery OAuth invalid credentials",code:"embedded_wallet_recovery_error"});d=yield Ee({oAuthCode:u,oAuthState:c,client:r});break}default:throw new J({error:"Recovery OAuth invalid provider",code:"embedded_wallet_recovery_error"})}return d}catch(o){throw n==null||n(E(o)),o}})}function Ee(n){return l(this,arguments,function*({oAuthCode:e,oAuthState:t,client:r}){let{access_token:i}=yield r.recovery.auth.authorize(e,t);if(!i)throw new J({error:"OAuth invalid credentials",code:"login_with_oauth_returned_with_invalid_credentials"});return i})}var ro=2*60*1e3;function oo(e){let t;return new Promise((r,n)=>{t=H.addEventListener("url",o=>l(this,[o],function*({url:i}){if(!i)return;let{queryParams:a}=H.parse(i),{privy_oauth_state:s,privy_oauth_code:d}=a!=null?a:{};if(typeof d!="string"||typeof s!="string")return;let c=yield Ee({client:e,oAuthCode:d,oAuthState:s});r(c)})),setTimeout(()=>{n(new J({code:"embedded_wallet_set_recovery_error",error:"Failed to complete Google Drive recovery flow"}))},ro)}).finally(()=>{t==null||t.remove()})}function _e(e){return l(this,null,function*(){let t;Ut.OS==="android"&&(t=oo(e));let r=yield ne({provider:"google-drive",client:e});return r!=null?r:yield t})}import{getUserEmbeddedWallet as no,PrivyClientError as io}from"@privy-io/js-sdk-core";function Ce(o){return l(this,arguments,function*({client:e,recoveryInput:t,setWalletRecoveryCallbacks:r,setRecoveryFlowState:n,setWallet:i}){var a,s,d,c;try{let{provider:u,user:m}=yield e.embeddedWallet.setRecovery(t),p=u,w=no(m);return i({status:"connected",provider:p,account:w}),(s=(a=r.current)==null?void 0:a.onSuccess)==null||s.call(a,p),n({status:"initial"}),p}catch(u){let m=new io({code:"embedded_wallet_set_recovery_error",error:u instanceof Error?u.message:"Error setting password on embedded wallet"});throw(c=(d=r.current)==null?void 0:d.onError)==null||c.call(d,m),n({status:"initial"}),m}})}function It(e){return e===void 0?{recoveryMethod:"privy"}:typeof e=="string"?{recoveryMethod:"user-passcode",password:e}:e.recoveryMethod==="user-passcode"?{recoveryMethod:"user-passcode",password:e.password}:e.recoveryMethod==="recovery-encryption-key"?{recoveryMethod:"recovery-encryption-key",recoveryKey:e.recoveryKey}:{recoveryMethod:e.recoveryMethod}}var Ot=({client:e,appId:t,wallet:r,setWallet:n,setRecoveryFlowState:i,createWalletCallbacks:o,recoverWalletCallbacks:a,setWalletRecoveryCallbacks:s})=>{let d=U(),c=ao(()=>so(d),[d]),u=V(),m=ie(y=>l(void 0,null,function*(){var ue,me;if(c)throw new A({error:"This user already has an embedded wallet",code:"embedded_wallet_already_exists"});let{user:h}=yield e.user.get(),{password:S,recoveryMethod:_,recoveryKey:C}=It(y),k,x,M;if(_==="google-drive"&&(k=yield ne({provider:_,client:e,onError:(ue=o.current)==null?void 0:ue.onError}),i({status:"creating-wallet"}),!k))return null;if(_==="icloud"){if(!h)throw new A({code:"embedded_wallet_recovery_error",error:"User must be loaded before creating a wallet with iCloud."});let{recoverySecret:Ae,iCloudRecordName:te}=yield oe({user:h,appId:t,client:e});x=Ae,M=te}return yield ve({client:e,setWallet:n,createWalletCallbacks:o,recoveryMethod:_,recoveryKey:C,setRecoveryFlowState:i,password:S,recoverySecretOverride:x,iCloudRecordNameOverride:M,solanaAccount:(me=Rt(h))!=null?me:void 0})}),[e,c,d]),p=ie(y=>l(void 0,null,function*(){var _;if(r.status!=="connected")throw new A({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"});if(!c)throw new A({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(Rt(d))throw new A({code:"embedded_wallet_set_recovery_error",error:"Cannot set user-controlled recovery for a user with an embedded Solana wallet."});if(co(c))throw new A({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"});lo({currentRecoveryMethod:c.recovery_method,upgradeToRecoveryMethod:y.recoveryMethod});let h,S;switch(y.recoveryMethod){case"privy":S=N(P({},y),{wallet:c});break;case"user-passcode":S=N(P({},y),{wallet:c,password:y.password});break;case"google-drive":if(h=yield ne({provider:y.recoveryMethod,client:e,onError:(_=s.current)==null?void 0:_.onError}),i({status:"upgrading-recovery"}),!h)return null;S={recoveryMethod:"google-drive",wallet:c,recoveryAccessToken:h};break;case"icloud":if(!d)throw new A({code:"embedded_wallet_recovery_error",error:"User must be loaded before backing up to iCloud."});let{recoverySecret:C,iCloudRecordName:k}=yield oe({user:d,appId:t,client:e});S={recoveryMethod:"icloud-native",recoverySecretOverride:C,iCloudRecordNameOverride:k,wallet:c};break;default:throw new A({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}return Ce({client:e,recoveryInput:S,setWalletRecoveryCallbacks:s,setRecoveryFlowState:i,setWallet:n})}),[e,c,r.status,d]),w=ie(y=>l(void 0,null,function*(){return p({recoveryMethod:"user-passcode",password:y})}),[e,c,r.status]),g=ie(y=>l(void 0,null,function*(){var x;if(!c)throw new A({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{password:h,recoveryMethod:S,recoveryKey:_}=It(y),C,k;if(S==="google-drive"&&(C=yield ne({provider:S,client:e,onError:(x=a.current)==null?void 0:x.onError}),i({status:"recovering"}),!C))return null;if(S==="icloud"){if(!d)throw new A({code:"embedded_wallet_recovery_error",error:"User must be loaded before recovering via iCloud."});let{recoverySecret:M}=yield be({client:e,walletAddress:c.address});k=M}return we({client:e,account:c,setWallet:n,recoverWalletCallbacks:a,recoveryMethod:S,setRecoveryFlowState:i,recoveryKey:_,password:h,recoveryToken:C,recoverySecretOverride:k})}),[e,c]),v=ie(()=>l(void 0,null,function*(){if(!c)throw n({status:"not-created",account:null}),new A({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});n(y=>y.status==="connected"?{status:"reconnecting",account:c}:{status:"connecting",account:c});try{let y=yield e.embeddedWallet.getProvider(c);return n({status:"connected",provider:y,account:c}),y}catch(y){throw uo(y)?(n({status:"needs-recovery",account:c}),new A({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):y instanceof Error?(n({status:"error",error:y.message,account:c}),new A({code:"unknown_embedded_wallet_error",error:y.message})):(n({status:"error",error:"Error loading embedded wallet",account:c}),new A({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[e,c]);return At(()=>{if(!d&&r.status!=="disconnected")return n({status:"disconnected",account:null});u&&v().catch(()=>{})},[u,d,c]),At(()=>{r.status==="error"&&r.error.includes("User must be logged in")&&v()},[r.status]),{create:m,recover:g,setPassword:w,setRecovery:p,getProvider:v}};import{useEffect as mo,useState as po}from"react";import{PrivyClientError as Lt}from"@privy-io/js-sdk-core";var Mt=({client:e,isReady:t})=>{let r=U(),n=ge(a=>a==null?void 0:a.customAuth),[i,o]=po({status:"initial"});return mo(()=>{(()=>l(void 0,null,function*(){if(!(n!=null&&n.enabled)){o({status:"not-enabled"});return}o({status:"loading"});let{getCustomAccessToken:s,isLoading:d}=n;if(!(!t||d))try{let c=yield s();if(!c&&r){yield e.auth.logout(),o({status:"done"});return}if(!c){o({status:"done"});return}if(r){o({status:"done"});return}let u=W();if(!(yield e.auth.customProvider.syncWithToken(c,{embedded:u==null?void 0:u.embedded}))){yield e.auth.logout(),o({status:"error",error:new Lt({error:"Failed to sync with custom auth provider",code:"third_party_auth_error"})});return}o({status:"done"})}catch(c){if(console.log("Error syncing with custom auth provider",c),o({status:"error",error:c}),r)throw yield e.auth.logout(),new Lt({error:"Third-party auth failed",code:"third_party_auth_error"})}}))()},[e,r,t,n==null?void 0:n.enabled,n==null?void 0:n.getCustomAccessToken,n==null?void 0:n.isLoading]),{customAuthState:i,customAuthStateIsSettled:i.status!=="loading"&&i.status!=="initial"}};import*as $ from"expo-linking";import{useCallback as yo,useEffect as fo,useMemo as go}from"react";import{Platform as ho}from"react-native";import{getUserEmbeddedSolanaWallet as wo,getUserEmbeddedWallet as vo}from"@privy-io/js-sdk-core";var Ft=({client:e,createWalletCallbacks:t,recoverWalletCallbacks:r,setWalletRecoveryCallbacks:n,recoveryFlowState:i,oAuthState:o,setRecoveryFlowState:a,setWallet:s,appStateVisible:d})=>{let c=$.useURL(),u=U(),m=go(()=>vo(u),[u]),p=V(),w=yo(g=>{var y,h,S,_;let v=E(g);i.status==="creating-wallet"?(h=(y=t.current).onError)==null||h.call(y,E(v)):(_=(S=r.current).onError)==null||_.call(S,E(v)),a({status:"initial"})},[i]);return fo(()=>{function g(){return l(this,null,function*(){var S;if(!c&&i.status!=="initial"&&d&&w(new Error("Recovery OAuth session failed")),!c||i.status==="initial"||o.status!=="initial"||!d||!p)return;let{queryParams:v}=$.parse(c),{privy_oauth_state:y,privy_oauth_code:h}=v;if(!(!h||!y)){yield $.openURL(c.split("?")[0]);try{let _=yield Ee({oAuthCode:h,oAuthState:y,client:e});if(i.status==="creating-wallet"){let C=(S=wo(u))!=null?S:void 0;yield ve({client:e,setWallet:s,createWalletCallbacks:t,recoveryMethod:"google-drive",setRecoveryFlowState:a,recoveryToken:_,solanaAccount:C})}else if(i.status==="upgrading-recovery"){if(!m)throw new Error("Embedded wallet not found");yield Ce({client:e,recoveryInput:{recoveryMethod:"google-drive",wallet:m,recoveryAccessToken:_},setWalletRecoveryCallbacks:n,setRecoveryFlowState:a,setWallet:s})}else yield we({client:e,account:m,setWallet:s,recoverWalletCallbacks:r,recoveryMethod:"google-drive",setRecoveryFlowState:a,recoveryToken:_})}catch(_){w(_)}}})}ho.OS==="android"&&g()},[c,i.status,d,p])};import{useEffect as bo}from"react";var Tt=({client:e,isUserInitialized:t,setIsUserInitialized:r,setError:n})=>{bo(()=>{t||(()=>l(void 0,null,function*(){try{yield e.initialize()}catch(o){n(o instanceof Error?o:new Error(String(o)))}try{yield e.user.get()}catch(o){}finally{r(!0)}}))()},[e,t,n,r])};import{useEffect as _i,useRef as Ci}from"react";import{useCallback as je,useContext as So}from"react";import{PrivyClientError as Eo}from"@privy-io/js-sdk-core";var Ls=e=>{let{client:t,setSiweState:r,siweState:n}=So(f),i=je(s=>{var c;let d=E(s);return r({status:"error",error:d}),(c=e==null?void 0:e.onError)==null||c.call(e,d),d},[e==null?void 0:e.onError]),o=je(u=>l(void 0,[u],function*({wallet:s,from:{domain:d,uri:c}}){var m;try{r({status:"generating-message"});let p=yield t.auth.siwe.init(s,d,c);return r({status:"awaiting-signature"}),(m=e==null?void 0:e.onGenerateMessage)==null||m.call(e,p.message),p.message}catch(p){throw i(p)}}),[t,i,e==null?void 0:e.onGenerateMessage]);return{loginWithSiwe:je(u=>l(void 0,[u],function*({signature:s,messageOverride:d,disableSignup:c}){var m;try{if(b())throw new Eo({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"});r({status:"submitting-signature"});let w=W(),g=yield t.auth.siwe.loginWithSiwe(s,void 0,d,c?"no-signup":"login-or-sign-up",{embedded:w==null?void 0:w.embedded});return r({status:"done"}),(m=e==null?void 0:e.onSuccess)==null||m.call(e,g.user,g.is_new_user),g.user}catch(p){throw i(p)}}),[t,i,e==null?void 0:e.onSuccess]),generateSiweMessage:o,state:n}};import{useCallback as Nt}from"react";import{createSiwsMessage as Co,PrivyClientError as ko}from"@privy-io/js-sdk-core";import{useContext as _o}from"react";var O=()=>{let{client:e}=_o(f);return e};var Bs=()=>{let e=O(),t=Nt(a=>l(void 0,[a],function*({wallet:{address:n},from:{domain:i,uri:o}}){try{let{nonce:s}=yield e.auth.siws.fetchNonce({address:n});return{message:Co({address:n,domain:i,uri:o,nonce:s})}}catch(s){throw E(s)}}),[e]),r=Nt(s=>l(void 0,[s],function*({signature:n,message:i,wallet:{walletClientType:o,connectorType:a}={}}){try{if(!b())throw new ko({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:c}=yield e.auth.siws.link({signature:n,message:i,walletClientType:o,connectorType:a});return c}catch(d){throw E(d)}}),[e]);return{generateMessage:t,link:r}};import{useCallback as Dt}from"react";import{createSiwsMessage as Wo,PrivyClientError as xo}from"@privy-io/js-sdk-core";var ec=()=>{let e=O(),t=Dt(a=>l(void 0,[a],function*({wallet:{address:n},from:{domain:i,uri:o}}){try{let{nonce:s}=yield e.auth.siws.fetchNonce({address:n});return{message:Wo({address:n,domain:i,uri:o,nonce:s})}}catch(s){throw E(s)}}),[e]),r=Dt(d=>l(void 0,[d],function*({signature:n,message:i,wallet:{walletClientType:o,connectorType:a}={},disableSignup:s}){try{if(b())throw new xo({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"});let u=W();return(yield e.auth.siws.login({signature:n,message:i,walletClientType:o,connectorType:a,mode:s?"no-signup":"login-or-sign-up",opts:{embedded:u==null?void 0:u.embedded}})).user}catch(c){throw E(c)}}),[e]);return{generateMessage:t,login:r}};import{useCallback as jt,useContext as Po}from"react";import{PrivyClientError as Uo}from"@privy-io/js-sdk-core";var cc=e=>{let{client:t}=Po(f),r=jt(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{unlinkWallet:jt(o=>l(void 0,[o],function*({address:i}){var a;try{if(!b())throw new Uo({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:d}=yield t.auth.siwe.unlinkWallet(i);return(a=e==null?void 0:e.onSuccess)==null||a.call(e,d),d}catch(s){throw r(s)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useCallback as Ve,useContext as Ao,useState as Ro}from"react";import{PrivyClientError as Vt}from"@privy-io/js-sdk-core";var gc=e=>{let[t,r]=Ro(""),{client:n,otpState:i,setOtpState:o}=Ao(f),a=Ve(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=Ve(u=>l(void 0,[u],function*({email:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.email.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{email:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=Ve(m=>l(void 0,[m],function*({code:c,email:u}){var p;try{if(!b())throw new Vt({code:"attempted_link_email_before_logged_in",error:"Must be logged in to link an email, Use `useLoginWithEmail` to login with email"});let g=u||t;if(!g)throw new Vt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});o({status:"submitting-code"});let{user:v}=yield n.auth.email.linkWithCode(g,c);return o({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,v),v}catch(w){throw a(w)}}),[t,o,n,e,a]);return{sendCode:s,linkWithCode:d,state:i}};import{useCallback as Kt,useContext as Io}from"react";var Ec=e=>{let{client:t}=Io(f),r=Kt(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{unlinkEmail:Kt(o=>l(void 0,[o],function*({email:i}){var a;try{let{user:s}=yield t.auth.email.unlink(i);return(a=e==null?void 0:e.onSuccess)==null||a.call(e,s),s}catch(s){throw r(s)}}),[t,e==null?void 0:e.onSuccess,r])}};import{useCallback as Ke,useContext as Oo,useState as Lo}from"react";import{PrivyClientError as zt}from"@privy-io/js-sdk-core";var Rc=e=>{let[t,r]=Lo(""),{client:n,otpState:i,setOtpState:o}=Oo(f),a=Ke(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=Ke(u=>l(void 0,[u],function*({email:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.email.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{email:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=Ke(p=>l(void 0,[p],function*({code:c,email:u,disableSignup:m}){var w;try{if(b())throw new zt({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=u||t;if(!v)throw new zt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `loginWithCode`"});o({status:"submitting-code"});let y=W(),h=yield n.auth.email.loginWithCode(v,c,m?"no-signup":"login-or-sign-up",{embedded:y==null?void 0:y.embedded});return o({status:"done"}),(w=e==null?void 0:e.onLoginSuccess)==null||w.call(e,h.user,h.is_new_user),h==null?void 0:h.user}catch(g){throw a(g)}}),[t,o,n,e,a]);return{sendCode:s,loginWithCode:d,state:i}};import{useCallback as ze,useContext as Mo,useState as Fo}from"react";import{PrivyClientError as Ht}from"@privy-io/js-sdk-core";var Dc=e=>{let[t,r]=Fo(""),{client:n,otpState:i,setOtpState:o}=Mo(f),a=ze(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=ze(u=>l(void 0,[u],function*({phone:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.phone.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{phone:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=ze(m=>l(void 0,[m],function*({code:c,phone:u}){var p;try{if(!b())throw new Ht({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(!(u||t))throw new Ht({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});o({status:"submitting-code"});let{user:v}=yield n.auth.phone.linkWithCode(u||t,c);return o({status:"done"}),(p=e==null?void 0:e.onLinkSuccess)==null||p.call(e,v),v}catch(w){throw a(w)}}),[t,o,n,e,a]);return{sendCode:s,linkWithCode:d,state:i}};import{useCallback as He,useContext as To,useState as No}from"react";import{PrivyClientError as Bt}from"@privy-io/js-sdk-core";var Jc=e=>{let[t,r]=No(""),{client:n,otpState:i,setOtpState:o}=To(f),a=He(c=>{var m;let u=E(c);return o({status:"error",error:u}),(m=e==null?void 0:e.onError)==null||m.call(e,u),u},[e,o]),s=He(u=>l(void 0,[u],function*({phone:c}){var m;r(c);try{o({status:"sending-code"});let p=yield n.auth.phone.sendCode(c);return o({status:"awaiting-code-input"}),(m=e==null?void 0:e.onSendCodeSuccess)==null||m.call(e,{phone:c}),p}catch(p){throw a(p)}}),[n,a,e,o]),d=He(p=>l(void 0,[p],function*({code:c,phone:u,disableSignup:m}){var w;try{if(b())throw new Bt({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(!(u||t))throw new Bt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});o({status:"submitting-code"});let y=W(),h=yield n.auth.phone.loginWithCode(u||t,c,m?"no-signup":"login-or-sign-up",{embedded:y==null?void 0:y.embedded});return o({status:"done"}),(w=e==null?void 0:e.onLoginSuccess)==null||w.call(e,h.user,h.is_new_user),h==null?void 0:h.user}catch(g){throw a(g)}}),[t,o,n,e,a]);return{sendCode:s,loginWithCode:d,state:i}};import*as ke from"expo-linking";import{useCallback as Be,useContext as Do,useRef as jo}from"react";import{PrivyClientError as ae}from"@privy-io/js-sdk-core";var rd=e=>{let{appState:t,getCurrentAppState:r}=Se(),{client:n,farcasterState:i,setFarcasterState:o}=Do(f),a=jo(!1),s=Be(u=>{var p;let m=E(u);return o({status:"error",error:m}),(p=e==null?void 0:e.onError)==null||p.call(e,m),m},[e==null?void 0:e.onError,o]),d=Be(()=>{a.current=!0},[]);return{linkWithFarcaster:Be((w,...g)=>l(void 0,[w,...g],function*({relyingParty:u,redirectUrl:m},p={pollAttempts:10,pollIntervalMs:1e3}){var v;try{let y=b();if(a.current=!1,!y)throw new ae({code:"attempted_link_farcaster_before_logged_in",error:"Must be logged in to link a Farcaster account."});o({status:"generating-uri"});let{connect_uri:h,channel_token:S}=yield n.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:ke.createURL(m!=null?m:"/")});if(!h)throw new ae({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!S)throw new ae({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield ke.openURL(h),o({status:"polling-status"});let _=0;for(;_<p.pollAttempts;){if(a.current)throw new ae({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield G(p.pollIntervalMs);continue}let C=yield n.auth.farcaster.getFarcasterStatus({channel_token:S});if(C.state==="completed"){o({status:"submitting-token"});let{user:k}=yield n.auth.farcaster.link(P({channel_token:S},C));return o({status:"done"}),(v=e==null?void 0:e.onSuccess)==null||v.call(e,k),k}_++,yield G(p.pollIntervalMs)}throw new ae({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(y){throw s(y)}}),[n,e==null?void 0:e.onSuccess,s,o]),state:i,cancel:d}};import{useCallback as qt,useContext as Vo}from"react";var cd=e=>{let{client:t}=Vo(f),r=qt(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{unlinkFarcaster:qt(o=>l(void 0,[o],function*({fid:i}){var a;try{let{user:s}=yield t.auth.farcaster.unlink({fid:i});return(a=e==null?void 0:e.onSuccess)==null||a.call(e,s),s}catch(s){throw r(s)}}),[t,e==null?void 0:e.onSuccess,r])}};import*as We from"expo-linking";import{useCallback as Je,useContext as Ko,useRef as zo}from"react";import{PrivyClientError as se}from"@privy-io/js-sdk-core";var hd=e=>{let{appState:t,getCurrentAppState:r}=Se(),{client:n,farcasterState:i,setFarcasterState:o}=Ko(f),a=zo(!1),s=Je(u=>{var p;let m=E(u);return o({status:"error",error:m}),(p=e==null?void 0:e.onError)==null||p.call(e,m),m},[e==null?void 0:e.onError,o]),d=Je(()=>{a.current=!0},[]);return{loginWithFarcaster:Je((g,...v)=>l(void 0,[g,...v],function*({relyingParty:u,redirectUrl:m,disableSignup:p},w={pollAttempts:10,pollIntervalMs:1e3}){var y;try{if(a.current=!1,b())throw new se({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"});o({status:"generating-uri"});let{connect_uri:S,channel_token:_}=yield n.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:We.createURL(m!=null?m:"/")});if(!S)throw new se({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!_)throw new se({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield We.openURL(S),o({status:"polling-status"});let C=0;for(;C<w.pollAttempts;){if(a.current)throw new se({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield G(w.pollIntervalMs);continue}let k=yield n.auth.farcaster.getFarcasterStatus({channel_token:_});if(k.state==="completed"){o({status:"submitting-token"});let x=W(),M=yield n.auth.farcaster.authenticate(P({channel_token:_,mode:p?"no-signup":"login-or-sign-up"},k),{embedded:x==null?void 0:x.embedded});return o({status:"done"}),(y=e==null?void 0:e.onSuccess)==null||y.call(e,M.user,M.is_new_user),M.user}C++,yield G(w.pollIntervalMs)}throw new se({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(h){throw s(h)}}),[n,s,e==null?void 0:e.onSuccess,o,t]),state:i,cancel:d}};import{useCallback as Gt,useContext as Ho}from"react";import{create as Bo}from"zustand";import{PrivyClientError as qo}from"@privy-io/js-sdk-core";var $e=Bo(()=>({status:"initial"})),K=e=>$e.setState(e,!0),Go=$e.getState,xd=()=>{let{client:e}=Ho(f),t=$e(),r=Gt(()=>l(void 0,null,function*(){try{K({status:"fetching-nonce"});let i=yield e.auth.farcasterV2.initializeAuth();return K({status:"awaiting-signature"}),i}catch(i){let o=E(i);throw K({status:"initial",error:o}),o}}),[e]),n=Gt(i=>l(void 0,null,function*(){let o=Go().status;try{if(b()){let c=new qo({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 K({status:o,error:c}),c}K({status:"submitting-signature"});let s=W(),d=yield e.auth.farcasterV2.authenticate(i,{embedded:s==null?void 0:s.embedded});return K({status:"done"}),setTimeout(()=>K({status:"initial"}),1500),{user:d.user}}catch(a){let s=E(a);throw K({status:o,error:s}),s}}),[e]);return{init:r,login:n,state:t}};import{useContext as Jo,useMemo as $o}from"react";import{delegatedActions as Jt}from"@privy-io/js-sdk-core";var Od=()=>{let{client:e}=Jo(f);return $o(()=>({delegateWallet:Jt.delegateWallet(e),revokeWallets:Jt.revokeWallets(e)}),[e])};import{useContext as Xo,useMemo as Zo}from"react";import{addSessionSigners as en,removeSessionSigners as tn}from"@privy-io/js-sdk-core";import{isEmbeddedWalletAccount as Yo}from"@privy-io/js-sdk-core";function Qo(e,t){return e.linked_accounts.filter(Yo).find(r=>r.address===t)}function Y(e){let t=b();if(!t)throw new Error("User must be authenticated to perform this operation");let r=Qo(t,e);if(!r)throw new Error(`No wallet found with address ${e}`);return r}var Kd=()=>{let{client:e}=Xo(f);return Zo(()=>({addSessionSigners:({address:t,signers:r})=>en({client:e,wallet:Y(t),signers:r.map(n=>({signer_id:n.signerId,override_policy_ids:n.policyIds}))}),removeSessionSigners:({address:t})=>tn({client:e,wallet:Y(t)})}),[e])};import{useContext as rn,useMemo as on}from"react";import{addSessionSigners as nn,removeSessionSigners as an}from"@privy-io/js-sdk-core";var Jd=()=>{let{client:e}=rn(f);return on(()=>({addSigners:({address:t,signers:r})=>nn({client:e,wallet:Y(t),signers:r.map(n=>({signer_id:n.signerId,override_policy_ids:n.policyIds}))}),removeSigners:({address:t})=>an({client:e,wallet:Y(t)})}),[e])};import{useContext as sn,useMemo as cn}from"react";import{PrivyClientError as Yt}from"@privy-io/js-sdk-core";var el=()=>{let{client:e}=sn(f);return cn(()=>({sendCode(n){return l(this,arguments,function*({newEmailAddress:r}){$t(),yield e.auth.email.sendCode(r)})},updateEmail(i){return l(this,arguments,function*({newEmailAddress:r,code:n}){let{address:o}=$t(),{user:a}=yield e.auth.email.updateEmail({oldEmailAddress:o,newEmailAddress:r,code:n});return a})}}),[e])};function $t(){let t=dn().linked_accounts.find(r=>r.type==="email");if(!t)throw new Yt({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 dn(){let e=b();if(!e)throw new Yt({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import{useContext as ln,useMemo as un}from"react";import{PrivyClientError as Xt}from"@privy-io/js-sdk-core";var sl=()=>{let{client:e}=ln(f);return un(()=>({sendCode(n){return l(this,arguments,function*({newPhoneNumber:r}){Qt(),yield e.auth.phone.sendCode(r)})},updatePhone(i){return l(this,arguments,function*({newPhoneNumber:r,code:n}){let{phoneNumber:o}=Qt(),{user:a}=yield e.auth.phone.updatePhone({oldPhoneNumber:o,newPhoneNumber:r,code:n});return a})}}),[e])};function Qt(){let t=mn().linked_accounts.find(r=>r.type==="phone");if(!t)throw new Xt({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 mn(){let e=b();if(!e)throw new Xt({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import*as tr from"expo-linking";import{useCallback as yn,useContext as fn,useMemo as gn}from"react";import{crossApp as hn,PrivyClientError as wn}from"@privy-io/js-sdk-core";import*as er from"expo-linking";import*as ce from"expo-web-browser";import{PrivyClientError as Zt}from"@privy-io/js-sdk-core";var T=(e,t)=>l(void 0,null,function*(){let r=yield ce.openAuthSessionAsync(e,t,{createTask:!1});if(r.type!=="success")throw r.type===ce.WebBrowserResultType.CANCEL||r.type===ce.WebBrowserResultType.DISMISS?new Zt({error:"OAuth session was cancelled",code:"oauth_session_failed"}):new Zt({error:"OAuth session failed",code:"oauth_session_failed"});return pn(r.url)});function pn(e){let{queryParams:t}=er.parse(e);return t}var wl=()=>{let{client:e}=fn(f),t=gn(()=>hn.loginWithCrossAppAuth({client:e,openAuthSession:T}),[e]);return{loginWithCrossApp:yn(o=>l(void 0,[o],function*({appId:n,redirectUri:i}){if(b())throw new wn({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:s}=yield t({providerAppId:n,redirectUrl:tr.createURL(i||"/")});return{user:s}}),[t])}};import*as rr from"expo-linking";import{useCallback as vn,useContext as bn,useMemo as Sn}from"react";import{crossApp as En,PrivyClientError as _n}from"@privy-io/js-sdk-core";var Wl=()=>{let{client:e}=bn(f),t=Sn(()=>En.linkWithCrossAppAuth({client:e,openAuthSession:T}),[e]);return{linkWithCrossApp:vn(o=>l(void 0,[o],function*({appId:n,redirectUri:i}){if(!b())throw new _n({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:rr.createURL(i||"/")})}}),[t])}};import*as nr from"expo-linking";import{useContext as Cn,useMemo as or}from"react";import{crossApp as kn}from"@privy-io/js-sdk-core";var Ll=()=>{let{client:e}=Cn(f),t=or(()=>kn.wallet.signMessage({client:e,openAuthSession:T}),[e]);return or(()=>({signMessage:({address:r,message:n,redirectUri:i="/"})=>t({user:b(),address:r,message:n,redirectUrl:nr.createURL(i)})}),[t])};import*as ar from"expo-linking";import{useContext as Wn,useMemo as ir}from"react";import{crossApp as xn}from"@privy-io/js-sdk-core";var Vl=()=>{let{client:e}=Wn(f),t=ir(()=>xn.wallet.signTypedData({client:e,openAuthSession:T}),[e]);return ir(()=>({signTypedData:({address:r,typedData:n,redirectUri:i="/"})=>t({user:b(),address:r,typedData:n,redirectUrl:ar.createURL(i)})}),[t])};import*as cr from"expo-linking";import{useContext as Pn,useMemo as sr}from"react";import{crossApp as Un}from"@privy-io/js-sdk-core";var Jl=()=>{let{client:e}=Pn(f),t=sr(()=>Un.wallet.sendTransaction({client:e,openAuthSession:T}),[e]);return sr(()=>({sendTransaction:({address:r,transaction:n,redirectUri:i="/"})=>t({user:b(),address:r,transaction:n,redirectUrl:cr.createURL(i)})}),[t])};import{useCallback as An,useContext as Rn}from"react";import{getUserEmbeddedEthereumWallet as In,getUserEmbeddedSolanaWallet as On,isUnifiedWallet as Ln,PrivyClientError as Q,throwIfInvalidRecoveryUpgradePath as Mn}from"@privy-io/js-sdk-core";var ru=()=>{let{client:e}=Rn(f);return{setRecovery:An(r=>l(void 0,null,function*(){var s;let n=b(),i=e.app.appId;if(!n)throw new Q({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let o=(s=In(n))!=null?s:On(n);if(!o)throw new Q({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(Ln(o))throw new Q({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{o.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(o):o.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(o,o.address,"solana-address-verifier"))}catch(d){throw new Q({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}Mn({currentRecoveryMethod:o.recovery_method,upgradeToRecoveryMethod:r.recoveryMethod});let a=yield Fn({appId:i,client:e,user:n,primaryAccount:o,recoveryParams:r});try{let{user:d}=yield e.embeddedWallet.setRecovery(a);return{user:d}}catch(d){throw new Q({code:"embedded_wallet_set_recovery_error",error:d instanceof Error?d.message:"Error setting password on embedded wallet"})}}),[e])}},Fn=o=>l(void 0,[o],function*({appId:e,client:t,user:r,primaryAccount:n,recoveryParams:i}){switch(i.recoveryMethod){case"privy":return{recoveryMethod:"privy",wallet:n};case"user-passcode":return N(P({},i),{wallet:n});case"google-drive":{let a=yield _e(t);return{recoveryMethod:"google-drive",wallet:n,recoveryAccessToken:a}}case"icloud":{let{recoverySecret:a,iCloudRecordName:s}=yield oe({appId:e,client:t,user:r});return{recoveryMethod:"icloud-native",recoverySecretOverride:a,iCloudRecordNameOverride:s,wallet:n}}case"recovery-encryption-key":return{recoveryMethod:"recovery-encryption-key",wallet:n,recoveryKey:i.recoveryKey};default:throw new Q({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}});import{useCallback as Tn,useContext as Nn}from"react";import{getUserEmbeddedEthereumWallet as Dn,getUserEmbeddedSolanaWallet as jn,PrivyClientError as de,isUnifiedWallet as Vn}from"@privy-io/js-sdk-core";var uu=()=>{let{client:e}=Nn(f);return{recover:Tn(r=>l(void 0,null,function*(){var c;let n=b();if(!n)throw new de({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let i=(c=Dn(n))!=null?c:jn(n);if(!i)throw new de({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(Vn(i))throw new de({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 o,a,s,d;switch(r.recoveryMethod){case"user-passcode":a=r.password;break;case"google-drive":s=yield _e(e);break;case"icloud":let{recoverySecret:u}=yield be({client:e,walletAddress:i.address,chainType:i.chain_type});d=u;break;case"recovery-encryption-key":o=r.recoveryKey;break;case"privy":break;default:throw new de({code:"unsupported_recovery_method",error:`Unsupported recovery options ${r}`})}try{i.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(i,a,s,d,o):i.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(i,i.address,"solana-address-verifier",a,s,d))}catch(u){throw new de({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};import{useEffect as zn}from"react";import{useContext as Kn,useEffect as Ye}from"react";var Qe=(e={})=>{let{wallet:t,createWalletCallbacks:r,recoverWalletCallbacks:n,setWalletRecoveryCallbacks:i}=Kn(f),{onCreateWalletSuccess:o,onCreateWalletError:a,onRecoverWalletError:s,onRecoverWalletSuccess:d,onSetWalletRecoverySuccess:c,onSetWalletRecoveryError:u}=e;return Ye(()=>{r.current={onSuccess:o,onError:a}},[o,a]),Ye(()=>{n.current={onSuccess:d,onError:s}},[d,s]),Ye(()=>{i.current={onSuccess:c,onError:u}},[d,s]),t};var vu=({onStateChange:e})=>{let t=Qe();return zn(()=>{e(t)},[t])};import{useContext as Hn}from"react";var _u=()=>{let{getIdentityToken:e}=Hn(f);return{getIdentityToken:e}};import{useCallback as dr,useContext as Bn}from"react";import{PrivyClientError as qn}from"@privy-io/js-sdk-core";var Ru=e=>{let{client:t}=Bn(f),r=dr(i=>{var a;let o=E(i);return(a=e==null?void 0:e.onError)==null||a.call(e,o),o},[e==null?void 0:e.onError]);return{create:dr(()=>l(void 0,null,function*(){var i;try{if(b())throw new qn({code:"attempted_to_create_guest_account_for_logged_in_user",error:"Already logged in, you cannot create a guest account"});let a=W(),s=yield t.auth.guest.create({embedded:a==null?void 0:a.embedded});return(i=e==null?void 0:e.onSuccess)==null||i.call(e,s.user,s.is_new_user),s.user}catch(o){throw r(o)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useContext as Gn,useEffect as Jn}from"react";function Tu({onMfaRequired:e}){let{client:t}=Gn(f);Jn(()=>{function r(){return l(this,null,function*(){var i;let n=b();yield e((i=n==null?void 0:n.mfa_methods.map(({type:o})=>o))!=null?i:[])})}return t.mfaPromises.on("mfaRequired",r),()=>{t.mfaPromises.off("mfaRequired",r)}},[t,e])}import{useCallback as xe,useContext as Zn}from"react";import{PrivyClientError as Pe}from"@privy-io/js-sdk-core";import{PrivyClientError as $n}from"@privy-io/js-sdk-core";var Yn=e=>l(void 0,null,function*(){var n;let r=yield(yield import("react-native-passkeys")).create({rp:e.rp,user:e.user,challenge:e.challenge,pubKeyCredParams:e.pubKeyCredParams,excludeCredentials:e.excludeCredentials,authenticatorSelection:e.authenticatorSelection,timeout:12e4});if(!r)throw new $n({code:"failed_to_create_passkey",error:"Could not create passkey"});return N(P({},r),{type:(n=r.type)!=null?n:"public-key",clientExtensionResults:{}})});import{PrivyClientError as Qn}from"@privy-io/js-sdk-core";var Ze=e=>l(void 0,null,function*(){var n;let r=yield(yield import("react-native-passkeys")).get({rpId:e.rpId,challenge:e.challenge,allowCredentials:e.allowCredentials,timeout:12e4});if(!r)throw new Qn({code:"no_passkey_found_for_challenge",error:"Could not find a matching passkey to login with"});return N(P({},r),{type:(n=r.type)!=null?n:"public-key",clientExtensionResults:{}})});function lr(e){var t;return{id:e.id,client_extension_results:{app_id:e.clientExtensionResults.appid,cred_props:e.clientExtensionResults.credProps,hmac_create_secret:e.clientExtensionResults.hmacCreateSecret},raw_id:e.rawId,type:e.type,authenticator_attachment:(t=e.authenticatorAttachment)!=null?t:"platform",response:{authenticator_data:e.response.authenticatorData,client_data_json:e.response.clientDataJSON,signature:e.response.signature,user_handle:e.response.userHandle}}}function ur(e){var t,r,n,i;return{challenge:e.challenge,rpId:e.rp_id,extensions:{appid:(t=e.extensions)==null?void 0:t.app_id,credProps:(r=e.extensions)==null?void 0:r.cred_props,hmacCreateSecret:(n=e.extensions)==null?void 0:n.hmac_create_secret},timeout:e.timeout,allowCredentials:(i=e.allow_credentials)==null?void 0:i.map(({id:o,type:a,transports:s})=>({id:o,type:a,transports:s})),userVerification:e.user_verification}}function Qu(e){var t,r,n,i,o,a,s,d;return{rp:e.rp,user:{id:e.user.id,name:e.user.name,displayName:e.user.display_name},challenge:e.challenge,pubKeyCredParams:e.pub_key_cred_params,extensions:{hmacCreateSecret:(t=e.extensions)==null?void 0:t.hmac_create_secret,credProps:(n=(r=e.extensions)==null?void 0:r.cred_props)==null?void 0:n.rk,appid:(i=e.extensions)==null?void 0:i.app_id},attestation:e.attestation,excludeCredentials:e.exclude_credentials,authenticatorSelection:{authenticatorAttachment:(o=e.authenticator_selection)==null?void 0:o.authenticator_attachment,residentKey:(a=e.authenticator_selection)==null?void 0:a.resident_key,userVerification:(s=e.authenticator_selection)==null?void 0:s.user_verification,requireResidentKey:(d=e.authenticator_selection)==null?void 0:d.require_resident_key}}}function om(){let{client:e}=Zn(f),t=xe(o=>l(this,null,function*(){var a,s;switch(o.method){case"sms":yield e.mfa.sms.sendCode({action:"verify"});return;case"passkey":let{options:d}=yield e.mfa.passkey.generateAuthenticationOptions({relying_party:o.relyingParty||((s=(a=W())==null?void 0:a.mfa)==null?void 0:s.relyingParty)});return ur(d);case"totp":return;default:throw new Error(`Unsupported MFA method: ${o.mfaMethod}`)}}),[e]),r=xe(o=>l(this,null,function*(){var a,s,d,c,u,m,p;switch(o.method){case"totp":case"sms":if(typeof o.mfaCode!="string")throw new Pe({code:"invalid_mfa_code",error:"Invalid MFA code"});(d=e.mfaPromises.rootPromise.current)==null||d.resolve({mfaMethod:o.method,mfaCode:o.mfaCode,relyingParty:o.relyingParty||((s=(a=W())==null?void 0:a.mfa)==null?void 0:s.relyingParty)||""}),yield new Promise((y,h)=>{e.mfaPromises.submitPromise.current={resolve:y,reject:h}});break;case"passkey":if(typeof o.mfaCode=="string")throw new Pe({code:"invalid_passkey_response",error:"Invalid authenticator response"});let w=yield Ze(o.mfaCode),g=lr(w);(m=e.mfaPromises.rootPromise.current)==null||m.resolve({mfaMethod:o.method,relyingParty:o.relyingParty||((u=(c=W())==null?void 0:c.mfa)==null?void 0:u.relyingParty)||"",mfaCode:g}),yield new Promise((y,h)=>{e.mfaPromises.submitPromise.current={resolve:y,reject:h}});break;default:let v=new Pe({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(p=e.mfaPromises.rootPromise.current)==null||p.reject(v),v}}),[e]),n=xe(()=>l(this,null,function*(){let o=b();!o||o.mfa_methods.length===0||(yield e.mfa.verifyMfa())}),[e]),i=xe(()=>{var o;(o=e.mfaPromises.rootPromise.current)==null||o.reject(new Pe({code:"mfa_canceled",error:"MFA canceled"}))},[e]);return{init:t,submit:r,prompt:n,cancel:i}}import{useCallback as et,useContext as ei}from"react";function cm(){let{client:e}=ei(f),t=et(i=>l(this,null,function*(){switch(i.method){case"sms":case"totp":return yield e.mfa.initEnrollMfa(i);case"passkey":return;default:throw new Error(`Unsupported MFA method: ${i.method}`)}}),[e]),r=et(i=>l(this,null,function*(){switch(i.method){case"sms":case"totp":case"passkey":yield e.mfa.submitEnrollMfa(i);return;default:throw new Error(`Unsupported MFA method: ${i.method}`)}}),[e]),n=et(i=>l(this,null,function*(){switch(i.method){case"sms":case"totp":yield e.mfa.unenrollMfa(i.method);return;case"passkey":yield e.mfa.submitEnrollMfa({method:"passkey",credentialIds:[],removeForLogin:i.removeForLogin});return;default:throw new Error(`Unsupported MFA method: ${i.method}`)}}),[e]);return{initMfaEnrollment:t,submitMfaEnrollment:r,unenrollMfa:n}}import{useCallback as ti,useMemo as mr}from"react";import{getAllUserEmbeddedEthereumWallets as rt,getEntropyDetailsFromUser as pr,getUserEmbeddedSolanaWallet as ri,PrivyClientError as yr}from"@privy-io/js-sdk-core";var oi=()=>{let e=U(),t=O(),r=mr(()=>{let o=rt(e).map(a=>{let s=pr(e,a);return s?{account:a,entropy:s}:null});return o.some(a=>a===null)?[]:o.filter(a=>a!==null).map(({account:a,entropy:{entropyId:s,entropyIdVerifier:d}})=>({address:a.address,walletIndex:a.wallet_index,chainType:a.chain_type,getProvider:()=>t.embeddedWallet.getEthereumProvider({wallet:a,entropyId:s,entropyIdVerifier:d,onNeedsRecovery:c=>l(void 0,null,function*(){var u;yield(u=fe())==null?void 0:u(c)})})}))},[t,e]),n=ti((...o)=>l(void 0,[...o],function*({createAdditional:i=!1}={}){let{user:a}=yield t.user.get(),s=rt(a);if(!i&&s.length>0)throw new yr({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let d=pr(a);if(!d){let g=yield t.embeddedWallet.create({});return tt(g.user,0),{user:g.user}}let{entropyId:c,entropyIdVerifier:u}=d;if(u==="solana-address-verifier"){let g=ri(a),v=yield t.embeddedWallet.create({solanaAccount:g});return tt(v.user,0),{user:v.user}}let p=s.map(g=>g.wallet_index).reduce((g,v)=>Math.max(g,v),0)+1,w=yield t.embeddedWallet.add({chainType:"ethereum",hdWalletIndex:p,entropyId:c,entropyIdVerifier:u});return tt(w.user,p),{user:w.user}}),[t]);return mr(()=>({wallets:r,create:n}),[r,n])};function tt(e,t){let r=rt(e).find(n=>n.wallet_index===t);if(!e||!r)throw new yr({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}import{useContext as ni,useEffect as fr}from"react";var ii=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:r,recoverSolanaWalletCallbacks:n}=ni(f),{onCreateWalletSuccess:i,onCreateWalletError:o,onRecoverWalletError:a,onRecoverWalletSuccess:s}=e;return fr(()=>{r.current={onSuccess:i,onError:o}},[i,o]),fr(()=>{n.current={onSuccess:s,onError:a}},[s,a]),t};import{useCallback as ai,useMemo as si}from"react";import{getAllUserEmbeddedBitcoinWallets as ot,getEntropyDetailsFromUser as gr,isUnifiedWallet as ci,PrivyClientError as X}from"@privy-io/js-sdk-core";var di=()=>{let e=U(),t=O(),r=si(()=>{let i=gr(e);if(!i)return[];let o=ot(e),{entropyId:a,entropyIdVerifier:s}=i;return o.map(d=>({address:d.address,walletIndex:d.wallet_index,publicKey:d.public_key,chainType:d.chain_type,getProvider:()=>ci(d)?Promise.reject(new X({code:"unsupported_wallet_type",error:"Bitcoin wallet providers are only supported for on-device execution and this app uses TEE execution. Use the useSignRawHash hook from @privy-io/expo/extended-chains to sign over a hash with this wallet. Learn more at https://docs.privy.io/recipes/tee-wallet-migration-guide"})):t.embeddedWallet.getBitcoinProvider({wallet:d,entropyId:a,entropyIdVerifier:s})}))},[t,e]),n=ai(a=>l(void 0,[a],function*({chainType:i,createAdditional:o=!1}){var y;let s=t.app.getConfig();if(((y=s==null?void 0:s.embedded_wallet_config)==null?void 0:y.mode)==="user-controlled-server-wallets-only")throw i==="bitcoin-segwit"?new X({code:"unsupported_wallet_type",error:"This app uses TEE execution. Use the useCreateWallet hook from @privy-io/expo/extended-chains to create the wallet instead. Learn more https://docs.privy.io/recipes/tee-wallet-migration-guide"}):new X({code:"unsupported_wallet_type",error:`Bitcoin (${i}) 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:d}=yield t.user.get(),c=gr(d);if(!c)throw new X({code:"embedded_wallet_creation_error",error:"No existing wallet for this user, create an Ethereum walet first to add a Bitcoin wallet"});let{entropyId:u,entropyIdVerifier:m}=c,p=ot(d).filter(h=>h.chain_type===i);if(!o&&p.length>0)throw new X({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let w=p.length===0?0:Math.max(...p.map(h=>h.wallet_index),0)+1,g=yield t.embeddedWallet.add({chainType:i,hdWalletIndex:w,entropyId:u,entropyIdVerifier:m}),v=ot(g.user).find(h=>h.chain_type===i&&h.wallet_index===w);if(!g.user||!v)throw new X({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"});return{user:g.user,provider:yield t.embeddedWallet.getBitcoinProvider({wallet:v,entropyId:u,entropyIdVerifier:m})}}),[t]);return{wallets:r,create:n}};import{useContext as li}from"react";var nt=()=>{let{isReady:e,logout:t,getAccessToken:r,error:n}=li(f);return{user:U(),isReady:e,error:n,logout:t,getAccessToken:r}};import{useContext as ui}from"react";function mi(){let{client:e}=ui(f);return{acceptTerms:()=>l(this,null,function*(){return e.user.acceptTerms()})}}import{useMemo as pi}from"react";import{generateAuthorizationSignature as yi}from"@privy-io/js-sdk-core";var fi=()=>{let e=O();return pi(()=>({generateAuthorizationSignature(r){return l(this,null,function*(){let{signature:n}=yield yi((...i)=>e.embeddedWallet.signWithUserSigner(...i),r);return{signature:n}})}}),[e])};import{useCallback as Si}from"react";import{PrivyClientError as Ei}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedBitcoinWallets as gi,getUserEmbeddedEthereumWallet as hi,getUserEmbeddedSolanaWallet as wi,isEmbeddedWalletAccount as vi,isUnifiedWallet as bi}from"@privy-io/js-sdk-core";function hr(e,t){return l(this,null,function*(){var i;let r=(i=hi(t))!=null?i:wi(t);if(!r||bi(r))return{success:!0,migrated:!1};if(r.imported)throw new Error("Imported wallets cannot be migrated");if(gi(t).length>0)throw new Error("Bitcoin wallets cannot be migrated");let n=t.linked_accounts.filter(vi).filter(o=>!o.imported).filter(o=>o.chain_type==="ethereum"||o.chain_type==="solana");return r.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(r):r.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(r,r.address,"solana-address-verifier")),yield e.embeddedWallet.delegateWallets({rootWallet:{address:r.address,chainType:r.chain_type,imported:r.imported},delegatedWallets:n.map(o=>({address:o.address,chainType:o.chain_type,walletIndex:o.wallet_index}))}),yield e.user.get(),{success:!0,migrated:!0}})}var wr=()=>{let e=O();return{migrate:Si(()=>l(void 0,null,function*(){var o;let r=b(),n=e.app.getConfig();if(((o=n==null?void 0:n.embedded_wallet_config)==null?void 0:o.mode)!=="user-controlled-server-wallets-only")return{success:!0};if(!r)throw new Ei({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before migrating wallets"});return hr(e,r)}),[e])}};var vr=({disabled:e})=>{let{migrate:t}=wr(),{user:r}=nt(),n=Ci(!1);return _i(()=>{e||r&&(n.current||(n.current=!0,t().then(i=>{i.migrated&&!n.current&&(console.info("Migrated wallets for user"),n.current=!0)}).catch(i=>{console.debug("Unable to migrate wallets: ",i)}).finally(()=>{n.current=!1})))},[t,r,e]),null};var f=Wi(null),ee;function ry(e){return ee?ee.getAccessToken():e!=null&&e.strict?Promise.reject(new Er({code:"attempted_to_read_storage_before_client_initialized",error:"Called `getAccessToken` before client initialized"})):(console.warn("Called `getAccessToken` before client initialized"),Promise.resolve(null))}var oy=e=>{var ct,dt,lt;Ui();let[t,r]=L(Sr.currentState==="active");br(()=>{let I=Sr.addEventListener("change",Ar=>{r(Ar==="active")});return()=>{I.remove()}},[]),br(()=>gt(e.config),[e.config]);let[n,i]=L(!1),[o,a]=L(null),[s,d]=L(!1),[c,u]=L({status:"disconnected",account:null}),[m,p]=L({status:"disconnected"}),[w,g]=L({status:"initial"}),[v,y]=L({status:"initial"}),[h,S]=L({status:"initial"}),[_,C]=L({status:"initial"}),[k,x]=L({status:"initial"}),[M,ue]=L({status:"initial"}),[me,Ae]=L({status:"initial"}),te=le({}),Re=le({}),Ie=le({}),at=le({}),st=le({}),pe=Ue(I=>{if(I){Me(I),a(null);return}Me(null),g({status:"initial"}),y({status:"initial"}),u({status:"disconnected",account:null})},[]),R=ki(()=>{let I=e.storage||ye;return e.client?ee=e.client:ee=ft({appId:e.appId,clientId:e.clientId,supportedChains:e.supportedChains,storage:I,baseUrl:e.baseUrl,logLevel:e.logLevel}),ee.setCallbacks({setUser:pe,setIsReady:d}),ee},[e.client,e.storage,e.appId,e.clientId,e.baseUrl,e.supportedChains,e.logLevel,pe]),_r=Ue(()=>l(void 0,null,function*(){let I=b();yield R.auth.logout(I?{userId:I==null?void 0:I.id}:void 0),pe(null)}),[pe,R]),Cr=Ue(()=>l(void 0,null,function*(){try{return yield R.getAccessToken()}catch(I){return console.debug(I),null}}),[R]),kr=Ue(()=>R.getIdentityToken(),[R]);Tt({client:R,isUserInitialized:n,setIsUserInitialized:i,setError:a});let Wr=Ot({client:R,appId:e.appId,createWalletCallbacks:te,recoverWalletCallbacks:Re,setWalletRecoveryCallbacks:Ie,setRecoveryFlowState:S,wallet:c,setWallet:u}),xr=kt({client:R,createSolanaWalletCallbacks:at,recoverSolanaWalletCallbacks:st,setSolanaRecoveryFlowState:C,solanaWallet:m,setSolanaWallet:p});Ft({client:R,createWalletCallbacks:te,recoverWalletCallbacks:Re,setWalletRecoveryCallbacks:Ie,recoveryFlowState:h,oAuthState:v,setRecoveryFlowState:S,setWallet:u,appStateVisible:t});let{customAuthStateIsSettled:Pr}=Mt({client:R,isReady:n}),Ur=V();return Z.createElement(Z.Fragment,null,Z.createElement(f.Provider,{value:{client:R,isReady:Ur&&n&&Pr,error:o,logout:_r,getAccessToken:Cr,getIdentityToken:kr,wallet:P(P({},c),Wr),solanaWallet:P(P({},m),xr),oAuthState:v,recoveryFlowState:h,setRecoveryFlowState:S,solanaRecoveryFlowState:_,setSolanaRecoveryFlowState:C,createWalletCallbacks:te,recoverWalletCallbacks:Re,setWalletRecoveryCallbacks:Ie,createSolanaWalletCallbacks:at,recoverSolanaWalletCallbacks:st,setOAuthState:y,siweState:k,setSiweState:x,otpState:w,setOtpState:g,passkeyState:M,setPasskeyState:ue,farcasterState:me,setFarcasterState:Ae}},e.children,Z.createElement(vr,{disabled:(lt=(dt=(ct=e.config)==null?void 0:ct.embedded)==null?void 0:dt.disableAutomaticMigration)!=null?lt:!1})),Z.createElement(Pi,{style:{width:0,height:0,overflow:"hidden"}},Z.createElement(vt,{client:R,isClientReady:s})))},Ui=()=>{if(xi(f))throw new Er({code:"configuration_error",error:"Found multiple instances of PrivyProvider, ensure there is only one mounted in your application tree."})};var uy=e=>{let{client:t,setSiweState:r,siweState:n}=Ai(f),i=it(s=>{var c;let d=E(s);return r({status:"error",error:d}),(c=e==null?void 0:e.onError)==null||c.call(e,d),d},[e==null?void 0:e.onError]),o=it(u=>l(void 0,[u],function*({wallet:s,from:{domain:d,uri:c}}){var m;try{r({status:"generating-message"});let p=yield t.auth.siwe.init(s,d,c);return r({status:"awaiting-signature"}),(m=e==null?void 0:e.onGenerateMessage)==null||m.call(e,p.message),p.message}catch(p){throw i(p)}}),[t,i,e==null?void 0:e.onGenerateMessage]),a=it(c=>l(void 0,[c],function*({signature:s,messageOverride:d}){var u;try{if(!b())throw new Ri({code:"attempted_link_siwe_before_logged_in",error:"Must be logged in to link a wallet, Use `useLoginWithSiwe` to login with a wallet"});r({status:"submitting-signature"});let{user:p}=yield t.auth.siwe.linkWithSiwe(s,void 0,d);return r({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,p),p}catch(m){throw i(m)}}),[t,i,e==null?void 0:e.onSuccess]);return{generateSiweMessage:o,linkWithSiwe:a,state:n}};export{W as a,b,Ji as c,U as d,$i as e,Or as f,E as g,G as h,ft as i,uy as j,Ls as k,O as l,Bs as m,ec as n,cc as o,gc as p,Ec as q,Rc as r,Dc as s,Jc as t,rd as u,cd as v,hd as w,xd as x,Od as y,Kd as z,Jd as A,el as B,sl as C,wl as D,Wl as E,Ll as F,Vl as G,Jl as H,ru as I,uu as J,Qe as K,vu as L,_u as M,Ru as N,Tu as O,Yn as P,Ze as Q,Qu as R,om as S,cm as T,oi as U,ii as V,di as W,nt as X,mi as Y,fi as Z,wr as _,f as $,ry as aa,oy as ba};
@@ -1 +1 @@
1
- import{$ as D,a as N,b as B,g as T}from"./chunk-HX3SSIK2.js";import{a as P,b as F,c as R,d as h}from"./chunk-QTVIWU3N.js";import*as y from"expo-linking";import{useCallback as Y,useContext as Z,useEffect as q,useRef as tt}from"react";import{Platform as et}from"react-native";import{PrivyClientError as S}from"@privy-io/js-sdk-core";import*as g from"expo-apple-authentication";import{PrivyClientError as J}from"@privy-io/js-sdk-core";function H(a){return h(this,arguments,function*({oauthProviderUrl:t,isLogin:i}){try{return yield g.signInAsync({state:K(t),requestedScopes:[g.AppleAuthenticationScope.EMAIL,g.AppleAuthenticationScope.FULL_NAME]})}catch(r){throw r instanceof Error&&"code"in r&&r.code==="ERR_REQUEST_CANCELED"?new J({error:"Apple login was cancelled",code:i?"login_with_oauth_was_cancelled_by_user":"link_with_oauth_was_cancelled_by_user"}):r}})}function K(t){var a;return(a=new URL(t).searchParams.get("state"))!=null?a:""}import{Platform as X}from"react-native";function z(t){return X.select({android:t.replace("x.com","twitter.com"),default:t})}import*as j from"expo-linking";import*as m from"expo-web-browser";import{PrivyClientError as M}from"@privy-io/js-sdk-core";function Q(r){return h(this,arguments,function*({oauthProviderUrl:t,isLogin:i,returnUrl:a}){var u,l;let s=yield m.openAuthSessionAsync(t,a,{createTask:!1});if(s.type===m.WebBrowserResultType.CANCEL||s.type===m.WebBrowserResultType.DISMISS)throw new M({error:"OAuth was cancelled",code:i?"login_with_oauth_was_cancelled_by_user":"link_with_oauth_was_cancelled_by_user"});if(s.type!=="success")throw new M({error:"OAuth session failed",code:i?"failed_to_complete_login_with_oauth":"failed_to_complete_link_with_oauth"});let o=j.parse(s.url).queryParams;return{authorizationCode:(u=o==null?void 0:o.privy_oauth_code)!=null?u:null,state:(l=o==null?void 0:o.privy_oauth_state)!=null?l:null,resultUrl:s.url}})}var V=(a={})=>{var r=a,{action:t}=r,i=R(r,["action"]);let{oAuthState:s,setOAuthState:o,client:u}=Z(D),l=tt(i);return q(()=>{l.current=i},[i]),{start:Y(function(Lt){return h(this,arguments,function*({provider:c,redirectUri:d,isLegacyAppleIosBehaviorEnabled:$=!1,disableSignup:G,onAppleOAuthUserInfo:U}){var C,L,v,E;o({status:"loading"});let b=B(),_=t?t==="login":!!!b;try{if(b&&t==="login")throw new S({code:"attempted_login_with_oauth_while_already_logged_in",error:"Already logged in, if trying to link an OAuth account use `useLinkWithOAuth`"});if(!b&&t==="link")throw new S({code:"attempted_link_oauth_before_logged_in",error:"Must be logged in to link an OAuth account, use `useLoginWithOAuth`"});if(__DEV__&&d!=null&&d.includes("://")){let e=d.split("://")[0];console.warn(`redirectUri includes a scheme prefix (${e}://), it should be a path instead, such as '/authenticated'`)}let w=y.createURL(d||"/"),{url:n}=yield u.auth.oauth.generateURL(c,w);c==="twitter"&&(n=z(n));let p,k,A,f,I,W,O;if(et.OS==="ios"&&c==="apple"&&!$){let e=yield H({oauthProviderUrl:n,isLogin:_});A=e.authorizationCode,f=e.state,O=e,I="raw"}else{let e=yield Q({oauthProviderUrl:n,isLogin:_,returnUrl:w});A=e.authorizationCode,f=e.state,W=e.resultUrl}if(!A||!f)throw new S({error:"OAuth invalid credentials",code:_?"login_with_oauth_returned_with_invalid_credentials":"link_with_oauth_returned_with_invalid_credentials"});if(_){let e=N(),x=yield u.auth.oauth.loginWithCode(A,f,c,I,G?"no-signup":"login-or-sign-up",{embedded:e==null?void 0:e.embedded});p=x.user,k=x.is_new_user}else({user:p}=yield u.auth.oauth.linkWithCode(A,f,c,I));return O&&U&&U({fullName:O.fullName,email:O.email}),(L=(C=l.current).onSuccess)==null||L.call(C,p,k),W&&(yield y.openURL(W.split("?")[0])),o({status:"done",isNewUser:k}),p!=null?p:void 0}catch(w){let n=T(w);throw o({status:"error",error:n}),(E=(v=l.current).onError)==null||E.call(v,n),n}})},[u.auth.oauth,t,o]),state:s}};function St(t){let{state:i,start:a}=V(F(P({},t),{action:"login"}));return{state:i,login:a}}export{V as a,St as b};
1
+ import{$ as D,a as N,b as B,g as T}from"./chunk-HXIVVEZ6.js";import{a as P,b as F,c as R,d as h}from"./chunk-QTVIWU3N.js";import*as y from"expo-linking";import{useCallback as Y,useContext as Z,useEffect as q,useRef as tt}from"react";import{Platform as et}from"react-native";import{PrivyClientError as S}from"@privy-io/js-sdk-core";import*as g from"expo-apple-authentication";import{PrivyClientError as J}from"@privy-io/js-sdk-core";function H(a){return h(this,arguments,function*({oauthProviderUrl:t,isLogin:i}){try{return yield g.signInAsync({state:K(t),requestedScopes:[g.AppleAuthenticationScope.EMAIL,g.AppleAuthenticationScope.FULL_NAME]})}catch(r){throw r instanceof Error&&"code"in r&&r.code==="ERR_REQUEST_CANCELED"?new J({error:"Apple login was cancelled",code:i?"login_with_oauth_was_cancelled_by_user":"link_with_oauth_was_cancelled_by_user"}):r}})}function K(t){var a;return(a=new URL(t).searchParams.get("state"))!=null?a:""}import{Platform as X}from"react-native";function z(t){return X.select({android:t.replace("x.com","twitter.com"),default:t})}import*as j from"expo-linking";import*as m from"expo-web-browser";import{PrivyClientError as M}from"@privy-io/js-sdk-core";function Q(r){return h(this,arguments,function*({oauthProviderUrl:t,isLogin:i,returnUrl:a}){var u,l;let s=yield m.openAuthSessionAsync(t,a,{createTask:!1});if(s.type===m.WebBrowserResultType.CANCEL||s.type===m.WebBrowserResultType.DISMISS)throw new M({error:"OAuth was cancelled",code:i?"login_with_oauth_was_cancelled_by_user":"link_with_oauth_was_cancelled_by_user"});if(s.type!=="success")throw new M({error:"OAuth session failed",code:i?"failed_to_complete_login_with_oauth":"failed_to_complete_link_with_oauth"});let o=j.parse(s.url).queryParams;return{authorizationCode:(u=o==null?void 0:o.privy_oauth_code)!=null?u:null,state:(l=o==null?void 0:o.privy_oauth_state)!=null?l:null,resultUrl:s.url}})}var V=(a={})=>{var r=a,{action:t}=r,i=R(r,["action"]);let{oAuthState:s,setOAuthState:o,client:u}=Z(D),l=tt(i);return q(()=>{l.current=i},[i]),{start:Y(function(Lt){return h(this,arguments,function*({provider:c,redirectUri:d,isLegacyAppleIosBehaviorEnabled:$=!1,disableSignup:G,onAppleOAuthUserInfo:U}){var C,L,v,E;o({status:"loading"});let b=B(),_=t?t==="login":!!!b;try{if(b&&t==="login")throw new S({code:"attempted_login_with_oauth_while_already_logged_in",error:"Already logged in, if trying to link an OAuth account use `useLinkWithOAuth`"});if(!b&&t==="link")throw new S({code:"attempted_link_oauth_before_logged_in",error:"Must be logged in to link an OAuth account, use `useLoginWithOAuth`"});if(__DEV__&&d!=null&&d.includes("://")){let e=d.split("://")[0];console.warn(`redirectUri includes a scheme prefix (${e}://), it should be a path instead, such as '/authenticated'`)}let w=y.createURL(d||"/"),{url:n}=yield u.auth.oauth.generateURL(c,w);c==="twitter"&&(n=z(n));let p,k,A,f,I,W,O;if(et.OS==="ios"&&c==="apple"&&!$){let e=yield H({oauthProviderUrl:n,isLogin:_});A=e.authorizationCode,f=e.state,O=e,I="raw"}else{let e=yield Q({oauthProviderUrl:n,isLogin:_,returnUrl:w});A=e.authorizationCode,f=e.state,W=e.resultUrl}if(!A||!f)throw new S({error:"OAuth invalid credentials",code:_?"login_with_oauth_returned_with_invalid_credentials":"link_with_oauth_returned_with_invalid_credentials"});if(_){let e=N(),x=yield u.auth.oauth.loginWithCode(A,f,c,I,G?"no-signup":"login-or-sign-up",{embedded:e==null?void 0:e.embedded});p=x.user,k=x.is_new_user}else({user:p}=yield u.auth.oauth.linkWithCode(A,f,c,I));return O&&U&&U({fullName:O.fullName,email:O.email}),(L=(C=l.current).onSuccess)==null||L.call(C,p,k),W&&(yield y.openURL(W.split("?")[0])),o({status:"done",isNewUser:k}),p!=null?p:void 0}catch(w){let n=T(w);throw o({status:"error",error:n}),(E=(v=l.current).onError)==null||E.call(v,n),n}})},[u.auth.oauth,t,o]),state:s}};function St(t){let{state:i,start:a}=V(F(P({},t),{action:"login"}));return{state:i,login:a}}export{V as a,St as b};
@@ -1 +1 @@
1
- import{b as u,l as i}from"./chunk-HX3SSIK2.js";import{d as a}from"./chunk-QTVIWU3N.js";import{useMemo as d}from"react";import{create as g}from"@privy-io/js-sdk-core";var f=()=>{let e=i();return d(()=>({createWallet(n){return a(this,null,function*(){let s=yield g(e,{request:{chain_type:n.chainType}}),{user:o}=yield e.user.get();return{user:o,wallet:s}})}}),[e])};import{useMemo as h}from"react";import{isEmbeddedWalletAccount as m,isUnifiedWallet as w,PrivyClientError as c,rawSign as y}from"@privy-io/js-sdk-core";var C=()=>{let e=i();return h(()=>({signRawHash(k){return a(this,arguments,function*({address:n,chainType:s,hash:o}){let l=u();if(!l)throw new c({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before signing a raw hash"});let p=l.linked_accounts.filter(m).filter(w).filter(t=>t.chain_type===s).find(t=>t.address===n);if(!p)throw new c({code:"embedded_wallet_does_not_exist",error:"No embedded wallet found for the given address and chain type"});let r=yield y(e,(...t)=>e.embeddedWallet.signWithUserSigner(...t),{wallet_id:p.id,params:{hash:o}});if(r.data&&"signature"in r.data&&r.data.encoding==="hex")return{signature:r.data.signature};throw new Error("Failed to sign")})}}),[e])};export{f as useCreateWallet,C as useSignRawHash};
1
+ import{b as u,l as i}from"./chunk-HXIVVEZ6.js";import{d as a}from"./chunk-QTVIWU3N.js";import{useMemo as d}from"react";import{create as g}from"@privy-io/js-sdk-core";var f=()=>{let e=i();return d(()=>({createWallet(n){return a(this,null,function*(){let s=yield g(e,{request:{chain_type:n.chainType}}),{user:o}=yield e.user.get();return{user:o,wallet:s}})}}),[e])};import{useMemo as h}from"react";import{isEmbeddedWalletAccount as m,isUnifiedWallet as w,PrivyClientError as c,rawSign as y}from"@privy-io/js-sdk-core";var C=()=>{let e=i();return h(()=>({signRawHash(k){return a(this,arguments,function*({address:n,chainType:s,hash:o}){let l=u();if(!l)throw new c({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before signing a raw hash"});let p=l.linked_accounts.filter(m).filter(w).filter(t=>t.chain_type===s).find(t=>t.address===n);if(!p)throw new c({code:"embedded_wallet_does_not_exist",error:"No embedded wallet found for the given address and chain type"});let r=yield y(e,(...t)=>e.embeddedWallet.signWithUserSigner(...t),{wallet_id:p.id,params:{hash:o}});if(r.data&&"signature"in r.data&&r.data.encoding==="hex")return{signature:r.data.signature};throw new Error("Failed to sign")})}}),[e])};export{f as useCreateWallet,C as useSignRawHash};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{a as Pt,b as Tt,c as Ft,d as Lt,e as Wt,f as Rt,g as gt,h as Ht}from"./chunk-QSWCX5XI.js";import{a as O,b as P}from"./chunk-DXXOXGZI.js";import{$ as A,A as et,B as ot,C as rt,D as nt,E as ut,F as it,G as pt,H as st,I as ht,J as At,K as Ot,L as at,M as ct,N as mt,O as ft,S as kt,T as lt,U as yt,V as xt,W as Ut,X as U,Y as dt,Z as vt,_ as I,aa as wt,ba as It,e as y,f as G,g as x,i as w,j,k as D,l as E,m as _,n as B,o as M,p as q,q as z,r as J,s as K,t as Q,u as V,v as X,w as Y,x as Z,y as $,z as tt}from"./chunk-HX3SSIK2.js";import{a as f,b as k,d as l,g as v}from"./chunk-QTVIWU3N.js";export*from"@privy-io/js-sdk-core";import r from"react";var bt=({loading:t,error:e,unauthenticated:o,children:i})=>{let{isReady:u,error:p}=U(),d=y();if(!u)return r.createElement(r.Fragment,null,t);if(p&&e){let n=typeof e=="function"?e(p):e;return r.createElement(r.Fragment,null,n)}return d?r.createElement(r.Fragment,null,i):r.createElement(r.Fragment,null,o)};function T(t){return O(t)}function F(t){let{state:e,start:o}=O(k(f({},t),{action:"link"}));return{state:e,link:o}}import{useCallback as L,useContext as W,useEffect as R,useRef as g}from"react";var H=t=>{let{client:e}=W(A),o=g(t);return R(()=>{o.current=t},[t]),{unlinkOAuth:L(d=>l(void 0,[d],function*({provider:u,subject:p}){var n,a,s,c;try{let{user:h}=yield e.auth.oauth.unlink(u,p);return(a=(n=o.current)==null?void 0:n.onSuccess)==null||a.call(n,h),h}catch(h){let m=x(h);throw(c=(s=o.current)==null?void 0:s.onError)==null||c.call(s,m),m}}),[e.auth.oauth])}};import{useContext as C,useEffect as N,useRef as S}from"react";var b=t=>{let{client:e}=C(A),o=S(t.onOAuthTokenGrant);o.current=t.onOAuthTokenGrant,N(()=>{let{unsubscribe:i}=e.addOAuthTokensListener(u=>{o.current(u)});return i},[e])};export{bt as AuthBoundary,A as PrivyContext,It as PrivyProvider,v as SecureStorageAdapter,w as createPrivyClient,wt as getAccessToken,gt as hasError,Pt as isConnected,Ft as isConnecting,Rt as isCreating,Lt as isDisconnected,Wt as isNotCreated,Tt as isReconnecting,Ht as needsRecovery,dt as useAcceptTerms,vt as useAuthorizationSignature,mt as useCreateGuestAccount,Ut as useEmbeddedBitcoinWallet,yt as useEmbeddedEthereumWallet,xt as useEmbeddedSolanaWallet,Ot as useEmbeddedWallet,at as useEmbeddedWalletStateChange,$ as useHeadlessDelegatedActions,ct as useIdentityToken,q as useLinkEmail,K as useLinkSMS,ut as useLinkWithCrossApp,V as useLinkWithFarcaster,F as useLinkWithOAuth,j as useLinkWithSiwe,_ as useLinkWithSiws,nt as useLoginWithCrossApp,J as useLoginWithEmail,Y as useLoginWithFarcaster,Z as useLoginWithFarcasterV2,P as useLoginWithOAuth,Q as useLoginWithSMS,D as useLoginWithSiwe,B as useLoginWithSiws,kt as useMfa,lt as useMfaEnrollment,I as useMigrateWallets,T as useOAuthFlow,b as useOAuthTokens,G as useOnNeedsRecovery,U as usePrivy,E as usePrivyClient,At as useRecoverEmbeddedWallet,ft as useRegisterMfaListener,st as useSendTransactionWithCrossApp,tt as useSessionSigners,ht as useSetEmbeddedWalletRecovery,it as useSignMessageWithCrossApp,pt as useSignTypedDataWithCrossApp,et as useSigners,z as useUnlinkEmail,X as useUnlinkFarcaster,H as useUnlinkOAuth,M as useUnlinkWallet,ot as useUpdateEmail,rt as useUpdatePhone};
1
+ import{a as Pt,b as Tt,c as Ft,d as Lt,e as Wt,f as Rt,g as gt,h as Ht}from"./chunk-QSWCX5XI.js";import{a as O,b as P}from"./chunk-QCIAFL2D.js";import{$ as A,A as et,B as ot,C as rt,D as nt,E as ut,F as it,G as pt,H as st,I as ht,J as At,K as Ot,L as at,M as ct,N as mt,O as ft,S as kt,T as lt,U as yt,V as xt,W as Ut,X as U,Y as dt,Z as vt,_ as I,aa as wt,ba as It,e as y,f as G,g as x,i as w,j,k as D,l as E,m as _,n as B,o as M,p as q,q as z,r as J,s as K,t as Q,u as V,v as X,w as Y,x as Z,y as $,z as tt}from"./chunk-HXIVVEZ6.js";import{a as f,b as k,d as l,g as v}from"./chunk-QTVIWU3N.js";export*from"@privy-io/js-sdk-core";import r from"react";var bt=({loading:t,error:e,unauthenticated:o,children:i})=>{let{isReady:u,error:p}=U(),d=y();if(!u)return r.createElement(r.Fragment,null,t);if(p&&e){let n=typeof e=="function"?e(p):e;return r.createElement(r.Fragment,null,n)}return d?r.createElement(r.Fragment,null,i):r.createElement(r.Fragment,null,o)};function T(t){return O(t)}function F(t){let{state:e,start:o}=O(k(f({},t),{action:"link"}));return{state:e,link:o}}import{useCallback as L,useContext as W,useEffect as R,useRef as g}from"react";var H=t=>{let{client:e}=W(A),o=g(t);return R(()=>{o.current=t},[t]),{unlinkOAuth:L(d=>l(void 0,[d],function*({provider:u,subject:p}){var n,a,s,c;try{let{user:h}=yield e.auth.oauth.unlink(u,p);return(a=(n=o.current)==null?void 0:n.onSuccess)==null||a.call(n,h),h}catch(h){let m=x(h);throw(c=(s=o.current)==null?void 0:s.onError)==null||c.call(s,m),m}}),[e.auth.oauth])}};import{useContext as C,useEffect as N,useRef as S}from"react";var b=t=>{let{client:e}=C(A),o=S(t.onOAuthTokenGrant);o.current=t.onOAuthTokenGrant,N(()=>{let{unsubscribe:i}=e.addOAuthTokensListener(u=>{o.current(u)});return i},[e])};export{bt as AuthBoundary,A as PrivyContext,It as PrivyProvider,v as SecureStorageAdapter,w as createPrivyClient,wt as getAccessToken,gt as hasError,Pt as isConnected,Ft as isConnecting,Rt as isCreating,Lt as isDisconnected,Wt as isNotCreated,Tt as isReconnecting,Ht as needsRecovery,dt as useAcceptTerms,vt as useAuthorizationSignature,mt as useCreateGuestAccount,Ut as useEmbeddedBitcoinWallet,yt as useEmbeddedEthereumWallet,xt as useEmbeddedSolanaWallet,Ot as useEmbeddedWallet,at as useEmbeddedWalletStateChange,$ as useHeadlessDelegatedActions,ct as useIdentityToken,q as useLinkEmail,K as useLinkSMS,ut as useLinkWithCrossApp,V as useLinkWithFarcaster,F as useLinkWithOAuth,j as useLinkWithSiwe,_ as useLinkWithSiws,nt as useLoginWithCrossApp,J as useLoginWithEmail,Y as useLoginWithFarcaster,Z as useLoginWithFarcasterV2,P as useLoginWithOAuth,Q as useLoginWithSMS,D as useLoginWithSiwe,B as useLoginWithSiws,kt as useMfa,lt as useMfaEnrollment,I as useMigrateWallets,T as useOAuthFlow,b as useOAuthTokens,G as useOnNeedsRecovery,U as usePrivy,E as usePrivyClient,At as useRecoverEmbeddedWallet,ft as useRegisterMfaListener,st as useSendTransactionWithCrossApp,tt as useSessionSigners,ht as useSetEmbeddedWalletRecovery,it as useSignMessageWithCrossApp,pt as useSignTypedDataWithCrossApp,et as useSigners,z as useUnlinkEmail,X as useUnlinkFarcaster,H as useUnlinkOAuth,M as useUnlinkWallet,ot as useUpdateEmail,rt as useUpdatePhone};
@@ -1 +1 @@
1
- import{a as q,b as D,c as F,d as J,e as K,f as N,g as T,h as M}from"./chunk-QSWCX5XI.js";import{$ as p,P as d,Q as C,R as S,a as b,b as m,g}from"./chunk-HX3SSIK2.js";import{d as l}from"./chunk-QTVIWU3N.js";import{useCallback as x,useContext as U}from"react";import{PrivyClientError as R}from"@privy-io/js-sdk-core";var X=e=>{let{client:n,passkeyState:h,setPasskeyState:s}=U(p),c=x(o=>{var r;let a=g(o);return s({status:"error",error:a}),(r=e==null?void 0:e.onError)==null||r.call(e,a),a},[e==null?void 0:e.onError]);return{linkWithPasskey:x(a=>l(void 0,[a],function*({relyingParty:o}){var r;try{if(!m())throw new R({code:"attempted_link_passkey_before_logged_in",error:"Must be logged in to link a passkey."});s({status:"generating-challenege"});let{options:u}=yield n.auth.passkey.generateRegistrationOptions(o);s({status:"awaiting-passkey"});let k=yield d(S(u));s({status:"submitting-response"});let{user:y}=yield n.auth.passkey.linkWithPasskey(k,o);return s({status:"done"}),(r=e==null?void 0:e.onSuccess)==null||r.call(e,y),y}catch(t){throw c(t)}}),[n,c,e==null?void 0:e.onSuccess]),state:h}};import{useCallback as E,useContext as v}from"react";import{PrivyClientError as H}from"@privy-io/js-sdk-core";var ne=e=>{let{client:n,passkeyState:h,setPasskeyState:s}=v(p),c=E(o=>{var r;let a=g(o);return s({status:"error",error:a}),(r=e==null?void 0:e.onError)==null||r.call(e,a),a},[e==null?void 0:e.onError]);return{loginWithPasskey:E(a=>l(void 0,[a],function*({relyingParty:o}){var r,t,u,k;try{if(m())throw new H({code:"attempted_login_with_passkey_while_already_logged_in",error:"Already logged in, use `useLinkWithPasskey` if you are trying to link a passkey to an existing account"});s({status:"generating-challenege"});let{options:i}=yield n.auth.passkey.generateAuthenticationOptions(o);s({status:"awaiting-passkey"});let P=yield C({challenge:i.challenge,rpId:i.rp_id,extensions:{appid:(r=i.extensions)==null?void 0:r.app_id,credProps:(t=i.extensions)==null?void 0:t.cred_props,hmacCreateSecret:(u=i.extensions)==null?void 0:u.hmac_create_secret},timeout:i.timeout,allowCredentials:i.allow_credentials,userVerification:i.user_verification});s({status:"submitting-response"});let w=b(),_=yield n.auth.passkey.loginWithPasskey(P,i.challenge,o,{embedded:w==null?void 0:w.embedded});return s({status:"done"}),(k=e==null?void 0:e.onSuccess)==null||k.call(e,_.user,_.is_new_user),_.user}catch(y){throw c(y)}}),[n,c,e==null?void 0:e.onSuccess]),state:h}};import{useCallback as O,useContext as I,useEffect as L,useRef as A}from"react";import{PrivyClientError as V}from"@privy-io/js-sdk-core";var me=e=>{let{client:n,passkeyState:h,setPasskeyState:s}=I(p),c=A(e);L(()=>{c.current=e},[e]);let f=O(a=>{var t,u;let r=g(a);return s({status:"error",error:r}),(u=(t=c.current)==null?void 0:t.onError)==null||u.call(t,r),r},[s]);return{signupWithPasskey:O(r=>l(void 0,[r],function*({relyingParty:a}){var t,u;try{if(m())throw new V({code:"attempted_login_with_passkey_while_already_logged_in",error:"Already logged in, use `useLinkWithPasskey` if you are trying to link a passkey to an existing account"});s({status:"generating-challenege"});let{options:y}=yield n.auth.passkey.generateSignupOptions(a);s({status:"awaiting-passkey"});let i=yield d(S(y));s({status:"submitting-response"});let P=yield n.auth.passkey.signupWithPasskey(i,a);return s({status:"done"}),(u=(t=c.current)==null?void 0:t.onSuccess)==null||u.call(t,P.user,P.is_new_user),{user:P.user}}catch(k){throw f(k)}}),[n.auth.passkey,f,s]),state:h}};export{T as hasError,q as isConnected,F as isConnecting,N as isCreating,J as isDisconnected,K as isNotCreated,D as isReconnecting,M as needsRecovery,X as useLinkWithPasskey,ne as useLoginWithPasskey,me as useSignupWithPasskey};
1
+ import{a as q,b as D,c as F,d as J,e as K,f as N,g as T,h as M}from"./chunk-QSWCX5XI.js";import{$ as p,P as d,Q as C,R as S,a as b,b as m,g}from"./chunk-HXIVVEZ6.js";import{d as l}from"./chunk-QTVIWU3N.js";import{useCallback as x,useContext as U}from"react";import{PrivyClientError as R}from"@privy-io/js-sdk-core";var X=e=>{let{client:n,passkeyState:h,setPasskeyState:s}=U(p),c=x(o=>{var r;let a=g(o);return s({status:"error",error:a}),(r=e==null?void 0:e.onError)==null||r.call(e,a),a},[e==null?void 0:e.onError]);return{linkWithPasskey:x(a=>l(void 0,[a],function*({relyingParty:o}){var r;try{if(!m())throw new R({code:"attempted_link_passkey_before_logged_in",error:"Must be logged in to link a passkey."});s({status:"generating-challenege"});let{options:u}=yield n.auth.passkey.generateRegistrationOptions(o);s({status:"awaiting-passkey"});let k=yield d(S(u));s({status:"submitting-response"});let{user:y}=yield n.auth.passkey.linkWithPasskey(k,o);return s({status:"done"}),(r=e==null?void 0:e.onSuccess)==null||r.call(e,y),y}catch(t){throw c(t)}}),[n,c,e==null?void 0:e.onSuccess]),state:h}};import{useCallback as E,useContext as v}from"react";import{PrivyClientError as H}from"@privy-io/js-sdk-core";var ne=e=>{let{client:n,passkeyState:h,setPasskeyState:s}=v(p),c=E(o=>{var r;let a=g(o);return s({status:"error",error:a}),(r=e==null?void 0:e.onError)==null||r.call(e,a),a},[e==null?void 0:e.onError]);return{loginWithPasskey:E(a=>l(void 0,[a],function*({relyingParty:o}){var r,t,u,k;try{if(m())throw new H({code:"attempted_login_with_passkey_while_already_logged_in",error:"Already logged in, use `useLinkWithPasskey` if you are trying to link a passkey to an existing account"});s({status:"generating-challenege"});let{options:i}=yield n.auth.passkey.generateAuthenticationOptions(o);s({status:"awaiting-passkey"});let P=yield C({challenge:i.challenge,rpId:i.rp_id,extensions:{appid:(r=i.extensions)==null?void 0:r.app_id,credProps:(t=i.extensions)==null?void 0:t.cred_props,hmacCreateSecret:(u=i.extensions)==null?void 0:u.hmac_create_secret},timeout:i.timeout,allowCredentials:i.allow_credentials,userVerification:i.user_verification});s({status:"submitting-response"});let w=b(),_=yield n.auth.passkey.loginWithPasskey(P,i.challenge,o,{embedded:w==null?void 0:w.embedded});return s({status:"done"}),(k=e==null?void 0:e.onSuccess)==null||k.call(e,_.user,_.is_new_user),_.user}catch(y){throw c(y)}}),[n,c,e==null?void 0:e.onSuccess]),state:h}};import{useCallback as O,useContext as I,useEffect as L,useRef as A}from"react";import{PrivyClientError as V}from"@privy-io/js-sdk-core";var me=e=>{let{client:n,passkeyState:h,setPasskeyState:s}=I(p),c=A(e);L(()=>{c.current=e},[e]);let f=O(a=>{var t,u;let r=g(a);return s({status:"error",error:r}),(u=(t=c.current)==null?void 0:t.onError)==null||u.call(t,r),r},[s]);return{signupWithPasskey:O(r=>l(void 0,[r],function*({relyingParty:a}){var t,u;try{if(m())throw new V({code:"attempted_login_with_passkey_while_already_logged_in",error:"Already logged in, use `useLinkWithPasskey` if you are trying to link a passkey to an existing account"});s({status:"generating-challenege"});let{options:y}=yield n.auth.passkey.generateSignupOptions(a);s({status:"awaiting-passkey"});let i=yield d(S(y));s({status:"submitting-response"});let P=yield n.auth.passkey.signupWithPasskey(i,a);return s({status:"done"}),(u=(t=c.current)==null?void 0:t.onSuccess)==null||u.call(t,P.user,P.is_new_user),{user:P.user}}catch(k){throw f(k)}}),[n.auth.passkey,f,s]),state:h}};export{T as hasError,q as isConnected,F as isConnecting,N as isCreating,J as isDisconnected,K as isNotCreated,D as isReconnecting,M as needsRecovery,X as useLinkWithPasskey,ne as useLoginWithPasskey,me as useSignupWithPasskey};
@@ -1 +1 @@
1
- import{a as E}from"./chunk-QSWCX5XI.js";import{$ as C,b,d as h,l as x}from"./chunk-HX3SSIK2.js";import{d as c}from"./chunk-QTVIWU3N.js";import u,{createContext as _,useCallback as X,useContext as p,useEffect as g,useState as A}from"react";import{getUserSmartWallet as S,PrivyClientError as m}from"@privy-io/js-sdk-core";import{createPublicClient as F,http as L}from"viem";import{getJsonRpcEndpointFromChain as M,getUserSmartWallet as R,PrivyClientError as I}from"@privy-io/js-sdk-core";import{signerToSmartAccountClient as G}from"@privy-io/js-sdk-core/smart-wallets";var W=l=>c(void 0,[l],function*({chain:t,privyAppId:e,user:a,embeddedWallet:r,smartWalletsConfig:n,client:o}){if(!(n!=null&&n.enabled)||!r||!E(r))return;let f=yield o.embeddedWallet.getProvider(r.account),i=n==null?void 0:n.configured_networks.find($=>$.chain_id===`eip155:${t.id}`);if(!i)throw new I({code:"chain_not_supported",error:`The chain ${t.name} (eip155:${t.id}) must be configured in the smart wallet configuration in your dashboard`});let s=R(a),y=s?s.smart_wallet_type:n.smart_wallet_type,w=s?s.smart_wallet_version:n.smart_wallet_version,N=M(t,{rpcUrls:[]},e),O=F({chain:t,transport:L(N)}),P=yield G({owner:f,smartWalletType:y,smartWalletVersion:w,chain:t,publicClient:O,paymasterContext:j(i.paymaster_url,i.paymaster_context),bundlerUrl:i.bundler_url,paymasterUrl:i.paymaster_url});if(!P)throw new I({code:"smart_wallet_client_error",error:`Failed to create smart wallet client for chain ${t.name} (eip155:${t.id})`});return P}),B=/paymaster\.biconomy\.io\/api/i;function D(t){return B.test(t)}var Y={mode:"SPONSORED",calculateGasLimits:!0,expiryDuration:300,sponsorshipInfo:{webhookData:{},smartAccountInfo:{name:"BICONOMY",version:"2.0.0"}}},j=(t,e)=>{if(t&&D(t))return Y;if(e&&e.policy_id)return{policyId:e.policy_id}};var J=({children:t})=>u.createElement(z,null,u.createElement(H,null,u.createElement(K,null,t))),T=_({config:void 0}),v=()=>{let{config:t}=p(T);return{config:t}},k=_({smartWalletClient:void 0}),V=()=>{let{smartWalletClient:t}=p(k);return{smartWalletClient:t}},U=_({client:void 0}),q=()=>{let{client:t}=p(U),e=Q();return{client:t,getClientForChain:e}},z=({children:t})=>{let[e,a]=A(void 0),r=x();return g(()=>{!e&&r&&(()=>c(void 0,null,function*(){try{if(!r){console.warn("No client found");return}let o=yield r.app.getSmartWalletConfig();a(o)}catch(o){console.warn("Error generating smart wallet config: ",o)}}))()},[r,e]),u.createElement(T.Provider,{value:{config:e}},t)},H=({children:t})=>{let{config:e}=v(),{client:a,wallet:r}=p(C),n=h(),[o,l]=A();return g(()=>{(()=>c(void 0,null,function*(){if(!n&&o&&l(void 0),!(e!=null&&e.enabled)||!n||r.status!=="connected"||n&&o&&r.status==="connected")return;let i=a.embeddedWallet.chains.find(y=>e.configured_networks.map(w=>w.chain_id).includes(`eip155:${y.id}`));if(!i)throw new m({error:"Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.",code:"chain_not_supported"});let s=yield W({chain:i,privyAppId:a.app.appId,user:n,embeddedWallet:r,smartWalletsConfig:e,client:a});if(!s)throw new m({error:"Could not create smart wallet client",code:"smart_wallet_client_error"});l(s)}))()},[!!(e!=null&&e.enabled),!!a,!!n,r.status]),u.createElement(k.Provider,{value:{smartWalletClient:o}},t)},K=({children:t})=>{let{client:e}=p(C),a=h(),{smartWalletClient:r}=V(),{config:n}=v();return g(()=>{(()=>c(void 0,null,function*(){if(!(!r||!a||S(a)||!(n!=null&&n.enabled)))try{let{message:l}=yield e.auth.smartWallet.init({address:r.account.address,chainId:`eip155:${r.chain.id}`}),d=yield r.signMessage({message:l});yield e.auth.smartWallet.link(l,d,n.smart_wallet_type,n.smart_wallet_version)}catch(l){console.error("Error creating smart wallet:",l)}}))()},[!!r,!!a,!!S(a),n]),u.createElement(U.Provider,{value:{client:S(a)?r:void 0}},t)},Q=()=>{let{client:t,wallet:e}=p(C),{config:a}=v();return X(n=>c(void 0,[n],function*({chainId:r}){let o=b();if(!o)throw new m({error:"Must be logged in to get a smart wallet client",code:"smart_wallet_client_error"});if(!a||!a.enabled)throw new m({error:"Must have smart wallets enabled to get a smart wallet client",code:"smart_wallet_client_error"});let d=t.embeddedWallet.chains.find(i=>i.id===r);if(!d)throw new m({error:`Could not find chain with id: ${r}`,code:"chain_not_supported"});let f=yield W({chain:d,privyAppId:t.app.appId,user:o,embeddedWallet:e,smartWalletsConfig:a,client:t});if(!f)throw new m({error:`Could not create smart wallet client for chain ${r}`,code:"smart_wallet_client_error"});return f}),[a,e,t])};export{J as SmartWalletsProvider,q as useSmartWallets};
1
+ import{a as E}from"./chunk-QSWCX5XI.js";import{$ as C,b,d as h,l as x}from"./chunk-HXIVVEZ6.js";import{d as c}from"./chunk-QTVIWU3N.js";import u,{createContext as _,useCallback as X,useContext as p,useEffect as g,useState as A}from"react";import{getUserSmartWallet as S,PrivyClientError as m}from"@privy-io/js-sdk-core";import{createPublicClient as F,http as L}from"viem";import{getJsonRpcEndpointFromChain as M,getUserSmartWallet as R,PrivyClientError as I}from"@privy-io/js-sdk-core";import{signerToSmartAccountClient as G}from"@privy-io/js-sdk-core/smart-wallets";var W=l=>c(void 0,[l],function*({chain:t,privyAppId:e,user:a,embeddedWallet:r,smartWalletsConfig:n,client:o}){if(!(n!=null&&n.enabled)||!r||!E(r))return;let f=yield o.embeddedWallet.getProvider(r.account),i=n==null?void 0:n.configured_networks.find($=>$.chain_id===`eip155:${t.id}`);if(!i)throw new I({code:"chain_not_supported",error:`The chain ${t.name} (eip155:${t.id}) must be configured in the smart wallet configuration in your dashboard`});let s=R(a),y=s?s.smart_wallet_type:n.smart_wallet_type,w=s?s.smart_wallet_version:n.smart_wallet_version,N=M(t,{rpcUrls:[]},e),O=F({chain:t,transport:L(N)}),P=yield G({owner:f,smartWalletType:y,smartWalletVersion:w,chain:t,publicClient:O,paymasterContext:j(i.paymaster_url,i.paymaster_context),bundlerUrl:i.bundler_url,paymasterUrl:i.paymaster_url});if(!P)throw new I({code:"smart_wallet_client_error",error:`Failed to create smart wallet client for chain ${t.name} (eip155:${t.id})`});return P}),B=/paymaster\.biconomy\.io\/api/i;function D(t){return B.test(t)}var Y={mode:"SPONSORED",calculateGasLimits:!0,expiryDuration:300,sponsorshipInfo:{webhookData:{},smartAccountInfo:{name:"BICONOMY",version:"2.0.0"}}},j=(t,e)=>{if(t&&D(t))return Y;if(e&&e.policy_id)return{policyId:e.policy_id}};var J=({children:t})=>u.createElement(z,null,u.createElement(H,null,u.createElement(K,null,t))),T=_({config:void 0}),v=()=>{let{config:t}=p(T);return{config:t}},k=_({smartWalletClient:void 0}),V=()=>{let{smartWalletClient:t}=p(k);return{smartWalletClient:t}},U=_({client:void 0}),q=()=>{let{client:t}=p(U),e=Q();return{client:t,getClientForChain:e}},z=({children:t})=>{let[e,a]=A(void 0),r=x();return g(()=>{!e&&r&&(()=>c(void 0,null,function*(){try{if(!r){console.warn("No client found");return}let o=yield r.app.getSmartWalletConfig();a(o)}catch(o){console.warn("Error generating smart wallet config: ",o)}}))()},[r,e]),u.createElement(T.Provider,{value:{config:e}},t)},H=({children:t})=>{let{config:e}=v(),{client:a,wallet:r}=p(C),n=h(),[o,l]=A();return g(()=>{(()=>c(void 0,null,function*(){if(!n&&o&&l(void 0),!(e!=null&&e.enabled)||!n||r.status!=="connected"||n&&o&&r.status==="connected")return;let i=a.embeddedWallet.chains.find(y=>e.configured_networks.map(w=>w.chain_id).includes(`eip155:${y.id}`));if(!i)throw new m({error:"Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.",code:"chain_not_supported"});let s=yield W({chain:i,privyAppId:a.app.appId,user:n,embeddedWallet:r,smartWalletsConfig:e,client:a});if(!s)throw new m({error:"Could not create smart wallet client",code:"smart_wallet_client_error"});l(s)}))()},[!!(e!=null&&e.enabled),!!a,!!n,r.status]),u.createElement(k.Provider,{value:{smartWalletClient:o}},t)},K=({children:t})=>{let{client:e}=p(C),a=h(),{smartWalletClient:r}=V(),{config:n}=v();return g(()=>{(()=>c(void 0,null,function*(){if(!(!r||!a||S(a)||!(n!=null&&n.enabled)))try{let{message:l}=yield e.auth.smartWallet.init({address:r.account.address,chainId:`eip155:${r.chain.id}`}),d=yield r.signMessage({message:l});yield e.auth.smartWallet.link(l,d,n.smart_wallet_type,n.smart_wallet_version)}catch(l){console.error("Error creating smart wallet:",l)}}))()},[!!r,!!a,!!S(a),n]),u.createElement(U.Provider,{value:{client:S(a)?r:void 0}},t)},Q=()=>{let{client:t,wallet:e}=p(C),{config:a}=v();return X(n=>c(void 0,[n],function*({chainId:r}){let o=b();if(!o)throw new m({error:"Must be logged in to get a smart wallet client",code:"smart_wallet_client_error"});if(!a||!a.enabled)throw new m({error:"Must have smart wallets enabled to get a smart wallet client",code:"smart_wallet_client_error"});let d=t.embeddedWallet.chains.find(i=>i.id===r);if(!d)throw new m({error:`Could not find chain with id: ${r}`,code:"chain_not_supported"});let f=yield W({chain:d,privyAppId:t.app.appId,user:o,embeddedWallet:e,smartWalletsConfig:a,client:t});if(!f)throw new m({error:`Could not create smart wallet client for chain ${r}`,code:"smart_wallet_client_error"});return f}),[a,e,t])};export{J as SmartWalletsProvider,q as useSmartWallets};