@privy-io/expo 0.74.1 → 0.74.2

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,4 +1,4 @@
1
- import{b as _,c as M,e as l,f as ht,g as wt,h as ge}from"./chunk-K5SPDXVF.js";import{useEffect as Kr}from"react";import{create as Gr}from"zustand";var vt=Gr(()=>({status:"disconnected"})),he=()=>vt.getState().onNeedsRecovery,qr=e=>{Kr(()=>{vt.setState({onNeedsRecovery:e==null?void 0:e.onNeedsRecovery})},[e==null?void 0:e.onNeedsRecovery])};import{digest as Br,randomUUID as Jr}from"expo-crypto";import $r from"@privy-io/js-sdk-core";var bt={name:"@privy-io/expo",version:"0.74.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 *.tsbuildinfo","clean:reset":"rm -rf dist .turbo node_modules *.tsbuildinfo",dev:"tsup --watch",format:"oxlint src --fix","generate-types":"tsup --dts-only",lint:"oxlint src",test:"jest"},browserslist:["defaults","node >= 18","not op_mini all"],dependencies:{"@privy-io/api-types":"catalog:","@privy-io/are-addresses-equal":"workspace:*","@privy-io/encoding":"workspace:*","@privy-io/js-sdk-core":"workspace:*","@privy-io/routes":"workspace:*","@scure/base":"^1.2.4","react-fast-compare":"^3.2.2",tweetnacl:"catalog:",zustand:"catalog:"},devDependencies:{oxlint:"catalog:package-new","oxlint-tsgolint":"catalog:package-new","@privy-io/eslint-plugin-privy-rules":"workspace:*","@privy-io/tsconfig":"workspace:*","@simplewebauthn/types":"9.0.1","@solana/web3.js":"catalog:","@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":"catalog:","@types/jest":"catalog:","@types/react":"catalog:",expo:"56.0.9","expo-apple-authentication":"56.0.4","expo-application":"56.0.3","expo-clipboard":"56.0.3","expo-crypto":"56.0.4","expo-linking":"56.0.13","expo-secure-store":"56.0.4","expo-web-browser":"56.0.5",jest:"catalog:","jest-expo":"56.0.4","lucide-react-native":"^0.474.0",react:"catalog:","react-native":"0.85.3","react-native-webview":"13.16.1","react-test-renderer":"19.2.3",tsup:"^6.2.3",typescript:"catalog:"},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":"catalog:","react-native-qrcode-styled":"0.3.3","react-native-safe-area-context":"*","react-native-svg":"*","react-native-webview":"*",viem:"catalog:"},peerDependenciesMeta:{permissionless:{optional:!0},viem:{optional:!0},"react-native-svg":{optional:!0},"expo-apple-authentication":{optional:!0},"expo-clipboard":{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 St=({appId:e,clientId:t,storage:r=ge,supportedChains:o,baseUrl:n,logLevel:s,logger:i,sessions:c,plugins:d})=>{let a=c!=null&&c.mode?{mode:c.mode}:void 0;return new $r({appId:e,clientId:t,plugins:d,supportedChains:o,storage:wt(r),sdkVersion:`expo:${bt.version}`,nativeAppIdentifier:ht(),crypto:{digest:Br,randomUUID:Jr},baseUrl:n,logLevel:s,logger:i,sessions:a})};import{useCallback as ut,useContext as xs}from"react";import{PrivyClientError as As}from"@privy-io/js-sdk-core";import Z,{useState as L,useMemo as Cs,createContext as Es,useCallback as Me,useRef as pe,useEffect as Ir,useContext as _s}from"react";import{AppState as Or,View as ks}from"react-native";import{PrivyClientError as Lr}from"@privy-io/js-sdk-core";import Qr from"react-fast-compare";import{create as Yr}from"zustand";var we=Yr(()=>{}),Ct=e=>we.setState(t=>Qr(t,e)?t:e),A=we.getState;import eo from"react";import{useCallback as Se,useEffect as to,useRef as ro,useState as oo}from"react";import{AppState as no}from"react-native";import io from"react-native-webview";import*as T from"expo-secure-store";function Et(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 _t(e){return l(this,null,function*(){switch(e.event){case"app:secure-storage:get":{let{key:t}=e.data,r=yield T.getItemAsync(Ne(t),{keychainAccessible:T.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).catch(o=>(console.warn("Failed to get the value from secure store",o),null));return{event:e.event,id:e.id,data:{value:r}}}case"app:secure-storage:remove":{let{key:t}=e.data,r=yield T.deleteItemAsync(Ne(t),{keychainAccessible:T.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(o=>(console.warn("Failed to remove the value from secure store",o),!1));return{event:e.event,id:e.id,data:{success:r}}}case"app:secure-storage:set":{let{key:t,value:r}=e.data,o=yield T.setItemAsync(Ne(t),r,{keychainAccessible:T.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(n=>(console.warn("Failed to write the value to secure store",n),!1));return{event:e.event,id:e.id,data:{success:o}}}}})}var Ne=e=>e.replaceAll(":","-");import Xr from"react-fast-compare";import{createStore as Zr,useStore as ve}from"zustand";var D=Zr()(()=>({user:null,storedUsers:[],proxyStatus:"loading"}));function b(){return D.getState().user}var qs=D.subscribe.bind(D);function ze(e){D.setState(({user:t})=>Xr(t,e)?{}:{user:e})}var kt=e=>D.setState({storedUsers:e.users}),be=e=>D.setState({proxyStatus:e});function U(){return ve(D,e=>e.user)}function Hs(){return ve(D,e=>!!e.user)}function Wt(){return ve(D,e=>e.storedUsers)}function j(){return ve(D,e=>e.proxyStatus!=="loading")}var so={shouldUseAppBackedStorage:!0},ao=";",xt=({client:e,isClientReady:t})=>{let r=ro(null),[o,n]=oo(0);to(()=>{let a=no.addEventListener("change",u=>l(void 0,null,function*(){u==="background"?e.embeddedWallet.onBackground():u==="active"&&((yield e.embeddedWallet.ping(500))||(be("reloading"),e.embeddedWallet.reload()))}));return()=>a.remove()},[e]);let s=Se(a=>l(void 0,null,function*(){var m;let{data:u}=a.nativeEvent,p=JSON.parse(u);if(Et(p)){let h=yield _t(p);(m=r.current)==null||m.postMessage(JSON.stringify(h));return}e.embeddedWallet.onMessage(p)}),[e]),i=Se(a=>{e.logger.info(`[privy:webview] process error, ${a}`),be("reloading"),e.embeddedWallet.reload(),n(u=>u+1)},[e]),c=Se(()=>{i("content process terminated")},[i]),d=Se(()=>{i("render process gone")},[i]);return t?eo.createElement(io,{key:o,style:{flex:1},ref:a=>{a&&(e.setMessagePoster(a),r.current=a)},cacheEnabled:!1,cacheMode:"LOAD_NO_CACHE",injectedJavaScriptObject:so,injectedJavaScriptBeforeContentLoaded:ao,source:{uri:e.embeddedWallet.getURL()},webviewDebuggingEnabled:e.logger.level==="DEBUG",onLoad:()=>be("loaded"),onError:console.error,onMessage:s,onContentProcessDidTerminate:c,onRenderProcessGone:d}):null};import{useCallback as je,useEffect as Rt,useMemo as Ve}from"react";import{errorIndicatesRecoveryIsNeeded as lo,getAllUserEmbeddedSolanaWallets as uo,getEntropyDetailsFromUser as It,PrivyClientError as re}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedSolanaWallets as Ce,getEntropyDetailsFromAccount as At,getUserEmbeddedEthereumWallet as co,PrivyClientError as q}from"@privy-io/js-sdk-core";function Pt(s){return l(this,arguments,function*({client:e,setSolanaWallet:t,createSolanaWalletCallbacks:r,setSolanaRecoveryFlowState:o,opts:n}){var i,c,d;t({status:"creating"});try{let{user:a}=yield e.user.get(),u=Ce(a),p=u[0],m=(i=co(a))!=null?i:void 0;if(n!=null&&n.recoveryMethod&&n.recoveryMethod!=="privy")throw new q({code:"embedded_wallet_creation_error",error:"Unsupported recovery method for solana wallet."});if(!(n!=null&&n.createAdditional)&&p)throw new q({code:"embedded_wallet_creation_error",error:"Solana wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let h,g;if(p){let f=m!=null?m:p,{entropyId:w,entropyIdVerifier:S}=At(f),E=Math.max(...u.map(P=>P.wallet_index),0)+1,k=yield e.embeddedWallet.add({chainType:"solana",entropyId:w,entropyIdVerifier:S,hdWalletIndex:E}),x=Ce(k.user).find(P=>P.wallet_index===E);if(!x)throw new q({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});h=yield e.embeddedWallet.getSolanaProvider(x,w,S),g=k.user}else{let f=yield e.embeddedWallet.createSolana({ethereumAccount:m}),w=Ce(f.user).find(x=>x.wallet_index===0);if(!w)throw new q({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let S=m!=null?m:w,{entropyId:E,entropyIdVerifier:k}=At(S);h=yield e.embeddedWallet.getSolanaProvider(w,E,k),g=f.user}let v=Ce(g)[0];if(!v)throw new q({code:"embedded_wallet_creation_error",error:"Unknown error creating solana wallet"});return(d=(c=r.current)==null?void 0:c.onSuccess)==null||d.call(c,h),t({status:"connected",publicKey:v.public_key}),o({status:"initial"}),h}catch(a){let u=a instanceof Error?a.message:"Error creating embedded wallet";throw t({status:"error",error:u}),o({status:"initial"}),new q({code:"embedded_wallet_creation_error",error:u})}})}import{PrivyClientError as K}from"@privy-io/js-sdk-core";function Ee(u){return l(this,arguments,function*({client:e,account:t,setWallet:r,recoverWalletCallbacks:o,recoveryMethod:n,setRecoveryFlowState:s,password:i,recoveryKey:c,recoveryToken:d,recoverySecretOverride:a}){var p,m,h,g;if(!t)throw new K({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});switch(n){case"user-passcode":if(!i)throw new K({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"google-drive":if(!d)throw new K({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!a)throw new K({code:"embedded_wallet_recovery_error",error:"Record name is required for icloud recovery method"});break;case"recovery-encryption-key":if(!c)throw new K({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,i,d,a,c);return r({status:"connected",provider:v,account:t}),s({status:"initial"}),(m=(p=o.current)==null?void 0:p.onSuccess)==null||m.call(p,v),v}catch(v){r({status:"needs-recovery",account:t}),s({status:"initial"});let f=new K({code:"embedded_wallet_recovery_error",error:v instanceof Error?v.message:"Error recovering embedded wallet"});throw(g=(h=o.current)==null?void 0:h.onError)==null||g.call(h,f),f}})}function Ut(c){return l(this,arguments,function*({client:e,account:t,entropyId:r,entropyIdVerifier:o,setSolanaWallet:n,recoverSolanaWalletCallbacks:s,setSolanaRecoveryFlowState:i}){var d,a,u,p;n({status:"connecting"});try{let m=yield e.embeddedWallet.getSolanaProvider(t,r,o);return n({status:"connected",publicKey:m._publicKey}),i({status:"initial"}),(a=(d=s.current)==null?void 0:d.onSuccess)==null||a.call(d,m),m}catch(m){n({status:"needs-recovery"}),i({status:"initial"});let h=new K({code:"embedded_wallet_recovery_error",error:m instanceof Error?m.message:"Error recovering embedded wallet"});throw(p=(u=s.current)==null?void 0:u.onError)==null||p.call(u,h),h}})}var Ot=({client:e,solanaWallet:t,setSolanaWallet:r,setSolanaRecoveryFlowState:o,createSolanaWalletCallbacks:n,recoverSolanaWalletCallbacks:s})=>{let i=U(),c=Ve(()=>uo(i),[i]),d=j(),a=Ve(()=>c.length===0?null:It(i),[i,c]),u=Ve(()=>{let g=c.map(S=>{let E=It(i,S);return E?{account:S,entropy:E}:null});if(g.some(S=>S===null))return[];let v=void 0,f=void 0,w=void 0;return g.filter(S=>S!==null).map(({account:S,entropy:{entropyId:E,entropyIdVerifier:k}})=>({address:S.address,publicKey:S.address,walletIndex:S.wallet_index,getProvider:()=>e.embeddedWallet.getSolanaProvider(S,E,k,v,f,w,x=>l(void 0,null,function*(){var P;yield(P=he())==null?void 0:P(x)}))}))},[c,i,e]),p=je(g=>l(void 0,null,function*(){return yield Pt({client:e,setSolanaWallet:r,createSolanaWalletCallbacks:n,setSolanaRecoveryFlowState:o,opts:g})}),[e,n]),m=je(()=>l(void 0,null,function*(){if(!a)throw new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{entropyId:g,entropyIdVerifier:v}=a;return Ut({client:e,account:c[0],entropyId:g,entropyIdVerifier:v,setSolanaWallet:r,recoverSolanaWalletCallbacks:s,setSolanaRecoveryFlowState:o})}),[e,a,c,s,o,r]),h=je(()=>l(void 0,null,function*(){if(!a)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}=a,f=yield e.embeddedWallet.getSolanaProvider(c[0],g,v);return r({status:"connected",publicKey:c[0].public_key}),f}catch(g){throw lo(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"}))}}),[c,e,a,r]);return Rt(()=>{if(!i&&t.status!=="disconnected")return r({status:"disconnected"});d&&h().catch(()=>{})},[d,i]),Rt(()=>{t.status==="error"&&t.error.includes("User must be logged in")&&h()},[t.status]),{create:p,recover:m,getProvider:h,wallets:u}};import{useCallback as ie,useEffect as Nt,useMemo as Co}from"react";import{getUserEmbeddedEthereumWallet as Eo,getUserEmbeddedSolanaWallet as zt,isUnifiedWallet as _o,throwIfInvalidRecoveryUpgradePath as ko}from"@privy-io/js-sdk-core";import{errorIndicatesRecoveryIsNeeded as Wo,PrivyClientError as R}from"@privy-io/js-sdk-core";import{getUserEmbeddedEthereumWallet as po}from"@privy-io/js-sdk-core";import{PrivyClientError as H}from"@privy-io/js-sdk-core";function _e(p){return l(this,arguments,function*({client:e,setWallet:t,createWalletCallbacks:r,recoveryMethod:o,setRecoveryFlowState:n,password:s,recoveryKey:i,recoveryToken:c,recoverySecretOverride:d,iCloudRecordNameOverride:a,solanaAccount:u}){var h,g;switch(o){case"user-passcode":if(!s)throw new H({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"recovery-encryption-key":if(!i)throw new H({code:"embedded_wallet_recovery_error",error:"key is required for recovery-encryption-key recovery method"});break;case"google-drive":if(!c)throw new H({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!d||!a)throw new H({code:"embedded_wallet_recovery_error",error:"iCloud recovery failed due to inability to store credentials"});break}t({status:"creating",account:null});let m=o==="icloud"?"icloud-native":o;try{let{user:v}=yield e.embeddedWallet.create({password:s,recoveryMethod:m,recoveryKey:i,recoveryToken:c,recoverySecretOverride:d,iCloudRecordNameOverride:a,solanaAccount:u}),f=po(v);if(!f)throw new H({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let w=yield e.embeddedWallet.getProvider(f);return(g=(h=r.current)==null?void 0:h.onSuccess)==null||g.call(h,w),t({status:"connected",provider:w,account:f}),n({status:"initial"}),w}catch(v){let f=v instanceof Error?v.message:"Error creating embedded wallet";throw t({status:"error",error:f,account:null}),n({status:"initial"}),new H({code:"embedded_wallet_creation_error",error:f})}})}import{Platform as Mt}from"react-native";import{PrivyClientError as N}from"@privy-io/js-sdk-core";import{Platform as mo}from"react-native";var Lt=new Set;function ke(e,{isDevelopment:t=__DEV__,reactNativeVersion:r=mo.constants.reactNativeVersion,warn:o=n=>console.warn(n)}={}){if(!t||Lt.has(e))return;let{major:n,minor:s,patch:i}=r;if(n>0||n===0&&s>=81)return;let d=`[Privy] Upcoming optional dependency change
1
+ import{b as _,c as M,e as l,f as ht,g as wt,h as ge}from"./chunk-K5SPDXVF.js";import{useEffect as Vr}from"react";import{create as Kr}from"zustand";var vt=Kr(()=>({status:"disconnected"})),he=()=>vt.getState().onNeedsRecovery,Gr=e=>{Vr(()=>{vt.setState({onNeedsRecovery:e==null?void 0:e.onNeedsRecovery})},[e==null?void 0:e.onNeedsRecovery])};import{digest as Br,randomUUID as Hr}from"expo-crypto";import Jr from"@privy-io/js-sdk-core";var bt={name:"@privy-io/expo",version:"0.74.2",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 *.tsbuildinfo","clean:reset":"rm -rf dist .turbo node_modules *.tsbuildinfo",dev:"tsup --watch",format:"oxlint src --fix","generate-types":"tsup --dts-only",lint:"oxlint src",test:"jest"},browserslist:["defaults","node >= 18","not op_mini all"],dependencies:{"@privy-io/api-types":"catalog:","@privy-io/are-addresses-equal":"workspace:*","@privy-io/encoding":"workspace:*","@privy-io/js-sdk-core":"workspace:*","@privy-io/routes":"workspace:*","@scure/base":"^1.2.4","react-fast-compare":"^3.2.2",tweetnacl:"catalog:",zustand:"catalog:"},devDependencies:{oxlint:"catalog:package-new","oxlint-tsgolint":"catalog:package-new","@privy-io/eslint-plugin-privy-rules":"workspace:*","@privy-io/tsconfig":"workspace:*","@simplewebauthn/types":"9.0.1","@solana/web3.js":"catalog:","@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":"catalog:","@types/jest":"catalog:","@types/react":"catalog:",expo:"56.0.9","expo-apple-authentication":"56.0.4","expo-application":"56.0.3","expo-clipboard":"56.0.3","expo-crypto":"56.0.4","expo-linking":"56.0.13","expo-secure-store":"56.0.4","expo-web-browser":"56.0.5",jest:"catalog:","jest-expo":"56.0.4","lucide-react-native":"^0.474.0",react:"catalog:","react-native":"0.85.3","react-native-webview":"13.16.1","react-test-renderer":"19.2.3",tsup:"^6.2.3",typescript:"catalog:"},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":"catalog:","react-native-qrcode-styled":"0.3.3","react-native-safe-area-context":"*","react-native-svg":"*","react-native-webview":"*",viem:"catalog:"},peerDependenciesMeta:{permissionless:{optional:!0},viem:{optional:!0},"react-native-svg":{optional:!0},"expo-apple-authentication":{optional:!0},"expo-clipboard":{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 St=({appId:e,clientId:t,storage:r=ge,supportedChains:o,baseUrl:n,logLevel:s,logger:i,sessions:c,plugins:d})=>{let a=c!=null&&c.mode?{mode:c.mode}:void 0;return new Jr({appId:e,clientId:t,plugins:d,supportedChains:o,storage:wt(r),sdkVersion:`expo:${bt.version}`,nativeAppIdentifier:ht(),crypto:{digest:Br,randomUUID:Hr},baseUrl:n,logLevel:s,logger:i,sessions:a})};import{useCallback as ut,useContext as xs}from"react";import{PrivyClientError as Ps}from"@privy-io/js-sdk-core";import Z,{useState as L,useMemo as Es,createContext as _s,useCallback as Fe,useRef as pe,useEffect as Rr,useContext as ks}from"react";import{AppState as Ir,View as Ws}from"react-native";import{PrivyClientError as Or}from"@privy-io/js-sdk-core";import $r from"react-fast-compare";import{create as Qr}from"zustand";var we=Qr(()=>{}),Ct=e=>we.setState(t=>$r(t,e)?t:e),x=we.getState;import Zr from"react";import{useCallback as Se,useEffect as eo,useRef as to,useState as ro}from"react";import{AppState as oo}from"react-native";import no from"react-native-webview";import*as T from"expo-secure-store";function Et(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 _t(e){return l(this,null,function*(){switch(e.event){case"app:secure-storage:get":{let{key:t}=e.data,r=yield T.getItemAsync(ze(t),{keychainAccessible:T.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).catch(o=>(console.warn("Failed to get the value from secure store",o),null));return{event:e.event,id:e.id,data:{value:r}}}case"app:secure-storage:remove":{let{key:t}=e.data,r=yield T.deleteItemAsync(ze(t),{keychainAccessible:T.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(o=>(console.warn("Failed to remove the value from secure store",o),!1));return{event:e.event,id:e.id,data:{success:r}}}case"app:secure-storage:set":{let{key:t,value:r}=e.data,o=yield T.setItemAsync(ze(t),r,{keychainAccessible:T.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY}).then(()=>!0).catch(n=>(console.warn("Failed to write the value to secure store",n),!1));return{event:e.event,id:e.id,data:{success:o}}}}})}var ze=e=>e.replaceAll(":","-");import Yr from"react-fast-compare";import{createStore as Xr,useStore as ve}from"zustand";var D=Xr()(()=>({user:null,storedUsers:[],proxyStatus:"loading"}));function b(){return D.getState().user}var Bs=D.subscribe.bind(D);function je(e){D.setState(({user:t})=>Yr(t,e)?{}:{user:e})}var kt=e=>D.setState({storedUsers:e.users}),be=e=>D.setState({proxyStatus:e});function U(){return ve(D,e=>e.user)}function Hs(){return ve(D,e=>!!e.user)}function Wt(){return ve(D,e=>e.storedUsers)}function j(){return ve(D,e=>e.proxyStatus!=="loading")}var io={shouldUseAppBackedStorage:!0},so=";",ao=500,At=({client:e,isClientReady:t})=>{let r=to(null),[o,n]=ro(0);eo(()=>{let a=oo.addEventListener("change",u=>l(void 0,null,function*(){u==="background"?e.embeddedWallet.onBackground():u==="active"&&((yield e.embeddedWallet.ping(ao))||(be("reloading"),e.embeddedWallet.reload()))}));return()=>a.remove()},[e]);let s=Se(a=>l(void 0,null,function*(){var m;let{data:u}=a.nativeEvent,p=JSON.parse(u);if(Et(p)){let g=yield _t(p);(m=r.current)==null||m.postMessage(JSON.stringify(g));return}e.embeddedWallet.onMessage(p)}),[e]),i=Se(a=>{e.logger.info(`[privy:webview] process error, ${a}`),be("reloading"),e.embeddedWallet.reload(),n(u=>u+1)},[e]),c=Se(()=>{i("content process terminated")},[i]),d=Se(()=>{i("render process gone")},[i]);return t?Zr.createElement(no,{key:o,style:{flex:1},ref:a=>{a&&(e.setMessagePoster(a),r.current=a)},cacheEnabled:!1,cacheMode:"LOAD_NO_CACHE",injectedJavaScriptObject:io,injectedJavaScriptBeforeContentLoaded:so,source:{uri:e.embeddedWallet.getURL()},webviewDebuggingEnabled:e.logger.level==="DEBUG",onLoad:()=>be("loaded"),onError:console.error,onMessage:s,onContentProcessDidTerminate:c,onRenderProcessGone:d}):null};import{useCallback as Ve,useEffect as Rt,useMemo as Ke}from"react";import{errorIndicatesRecoveryIsNeeded as lo,getAllUserEmbeddedSolanaWallets as uo,getEntropyDetailsFromUser as It,PrivyClientError as re}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedSolanaWallets as Ce,getEntropyDetailsFromAccount as xt,getUserEmbeddedEthereumWallet as co,PrivyClientError as q}from"@privy-io/js-sdk-core";function Pt(s){return l(this,arguments,function*({client:e,setSolanaWallet:t,createSolanaWalletCallbacks:r,setSolanaRecoveryFlowState:o,opts:n}){var i,c,d;t({status:"creating"});try{let{user:a}=yield e.user.get(),u=Ce(a),p=u[0],m=(i=co(a))!=null?i:void 0;if(n!=null&&n.recoveryMethod&&n.recoveryMethod!=="privy")throw new q({code:"embedded_wallet_creation_error",error:"Unsupported recovery method for solana wallet."});if(!(n!=null&&n.createAdditional)&&p)throw new q({code:"embedded_wallet_creation_error",error:"Solana wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let g,h;if(p){let f=m!=null?m:p,{entropyId:w,entropyIdVerifier:S}=xt(f),E=Math.max(...u.map(P=>P.wallet_index),0)+1,k=yield e.embeddedWallet.add({chainType:"solana",entropyId:w,entropyIdVerifier:S,hdWalletIndex:E}),A=Ce(k.user).find(P=>P.wallet_index===E);if(!A)throw new q({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});g=yield e.embeddedWallet.getSolanaProvider(A,w,S),h=k.user}else{let f=yield e.embeddedWallet.createSolana({ethereumAccount:m}),w=Ce(f.user).find(A=>A.wallet_index===0);if(!w)throw new q({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let S=m!=null?m:w,{entropyId:E,entropyIdVerifier:k}=xt(S);g=yield e.embeddedWallet.getSolanaProvider(w,E,k),h=f.user}let v=Ce(h)[0];if(!v)throw new q({code:"embedded_wallet_creation_error",error:"Unknown error creating solana wallet"});return(d=(c=r.current)==null?void 0:c.onSuccess)==null||d.call(c,g),t({status:"connected",publicKey:v.public_key}),o({status:"initial"}),g}catch(a){let u=a instanceof Error?a.message:"Error creating embedded wallet";throw t({status:"error",error:u}),o({status:"initial"}),new q({code:"embedded_wallet_creation_error",error:u})}})}import{PrivyClientError as K}from"@privy-io/js-sdk-core";function Ee(u){return l(this,arguments,function*({client:e,account:t,setWallet:r,recoverWalletCallbacks:o,recoveryMethod:n,setRecoveryFlowState:s,password:i,recoveryKey:c,recoveryToken:d,recoverySecretOverride:a}){var p,m,g,h;if(!t)throw new K({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});switch(n){case"user-passcode":if(!i)throw new K({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"google-drive":if(!d)throw new K({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!a)throw new K({code:"embedded_wallet_recovery_error",error:"Record name is required for icloud recovery method"});break;case"recovery-encryption-key":if(!c)throw new K({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,i,d,a,c);return r({status:"connected",provider:v,account:t}),s({status:"initial"}),(m=(p=o.current)==null?void 0:p.onSuccess)==null||m.call(p,v),v}catch(v){r({status:"needs-recovery",account:t}),s({status:"initial"});let f=new K({code:"embedded_wallet_recovery_error",error:v instanceof Error?v.message:"Error recovering embedded wallet"});throw(h=(g=o.current)==null?void 0:g.onError)==null||h.call(g,f),f}})}function Ut(c){return l(this,arguments,function*({client:e,account:t,entropyId:r,entropyIdVerifier:o,setSolanaWallet:n,recoverSolanaWalletCallbacks:s,setSolanaRecoveryFlowState:i}){var d,a,u,p;n({status:"connecting"});try{let m=yield e.embeddedWallet.getSolanaProvider(t,r,o);return n({status:"connected",publicKey:m._publicKey}),i({status:"initial"}),(a=(d=s.current)==null?void 0:d.onSuccess)==null||a.call(d,m),m}catch(m){n({status:"needs-recovery"}),i({status:"initial"});let g=new K({code:"embedded_wallet_recovery_error",error:m instanceof Error?m.message:"Error recovering embedded wallet"});throw(p=(u=s.current)==null?void 0:u.onError)==null||p.call(u,g),g}})}var Ot=({client:e,solanaWallet:t,setSolanaWallet:r,setSolanaRecoveryFlowState:o,createSolanaWalletCallbacks:n,recoverSolanaWalletCallbacks:s})=>{let i=U(),c=Ke(()=>uo(i),[i]),d=j(),a=Ke(()=>c.length===0?null:It(i,c[0]),[i,c]),u=Ke(()=>{let h=c.map(S=>{let E=It(i,S);return E?{account:S,entropy:E}:null});if(h.some(S=>S===null))return[];let v=void 0,f=void 0,w=void 0;return h.filter(S=>S!==null).map(({account:S,entropy:{entropyId:E,entropyIdVerifier:k}})=>({address:S.address,publicKey:S.address,walletIndex:S.wallet_index,getProvider:()=>e.embeddedWallet.getSolanaProvider(S,E,k,v,f,w,A=>l(void 0,null,function*(){var P;yield(P=he())==null?void 0:P(A)}))}))},[c,i,e]),p=Ve(h=>l(void 0,null,function*(){return yield Pt({client:e,setSolanaWallet:r,createSolanaWalletCallbacks:n,setSolanaRecoveryFlowState:o,opts:h})}),[e,n]),m=Ve(()=>l(void 0,null,function*(){if(!a)throw new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{entropyId:h,entropyIdVerifier:v}=a;return Ut({client:e,account:c[0],entropyId:h,entropyIdVerifier:v,setSolanaWallet:r,recoverSolanaWalletCallbacks:s,setSolanaRecoveryFlowState:o})}),[e,a,c,s,o,r]),g=Ve(()=>l(void 0,null,function*(){if(!a)throw r({status:"not-created"}),new re({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});r(h=>h.status==="connected"?{status:"reconnecting"}:{status:"connecting"});try{let{entropyId:h,entropyIdVerifier:v}=a,f=yield e.embeddedWallet.getSolanaProvider(c[0],h,v);return r({status:"connected",publicKey:c[0].public_key}),f}catch(h){throw lo(h)?(r({status:"needs-recovery"}),new re({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):h instanceof Error?(r({status:"error",error:h.message}),new re({code:"unknown_embedded_wallet_error",error:h.message})):(r({status:"error",error:"Error loading embedded wallet"}),new re({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[c,e,a,r]);return Rt(()=>{if(!i&&t.status!=="disconnected")return r({status:"disconnected"});d&&g().catch(()=>{})},[d,i]),Rt(()=>{t.status==="error"&&t.error.includes("User must be logged in")&&g()},[t.status]),{create:p,recover:m,getProvider:g,wallets:u}};import{useCallback as ie,useEffect as Nt,useMemo as Co}from"react";import{getUserEmbeddedEthereumWallet as Eo,getUserEmbeddedSolanaWallet as zt,isUnifiedWallet as _o,throwIfInvalidRecoveryUpgradePath as ko}from"@privy-io/js-sdk-core";import{errorIndicatesRecoveryIsNeeded as Wo,PrivyClientError as R}from"@privy-io/js-sdk-core";import{getUserEmbeddedEthereumWallet as po}from"@privy-io/js-sdk-core";import{PrivyClientError as B}from"@privy-io/js-sdk-core";function _e(p){return l(this,arguments,function*({client:e,setWallet:t,createWalletCallbacks:r,recoveryMethod:o,setRecoveryFlowState:n,password:s,recoveryKey:i,recoveryToken:c,recoverySecretOverride:d,iCloudRecordNameOverride:a,solanaAccount:u}){var g,h;switch(o){case"user-passcode":if(!s)throw new B({code:"embedded_wallet_recovery_error",error:"password is required for user-passcode recovery method"});break;case"recovery-encryption-key":if(!i)throw new B({code:"embedded_wallet_recovery_error",error:"key is required for recovery-encryption-key recovery method"});break;case"google-drive":if(!c)throw new B({code:"embedded_wallet_recovery_error",error:"Recovery token is required for google-drive recovery method"});break;case"icloud":if(!d||!a)throw new B({code:"embedded_wallet_recovery_error",error:"iCloud recovery failed due to inability to store credentials"});break}t({status:"creating",account:null});let m=o==="icloud"?"icloud-native":o;try{let{user:v}=yield e.embeddedWallet.create({password:s,recoveryMethod:m,recoveryKey:i,recoveryToken:c,recoverySecretOverride:d,iCloudRecordNameOverride:a,solanaAccount:u}),f=po(v);if(!f)throw new B({error:"Embedded wallet account not created",code:"embedded_wallet_creation_error"});let w=yield e.embeddedWallet.getProvider(f);return(h=(g=r.current)==null?void 0:g.onSuccess)==null||h.call(g,w),t({status:"connected",provider:w,account:f}),n({status:"initial"}),w}catch(v){let f=v instanceof Error?v.message:"Error creating embedded wallet";throw t({status:"error",error:f,account:null}),n({status:"initial"}),new B({code:"embedded_wallet_creation_error",error:f})}})}import{Platform as Mt}from"react-native";import{PrivyClientError as N}from"@privy-io/js-sdk-core";import{Platform as mo}from"react-native";var Lt=new Set;function ke(e,{isDevelopment:t=__DEV__,reactNativeVersion:r=mo.constants.reactNativeVersion,warn:o=n=>console.warn(n)}={}){if(!t||Lt.has(e))return;let{major:n,minor:s,patch:i}=r;if(n>0||n===0&&s>=81)return;let d=`[Privy] Upcoming optional dependency change
2
2
 
3
3
  This app uses React Native ${`${n}.${s}.${i}`}. A future @privy-io/expo release will make ${e} optional.
4
4
 
@@ -9,4 +9,4 @@ Check Metro with:
9
9
  npm ls metro metro-config metro-runtime
10
10
  yarn why metro
11
11
 
12
- If these requirements cannot be met, keep ${e} installed.`:d+`Expo SDK 52 and React Native 0.78 or earlier cannot safely omit ${e}. Upgrade to Expo SDK 54 or React Native 0.81, or keep ${e} installed.`;Lt.add(e),o(a)}function Ft(){return l(this,null,function*(){ke("@privy-io/expo-native-extensions");try{return yield import("@privy-io/expo-native-extensions")}catch(e){throw new N({code:"configuration_error",error:"`@privy-io/expo-native-extensions` is not installed. Install it and rebuild the native app."})}})}function oe(o){return l(this,arguments,function*({user:e,appId:t,client:r}){var c;if(Mt.OS==="android")throw new N({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let n=yield Ft(),s=yield r.recovery.icloudAuth.getICloudConfiguration("expo-ios");if(!(s==null?void 0:s.container_identifier))throw new N({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:d,iCloudRecordName:a}=yield n.writeRecoverySecretToICloud({containerId:s.container_identifier,appId:t,userId:e.id});return{recoverySecret:d,iCloudRecordName:a}}catch(d){if(d instanceof Error){let a=(c=d.message.split("Caused by: ")[1])!=null?c:"Error writing to iCloud";throw new N({code:"embedded_wallet_recovery_error",error:a})}throw new N({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}function We(o){return l(this,arguments,function*({walletAddress:e,client:t,chainType:r}){var a;if(Mt.OS==="android")throw new N({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let n=yield Ft(),i=(yield t.recovery.getRecoveryKeyMaterial(e,r)).icloud_record_name;if(!i)throw new N({code:"embedded_wallet_recovery_error",error:"iCloud recovery not properly backed up."});let c=yield t.recovery.icloudAuth.getICloudConfiguration("expo-ios"),d=c==null?void 0:c.container_identifier;if(!d)throw new N({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:u}=yield n.readRecoverySecretFromICloud({containerId:d,recordName:i});return{recoverySecret:u}}catch(u){if(u instanceof Error){let p=(a=u.message.split("Caused by: ")[1])!=null?a:"Error writing to iCloud";throw new N({code:"embedded_wallet_recovery_error",error:p})}throw new N({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}import*as G from"expo-linking";import*as Tt from"expo-web-browser";import{Platform as Dt}from"react-native";import{PrivyClientError as J}from"@privy-io/js-sdk-core";import Aa from"react-fast-compare";import{PrivyApiError as yo,PrivyClientError as fo}from"@privy-io/js-sdk-core";function C(e){return e instanceof Error||e instanceof yo||e instanceof fo?e:typeof e=="string"?new Error(e):new Error("Unknown error")}var B=e=>new Promise(t=>setTimeout(t,e));import{useEffect as go,useRef as ho}from"react";import{AppState as Ke}from"react-native";function xe(){let e=ho(Ke.currentState);go(()=>Ke.addEventListener("change",o=>{e.current=o}).remove,[]);function t(){return Ke.currentState}return{appState:e,getCurrentAppState:t}}function ne(n){return l(this,arguments,function*({provider:e,redirectUri:t,client:r,onError:o}){try{let s;switch(e){case"google-drive":{let{url:a}=yield r.recovery.auth.generateURL(G.createURL(t||"/"));s=a;break}default:throw new J({error:"OAuth invalid provider",code:"embedded_wallet_recovery_error"})}let i=yield Tt.openAuthSessionAsync(s);if(Dt.OS==="android")return;if(i.type!=="success")throw new J({error:"Recovery OAuth session failed",code:"embedded_wallet_recovery_error"});let{queryParams:c}=G.parse(i.url),d;switch(e){case"google-drive":{let{privy_oauth_state:a,privy_oauth_code:u}=c;if(!u||!a)throw new J({error:"Recovery OAuth invalid credentials",code:"embedded_wallet_recovery_error"});d=yield Ae({oAuthCode:u,oAuthState:a,client:r});break}default:throw new J({error:"Recovery OAuth invalid provider",code:"embedded_wallet_recovery_error"})}return d}catch(s){throw o==null||o(C(s)),s}})}function Ae(o){return l(this,arguments,function*({oAuthCode:e,oAuthState:t,client:r}){let{access_token:n}=yield r.recovery.auth.authorize(e,t);if(!n)throw new J({error:"OAuth invalid credentials",code:"login_with_oauth_returned_with_invalid_credentials"});return n})}var wo=2*60*1e3;function vo(e){let t;return new Promise((r,o)=>{t=G.addEventListener("url",s=>l(this,[s],function*({url:n}){if(!n)return;let{queryParams:i}=G.parse(n),{privy_oauth_state:c,privy_oauth_code:d}=i!=null?i:{};if(typeof d!="string"||typeof c!="string")return;let a=yield Ae({client:e,oAuthCode:d,oAuthState:c});r(a)})),setTimeout(()=>{o(new J({code:"embedded_wallet_set_recovery_error",error:"Failed to complete Google Drive recovery flow"}))},wo)}).finally(()=>{t==null||t.remove()})}function Pe(e){return l(this,null,function*(){let t;Dt.OS==="android"&&(t=vo(e));let r=yield ne({provider:"google-drive",client:e});return r!=null?r:yield t})}import{getUserEmbeddedWallet as bo,PrivyClientError as So}from"@privy-io/js-sdk-core";function Ue(s){return l(this,arguments,function*({client:e,recoveryInput:t,setWalletRecoveryCallbacks:r,setRecoveryFlowState:o,setWallet:n}){var i,c,d,a;try{let{provider:u,user:p}=yield e.embeddedWallet.setRecovery(t),m=u,h=bo(p);return n({status:"connected",provider:m,account:h}),(c=(i=r.current)==null?void 0:i.onSuccess)==null||c.call(i,m),o({status:"initial"}),m}catch(u){let p=new So({code:"embedded_wallet_set_recovery_error",error:u instanceof Error?u.message:"Error setting password on embedded wallet"});throw(a=(d=r.current)==null?void 0:d.onError)==null||a.call(d,p),o({status:"initial"}),p}})}function jt(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 Vt=({client:e,appId:t,wallet:r,setWallet:o,setRecoveryFlowState:n,createWalletCallbacks:s,recoverWalletCallbacks:i,setWalletRecoveryCallbacks:c})=>{let d=U(),a=Co(()=>Eo(d),[d]),u=j(),p=ie(f=>l(void 0,null,function*(){var me,ye;if(a)throw new R({error:"This user already has an embedded wallet",code:"embedded_wallet_already_exists"});let{user:w}=yield e.user.get(),{password:S,recoveryMethod:E,recoveryKey:k}=jt(f),x,P,F;if(E==="google-drive"&&(x=yield ne({provider:E,client:e,onError:(me=s.current)==null?void 0:me.onError}),n({status:"creating-wallet"}),!x))return null;if(E==="icloud"){if(!w)throw new R({code:"embedded_wallet_recovery_error",error:"User must be loaded before creating a wallet with iCloud."});let{recoverySecret:Fe,iCloudRecordName:te}=yield oe({user:w,appId:t,client:e});P=Fe,F=te}return yield _e({client:e,setWallet:o,createWalletCallbacks:s,recoveryMethod:E,recoveryKey:k,setRecoveryFlowState:n,password:S,recoverySecretOverride:P,iCloudRecordNameOverride:F,solanaAccount:(ye=zt(w))!=null?ye:void 0})}),[e,a,d]),m=ie(f=>l(void 0,null,function*(){var E;if(r.status!=="connected")throw new R({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"});if(!a)throw new R({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(zt(d))throw new R({code:"embedded_wallet_set_recovery_error",error:"Cannot set user-controlled recovery for a user with an embedded Solana wallet."});if(_o(a))throw new R({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"});ko({currentRecoveryMethod:a.recovery_method,upgradeToRecoveryMethod:f.recoveryMethod});let w,S;switch(f.recoveryMethod){case"privy":S=M(_({},f),{wallet:a});break;case"user-passcode":S=M(_({},f),{wallet:a,password:f.password});break;case"google-drive":if(w=yield ne({provider:f.recoveryMethod,client:e,onError:(E=c.current)==null?void 0:E.onError}),n({status:"upgrading-recovery"}),!w)return null;S={recoveryMethod:"google-drive",wallet:a,recoveryAccessToken:w};break;case"icloud":if(!d)throw new R({code:"embedded_wallet_recovery_error",error:"User must be loaded before backing up to iCloud."});let{recoverySecret:k,iCloudRecordName:x}=yield oe({user:d,appId:t,client:e});S={recoveryMethod:"icloud-native",recoverySecretOverride:k,iCloudRecordNameOverride:x,wallet:a};break;default:throw new R({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}return Ue({client:e,recoveryInput:S,setWalletRecoveryCallbacks:c,setRecoveryFlowState:n,setWallet:o})}),[e,a,r.status,d]),h=ie(f=>l(void 0,null,function*(){return m({recoveryMethod:"user-passcode",password:f})}),[e,a,r.status]),g=ie(f=>l(void 0,null,function*(){var P;if(!a)throw new R({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{password:w,recoveryMethod:S,recoveryKey:E}=jt(f),k,x;if(S==="google-drive"&&(k=yield ne({provider:S,client:e,onError:(P=i.current)==null?void 0:P.onError}),n({status:"recovering"}),!k))return null;if(S==="icloud"){if(!d)throw new R({code:"embedded_wallet_recovery_error",error:"User must be loaded before recovering via iCloud."});let{recoverySecret:F}=yield We({client:e,walletAddress:a.address});x=F}return Ee({client:e,account:a,setWallet:o,recoverWalletCallbacks:i,recoveryMethod:S,setRecoveryFlowState:n,recoveryKey:E,password:w,recoveryToken:k,recoverySecretOverride:x})}),[e,a]),v=ie(()=>l(void 0,null,function*(){if(!a)throw o({status:"not-created",account:null}),new R({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});o(f=>f.status==="connected"?{status:"reconnecting",account:a}:{status:"connecting",account:a});try{let f=yield e.embeddedWallet.getProvider(a);return o({status:"connected",provider:f,account:a}),f}catch(f){throw Wo(f)?(o({status:"needs-recovery",account:a}),new R({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):f instanceof Error?(o({status:"error",error:f.message,account:a}),new R({code:"unknown_embedded_wallet_error",error:f.message})):(o({status:"error",error:"Error loading embedded wallet",account:a}),new R({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[e,a]);return Nt(()=>{if(!d&&r.status!=="disconnected")return o({status:"disconnected",account:null});u&&v().catch(()=>{})},[u,d,a]),Nt(()=>{r.status==="error"&&r.error.includes("User must be logged in")&&v()},[r.status]),{create:p,recover:g,setPassword:h,setRecovery:m,getProvider:v}};import{useEffect as xo,useState as Ao}from"react";import{PrivyClientError as Kt}from"@privy-io/js-sdk-core";var Gt=({client:e,isReady:t})=>{let r=U(),o=we(i=>i==null?void 0:i.customAuth),[n,s]=Ao({status:"initial"});return xo(()=>{(()=>l(void 0,null,function*(){if(!(o!=null&&o.enabled)){s({status:"not-enabled"});return}s({status:"loading"});let{getCustomAccessToken:c,isLoading:d}=o;if(!(!t||d))try{let a=yield c();if(!a&&r){yield e.auth.logout(),s({status:"done"});return}if(!a){s({status:"done"});return}if(r){s({status:"done"});return}let u=A();if(!(yield e.auth.customProvider.syncWithToken(a,{embedded:u==null?void 0:u.embedded}))){yield e.auth.logout(),s({status:"error",error:new Kt({error:"Failed to sync with custom auth provider",code:"third_party_auth_error"})});return}s({status:"done"})}catch(a){if(s({status:"error",error:a}),r)throw yield e.auth.logout(),new Kt({error:"Third-party auth failed",code:"third_party_auth_error"})}}))()},[e,r,t,o==null?void 0:o.enabled,o==null?void 0:o.getCustomAccessToken,o==null?void 0:o.isLoading]),{customAuthState:n,customAuthStateIsSettled:n.status!=="loading"&&n.status!=="initial"}};import*as $ from"expo-linking";import{useCallback as Po,useEffect as Uo,useMemo as Ro}from"react";import{Platform as Io}from"react-native";import{getUserEmbeddedSolanaWallet as Oo,getUserEmbeddedWallet as Lo}from"@privy-io/js-sdk-core";var qt=({client:e,createWalletCallbacks:t,recoverWalletCallbacks:r,setWalletRecoveryCallbacks:o,recoveryFlowState:n,oAuthState:s,setRecoveryFlowState:i,setWallet:c,appStateVisible:d})=>{let a=$.useURL(),u=U(),p=Ro(()=>Lo(u),[u]),m=j(),h=Po(g=>{var f,w,S,E;let v=C(g);n.status==="creating-wallet"?(w=(f=t.current).onError)==null||w.call(f,C(v)):(E=(S=r.current).onError)==null||E.call(S,C(v)),i({status:"initial"})},[n]);return Uo(()=>{function g(){return l(this,null,function*(){var S;if(!a&&n.status!=="initial"&&d&&h(new Error("Recovery OAuth session failed")),!a||n.status==="initial"||s.status!=="initial"||!d||!m)return;let{queryParams:v}=$.parse(a),{privy_oauth_state:f,privy_oauth_code:w}=v;if(!(!w||!f)){yield $.openURL(a.split("?")[0]);try{let E=yield Ae({oAuthCode:w,oAuthState:f,client:e});if(n.status==="creating-wallet"){let k=(S=Oo(u))!=null?S:void 0;yield _e({client:e,setWallet:c,createWalletCallbacks:t,recoveryMethod:"google-drive",setRecoveryFlowState:i,recoveryToken:E,solanaAccount:k})}else if(n.status==="upgrading-recovery"){if(!p)throw new Error("Embedded wallet not found");yield Ue({client:e,recoveryInput:{recoveryMethod:"google-drive",wallet:p,recoveryAccessToken:E},setWalletRecoveryCallbacks:o,setRecoveryFlowState:i,setWallet:c})}else yield Ee({client:e,account:p,setWallet:c,recoverWalletCallbacks:r,recoveryMethod:"google-drive",setRecoveryFlowState:i,recoveryToken:E})}catch(E){h(E)}}})}Io.OS==="android"&&g()},[a,n.status,d,m])};import{useEffect as Fo}from"react";import{Platform as Ge}from"react-native";var Mo="sdk_initialize";function Ht(){let{major:e,minor:t,patch:r,prerelease:o}=Ge.constants.reactNativeVersion;return{name:Mo,properties:{reactNativeVersion:`${e}.${t}.${r}${o!=null?`-${o}`:""}`,operatingSystem:`${Ge.OS}:${Ge.Version}`}}}var Bt=({client:e,isUserInitialized:t,setIsUserInitialized:r,setError:o})=>{Fo(()=>{t||(()=>l(void 0,null,function*(){try{yield e.initialize(),e.track(Ht())}catch(s){o(s instanceof Error?s:new Error(String(s)))}try{yield e.user.get()}catch(s){}finally{r(!0)}}))()},[e,t,o,r])};import{useEffect as bs,useRef as Ss}from"react";import{useCallback as qe,useContext as To}from"react";import{PrivyClientError as Do}from"@privy-io/js-sdk-core";var Tc=e=>{let{client:t,setSiweState:r,siweState:o}=To(y),n=qe(c=>{var a;let d=C(c);return r({status:"error",error:d}),(a=e==null?void 0:e.onError)==null||a.call(e,d),d},[e==null?void 0:e.onError]),s=qe(u=>l(void 0,[u],function*({wallet:c,from:{domain:d,uri:a}}){var p;try{r({status:"generating-message"});let m=yield t.auth.siwe.init(c,d,a);return r({status:"awaiting-signature"}),(p=e==null?void 0:e.onGenerateMessage)==null||p.call(e,m.message),m.message}catch(m){throw n(m)}}),[t,n,e==null?void 0:e.onGenerateMessage]);return{loginWithSiwe:qe(u=>l(void 0,[u],function*({signature:c,messageOverride:d,disableSignup:a}){var p;try{if(b())throw new Do({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 h=A(),g=yield t.auth.siwe.loginWithSiwe(c,void 0,d,a?"no-signup":"login-or-sign-up",{embedded:h==null?void 0:h.embedded});return r({status:"done"}),(p=e==null?void 0:e.onSuccess)==null||p.call(e,g.user,g.is_new_user),g.user}catch(m){throw n(m)}}),[t,n,e==null?void 0:e.onSuccess]),generateSiweMessage:s,state:o}};import{useCallback as Jt}from"react";import{createSiwsMessage as zo,PrivyClientError as jo}from"@privy-io/js-sdk-core";import{useContext as No}from"react";var W=()=>{let{client:e}=No(y);return e};var Jc=()=>{let e=W(),t=Jt(i=>l(void 0,[i],function*({wallet:{address:o},from:{domain:n,uri:s}}){try{let{nonce:c}=yield e.auth.siws.fetchNonce({address:o});return{message:zo({address:o,domain:n,uri:s,nonce:c})}}catch(c){throw C(c)}}),[e]),r=Jt(c=>l(void 0,[c],function*({signature:o,message:n,wallet:{walletClientType:s,connectorType:i}={}}){try{if(!b())throw new jo({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:a}=yield e.auth.siws.link({signature:o,message:n,walletClientType:s,connectorType:i});return a}catch(d){throw C(d)}}),[e]);return{generateMessage:t,link:r}};import{useCallback as $t}from"react";import{createSiwsMessage as Vo,PrivyClientError as Ko}from"@privy-io/js-sdk-core";var od=()=>{let e=W(),t=$t(i=>l(void 0,[i],function*({wallet:{address:o},from:{domain:n,uri:s}}){try{let{nonce:c}=yield e.auth.siws.fetchNonce({address:o});return{message:Vo({address:o,domain:n,uri:s,nonce:c})}}catch(c){throw C(c)}}),[e]),r=$t(d=>l(void 0,[d],function*({signature:o,message:n,wallet:{walletClientType:s,connectorType:i}={},disableSignup:c}){try{if(b())throw new Ko({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=A();return(yield e.auth.siws.login({signature:o,message:n,walletClientType:s,connectorType:i,mode:c?"no-signup":"login-or-sign-up",opts:{embedded:u==null?void 0:u.embedded}})).user}catch(a){throw C(a)}}),[e]);return{generateMessage:t,login:r}};import{useCallback as Qt,useContext as Go}from"react";import{PrivyClientError as qo}from"@privy-io/js-sdk-core";var ud=e=>{let{client:t}=Go(y),r=Qt(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{unlinkWallet:Qt(s=>l(void 0,[s],function*({address:n}){var i;try{if(!b())throw new qo({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(n);return(i=e==null?void 0:e.onSuccess)==null||i.call(e,d),d}catch(c){throw r(c)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useCallback as He,useContext as Ho,useState as Bo}from"react";import{PrivyClientError as Yt}from"@privy-io/js-sdk-core";var vd=e=>{let[t,r]=Bo(""),{client:o,otpState:n,setOtpState:s}=Ho(y),i=He(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=He(u=>l(void 0,[u],function*({email:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.email.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{email:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=He(p=>l(void 0,[p],function*({code:a,email:u}){var m;try{if(!b())throw new Yt({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 Yt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});s({status:"submitting-code"});let{user:v}=yield o.auth.email.linkWithCode(g,a);return s({status:"done"}),(m=e==null?void 0:e.onLinkSuccess)==null||m.call(e,v),v}catch(h){throw i(h)}}),[t,s,o,e,i]);return{sendCode:c,linkWithCode:d,state:n}};import{useCallback as Xt,useContext as Jo}from"react";var kd=e=>{let{client:t}=Jo(y),r=Xt(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{unlinkEmail:Xt(s=>l(void 0,[s],function*({email:n}){var i;try{let{user:c}=yield t.auth.email.unlink(n);return(i=e==null?void 0:e.onSuccess)==null||i.call(e,c),c}catch(c){throw r(c)}}),[t,e==null?void 0:e.onSuccess,r])}};import{useCallback as Be,useContext as $o,useState as Qo}from"react";import{PrivyClientError as Zt}from"@privy-io/js-sdk-core";var Ld=e=>{let[t,r]=Qo(""),{client:o,otpState:n,setOtpState:s}=$o(y),i=Be(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=Be(u=>l(void 0,[u],function*({email:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.email.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{email:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=Be(m=>l(void 0,[m],function*({code:a,email:u,disableSignup:p}){var h;try{if(b()&&!o.isMultiUserModeEnabled)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`"});s({status:"submitting-code"});let f=A(),w=yield o.auth.email.loginWithCode(v,a,p?"no-signup":"login-or-sign-up",{embedded:f==null?void 0:f.embedded});return s({status:"done"}),(h=e==null?void 0:e.onLoginSuccess)==null||h.call(e,w.user,w.is_new_user),w==null?void 0:w.user}catch(g){throw i(g)}}),[t,s,o,e,i]);return{sendCode:c,loginWithCode:d,state:n}};import{useCallback as Je,useContext as Yo,useState as Xo}from"react";import{PrivyClientError as er}from"@privy-io/js-sdk-core";var Vd=e=>{let[t,r]=Xo(""),{client:o,otpState:n,setOtpState:s}=Yo(y),i=Je(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=Je(u=>l(void 0,[u],function*({phone:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.phone.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{phone:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=Je(p=>l(void 0,[p],function*({code:a,phone:u}){var m;try{if(!b())throw new er({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 er({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});s({status:"submitting-code"});let{user:v}=yield o.auth.phone.linkWithCode(u||t,a);return s({status:"done"}),(m=e==null?void 0:e.onLinkSuccess)==null||m.call(e,v),v}catch(h){throw i(h)}}),[t,s,o,e,i]);return{sendCode:c,linkWithCode:d,state:n}};import{useCallback as $e,useContext as Zo,useState as en}from"react";import{PrivyClientError as tr}from"@privy-io/js-sdk-core";var Yd=e=>{let[t,r]=en(""),{client:o,otpState:n,setOtpState:s}=Zo(y),i=$e(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=$e(u=>l(void 0,[u],function*({phone:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.phone.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{phone:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=$e(m=>l(void 0,[m],function*({code:a,phone:u,disableSignup:p}){var h;try{if(b())throw new tr({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 tr({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});s({status:"submitting-code"});let f=A(),w=yield o.auth.phone.loginWithCode(u||t,a,p?"no-signup":"login-or-sign-up",{embedded:f==null?void 0:f.embedded});return s({status:"done"}),(h=e==null?void 0:e.onLoginSuccess)==null||h.call(e,w.user,w.is_new_user),w==null?void 0:w.user}catch(g){throw i(g)}}),[t,s,o,e,i]);return{sendCode:c,loginWithCode:d,state:n}};import*as Re from"expo-linking";import{useCallback as Qe,useContext as tn,useRef as rn}from"react";import{PrivyClientError as se}from"@privy-io/js-sdk-core";var il=e=>{let{appState:t,getCurrentAppState:r}=xe(),{client:o,farcasterState:n,setFarcasterState:s}=tn(y),i=rn(!1),c=Qe(u=>{var m;let p=C(u);return s({status:"error",error:p}),(m=e==null?void 0:e.onError)==null||m.call(e,p),p},[e==null?void 0:e.onError,s]),d=Qe(()=>{i.current=!0},[]);return{linkWithFarcaster:Qe((h,...g)=>l(void 0,[h,...g],function*({relyingParty:u,redirectUrl:p},m={pollAttempts:10,pollIntervalMs:1e3}){var v;try{let f=b();if(i.current=!1,!f)throw new se({code:"attempted_link_farcaster_before_logged_in",error:"Must be logged in to link a Farcaster account."});s({status:"generating-uri"});let{connect_uri:w,channel_token:S}=yield o.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:Re.createURL(p!=null?p:"/")});if(!w)throw new se({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!S)throw new se({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield Re.openURL(w),s({status:"polling-status"});let E=0;for(;E<m.pollAttempts;){if(i.current)throw new se({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield B(m.pollIntervalMs);continue}let k=yield o.auth.farcaster.getFarcasterStatus({channel_token:S});if(k.state==="completed"){s({status:"submitting-token"});let{user:x}=yield o.auth.farcaster.link(_({channel_token:S},k));return s({status:"done"}),(v=e==null?void 0:e.onSuccess)==null||v.call(e,x),x}E++,yield B(m.pollIntervalMs)}throw new se({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(f){throw c(f)}}),[o,e==null?void 0:e.onSuccess,c,s]),state:n,cancel:d}};import{useCallback as rr,useContext as on}from"react";var ul=e=>{let{client:t}=on(y),r=rr(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{unlinkFarcaster:rr(s=>l(void 0,[s],function*({fid:n}){var i;try{let{user:c}=yield t.auth.farcaster.unlink({fid:n});return(i=e==null?void 0:e.onSuccess)==null||i.call(e,c),c}catch(c){throw r(c)}}),[t,e==null?void 0:e.onSuccess,r])}};import*as Ie from"expo-linking";import{useCallback as Ze,useContext as nn,useRef as sn}from"react";import{PrivyClientError as ae}from"@privy-io/js-sdk-core";var bl=e=>{let{appState:t,getCurrentAppState:r}=xe(),{client:o,farcasterState:n,setFarcasterState:s}=nn(y),i=sn(!1),c=Ze(u=>{var m;let p=C(u);return s({status:"error",error:p}),(m=e==null?void 0:e.onError)==null||m.call(e,p),p},[e==null?void 0:e.onError,s]),d=Ze(()=>{i.current=!0},[]);return{loginWithFarcaster:Ze((g,...v)=>l(void 0,[g,...v],function*({relyingParty:u,redirectUrl:p,disableSignup:m},h={pollAttempts:10,pollIntervalMs:1e3}){var f;try{if(i.current=!1,b())throw new ae({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"});s({status:"generating-uri"});let{connect_uri:S,channel_token:E}=yield o.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:Ie.createURL(p!=null?p:"/")});if(!S)throw new ae({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!E)throw new ae({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield Ie.openURL(S),s({status:"polling-status"});let k=0;for(;k<h.pollAttempts;){if(i.current)throw new ae({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield B(h.pollIntervalMs);continue}let x=yield o.auth.farcaster.getFarcasterStatus({channel_token:E});if(x.state==="completed"){s({status:"submitting-token"});let P=A(),F=yield o.auth.farcaster.authenticate(_({channel_token:E,mode:m?"no-signup":"login-or-sign-up"},x),{embedded:P==null?void 0:P.embedded});return s({status:"done"}),(f=e==null?void 0:e.onSuccess)==null||f.call(e,F.user,F.is_new_user),F.user}k++,yield B(h.pollIntervalMs)}throw new ae({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(w){throw c(w)}}),[o,c,e==null?void 0:e.onSuccess,s,t]),state:n,cancel:d}};import{useCallback as or,useContext as an}from"react";import{create as cn}from"zustand";import{PrivyClientError as dn}from"@privy-io/js-sdk-core";var et=cn(()=>({status:"initial"})),V=e=>et.setState(e,!0),ln=et.getState,Ul=()=>{let{client:e}=an(y),t=et(),r=or(()=>l(void 0,null,function*(){try{V({status:"fetching-nonce"});let n=yield e.auth.farcasterV2.initializeAuth();return V({status:"awaiting-signature"}),n}catch(n){let s=C(n);throw V({status:"initial",error:s}),s}}),[e]),o=or(n=>l(void 0,null,function*(){let s=ln().status;try{if(b()){let a=new dn({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 V({status:s,error:a}),a}V({status:"submitting-signature"});let c=A(),d=yield e.auth.farcasterV2.authenticate(n,{embedded:c==null?void 0:c.embedded});return V({status:"done"}),setTimeout(()=>V({status:"initial"}),1500),{user:d.user}}catch(i){let c=C(i);throw V({status:s,error:c}),c}}),[e]);return{init:r,login:o,state:t}};import{useContext as un,useMemo as pn}from"react";import{delegatedActions as nr}from"@privy-io/js-sdk-core";var Fl=()=>{let{client:e}=un(y);return pn(()=>({delegateWallet:nr.delegateWallet(e),revokeWallets:nr.revokeWallets(e)}),[e])};import{useContext as mn,useMemo as yn}from"react";import{depositAddress as ce}from"@privy-io/js-sdk-core";var jl=()=>{let{client:e}=mn(y);return yn(()=>({getConfig:()=>ce.getConfig(e),generateDepositAddress:t=>ce.generateDepositAddress(_({privy:e},t)),getDeposit:t=>ce.getDeposit(_({privy:e},t)),waitForDeposit:t=>ce.waitForDeposit(_({privy:e},t)),waitForCompletion:t=>ce.waitForCompletion(_({privy:e},t))}),[e])};import{useContext as fn,useMemo as gn}from"react";import{cryptoDepositAccount as ir}from"@privy-io/js-sdk-core";var Bl=()=>{let{client:e}=fn(y);return gn(()=>({createCryptoDepositAccount:t=>ir.createCryptoDepositAccount(e,(...r)=>e.embeddedWallet.signWithUserSigner(...r),t),getQuote:t=>ir.getCryptoDepositAccountQuote(e,t)}),[e])};import{useContext as vn,useMemo as bn}from"react";import{addSessionSigners as Sn,removeSessionSigners as Cn}from"@privy-io/js-sdk-core";import{isEmbeddedWalletAccount as hn}from"@privy-io/js-sdk-core";function wn(e,t){return e.linked_accounts.filter(hn).find(r=>r.address===t)}function Q(e){let t=b();if(!t)throw new Error("User must be authenticated to perform this operation");let r=wn(t,e);if(!r)throw new Error(`No wallet found with address ${e}`);return r}var ru=()=>{let{client:e}=vn(y);return bn(()=>({addSessionSigners:({address:t,signers:r})=>Sn({client:e,wallet:Q(t),signers:r.map(o=>({signer_id:o.signerId,override_policy_ids:o.policyIds}))}),removeSessionSigners:({address:t})=>Cn({client:e,wallet:Q(t)})}),[e])};import{useContext as En,useMemo as _n}from"react";import{addSessionSigners as kn,removeSessionSigners as Wn}from"@privy-io/js-sdk-core";var cu=()=>{let{client:e}=En(y);return _n(()=>({addSigners:({address:t,signers:r})=>kn({client:e,wallet:Q(t),signers:r.map(o=>({signer_id:o.signerId,override_policy_ids:o.policyIds}))}),removeSigners:({address:t})=>Wn({client:e,wallet:Q(t)})}),[e])};import{useContext as xn,useMemo as An}from"react";import{PrivyClientError as ar}from"@privy-io/js-sdk-core";var yu=()=>{let{client:e}=xn(y);return An(()=>({sendCode(o){return l(this,arguments,function*({newEmailAddress:r}){sr(),yield e.auth.email.sendCode(r)})},updateEmail(n){return l(this,arguments,function*({newEmailAddress:r,code:o}){let{address:s}=sr(),{user:i}=yield e.auth.email.updateEmail({oldEmailAddress:s,newEmailAddress:r,code:o});return i})}}),[e])};function sr(){let t=Pn().linked_accounts.find(r=>r.type==="email");if(!t)throw new ar({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 Pn(){let e=b();if(!e)throw new ar({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import{useContext as Un,useMemo as Rn}from"react";import{PrivyClientError as dr}from"@privy-io/js-sdk-core";var Su=()=>{let{client:e}=Un(y);return Rn(()=>({sendCode(o){return l(this,arguments,function*({newPhoneNumber:r}){cr(),yield e.auth.phone.sendCode(r)})},updatePhone(n){return l(this,arguments,function*({newPhoneNumber:r,code:o}){let{phoneNumber:s}=cr(),{user:i}=yield e.auth.phone.updatePhone({oldPhoneNumber:s,newPhoneNumber:r,code:o});return i})}}),[e])};function cr(){let t=In().linked_accounts.find(r=>r.type==="phone");if(!t)throw new dr({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 In(){let e=b();if(!e)throw new dr({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import*as pr from"expo-linking";import{useCallback as Ln,useContext as Mn,useMemo as Fn}from"react";import{crossApp as Tn,PrivyClientError as Dn}from"@privy-io/js-sdk-core";import*as ur from"expo-linking";import*as de from"expo-web-browser";import{PrivyClientError as lr}from"@privy-io/js-sdk-core";var z=(e,t)=>l(void 0,null,function*(){let r=yield de.openAuthSessionAsync(e,t,{createTask:!1});if(r.type!=="success")throw r.type===de.WebBrowserResultType.CANCEL||r.type===de.WebBrowserResultType.DISMISS?new lr({error:"OAuth session was cancelled",code:"oauth_session_failed"}):new lr({error:"OAuth session failed",code:"oauth_session_failed"});return On(r.url)});function On(e){let{queryParams:t}=ur.parse(e);return t}var Iu=()=>{let{client:e}=Mn(y),t=Fn(()=>Tn.loginWithCrossAppAuth({client:e,openAuthSession:z}),[e]);return{loginWithCrossApp:Ln(s=>l(void 0,[s],function*({appId:o,redirectUri:n}){if(b())throw new Dn({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:c}=yield t({providerAppId:o,redirectUrl:pr.createURL(n||"/")});return{user:c}}),[t])}};import*as mr from"expo-linking";import{useCallback as Nn,useContext as zn,useMemo as jn}from"react";import{crossApp as Vn,PrivyClientError as Kn}from"@privy-io/js-sdk-core";var zu=()=>{let{client:e}=zn(y),t=jn(()=>Vn.linkWithCrossAppAuth({client:e,openAuthSession:z}),[e]);return{linkWithCrossApp:Nn(s=>l(void 0,[s],function*({appId:o,redirectUri:n}){if(!b())throw new Kn({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:o,redirectUrl:mr.createURL(n||"/")})}}),[t])}};import*as fr from"expo-linking";import{useContext as Gn,useMemo as yr}from"react";import{crossApp as qn}from"@privy-io/js-sdk-core";var Ju=()=>{let{client:e}=Gn(y),t=yr(()=>qn.wallet.signMessage({client:e,openAuthSession:z}),[e]);return yr(()=>({signMessage:({address:r,message:o,redirectUri:n="/"})=>t({user:b(),address:r,message:o,redirectUrl:fr.createURL(n)})}),[t])};import*as hr from"expo-linking";import{useContext as Hn,useMemo as gr}from"react";import{crossApp as Bn}from"@privy-io/js-sdk-core";var tp=()=>{let{client:e}=Hn(y),t=gr(()=>Bn.wallet.signTypedData({client:e,openAuthSession:z}),[e]);return gr(()=>({signTypedData:({address:r,typedData:o,redirectUri:n="/"})=>t({user:b(),address:r,typedData:o,redirectUrl:hr.createURL(n)})}),[t])};import*as vr from"expo-linking";import{useContext as Jn,useMemo as wr}from"react";import{crossApp as $n}from"@privy-io/js-sdk-core";var cp=()=>{let{client:e}=Jn(y),t=wr(()=>$n.wallet.sendTransaction({client:e,openAuthSession:z}),[e]);return wr(()=>({sendTransaction:({address:r,transaction:o,redirectUri:n="/"})=>t({user:b(),address:r,transaction:o,redirectUrl:vr.createURL(n)})}),[t])};import{useCallback as Qn,useContext as Yn}from"react";import{getUserEmbeddedEthereumWallet as Xn,getUserEmbeddedSolanaWallet as Zn,isUnifiedWallet as ei,PrivyClientError as Y,throwIfInvalidRecoveryUpgradePath as ti}from"@privy-io/js-sdk-core";var gp=()=>{let{client:e}=Yn(y);return{setRecovery:Qn(r=>l(void 0,null,function*(){var c;let o=b(),n=e.app.appId;if(!o)throw new Y({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let s=(c=Xn(o))!=null?c:Zn(o);if(!s)throw new Y({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(ei(s))throw new Y({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{s.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(s):s.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(s,s.address,"solana-address-verifier"))}catch(d){throw new Y({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}ti({currentRecoveryMethod:s.recovery_method,upgradeToRecoveryMethod:r.recoveryMethod});let i=yield ri({appId:n,client:e,user:o,primaryAccount:s,recoveryParams:r});try{let{user:d}=yield e.embeddedWallet.setRecovery(i);return{user:d}}catch(d){throw new Y({code:"embedded_wallet_set_recovery_error",error:d instanceof Error?d.message:"Error setting password on embedded wallet"})}}),[e])}},ri=s=>l(void 0,[s],function*({appId:e,client:t,user:r,primaryAccount:o,recoveryParams:n}){switch(n.recoveryMethod){case"privy":return{recoveryMethod:"privy",wallet:o};case"user-passcode":return M(_({},n),{wallet:o});case"google-drive":{let i=yield Pe(t);return{recoveryMethod:"google-drive",wallet:o,recoveryAccessToken:i}}case"icloud":{let{recoverySecret:i,iCloudRecordName:c}=yield oe({appId:e,client:t,user:r});return{recoveryMethod:"icloud-native",recoverySecretOverride:i,iCloudRecordNameOverride:c,wallet:o}}case"recovery-encryption-key":return{recoveryMethod:"recovery-encryption-key",wallet:o,recoveryKey:n.recoveryKey};default:throw new Y({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}});import{useCallback as oi,useContext as ni}from"react";import{getUserEmbeddedEthereumWallet as ii,getUserEmbeddedSolanaWallet as si,PrivyClientError as le,isUnifiedWallet as ai}from"@privy-io/js-sdk-core";var kp=()=>{let{client:e}=ni(y);return{recover:oi(r=>l(void 0,null,function*(){var a;let o=b();if(!o)throw new le({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let n=(a=ii(o))!=null?a:si(o);if(!n)throw new le({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(ai(n))throw new le({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 s,i,c,d;switch(r.recoveryMethod){case"user-passcode":i=r.password;break;case"google-drive":c=yield Pe(e);break;case"icloud":let{recoverySecret:u}=yield We({client:e,walletAddress:n.address,chainType:n.chain_type});d=u;break;case"recovery-encryption-key":s=r.recoveryKey;break;case"privy":break;default:throw new le({code:"unsupported_recovery_method",error:`Unsupported recovery options ${r}`})}try{n.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(n,i,c,d,s):n.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(n,n.address,"solana-address-verifier",i,c,d))}catch(u){throw new le({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};import{useEffect as di}from"react";import{useContext as ci,useEffect as tt}from"react";var rt=(e={})=>{let{wallet:t,createWalletCallbacks:r,recoverWalletCallbacks:o,setWalletRecoveryCallbacks:n}=ci(y),{onCreateWalletSuccess:s,onCreateWalletError:i,onRecoverWalletError:c,onRecoverWalletSuccess:d,onSetWalletRecoverySuccess:a,onSetWalletRecoveryError:u}=e;return tt(()=>{r.current={onSuccess:s,onError:i}},[s,i]),tt(()=>{o.current={onSuccess:d,onError:c}},[d,c]),tt(()=>{n.current={onSuccess:a,onError:u}},[d,c]),t};var Op=({onStateChange:e})=>{let t=rt();return di(()=>{e(t)},[t])};import{useContext as li}from"react";var Tp=()=>{let{getIdentityToken:e}=li(y);return{getIdentityToken:e}};import{useCallback as br,useContext as ui}from"react";import{PrivyClientError as pi}from"@privy-io/js-sdk-core";var qp=e=>{let{client:t}=ui(y),r=br(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{create:br(()=>l(void 0,null,function*(){var n;try{if(b())throw new pi({code:"attempted_to_create_guest_account_for_logged_in_user",error:"Already logged in, you cannot create a guest account"});let i=A(),c=yield t.auth.guest.create({embedded:i==null?void 0:i.embedded});return(n=e==null?void 0:e.onSuccess)==null||n.call(e,c.user,c.is_new_user),c.user}catch(s){throw r(s)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useContext as mi,useEffect as yi}from"react";function Yp({onMfaRequired:e}){let{client:t}=mi(y);yi(()=>{function r(){return l(this,null,function*(){var n;let o=b();yield e((n=o==null?void 0:o.mfa_methods.map(({type:s})=>s).filter(s=>s!=="email"))!=null?n:[])})}return t.mfaPromises.on("mfaRequired",r),()=>{t.mfaPromises.off("mfaRequired",r)}},[t,e])}import{useCallback as ue,useContext as Si}from"react";import{PrivyClientError as Le}from"@privy-io/js-sdk-core";import{PrivyClientError as fi}from"@privy-io/js-sdk-core";function Oe(){return l(this,null,function*(){ke("react-native-passkeys");try{return yield import("react-native-passkeys")}catch(e){return Promise.reject(e)}})}var gi=(e,t)=>l(void 0,null,function*(){var n;let o=yield(yield Oe()).create(hi(e,t));if(!o)throw new fi({code:"failed_to_create_passkey",error:"Could not create passkey"});return M(_({},o),{type:(n=o.type)!=null?n:"public-key",clientExtensionResults:{}})});function hi(e,t){return M(_({},t),{rp:e.rp,user:e.user,challenge:e.challenge,pubKeyCredParams:e.pubKeyCredParams,excludeCredentials:e.excludeCredentials,authenticatorSelection:e.authenticatorSelection,timeout:12e4,attestation:void 0})}import{PrivyClientError as wi}from"@privy-io/js-sdk-core";var nt=(e,t)=>l(void 0,null,function*(){var n;let o=yield(yield Oe()).get(vi(e,t));if(!o)throw new wi({code:"no_passkey_found_for_challenge",error:"Could not find a matching passkey to login with"});return M(_({},o),{type:(n=o.type)!=null?n:"public-key",clientExtensionResults:{}})});function vi(e,t){return M(_({},t),{rpId:e.rpId,challenge:e.challenge,allowCredentials:e.allowCredentials,userVerification:e.userVerification,timeout:12e4})}function Sr(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 Cr(e){var t,r,o,n;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:(o=e.extensions)==null?void 0:o.hmac_create_secret},timeout:e.timeout,allowCredentials:(n=e.allow_credentials)==null?void 0:n.map(({id:s,type:i,transports:c})=>({id:s,type:i,transports:c})),userVerification:e.user_verification}}function gm(e){var t,r,o,n,s,i,c,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:(o=(r=e.extensions)==null?void 0:r.cred_props)==null?void 0:o.rk,appid:(n=e.extensions)==null?void 0:n.app_id},attestation:e.attestation,excludeCredentials:e.exclude_credentials,authenticatorSelection:{authenticatorAttachment:(s=e.authenticator_selection)==null?void 0:s.authenticator_attachment,residentKey:(i=e.authenticator_selection)==null?void 0:i.resident_key,userVerification:(c=e.authenticator_selection)==null?void 0:c.user_verification,requireResidentKey:(d=e.authenticator_selection)==null?void 0:d.require_resident_key}}}function Cm(){let{client:e}=Si(y),t=ue(i=>l(this,null,function*(){var c,d;switch(i.method){case"sms":yield e.mfa.sms.sendCode({action:"verify"});return;case"passkey":let{options:a}=yield e.mfa.passkey.generateAuthenticationOptions({relying_party:i.relyingParty||((d=(c=A())==null?void 0:c.mfa)==null?void 0:d.relyingParty)});return Cr(a);case"totp":return;default:throw new Error(`Unsupported MFA method: ${i.mfaMethod}`)}}),[e]),r=ue(i=>l(this,null,function*(){var c,d,a,u,p,m,h;switch(i.method){case"totp":case"sms":if(typeof i.mfaCode!="string")throw new Le({code:"invalid_mfa_code",error:"Invalid MFA code"});(a=e.mfaPromises.rootPromise.current)==null||a.resolve({mfaMethod:i.method,mfaCode:i.mfaCode,relyingParty:i.relyingParty||((d=(c=A())==null?void 0:c.mfa)==null?void 0:d.relyingParty)||""}),yield new Promise((w,S)=>{e.mfaPromises.submitPromise.current={resolve:w,reject:S}});break;case"passkey":if(typeof i.mfaCode=="string")throw new Le({code:"invalid_passkey_response",error:"Invalid authenticator response"});let g=yield nt(i.mfaCode),v=Sr(g);(m=e.mfaPromises.rootPromise.current)==null||m.resolve({mfaMethod:i.method,relyingParty:i.relyingParty||((p=(u=A())==null?void 0:u.mfa)==null?void 0:p.relyingParty)||"",mfaCode:v}),yield new Promise((w,S)=>{e.mfaPromises.submitPromise.current={resolve:w,reject:S}});break;default:let f=new Le({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(h=e.mfaPromises.rootPromise.current)==null||h.reject(f),f}}),[e]),o=ue(()=>l(this,null,function*(){let i=b();!i||i.mfa_methods.length===0||(yield e.mfa.verifyMfa())}),[e]),n=ue(()=>{var i;(i=e.mfaPromises.rootPromise.current)==null||i.reject(new Le({code:"mfa_canceled",error:"MFA canceled"}))},[e]),s=ue(()=>l(this,null,function*(){let i=b();i&&(yield e.mfa.clearMfa({userId:i.id}))}),[e]);return{init:t,submit:r,prompt:o,cancel:n,clear:s}}import{useCallback as it,useContext as Ci}from"react";function xm(){let{client:e}=Ci(y),t=it(n=>l(this,null,function*(){switch(n.method){case"sms":case"totp":return yield e.mfa.initEnrollMfa(n);case"passkey":return;default:throw new Error(`Unsupported MFA method: ${n.method}`)}}),[e]),r=it(n=>l(this,null,function*(){switch(n.method){case"sms":case"totp":case"passkey":yield e.mfa.submitEnrollMfa(n);return;default:throw new Error(`Unsupported MFA method: ${n.method}`)}}),[e]),o=it(n=>l(this,null,function*(){switch(n.method){case"sms":case"totp":yield e.mfa.unenrollMfa(n.method);return;case"passkey":yield e.mfa.submitEnrollMfa({method:"passkey",credentialIds:[],removeForLogin:n.removeForLogin});return;default:throw new Error(`Unsupported MFA method: ${n.method}`)}}),[e]);return{initMfaEnrollment:t,submitMfaEnrollment:r,unenrollMfa:o}}import{useCallback as Ei,useContext as _i}from"react";function Im(){let{client:e}=_i(y);return{unlink:Ei(n=>l(this,[n],function*({credentialId:r,removeAsMfa:o}){yield e.mfa.unlinkPasskey({credentialId:r,removeAsMfa:o})}),[e])}}import{useCallback as ki}from"react";import{areAddressesEqual as Wi}from"@privy-io/are-addresses-equal";import{getAllUserEmbeddedEthereumWallets as xi,getAllUserEmbeddedSolanaWallets as Ai,PrivyClientError as Pi}from"@privy-io/js-sdk-core";var Nm=()=>{let e=W();return{importWallet:ki(s=>l(void 0,[s],function*({privateKey:r,chainType:o,additionalSigners:n}){let{address:i,user:c}=yield e.embeddedWallet.importWallet({privateKey:r,chainType:o,additionalSigners:n}),a=(o==="solana"?Ai(c.user):xi(c.user)).find(u=>Wi(u.address,i));if(!a)throw new Pi({code:"embedded_wallet_creation_error",error:"Failed to import wallet"});return{user:c.user,wallet:a}}),[e])}};import{useCallback as Ui,useMemo as Er}from"react";import{getAllUserEmbeddedEthereumWallets as at,getEntropyDetailsFromUser as _r,getUserEmbeddedSolanaWallet as Ri,PrivyClientError as kr}from"@privy-io/js-sdk-core";var ct=()=>{let e=U(),t=W(),r=Er(()=>{let s=at(e).map(i=>{let c=_r(e,i);return c?{account:i,entropy:c}:null});return s.some(i=>i===null)?[]:s.filter(i=>i!==null).map(({account:i,entropy:{entropyId:c,entropyIdVerifier:d}})=>({address:i.address,walletIndex:i.wallet_index,chainType:i.chain_type,getProvider:()=>t.embeddedWallet.getEthereumProvider({wallet:i,entropyId:c,entropyIdVerifier:d,onNeedsRecovery:a=>l(void 0,null,function*(){var u;yield(u=he())==null?void 0:u(a)})})}))},[t,e]),o=Ui((...s)=>l(void 0,[...s],function*({createAdditional:n=!1}={}){let{user:i}=yield t.user.get(),c=at(i);if(!n&&c.length>0)throw new kr({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});let d=_r(i);if(!d){let g=yield t.embeddedWallet.create({});return st(g.user,0),{user:g.user}}let{entropyId:a,entropyIdVerifier:u}=d;if(u==="solana-address-verifier"){let g=Ri(i),v=yield t.embeddedWallet.create({solanaAccount:g});return st(v.user,0),{user:v.user}}let m=c.map(g=>g.wallet_index).reduce((g,v)=>Math.max(g,v),0)+1,h=yield t.embeddedWallet.add({chainType:"ethereum",hdWalletIndex:m,entropyId:a,entropyIdVerifier:u});return st(h.user,m),{user:h.user}}),[t]);return Er(()=>({wallets:r,create:o}),[r,o])};function st(e,t){let r=at(e).find(o=>o.wallet_index===t);if(!e||!r)throw new kr({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}import{useContext as Ii,useEffect as Wr}from"react";var Oi=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:r,recoverSolanaWalletCallbacks:o}=Ii(y),{onCreateWalletSuccess:n,onCreateWalletError:s,onRecoverWalletError:i,onRecoverWalletSuccess:c}=e;return Wr(()=>{r.current={onSuccess:n,onError:s}},[n,s]),Wr(()=>{o.current={onSuccess:c,onError:i}},[c,i]),t};import{useCallback as Li,useMemo as Mi}from"react";import{getAllUserEmbeddedBitcoinWallets as dt,getEntropyDetailsFromUser as xr,isUnifiedWallet as Fi,PrivyClientError as X}from"@privy-io/js-sdk-core";var Ti=()=>{let e=U(),t=W(),r=Mi(()=>{let n=xr(e);if(!n)return[];let s=dt(e),{entropyId:i,entropyIdVerifier:c}=n;return s.map(d=>({address:d.address,walletIndex:d.wallet_index,publicKey:d.public_key,chainType:d.chain_type,getProvider:()=>Fi(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:i,entropyIdVerifier:c})}))},[t,e]),o=Li(i=>l(void 0,[i],function*({chainType:n,createAdditional:s=!1}){var f;let c=t.app.getConfig();if(((f=c==null?void 0:c.embedded_wallet_config)==null?void 0:f.mode)==="user-controlled-server-wallets-only")throw n==="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 (${n}) 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(),a=xr(d);if(!a)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:p}=a,m=dt(d).filter(w=>w.chain_type===n);if(!s&&m.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 h=m.length===0?0:Math.max(...m.map(w=>w.wallet_index),0)+1,g=yield t.embeddedWallet.add({chainType:n,hdWalletIndex:h,entropyId:u,entropyIdVerifier:p}),v=dt(g.user).find(w=>w.chain_type===n&&w.wallet_index===h);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:p})}}),[t]);return{wallets:r,create:o}};import{useContext as Di}from"react";var lt=()=>{let{isReady:e,logout:t,getAccessToken:r,error:o,client:n}=Di(y);return{user:U(),isReady:e,error:o,logout:t,getAccessToken:r,refreshUser:()=>n.user.refreshUser()}};import{useContext as Ni}from"react";function zi(){let{client:e}=Ni(y);return{acceptTerms:()=>l(this,null,function*(){return e.user.acceptTerms()})}}import{useMemo as ji}from"react";import{generateAuthorizationSignature as Vi}from"@privy-io/js-sdk-core";var Ki=()=>{let e=W();return ji(()=>({generateAuthorizationSignature(r){return l(this,null,function*(){let{signature:o}=yield Vi((...n)=>e.embeddedWallet.signWithUserSigner(...n),r);return{signature:o}})}}),[e])};import{useContext as Gi,useMemo as qi}from"react";import{GetEncryptedAuthorizationKey as Hi}from"@privy-io/routes";var by=()=>{let{client:e}=Gi(y);return qi(()=>({getEncryptedAuthorizationKey:({id:t})=>e.fetchPrivyRoute(Hi,{params:{encrypted_authorization_key_id:t}})}),[e])};import{useCallback as Bi}from"react";import{createWalletClient as Ji,getAddress as Ar,http as $i,parseSignature as Qi,zeroAddress as Yi}from"viem";import{hashAuthorization as Xi}from"viem/utils";import{getJsonRpcEndpointFromChain as Zi,getUserEmbeddedEthereumWallet as es}from"@privy-io/js-sdk-core";var ts=()=>{let e=U(),{wallets:t}=ct(),r=W();return{signAuthorization:Bi((n,s)=>l(void 0,null,function*(){var p,m,h;if(!e)throw new Error("User must be authenticated before signing with a Privy wallet");let i=(h=(m=s==null?void 0:s.address)!=null?m:(p=es(e))==null?void 0:p.address)!=null?h:Yi,c=t.find(g=>Ar(g.address)===Ar(i));if(!c)throw new Error("Signing wallet not found.");let d;if(n.chainId===0){if(n.nonce===void 0)throw new Error("nonce is required when chainId is 0 \u2014 chain-agnostic authorizations are replayable across networks");d={chainId:0,address:n.contractAddress,nonce:n.nonce}}else{let v=r.embeddedWallet.chains.find(S=>S.id===n.chainId);if(!v)throw new Error("Error, chain not configured in PrivyProvider config");let f=Zi(v,{},r.app.appId);d=yield Ji({account:i,chain:v,transport:$i(f)}).prepareAuthorization(_({},n))}let u=yield(yield c.getProvider()).request({method:"secp256k1_sign",params:[Xi(d)]});return _(_({},d),Qi(u))}),[t,e,r])}};import{useMemo as rs}from"react";import{transfer as os}from"@privy-io/js-sdk-core";var ns=()=>{let e=W();return rs(()=>({transfer:(t,r)=>os(e,(...o)=>e.embeddedWallet.signWithUserSigner(...o),_({wallet_id:t},r))}),[e])};import{useMemo as is}from"react";import{getWalletAction as ss,listWalletActions as as}from"@privy-io/js-sdk-core";var cs=()=>{let e=W();return is(()=>({getAction:(t,r)=>ss(e,{wallet_id:t,action_id:r}),listActions:(t,r)=>as(e,_({wallet_id:t},r))}),[e])};import{useMemo as ds}from"react";var ls=()=>{let e=Wt();return ds(()=>({users:e}),[e])};import{useMemo as us}from"react";var ps=()=>{let e=W();return us(()=>({switchUser:r=>l(void 0,[r],function*({userId:t}){return yield e.user.switchActiveUser({userId:t})})}),[e])};import{useCallback as ws}from"react";import{PrivyClientError as vs}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedBitcoinWallets as ms,getUserEmbeddedEthereumWallet as ys,getUserEmbeddedSolanaWallet as fs,isEmbeddedWalletAccount as gs,isUnifiedWallet as hs}from"@privy-io/js-sdk-core";function Pr(e,t){return l(this,null,function*(){var n;let r=(n=ys(t))!=null?n:fs(t);if(!r||hs(r))return{success:!0,migrated:!1};if(r.imported)throw new Error("Imported wallets cannot be migrated");if(ms(t).length>0)throw new Error("Bitcoin wallets cannot be migrated");let o=t.linked_accounts.filter(gs).filter(s=>!s.imported).filter(s=>s.chain_type==="ethereum"||s.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:o.map(s=>({address:s.address,chainType:s.chain_type,walletIndex:s.wallet_index}))}),yield e.user.get(),{success:!0,migrated:!0}})}var Ur=()=>{let e=W();return{migrate:ws(()=>l(void 0,null,function*(){var s;let r=b(),o=e.app.getConfig();if(((s=o==null?void 0:o.embedded_wallet_config)==null?void 0:s.mode)!=="user-controlled-server-wallets-only")return{success:!0};if(!r)throw new vs({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before migrating wallets"});return Pr(e,r)}),[e])}};var Rr=({disabled:e})=>{let{migrate:t}=Ur(),{user:r}=lt(),o=Ss(!1);return bs(()=>{e||r&&(o.current||(o.current=!0,t().then(n=>{n.migrated&&!o.current&&(console.info("Migrated wallets for user"),o.current=!0)}).catch(n=>{console.debug("Unable to migrate wallets: ",n)}).finally(()=>{o.current=!1})))},[t,r,e]),null};var y=Es(null),ee;function Sg(e){return ee?ee.getAccessToken():e!=null&&e.strict?Promise.reject(new Lr({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 Cg=e=>{var yt,ft,gt;Ws();let[t,r]=L(Or.currentState==="active");Ir(()=>{let O=Or.addEventListener("change",Vr=>{r(Vr==="active")});return()=>{O.remove()}},[]),Ir(()=>Ct(e.config),[e.config]);let[o,n]=L(!1),[s,i]=L(null),[c,d]=L(!1),[a,u]=L({status:"disconnected",account:null}),[p,m]=L({status:"disconnected"}),[h,g]=L({status:"initial"}),[v,f]=L({status:"initial"}),[w,S]=L({status:"initial"}),[E,k]=L({status:"initial"}),[x,P]=L({status:"initial"}),[F,me]=L({status:"initial"}),[ye,Fe]=L({status:"initial"}),te=pe({}),Te=pe({}),De=pe({}),pt=pe({}),mt=pe({}),fe=Me(O=>{if(O){ze(O),i(null);return}ze(null),g({status:"initial"}),f({status:"initial"}),u({status:"disconnected",account:null})},[]),I=Cs(()=>{let O=e.storage||ge;return e.client?ee=e.client:ee=St({appId:e.appId,clientId:e.clientId,supportedChains:e.supportedChains,storage:O,baseUrl:e.baseUrl,logLevel:e.logLevel}),ee.setCallbacks({setUser:fe,setIsReady:d,setStoredUsers:kt}),ee},[e.client,e.storage,e.appId,e.clientId,e.baseUrl,e.supportedChains,e.logLevel,fe]),Mr=Me(()=>l(void 0,null,function*(){let O=b();yield I.auth.logout(O?{userId:O==null?void 0:O.id}:void 0),fe(null)}),[fe,I]),Fr=Me(()=>l(void 0,null,function*(){try{return yield I.getAccessToken()}catch(O){return console.debug(O),null}}),[I]),Tr=Me(()=>I.getIdentityToken(),[I]);Bt({client:I,isUserInitialized:o,setIsUserInitialized:n,setError:i});let Dr=Vt({client:I,appId:e.appId,createWalletCallbacks:te,recoverWalletCallbacks:Te,setWalletRecoveryCallbacks:De,setRecoveryFlowState:S,wallet:a,setWallet:u}),Nr=Ot({client:I,createSolanaWalletCallbacks:pt,recoverSolanaWalletCallbacks:mt,setSolanaRecoveryFlowState:k,solanaWallet:p,setSolanaWallet:m});qt({client:I,createWalletCallbacks:te,recoverWalletCallbacks:Te,setWalletRecoveryCallbacks:De,recoveryFlowState:w,oAuthState:v,setRecoveryFlowState:S,setWallet:u,appStateVisible:t});let{customAuthStateIsSettled:zr}=Gt({client:I,isReady:o}),jr=j();return Z.createElement(Z.Fragment,null,Z.createElement(y.Provider,{value:{client:I,isReady:jr&&o&&zr,error:s,logout:Mr,getAccessToken:Fr,getIdentityToken:Tr,wallet:_(_({},a),Dr),solanaWallet:_(_({},p),Nr),oAuthState:v,recoveryFlowState:w,setRecoveryFlowState:S,solanaRecoveryFlowState:E,setSolanaRecoveryFlowState:k,createWalletCallbacks:te,recoverWalletCallbacks:Te,setWalletRecoveryCallbacks:De,createSolanaWalletCallbacks:pt,recoverSolanaWalletCallbacks:mt,setOAuthState:f,siweState:x,setSiweState:P,otpState:h,setOtpState:g,passkeyState:F,setPasskeyState:me,farcasterState:ye,setFarcasterState:Fe}},e.children,Z.createElement(Rr,{disabled:(gt=(ft=(yt=e.config)==null?void 0:yt.embedded)==null?void 0:ft.disableAutomaticMigration)!=null?gt:!1})),Z.createElement(ks,{style:{width:0,height:0,overflow:"hidden"}},Z.createElement(xt,{client:I,isClientReady:c})))},Ws=()=>{if(_s(y))throw new Lr({code:"configuration_error",error:"Found multiple instances of PrivyProvider, ensure there is only one mounted in your application tree."})};var Ug=e=>{let{client:t,setSiweState:r,siweState:o}=xs(y),n=ut(c=>{var a;let d=C(c);return r({status:"error",error:d}),(a=e==null?void 0:e.onError)==null||a.call(e,d),d},[e==null?void 0:e.onError]),s=ut(u=>l(void 0,[u],function*({wallet:c,from:{domain:d,uri:a}}){var p;try{r({status:"generating-message"});let m=yield t.auth.siwe.init(c,d,a);return r({status:"awaiting-signature"}),(p=e==null?void 0:e.onGenerateMessage)==null||p.call(e,m.message),m.message}catch(m){throw n(m)}}),[t,n,e==null?void 0:e.onGenerateMessage]),i=ut(a=>l(void 0,[a],function*({signature:c,messageOverride:d}){var u;try{if(!b())throw new As({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:m}=yield t.auth.siwe.linkWithSiwe(c,void 0,d);return r({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,m),m}catch(p){throw n(p)}}),[t,n,e==null?void 0:e.onSuccess]);return{generateSiweMessage:s,linkWithSiwe:i,state:o}};export{A as a,b,qs as c,U as d,Hs as e,qr as f,ke as g,C as h,B as i,St as j,Ug as k,Tc as l,W as m,Jc as n,od as o,ud as p,vd as q,kd as r,Ld as s,Vd as t,Yd as u,il as v,ul as w,bl as x,Ul as y,Fl as z,jl as A,Bl as B,ru as C,cu as D,yu as E,Su as F,Iu as G,zu as H,Ju as I,tp as J,cp as K,gp as L,kp as M,rt as N,Op as O,Tp as P,qp as Q,Yp as R,gi as S,nt as T,gm as U,Cm as V,xm as W,Im as X,Nm as Y,ct as Z,Oi as _,Ti as $,lt as aa,zi as ba,Ki as ca,by as da,ts as ea,ns as fa,cs as ga,ls as ha,ps as ia,Ur as ja,y as ka,Sg as la,Cg as ma};
12
+ If these requirements cannot be met, keep ${e} installed.`:d+`Expo SDK 52 and React Native 0.78 or earlier cannot safely omit ${e}. Upgrade to Expo SDK 54 or React Native 0.81, or keep ${e} installed.`;Lt.add(e),o(a)}function Ft(){return l(this,null,function*(){ke("@privy-io/expo-native-extensions");try{return yield import("@privy-io/expo-native-extensions")}catch(e){throw new N({code:"configuration_error",error:"`@privy-io/expo-native-extensions` is not installed. Install it and rebuild the native app."})}})}function oe(o){return l(this,arguments,function*({user:e,appId:t,client:r}){var c;if(Mt.OS==="android")throw new N({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let n=yield Ft(),s=yield r.recovery.icloudAuth.getICloudConfiguration("expo-ios");if(!(s==null?void 0:s.container_identifier))throw new N({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:d,iCloudRecordName:a}=yield n.writeRecoverySecretToICloud({containerId:s.container_identifier,appId:t,userId:e.id});return{recoverySecret:d,iCloudRecordName:a}}catch(d){if(d instanceof Error){let a=(c=d.message.split("Caused by: ")[1])!=null?c:"Error writing to iCloud";throw new N({code:"embedded_wallet_recovery_error",error:a})}throw new N({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}function We(o){return l(this,arguments,function*({walletAddress:e,client:t,chainType:r}){var a;if(Mt.OS==="android")throw new N({code:"embedded_wallet_recovery_error",error:"iCloud recovery is not supported on Android"});let n=yield Ft(),i=(yield t.recovery.getRecoveryKeyMaterial(e,r)).icloud_record_name;if(!i)throw new N({code:"embedded_wallet_recovery_error",error:"iCloud recovery not properly backed up."});let c=yield t.recovery.icloudAuth.getICloudConfiguration("expo-ios"),d=c==null?void 0:c.container_identifier;if(!d)throw new N({code:"embedded_wallet_recovery_error",error:"An iCloud Container ID must be specified in the Privy Dashboard."});try{let{recoverySecret:u}=yield n.readRecoverySecretFromICloud({containerId:d,recordName:i});return{recoverySecret:u}}catch(u){if(u instanceof Error){let p=(a=u.message.split("Caused by: ")[1])!=null?a:"Error writing to iCloud";throw new N({code:"embedded_wallet_recovery_error",error:p})}throw new N({code:"embedded_wallet_recovery_error",error:"Error writing to iCloud"})}})}import*as G from"expo-linking";import*as Tt from"expo-web-browser";import{Platform as Dt}from"react-native";import{PrivyClientError as J}from"@privy-io/js-sdk-core";import Pa from"react-fast-compare";import{PrivyApiError as yo,PrivyClientError as fo}from"@privy-io/js-sdk-core";function C(e){return e instanceof Error||e instanceof yo||e instanceof fo?e:typeof e=="string"?new Error(e):new Error("Unknown error")}var H=e=>new Promise(t=>setTimeout(t,e));import{useEffect as go,useRef as ho}from"react";import{AppState as Ge}from"react-native";function Ae(){let e=ho(Ge.currentState);go(()=>Ge.addEventListener("change",o=>{e.current=o}).remove,[]);function t(){return Ge.currentState}return{appState:e,getCurrentAppState:t}}function ne(n){return l(this,arguments,function*({provider:e,redirectUri:t,client:r,onError:o}){try{let s;switch(e){case"google-drive":{let{url:a}=yield r.recovery.auth.generateURL(G.createURL(t||"/"));s=a;break}default:throw new J({error:"OAuth invalid provider",code:"embedded_wallet_recovery_error"})}let i=yield Tt.openAuthSessionAsync(s);if(Dt.OS==="android")return;if(i.type!=="success")throw new J({error:"Recovery OAuth session failed",code:"embedded_wallet_recovery_error"});let{queryParams:c}=G.parse(i.url),d;switch(e){case"google-drive":{let{privy_oauth_state:a,privy_oauth_code:u}=c;if(!u||!a)throw new J({error:"Recovery OAuth invalid credentials",code:"embedded_wallet_recovery_error"});d=yield xe({oAuthCode:u,oAuthState:a,client:r});break}default:throw new J({error:"Recovery OAuth invalid provider",code:"embedded_wallet_recovery_error"})}return d}catch(s){throw o==null||o(C(s)),s}})}function xe(o){return l(this,arguments,function*({oAuthCode:e,oAuthState:t,client:r}){let{access_token:n}=yield r.recovery.auth.authorize(e,t);if(!n)throw new J({error:"OAuth invalid credentials",code:"login_with_oauth_returned_with_invalid_credentials"});return n})}var wo=2*60*1e3;function vo(e){let t;return new Promise((r,o)=>{t=G.addEventListener("url",s=>l(this,[s],function*({url:n}){if(!n)return;let{queryParams:i}=G.parse(n),{privy_oauth_state:c,privy_oauth_code:d}=i!=null?i:{};if(typeof d!="string"||typeof c!="string")return;let a=yield xe({client:e,oAuthCode:d,oAuthState:c});r(a)})),setTimeout(()=>{o(new J({code:"embedded_wallet_set_recovery_error",error:"Failed to complete Google Drive recovery flow"}))},wo)}).finally(()=>{t==null||t.remove()})}function Pe(e){return l(this,null,function*(){let t;Dt.OS==="android"&&(t=vo(e));let r=yield ne({provider:"google-drive",client:e});return r!=null?r:yield t})}import{getUserEmbeddedWallet as bo,PrivyClientError as So}from"@privy-io/js-sdk-core";function Ue(s){return l(this,arguments,function*({client:e,recoveryInput:t,setWalletRecoveryCallbacks:r,setRecoveryFlowState:o,setWallet:n}){var i,c,d,a;try{let{provider:u,user:p}=yield e.embeddedWallet.setRecovery(t),m=u,g=bo(p);return n({status:"connected",provider:m,account:g}),(c=(i=r.current)==null?void 0:i.onSuccess)==null||c.call(i,m),o({status:"initial"}),m}catch(u){let p=new So({code:"embedded_wallet_set_recovery_error",error:u instanceof Error?u.message:"Error setting password on embedded wallet"});throw(a=(d=r.current)==null?void 0:d.onError)==null||a.call(d,p),o({status:"initial"}),p}})}function jt(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 Vt=({client:e,appId:t,wallet:r,setWallet:o,setRecoveryFlowState:n,createWalletCallbacks:s,recoverWalletCallbacks:i,setWalletRecoveryCallbacks:c})=>{let d=U(),a=Co(()=>Eo(d),[d]),u=j(),p=ie(f=>l(void 0,null,function*(){var me,ye;if(a)throw new R({error:"This user already has an embedded wallet",code:"embedded_wallet_already_exists"});let{user:w}=yield e.user.get(),{password:S,recoveryMethod:E,recoveryKey:k}=jt(f),A,P,F;if(E==="google-drive"&&(A=yield ne({provider:E,client:e,onError:(me=s.current)==null?void 0:me.onError}),n({status:"creating-wallet"}),!A))return null;if(E==="icloud"){if(!w)throw new R({code:"embedded_wallet_recovery_error",error:"User must be loaded before creating a wallet with iCloud."});let{recoverySecret:Te,iCloudRecordName:te}=yield oe({user:w,appId:t,client:e});P=Te,F=te}return yield _e({client:e,setWallet:o,createWalletCallbacks:s,recoveryMethod:E,recoveryKey:k,setRecoveryFlowState:n,password:S,recoverySecretOverride:P,iCloudRecordNameOverride:F,solanaAccount:(ye=zt(w))!=null?ye:void 0})}),[e,a,d]),m=ie(f=>l(void 0,null,function*(){var E;if(r.status!=="connected")throw new R({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"});if(!a)throw new R({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(zt(d))throw new R({code:"embedded_wallet_set_recovery_error",error:"Cannot set user-controlled recovery for a user with an embedded Solana wallet."});if(_o(a))throw new R({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"});ko({currentRecoveryMethod:a.recovery_method,upgradeToRecoveryMethod:f.recoveryMethod});let w,S;switch(f.recoveryMethod){case"privy":S=M(_({},f),{wallet:a});break;case"user-passcode":S=M(_({},f),{wallet:a,password:f.password});break;case"google-drive":if(w=yield ne({provider:f.recoveryMethod,client:e,onError:(E=c.current)==null?void 0:E.onError}),n({status:"upgrading-recovery"}),!w)return null;S={recoveryMethod:"google-drive",wallet:a,recoveryAccessToken:w};break;case"icloud":if(!d)throw new R({code:"embedded_wallet_recovery_error",error:"User must be loaded before backing up to iCloud."});let{recoverySecret:k,iCloudRecordName:A}=yield oe({user:d,appId:t,client:e});S={recoveryMethod:"icloud-native",recoverySecretOverride:k,iCloudRecordNameOverride:A,wallet:a};break;default:throw new R({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}return Ue({client:e,recoveryInput:S,setWalletRecoveryCallbacks:c,setRecoveryFlowState:n,setWallet:o})}),[e,a,r.status,d]),g=ie(f=>l(void 0,null,function*(){return m({recoveryMethod:"user-passcode",password:f})}),[e,a,r.status]),h=ie(f=>l(void 0,null,function*(){var P;if(!a)throw new R({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});let{password:w,recoveryMethod:S,recoveryKey:E}=jt(f),k,A;if(S==="google-drive"&&(k=yield ne({provider:S,client:e,onError:(P=i.current)==null?void 0:P.onError}),n({status:"recovering"}),!k))return null;if(S==="icloud"){if(!d)throw new R({code:"embedded_wallet_recovery_error",error:"User must be loaded before recovering via iCloud."});let{recoverySecret:F}=yield We({client:e,walletAddress:a.address});A=F}return Ee({client:e,account:a,setWallet:o,recoverWalletCallbacks:i,recoveryMethod:S,setRecoveryFlowState:n,recoveryKey:E,password:w,recoveryToken:k,recoverySecretOverride:A})}),[e,a]),v=ie(()=>l(void 0,null,function*(){if(!a)throw o({status:"not-created",account:null}),new R({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});o(f=>f.status==="connected"?{status:"reconnecting",account:a}:{status:"connecting",account:a});try{let f=yield e.embeddedWallet.getProvider(a);return o({status:"connected",provider:f,account:a}),f}catch(f){throw Wo(f)?(o({status:"needs-recovery",account:a}),new R({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"})):f instanceof Error?(o({status:"error",error:f.message,account:a}),new R({code:"unknown_embedded_wallet_error",error:f.message})):(o({status:"error",error:"Error loading embedded wallet",account:a}),new R({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"}))}}),[e,a]);return Nt(()=>{if(!d&&r.status!=="disconnected")return o({status:"disconnected",account:null});u&&v().catch(()=>{})},[u,d,a]),Nt(()=>{r.status==="error"&&r.error.includes("User must be logged in")&&v()},[r.status]),{create:p,recover:h,setPassword:g,setRecovery:m,getProvider:v}};import{useEffect as Ao,useState as xo}from"react";import{PrivyClientError as Kt}from"@privy-io/js-sdk-core";var Gt=({client:e,isReady:t})=>{let r=U(),o=we(i=>i==null?void 0:i.customAuth),[n,s]=xo({status:"initial"});return Ao(()=>{(()=>l(void 0,null,function*(){if(!(o!=null&&o.enabled)){s({status:"not-enabled"});return}s({status:"loading"});let{getCustomAccessToken:c,isLoading:d}=o;if(!(!t||d))try{let a=yield c();if(!a&&r){yield e.auth.logout(),s({status:"done"});return}if(!a){s({status:"done"});return}if(r){s({status:"done"});return}let u=x();if(!(yield e.auth.customProvider.syncWithToken(a,{embedded:u==null?void 0:u.embedded}))){yield e.auth.logout(),s({status:"error",error:new Kt({error:"Failed to sync with custom auth provider",code:"third_party_auth_error"})});return}s({status:"done"})}catch(a){if(s({status:"error",error:a}),r)throw yield e.auth.logout(),new Kt({error:"Third-party auth failed",code:"third_party_auth_error"})}}))()},[e,r,t,o==null?void 0:o.enabled,o==null?void 0:o.getCustomAccessToken,o==null?void 0:o.isLoading]),{customAuthState:n,customAuthStateIsSettled:n.status!=="loading"&&n.status!=="initial"}};import*as $ from"expo-linking";import{useCallback as Po,useEffect as Uo,useMemo as Ro}from"react";import{Platform as Io}from"react-native";import{getUserEmbeddedSolanaWallet as Oo,getUserEmbeddedWallet as Lo}from"@privy-io/js-sdk-core";var qt=({client:e,createWalletCallbacks:t,recoverWalletCallbacks:r,setWalletRecoveryCallbacks:o,recoveryFlowState:n,oAuthState:s,setRecoveryFlowState:i,setWallet:c,appStateVisible:d})=>{let a=$.useURL(),u=U(),p=Ro(()=>Lo(u),[u]),m=j(),g=Po(h=>{var f,w,S,E;let v=C(h);n.status==="creating-wallet"?(w=(f=t.current).onError)==null||w.call(f,C(v)):(E=(S=r.current).onError)==null||E.call(S,C(v)),i({status:"initial"})},[n]);return Uo(()=>{function h(){return l(this,null,function*(){var S;if(!a&&n.status!=="initial"&&d&&g(new Error("Recovery OAuth session failed")),!a||n.status==="initial"||s.status!=="initial"||!d||!m)return;let{queryParams:v}=$.parse(a),{privy_oauth_state:f,privy_oauth_code:w}=v;if(!(!w||!f)){yield $.openURL(a.split("?")[0]);try{let E=yield xe({oAuthCode:w,oAuthState:f,client:e});if(n.status==="creating-wallet"){let k=(S=Oo(u))!=null?S:void 0;yield _e({client:e,setWallet:c,createWalletCallbacks:t,recoveryMethod:"google-drive",setRecoveryFlowState:i,recoveryToken:E,solanaAccount:k})}else if(n.status==="upgrading-recovery"){if(!p)throw new Error("Embedded wallet not found");yield Ue({client:e,recoveryInput:{recoveryMethod:"google-drive",wallet:p,recoveryAccessToken:E},setWalletRecoveryCallbacks:o,setRecoveryFlowState:i,setWallet:c})}else yield Ee({client:e,account:p,setWallet:c,recoverWalletCallbacks:r,recoveryMethod:"google-drive",setRecoveryFlowState:i,recoveryToken:E})}catch(E){g(E)}}})}Io.OS==="android"&&h()},[a,n.status,d,m])};import{useEffect as Fo}from"react";import{Platform as qe}from"react-native";var Mo="sdk_initialize";function Bt(){let{major:e,minor:t,patch:r,prerelease:o}=qe.constants.reactNativeVersion;return{name:Mo,properties:{reactNativeVersion:`${e}.${t}.${r}${o!=null?`-${o}`:""}`,operatingSystem:`${qe.OS}:${qe.Version}`}}}var Ht=({client:e,isUserInitialized:t,setIsUserInitialized:r,setError:o})=>{Fo(()=>{t||(()=>l(void 0,null,function*(){try{yield e.initialize(),e.track(Bt())}catch(s){o(s instanceof Error?s:new Error(String(s)))}try{yield e.user.get()}catch(s){}finally{r(!0)}}))()},[e,t,o,r])};import{useEffect as Ss,useRef as Cs}from"react";import{useCallback as Be,useContext as To}from"react";import{PrivyClientError as Do}from"@privy-io/js-sdk-core";var Dc=e=>{let{client:t,setSiweState:r,siweState:o}=To(y),n=Be(c=>{var a;let d=C(c);return r({status:"error",error:d}),(a=e==null?void 0:e.onError)==null||a.call(e,d),d},[e==null?void 0:e.onError]),s=Be(u=>l(void 0,[u],function*({wallet:c,from:{domain:d,uri:a}}){var p;try{r({status:"generating-message"});let m=yield t.auth.siwe.init(c,d,a);return r({status:"awaiting-signature"}),(p=e==null?void 0:e.onGenerateMessage)==null||p.call(e,m.message),m.message}catch(m){throw n(m)}}),[t,n,e==null?void 0:e.onGenerateMessage]);return{loginWithSiwe:Be(u=>l(void 0,[u],function*({signature:c,messageOverride:d,disableSignup:a}){var p;try{if(b())throw new Do({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 g=x(),h=yield t.auth.siwe.loginWithSiwe(c,void 0,d,a?"no-signup":"login-or-sign-up",{embedded:g==null?void 0:g.embedded});return r({status:"done"}),(p=e==null?void 0:e.onSuccess)==null||p.call(e,h.user,h.is_new_user),h.user}catch(m){throw n(m)}}),[t,n,e==null?void 0:e.onSuccess]),generateSiweMessage:s,state:o}};import{useCallback as Jt}from"react";import{createSiwsMessage as zo,PrivyClientError as jo}from"@privy-io/js-sdk-core";import{useContext as No}from"react";var W=()=>{let{client:e}=No(y);return e};var $c=()=>{let e=W(),t=Jt(i=>l(void 0,[i],function*({wallet:{address:o},from:{domain:n,uri:s}}){try{let{nonce:c}=yield e.auth.siws.fetchNonce({address:o});return{message:zo({address:o,domain:n,uri:s,nonce:c})}}catch(c){throw C(c)}}),[e]),r=Jt(c=>l(void 0,[c],function*({signature:o,message:n,wallet:{walletClientType:s,connectorType:i}={}}){try{if(!b())throw new jo({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:a}=yield e.auth.siws.link({signature:o,message:n,walletClientType:s,connectorType:i});return a}catch(d){throw C(d)}}),[e]);return{generateMessage:t,link:r}};import{useCallback as $t}from"react";import{createSiwsMessage as Vo,PrivyClientError as Ko}from"@privy-io/js-sdk-core";var nd=()=>{let e=W(),t=$t(i=>l(void 0,[i],function*({wallet:{address:o},from:{domain:n,uri:s}}){try{let{nonce:c}=yield e.auth.siws.fetchNonce({address:o});return{message:Vo({address:o,domain:n,uri:s,nonce:c})}}catch(c){throw C(c)}}),[e]),r=$t(d=>l(void 0,[d],function*({signature:o,message:n,wallet:{walletClientType:s,connectorType:i}={},disableSignup:c}){try{if(b())throw new Ko({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=x();return(yield e.auth.siws.login({signature:o,message:n,walletClientType:s,connectorType:i,mode:c?"no-signup":"login-or-sign-up",opts:{embedded:u==null?void 0:u.embedded}})).user}catch(a){throw C(a)}}),[e]);return{generateMessage:t,login:r}};import{useCallback as Qt,useContext as Go}from"react";import{PrivyClientError as qo}from"@privy-io/js-sdk-core";var pd=e=>{let{client:t}=Go(y),r=Qt(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{unlinkWallet:Qt(s=>l(void 0,[s],function*({address:n}){var i;try{if(!b())throw new qo({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(n);return(i=e==null?void 0:e.onSuccess)==null||i.call(e,d),d}catch(c){throw r(c)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useCallback as He,useContext as Bo,useState as Ho}from"react";import{PrivyClientError as Yt}from"@privy-io/js-sdk-core";var bd=e=>{let[t,r]=Ho(""),{client:o,otpState:n,setOtpState:s}=Bo(y),i=He(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=He(u=>l(void 0,[u],function*({email:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.email.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{email:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=He(p=>l(void 0,[p],function*({code:a,email:u}){var m;try{if(!b())throw new Yt({code:"attempted_link_email_before_logged_in",error:"Must be logged in to link an email, Use `useLoginWithEmail` to login with email"});let h=u||t;if(!h)throw new Yt({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});s({status:"submitting-code"});let{user:v}=yield o.auth.email.linkWithCode(h,a);return s({status:"done"}),(m=e==null?void 0:e.onLinkSuccess)==null||m.call(e,v),v}catch(g){throw i(g)}}),[t,s,o,e,i]);return{sendCode:c,linkWithCode:d,state:n}};import{useCallback as Xt,useContext as Jo}from"react";var Wd=e=>{let{client:t}=Jo(y),r=Xt(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{unlinkEmail:Xt(s=>l(void 0,[s],function*({email:n}){var i;try{let{user:c}=yield t.auth.email.unlink(n);return(i=e==null?void 0:e.onSuccess)==null||i.call(e,c),c}catch(c){throw r(c)}}),[t,e==null?void 0:e.onSuccess,r])}};import{useCallback as Je,useContext as $o,useState as Qo}from"react";import{PrivyClientError as Zt}from"@privy-io/js-sdk-core";var Md=e=>{let[t,r]=Qo(""),{client:o,otpState:n,setOtpState:s}=$o(y),i=Je(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=Je(u=>l(void 0,[u],function*({email:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.email.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{email:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=Je(m=>l(void 0,[m],function*({code:a,email:u,disableSignup:p}){var g;try{if(b()&&!o.isMultiUserModeEnabled)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`"});s({status:"submitting-code"});let f=x(),w=yield o.auth.email.loginWithCode(v,a,p?"no-signup":"login-or-sign-up",{embedded:f==null?void 0:f.embedded});return s({status:"done"}),(g=e==null?void 0:e.onLoginSuccess)==null||g.call(e,w.user,w.is_new_user),w==null?void 0:w.user}catch(h){throw i(h)}}),[t,s,o,e,i]);return{sendCode:c,loginWithCode:d,state:n}};import{useCallback as $e,useContext as Yo,useState as Xo}from"react";import{PrivyClientError as er}from"@privy-io/js-sdk-core";var Kd=e=>{let[t,r]=Xo(""),{client:o,otpState:n,setOtpState:s}=Yo(y),i=$e(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=$e(u=>l(void 0,[u],function*({phone:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.phone.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{phone:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=$e(p=>l(void 0,[p],function*({code:a,phone:u}){var m;try{if(!b())throw new er({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 er({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});s({status:"submitting-code"});let{user:v}=yield o.auth.phone.linkWithCode(u||t,a);return s({status:"done"}),(m=e==null?void 0:e.onLinkSuccess)==null||m.call(e,v),v}catch(g){throw i(g)}}),[t,s,o,e,i]);return{sendCode:c,linkWithCode:d,state:n}};import{useCallback as Qe,useContext as Zo,useState as en}from"react";import{PrivyClientError as tr}from"@privy-io/js-sdk-core";var Xd=e=>{let[t,r]=en(""),{client:o,otpState:n,setOtpState:s}=Zo(y),i=Qe(a=>{var p;let u=C(a);return s({status:"error",error:u}),(p=e==null?void 0:e.onError)==null||p.call(e,u),u},[e,s]),c=Qe(u=>l(void 0,[u],function*({phone:a}){var p;r(a);try{s({status:"sending-code"});let m=yield o.auth.phone.sendCode(a);return s({status:"awaiting-code-input"}),(p=e==null?void 0:e.onSendCodeSuccess)==null||p.call(e,{phone:a}),m}catch(m){throw i(m)}}),[o,i,e,s]),d=Qe(m=>l(void 0,[m],function*({code:a,phone:u,disableSignup:p}){var g;try{if(b())throw new tr({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 tr({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});s({status:"submitting-code"});let f=x(),w=yield o.auth.phone.loginWithCode(u||t,a,p?"no-signup":"login-or-sign-up",{embedded:f==null?void 0:f.embedded});return s({status:"done"}),(g=e==null?void 0:e.onLoginSuccess)==null||g.call(e,w.user,w.is_new_user),w==null?void 0:w.user}catch(h){throw i(h)}}),[t,s,o,e,i]);return{sendCode:c,loginWithCode:d,state:n}};import*as Re from"expo-linking";import{useCallback as Ye,useContext as tn,useRef as rn}from"react";import{PrivyClientError as se}from"@privy-io/js-sdk-core";var sl=e=>{let{appState:t,getCurrentAppState:r}=Ae(),{client:o,farcasterState:n,setFarcasterState:s}=tn(y),i=rn(!1),c=Ye(u=>{var m;let p=C(u);return s({status:"error",error:p}),(m=e==null?void 0:e.onError)==null||m.call(e,p),p},[e==null?void 0:e.onError,s]),d=Ye(()=>{i.current=!0},[]);return{linkWithFarcaster:Ye((g,...h)=>l(void 0,[g,...h],function*({relyingParty:u,redirectUrl:p},m={pollAttempts:10,pollIntervalMs:1e3}){var v;try{let f=b();if(i.current=!1,!f)throw new se({code:"attempted_link_farcaster_before_logged_in",error:"Must be logged in to link a Farcaster account."});s({status:"generating-uri"});let{connect_uri:w,channel_token:S}=yield o.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:Re.createURL(p!=null?p:"/")});if(!w)throw new se({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!S)throw new se({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield Re.openURL(w),s({status:"polling-status"});let E=0;for(;E<m.pollAttempts;){if(i.current)throw new se({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield H(m.pollIntervalMs);continue}let k=yield o.auth.farcaster.getFarcasterStatus({channel_token:S});if(k.state==="completed"){s({status:"submitting-token"});let{user:A}=yield o.auth.farcaster.link(_({channel_token:S},k));return s({status:"done"}),(v=e==null?void 0:e.onSuccess)==null||v.call(e,A),A}E++,yield H(m.pollIntervalMs)}throw new se({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(f){throw c(f)}}),[o,e==null?void 0:e.onSuccess,c,s]),state:n,cancel:d}};import{useCallback as rr,useContext as on}from"react";var pl=e=>{let{client:t}=on(y),r=rr(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{unlinkFarcaster:rr(s=>l(void 0,[s],function*({fid:n}){var i;try{let{user:c}=yield t.auth.farcaster.unlink({fid:n});return(i=e==null?void 0:e.onSuccess)==null||i.call(e,c),c}catch(c){throw r(c)}}),[t,e==null?void 0:e.onSuccess,r])}};import*as Ie from"expo-linking";import{useCallback as et,useContext as nn,useRef as sn}from"react";import{PrivyClientError as ae}from"@privy-io/js-sdk-core";var Sl=e=>{let{appState:t,getCurrentAppState:r}=Ae(),{client:o,farcasterState:n,setFarcasterState:s}=nn(y),i=sn(!1),c=et(u=>{var m;let p=C(u);return s({status:"error",error:p}),(m=e==null?void 0:e.onError)==null||m.call(e,p),p},[e==null?void 0:e.onError,s]),d=et(()=>{i.current=!0},[]);return{loginWithFarcaster:et((h,...v)=>l(void 0,[h,...v],function*({relyingParty:u,redirectUrl:p,disableSignup:m},g={pollAttempts:10,pollIntervalMs:1e3}){var f;try{if(i.current=!1,b())throw new ae({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"});s({status:"generating-uri"});let{connect_uri:S,channel_token:E}=yield o.auth.farcaster.initializeAuth({relyingParty:u,redirectUrl:Ie.createURL(p!=null?p:"/")});if(!S)throw new ae({code:"failed_to_generate_farcaster_uri",error:"Failed to generate farcaster uri"});if(!E)throw new ae({code:"failed_to_generate_farcaster_channel_token",error:"Failed to generate farcaster channel token"});yield Ie.openURL(S),s({status:"polling-status"});let k=0;for(;k<g.pollAttempts;){if(i.current)throw new ae({code:"farcaster_polling_canceled",error:"Farcaster polling canceled"});if(t.current!=="active"&&r()!=="active"){yield H(g.pollIntervalMs);continue}let A=yield o.auth.farcaster.getFarcasterStatus({channel_token:E});if(A.state==="completed"){s({status:"submitting-token"});let P=x(),F=yield o.auth.farcaster.authenticate(_({channel_token:E,mode:m?"no-signup":"login-or-sign-up"},A),{embedded:P==null?void 0:P.embedded});return s({status:"done"}),(f=e==null?void 0:e.onSuccess)==null||f.call(e,F.user,F.is_new_user),F.user}k++,yield H(g.pollIntervalMs)}throw new ae({code:"farcaster_polling_timeout",error:"Farcasting polling timed out"})}catch(w){throw c(w)}}),[o,c,e==null?void 0:e.onSuccess,s,t]),state:n,cancel:d}};import{useCallback as or,useContext as an}from"react";import{create as cn}from"zustand";import{PrivyClientError as dn}from"@privy-io/js-sdk-core";var tt=cn(()=>({status:"initial"})),V=e=>tt.setState(e,!0),ln=tt.getState,Rl=()=>{let{client:e}=an(y),t=tt(),r=or(()=>l(void 0,null,function*(){try{V({status:"fetching-nonce"});let n=yield e.auth.farcasterV2.initializeAuth();return V({status:"awaiting-signature"}),n}catch(n){let s=C(n);throw V({status:"initial",error:s}),s}}),[e]),o=or(n=>l(void 0,null,function*(){let s=ln().status;try{if(b()){let a=new dn({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 V({status:s,error:a}),a}V({status:"submitting-signature"});let c=x(),d=yield e.auth.farcasterV2.authenticate(n,{embedded:c==null?void 0:c.embedded});return V({status:"done"}),setTimeout(()=>V({status:"initial"}),1500),{user:d.user}}catch(i){let c=C(i);throw V({status:s,error:c}),c}}),[e]);return{init:r,login:o,state:t}};import{useContext as un,useMemo as pn}from"react";import{delegatedActions as nr}from"@privy-io/js-sdk-core";var Tl=()=>{let{client:e}=un(y);return pn(()=>({delegateWallet:nr.delegateWallet(e),revokeWallets:nr.revokeWallets(e)}),[e])};import{useContext as mn,useMemo as yn}from"react";import{depositAddress as ce}from"@privy-io/js-sdk-core";var Vl=()=>{let{client:e}=mn(y);return yn(()=>({getConfig:()=>ce.getConfig(e),generateDepositAddress:t=>ce.generateDepositAddress(_({privy:e},t)),getDeposit:t=>ce.getDeposit(_({privy:e},t)),waitForDeposit:t=>ce.waitForDeposit(_({privy:e},t)),waitForCompletion:t=>ce.waitForCompletion(_({privy:e},t))}),[e])};import{useContext as fn,useMemo as gn}from"react";import{cryptoDepositAccount as ir}from"@privy-io/js-sdk-core";var Jl=()=>{let{client:e}=fn(y);return gn(()=>({createCryptoDepositAccount:t=>ir.createCryptoDepositAccount(e,(...r)=>e.embeddedWallet.signWithUserSigner(...r),t),getQuote:t=>ir.getCryptoDepositAccountQuote(e,t)}),[e])};import{useContext as vn,useMemo as bn}from"react";import{addSessionSigners as Sn,removeSessionSigners as Cn}from"@privy-io/js-sdk-core";import{isEmbeddedWalletAccount as hn}from"@privy-io/js-sdk-core";function wn(e,t){return e.linked_accounts.filter(hn).find(r=>r.address===t)}function Q(e){let t=b();if(!t)throw new Error("User must be authenticated to perform this operation");let r=wn(t,e);if(!r)throw new Error(`No wallet found with address ${e}`);return r}var ou=()=>{let{client:e}=vn(y);return bn(()=>({addSessionSigners:({address:t,signers:r})=>Sn({client:e,wallet:Q(t),signers:r.map(o=>({signer_id:o.signerId,override_policy_ids:o.policyIds}))}),removeSessionSigners:({address:t})=>Cn({client:e,wallet:Q(t)})}),[e])};import{useContext as En,useMemo as _n}from"react";import{addSessionSigners as kn,removeSessionSigners as Wn}from"@privy-io/js-sdk-core";var du=()=>{let{client:e}=En(y);return _n(()=>({addSigners:({address:t,signers:r})=>kn({client:e,wallet:Q(t),signers:r.map(o=>({signer_id:o.signerId,override_policy_ids:o.policyIds}))}),removeSigners:({address:t})=>Wn({client:e,wallet:Q(t)})}),[e])};import{useContext as An,useMemo as xn}from"react";import{PrivyClientError as ar}from"@privy-io/js-sdk-core";var fu=()=>{let{client:e}=An(y);return xn(()=>({sendCode(o){return l(this,arguments,function*({newEmailAddress:r}){sr(),yield e.auth.email.sendCode(r)})},updateEmail(n){return l(this,arguments,function*({newEmailAddress:r,code:o}){let{address:s}=sr(),{user:i}=yield e.auth.email.updateEmail({oldEmailAddress:s,newEmailAddress:r,code:o});return i})}}),[e])};function sr(){let t=Pn().linked_accounts.find(r=>r.type==="email");if(!t)throw new ar({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 Pn(){let e=b();if(!e)throw new ar({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import{useContext as Un,useMemo as Rn}from"react";import{PrivyClientError as dr}from"@privy-io/js-sdk-core";var Cu=()=>{let{client:e}=Un(y);return Rn(()=>({sendCode(o){return l(this,arguments,function*({newPhoneNumber:r}){cr(),yield e.auth.phone.sendCode(r)})},updatePhone(n){return l(this,arguments,function*({newPhoneNumber:r,code:o}){let{phoneNumber:s}=cr(),{user:i}=yield e.auth.phone.updatePhone({oldPhoneNumber:s,newPhoneNumber:r,code:o});return i})}}),[e])};function cr(){let t=In().linked_accounts.find(r=>r.type==="phone");if(!t)throw new dr({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 In(){let e=b();if(!e)throw new dr({code:"attempted_update_before_logged_in",error:"Must be logged in to update a user profile."});return e}import*as pr from"expo-linking";import{useCallback as Ln,useContext as Mn,useMemo as Fn}from"react";import{crossApp as Tn,PrivyClientError as Dn}from"@privy-io/js-sdk-core";import*as ur from"expo-linking";import*as de from"expo-web-browser";import{PrivyClientError as lr}from"@privy-io/js-sdk-core";var z=(e,t)=>l(void 0,null,function*(){let r=yield de.openAuthSessionAsync(e,t,{createTask:!1});if(r.type!=="success")throw r.type===de.WebBrowserResultType.CANCEL||r.type===de.WebBrowserResultType.DISMISS?new lr({error:"OAuth session was cancelled",code:"oauth_session_failed"}):new lr({error:"OAuth session failed",code:"oauth_session_failed"});return On(r.url)});function On(e){let{queryParams:t}=ur.parse(e);return t}var Ou=()=>{let{client:e}=Mn(y),t=Fn(()=>Tn.loginWithCrossAppAuth({client:e,openAuthSession:z}),[e]);return{loginWithCrossApp:Ln(s=>l(void 0,[s],function*({appId:o,redirectUri:n}){if(b())throw new Dn({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:c}=yield t({providerAppId:o,redirectUrl:pr.createURL(n||"/")});return{user:c}}),[t])}};import*as mr from"expo-linking";import{useCallback as Nn,useContext as zn,useMemo as jn}from"react";import{crossApp as Vn,PrivyClientError as Kn}from"@privy-io/js-sdk-core";var ju=()=>{let{client:e}=zn(y),t=jn(()=>Vn.linkWithCrossAppAuth({client:e,openAuthSession:z}),[e]);return{linkWithCrossApp:Nn(s=>l(void 0,[s],function*({appId:o,redirectUri:n}){if(!b())throw new Kn({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:o,redirectUrl:mr.createURL(n||"/")})}}),[t])}};import*as fr from"expo-linking";import{useContext as Gn,useMemo as yr}from"react";import{crossApp as qn}from"@privy-io/js-sdk-core";var $u=()=>{let{client:e}=Gn(y),t=yr(()=>qn.wallet.signMessage({client:e,openAuthSession:z}),[e]);return yr(()=>({signMessage:({address:r,message:o,redirectUri:n="/"})=>t({user:b(),address:r,message:o,redirectUrl:fr.createURL(n)})}),[t])};import*as hr from"expo-linking";import{useContext as Bn,useMemo as gr}from"react";import{crossApp as Hn}from"@privy-io/js-sdk-core";var rp=()=>{let{client:e}=Bn(y),t=gr(()=>Hn.wallet.signTypedData({client:e,openAuthSession:z}),[e]);return gr(()=>({signTypedData:({address:r,typedData:o,redirectUri:n="/"})=>t({user:b(),address:r,typedData:o,redirectUrl:hr.createURL(n)})}),[t])};import*as vr from"expo-linking";import{useContext as Jn,useMemo as wr}from"react";import{crossApp as $n}from"@privy-io/js-sdk-core";var dp=()=>{let{client:e}=Jn(y),t=wr(()=>$n.wallet.sendTransaction({client:e,openAuthSession:z}),[e]);return wr(()=>({sendTransaction:({address:r,transaction:o,redirectUri:n="/"})=>t({user:b(),address:r,transaction:o,redirectUrl:vr.createURL(n)})}),[t])};import{useCallback as Qn,useContext as Yn}from"react";import{getUserEmbeddedEthereumWallet as Xn,getUserEmbeddedSolanaWallet as Zn,isUnifiedWallet as ei,PrivyClientError as Y,throwIfInvalidRecoveryUpgradePath as ti}from"@privy-io/js-sdk-core";var hp=()=>{let{client:e}=Yn(y);return{setRecovery:Qn(r=>l(void 0,null,function*(){var c;let o=b(),n=e.app.appId;if(!o)throw new Y({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let s=(c=Xn(o))!=null?c:Zn(o);if(!s)throw new Y({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(ei(s))throw new Y({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{s.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(s):s.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(s,s.address,"solana-address-verifier"))}catch(d){throw new Y({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}ti({currentRecoveryMethod:s.recovery_method,upgradeToRecoveryMethod:r.recoveryMethod});let i=yield ri({appId:n,client:e,user:o,primaryAccount:s,recoveryParams:r});try{let{user:d}=yield e.embeddedWallet.setRecovery(i);return{user:d}}catch(d){throw new Y({code:"embedded_wallet_set_recovery_error",error:d instanceof Error?d.message:"Error setting password on embedded wallet"})}}),[e])}},ri=s=>l(void 0,[s],function*({appId:e,client:t,user:r,primaryAccount:o,recoveryParams:n}){switch(n.recoveryMethod){case"privy":return{recoveryMethod:"privy",wallet:o};case"user-passcode":return M(_({},n),{wallet:o});case"google-drive":{let i=yield Pe(t);return{recoveryMethod:"google-drive",wallet:o,recoveryAccessToken:i}}case"icloud":{let{recoverySecret:i,iCloudRecordName:c}=yield oe({appId:e,client:t,user:r});return{recoveryMethod:"icloud-native",recoverySecretOverride:i,iCloudRecordNameOverride:c,wallet:o}}case"recovery-encryption-key":return{recoveryMethod:"recovery-encryption-key",wallet:o,recoveryKey:n.recoveryKey};default:throw new Y({code:"embedded_wallet_recovery_error",error:"Unrecognized recovery method"})}});import{useCallback as oi,useContext as ni}from"react";import{getUserEmbeddedEthereumWallet as ii,getUserEmbeddedSolanaWallet as si,PrivyClientError as le,isUnifiedWallet as ai}from"@privy-io/js-sdk-core";var Wp=()=>{let{client:e}=ni(y);return{recover:oi(r=>l(void 0,null,function*(){var a;let o=b();if(!o)throw new le({code:"embedded_wallet_recovery_error",error:"User must be loaded before attempting to modify the recovery method."});let n=(a=ii(o))!=null?a:si(o);if(!n)throw new le({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if(ai(n))throw new le({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 s,i,c,d;switch(r.recoveryMethod){case"user-passcode":i=r.password;break;case"google-drive":c=yield Pe(e);break;case"icloud":let{recoverySecret:u}=yield We({client:e,walletAddress:n.address,chainType:n.chain_type});d=u;break;case"recovery-encryption-key":s=r.recoveryKey;break;case"privy":break;default:throw new le({code:"unsupported_recovery_method",error:`Unsupported recovery options ${r}`})}try{n.chain_type==="ethereum"?yield e.embeddedWallet.getProvider(n,i,c,d,s):n.chain_type==="solana"&&(yield e.embeddedWallet.getSolanaProvider(n,n.address,"solana-address-verifier",i,c,d))}catch(u){throw new le({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"})}}),[e])}};import{useEffect as di}from"react";import{useContext as ci,useEffect as rt}from"react";var ot=(e={})=>{let{wallet:t,createWalletCallbacks:r,recoverWalletCallbacks:o,setWalletRecoveryCallbacks:n}=ci(y),{onCreateWalletSuccess:s,onCreateWalletError:i,onRecoverWalletError:c,onRecoverWalletSuccess:d,onSetWalletRecoverySuccess:a,onSetWalletRecoveryError:u}=e;return rt(()=>{r.current={onSuccess:s,onError:i}},[s,i]),rt(()=>{o.current={onSuccess:d,onError:c}},[d,c]),rt(()=>{n.current={onSuccess:a,onError:u}},[d,c]),t};var Lp=({onStateChange:e})=>{let t=ot();return di(()=>{e(t)},[t])};import{useContext as li}from"react";var Dp=()=>{let{getIdentityToken:e}=li(y);return{getIdentityToken:e}};import{useCallback as br,useContext as ui}from"react";import{PrivyClientError as pi}from"@privy-io/js-sdk-core";var Bp=e=>{let{client:t}=ui(y),r=br(n=>{var i;let s=C(n);return(i=e==null?void 0:e.onError)==null||i.call(e,s),s},[e==null?void 0:e.onError]);return{create:br(()=>l(void 0,null,function*(){var n;try{if(b())throw new pi({code:"attempted_to_create_guest_account_for_logged_in_user",error:"Already logged in, you cannot create a guest account"});let i=x(),c=yield t.auth.guest.create({embedded:i==null?void 0:i.embedded});return(n=e==null?void 0:e.onSuccess)==null||n.call(e,c.user,c.is_new_user),c.user}catch(s){throw r(s)}}),[t,r,e==null?void 0:e.onSuccess])}};import{useContext as mi,useEffect as yi}from"react";function Xp({onMfaRequired:e}){let{client:t}=mi(y);yi(()=>{function r(){return l(this,null,function*(){var n;let o=b();yield e((n=o==null?void 0:o.mfa_methods.map(({type:s})=>s).filter(s=>s!=="email"))!=null?n:[])})}return t.mfaPromises.on("mfaRequired",r),()=>{t.mfaPromises.off("mfaRequired",r)}},[t,e])}import{useCallback as ue,useContext as Si}from"react";import{PrivyClientError as Le}from"@privy-io/js-sdk-core";import{PrivyClientError as fi}from"@privy-io/js-sdk-core";function Oe(){return l(this,null,function*(){ke("react-native-passkeys");try{return yield import("react-native-passkeys")}catch(e){return Promise.reject(e)}})}var gi=(e,t)=>l(void 0,null,function*(){var n;let o=yield(yield Oe()).create(hi(e,t));if(!o)throw new fi({code:"failed_to_create_passkey",error:"Could not create passkey"});return M(_({},o),{type:(n=o.type)!=null?n:"public-key",clientExtensionResults:{}})});function hi(e,t){return M(_({},t),{rp:e.rp,user:e.user,challenge:e.challenge,pubKeyCredParams:e.pubKeyCredParams,excludeCredentials:e.excludeCredentials,authenticatorSelection:e.authenticatorSelection,timeout:12e4,attestation:void 0})}import{PrivyClientError as wi}from"@privy-io/js-sdk-core";var it=(e,t)=>l(void 0,null,function*(){var n;let o=yield(yield Oe()).get(vi(e,t));if(!o)throw new wi({code:"no_passkey_found_for_challenge",error:"Could not find a matching passkey to login with"});return M(_({},o),{type:(n=o.type)!=null?n:"public-key",clientExtensionResults:{}})});function vi(e,t){return M(_({},t),{rpId:e.rpId,challenge:e.challenge,allowCredentials:e.allowCredentials,userVerification:e.userVerification,timeout:12e4})}function Sr(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 Cr(e){var t,r,o,n;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:(o=e.extensions)==null?void 0:o.hmac_create_secret},timeout:e.timeout,allowCredentials:(n=e.allow_credentials)==null?void 0:n.map(({id:s,type:i,transports:c})=>({id:s,type:i,transports:c})),userVerification:e.user_verification}}function hm(e){var t,r,o,n,s,i,c,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:(o=(r=e.extensions)==null?void 0:r.cred_props)==null?void 0:o.rk,appid:(n=e.extensions)==null?void 0:n.app_id},attestation:e.attestation,excludeCredentials:e.exclude_credentials,authenticatorSelection:{authenticatorAttachment:(s=e.authenticator_selection)==null?void 0:s.authenticator_attachment,residentKey:(i=e.authenticator_selection)==null?void 0:i.resident_key,userVerification:(c=e.authenticator_selection)==null?void 0:c.user_verification,requireResidentKey:(d=e.authenticator_selection)==null?void 0:d.require_resident_key}}}function Em(){let{client:e}=Si(y),t=ue(i=>l(this,null,function*(){var c,d;switch(i.method){case"sms":yield e.mfa.sms.sendCode({action:"verify"});return;case"passkey":let{options:a}=yield e.mfa.passkey.generateAuthenticationOptions({relying_party:i.relyingParty||((d=(c=x())==null?void 0:c.mfa)==null?void 0:d.relyingParty)});return Cr(a);case"totp":return;default:throw new Error(`Unsupported MFA method: ${i.mfaMethod}`)}}),[e]),r=ue(i=>l(this,null,function*(){var c,d,a,u,p,m,g;switch(i.method){case"totp":case"sms":if(typeof i.mfaCode!="string")throw new Le({code:"invalid_mfa_code",error:"Invalid MFA code"});(a=e.mfaPromises.rootPromise.current)==null||a.resolve({mfaMethod:i.method,mfaCode:i.mfaCode,relyingParty:i.relyingParty||((d=(c=x())==null?void 0:c.mfa)==null?void 0:d.relyingParty)||""}),yield new Promise((w,S)=>{e.mfaPromises.submitPromise.current={resolve:w,reject:S}});break;case"passkey":if(typeof i.mfaCode=="string")throw new Le({code:"invalid_passkey_response",error:"Invalid authenticator response"});let h=yield it(i.mfaCode),v=Sr(h);(m=e.mfaPromises.rootPromise.current)==null||m.resolve({mfaMethod:i.method,relyingParty:i.relyingParty||((p=(u=x())==null?void 0:u.mfa)==null?void 0:p.relyingParty)||"",mfaCode:v}),yield new Promise((w,S)=>{e.mfaPromises.submitPromise.current={resolve:w,reject:S}});break;default:let f=new Le({code:"unsupported_mfa_method",error:"Unsupported MFA method"});throw(g=e.mfaPromises.rootPromise.current)==null||g.reject(f),f}}),[e]),o=ue(()=>l(this,null,function*(){let i=b();!i||i.mfa_methods.length===0||(yield e.mfa.verifyMfa())}),[e]),n=ue(()=>{var i;(i=e.mfaPromises.rootPromise.current)==null||i.reject(new Le({code:"mfa_canceled",error:"MFA canceled"}))},[e]),s=ue(()=>l(this,null,function*(){let i=b();i&&(yield e.mfa.clearMfa({userId:i.id}))}),[e]);return{init:t,submit:r,prompt:o,cancel:n,clear:s}}import{useCallback as st,useContext as Ci}from"react";function xm(){let{client:e}=Ci(y),t=st(n=>l(this,null,function*(){switch(n.method){case"sms":case"totp":return yield e.mfa.initEnrollMfa(n);case"passkey":return;default:throw new Error(`Unsupported MFA method: ${n.method}`)}}),[e]),r=st(n=>l(this,null,function*(){switch(n.method){case"sms":case"totp":case"passkey":yield e.mfa.submitEnrollMfa(n);return;default:throw new Error(`Unsupported MFA method: ${n.method}`)}}),[e]),o=st(n=>l(this,null,function*(){switch(n.method){case"sms":case"totp":yield e.mfa.unenrollMfa(n.method);return;case"passkey":yield e.mfa.submitEnrollMfa({method:"passkey",credentialIds:[],removeForLogin:n.removeForLogin});return;default:throw new Error(`Unsupported MFA method: ${n.method}`)}}),[e]);return{initMfaEnrollment:t,submitMfaEnrollment:r,unenrollMfa:o}}import{useCallback as Ei,useContext as _i}from"react";function Om(){let{client:e}=_i(y);return{unlink:Ei(n=>l(this,[n],function*({credentialId:r,removeAsMfa:o}){yield e.mfa.unlinkPasskey({credentialId:r,removeAsMfa:o})}),[e])}}import{useCallback as ki}from"react";import{areAddressesEqual as Wi}from"@privy-io/are-addresses-equal";import{getAllUserEmbeddedEthereumWallets as Ai,getAllUserEmbeddedSolanaWallets as xi,PrivyClientError as Pi}from"@privy-io/js-sdk-core";var zm=()=>{let e=W();return{importWallet:ki(s=>l(void 0,[s],function*({privateKey:r,chainType:o,additionalSigners:n}){let{address:i,user:c}=yield e.embeddedWallet.importWallet({privateKey:r,chainType:o,additionalSigners:n}),a=(o==="solana"?xi(c.user):Ai(c.user)).find(u=>Wi(u.address,i));if(!a)throw new Pi({code:"embedded_wallet_creation_error",error:"Failed to import wallet"});return{user:c.user,wallet:a}}),[e])}};import{useCallback as Ui,useMemo as Er}from"react";import{getAllUserEmbeddedEthereumWallets as Me,getEntropyDetailsFromUser as _r,getUserEmbeddedSolanaWallet as Ri,PrivyClientError as at}from"@privy-io/js-sdk-core";var ct=()=>{let e=U(),t=W(),r=Er(()=>{let s=Me(e).map(i=>{let c=_r(e,i);return c?{account:i,entropy:c}:null});return s.some(i=>i===null)?[]:s.filter(i=>i!==null).map(({account:i,entropy:{entropyId:c,entropyIdVerifier:d}})=>({address:i.address,walletIndex:i.wallet_index,chainType:i.chain_type,getProvider:()=>t.embeddedWallet.getEthereumProvider({wallet:i,entropyId:c,entropyIdVerifier:d,onNeedsRecovery:a=>l(void 0,null,function*(){var u;yield(u=he())==null?void 0:u(a)})})}))},[t,e]),o=Ui((...s)=>l(void 0,[...s],function*({createAdditional:n=!1}={}){var p,m,g;let{user:i}=yield t.user.get(),c=Me(i);if(!n&&c.length>0)throw new at({code:"embedded_wallet_creation_error",error:"Wallet already exists for this user. Set `createAdditional` to `true` to create another wallet"});if(c.length===0){let h=(p=Ri(i))!=null?p:void 0,v=yield t.embeddedWallet.create(h?{solanaAccount:h}:{});return Ii(v.user),{user:v.user}}let d=_r(i),a=c.map(h=>h.wallet_index).reduce((h,v)=>Math.max(h,v),0)+1,u=yield t.embeddedWallet.add({chainType:"ethereum",hdWalletIndex:a,entropyId:(m=d==null?void 0:d.entropyId)!=null?m:"",entropyIdVerifier:(g=d==null?void 0:d.entropyIdVerifier)!=null?g:"ethereum-address-verifier"});if(Me(u.user).length<=c.length)throw new at({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"});return{user:u.user}}),[t]);return Er(()=>({wallets:r,create:o}),[r,o])};function Ii(e){if(!e||Me(e).length===0)throw new at({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"})}import{useContext as Oi,useEffect as kr}from"react";var Li=(e={})=>{let{solanaWallet:t,createSolanaWalletCallbacks:r,recoverSolanaWalletCallbacks:o}=Oi(y),{onCreateWalletSuccess:n,onCreateWalletError:s,onRecoverWalletError:i,onRecoverWalletSuccess:c}=e;return kr(()=>{r.current={onSuccess:n,onError:s}},[n,s]),kr(()=>{o.current={onSuccess:c,onError:i}},[c,i]),t};import{useCallback as Mi,useMemo as Fi}from"react";import{getAllUserEmbeddedBitcoinWallets as dt,getEntropyDetailsFromUser as Wr,isUnifiedWallet as Ti,PrivyClientError as X}from"@privy-io/js-sdk-core";var Di=()=>{let e=U(),t=W(),r=Fi(()=>{let n=Wr(e);if(!n)return[];let s=dt(e),{entropyId:i,entropyIdVerifier:c}=n;return s.map(d=>({address:d.address,walletIndex:d.wallet_index,publicKey:d.public_key,chainType:d.chain_type,getProvider:()=>Ti(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:i,entropyIdVerifier:c})}))},[t,e]),o=Mi(i=>l(void 0,[i],function*({chainType:n,createAdditional:s=!1}){var f;let c=t.app.getConfig();if(((f=c==null?void 0:c.embedded_wallet_config)==null?void 0:f.mode)==="user-controlled-server-wallets-only")throw n==="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 (${n}) 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(),a=Wr(d);if(!a)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:p}=a,m=dt(d).filter(w=>w.chain_type===n);if(!s&&m.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 g=m.length===0?0:Math.max(...m.map(w=>w.wallet_index),0)+1,h=yield t.embeddedWallet.add({chainType:n,hdWalletIndex:g,entropyId:u,entropyIdVerifier:p}),v=dt(h.user).find(w=>w.chain_type===n&&w.wallet_index===g);if(!h.user||!v)throw new X({code:"embedded_wallet_creation_error",error:"Unknown error creating wallet"});return{user:h.user,provider:yield t.embeddedWallet.getBitcoinProvider({wallet:v,entropyId:u,entropyIdVerifier:p})}}),[t]);return{wallets:r,create:o}};import{useContext as Ni}from"react";var lt=()=>{let{isReady:e,logout:t,getAccessToken:r,error:o,client:n}=Ni(y);return{user:U(),isReady:e,error:o,logout:t,getAccessToken:r,refreshUser:()=>n.user.refreshUser()}};import{useContext as zi}from"react";function ji(){let{client:e}=zi(y);return{acceptTerms:()=>l(this,null,function*(){return e.user.acceptTerms()})}}import{useMemo as Vi}from"react";import{generateAuthorizationSignature as Ki}from"@privy-io/js-sdk-core";var Gi=()=>{let e=W();return Vi(()=>({generateAuthorizationSignature(r){return l(this,null,function*(){let{signature:o}=yield Ki((...n)=>e.embeddedWallet.signWithUserSigner(...n),r);return{signature:o}})}}),[e])};import{useContext as qi,useMemo as Bi}from"react";import{GetEncryptedAuthorizationKey as Hi}from"@privy-io/routes";var Sy=()=>{let{client:e}=qi(y);return Bi(()=>({getEncryptedAuthorizationKey:({id:t})=>e.fetchPrivyRoute(Hi,{params:{encrypted_authorization_key_id:t}})}),[e])};import{useCallback as Ji}from"react";import{createWalletClient as $i,getAddress as Ar,http as Qi,parseSignature as Yi,zeroAddress as Xi}from"viem";import{hashAuthorization as Zi}from"viem/utils";import{getAllUserEmbeddedEthereumWallets as es,getJsonRpcEndpointFromChain as ts}from"@privy-io/js-sdk-core";var rs=()=>{let e=U(),{wallets:t}=ct(),r=W();return{signAuthorization:Ji((n,s)=>l(void 0,null,function*(){var p,m,g;if(!e)throw new Error("User must be authenticated before signing with a Privy wallet");let i=(g=(m=s==null?void 0:s.address)!=null?m:(p=es(e)[0])==null?void 0:p.address)!=null?g:Xi,c=t.find(h=>Ar(h.address)===Ar(i));if(!c)throw new Error("Signing wallet not found.");let d;if(n.chainId===0){if(n.nonce===void 0)throw new Error("nonce is required when chainId is 0 \u2014 chain-agnostic authorizations are replayable across networks");d={chainId:0,address:n.contractAddress,nonce:n.nonce}}else{let v=r.embeddedWallet.chains.find(S=>S.id===n.chainId);if(!v)throw new Error("Error, chain not configured in PrivyProvider config");let f=ts(v,{},r.app.appId);d=yield $i({account:i,chain:v,transport:Qi(f)}).prepareAuthorization(_({},n))}let u=yield(yield c.getProvider()).request({method:"secp256k1_sign",params:[Zi(d)]});return _(_({},d),Yi(u))}),[t,e,r])}};import{useMemo as os}from"react";import{transfer as ns}from"@privy-io/js-sdk-core";var is=()=>{let e=W();return os(()=>({transfer:(t,r)=>ns(e,(...o)=>e.embeddedWallet.signWithUserSigner(...o),_({wallet_id:t},r))}),[e])};import{useMemo as ss}from"react";import{getWalletAction as as,listWalletActions as cs}from"@privy-io/js-sdk-core";var ds=()=>{let e=W();return ss(()=>({getAction:(t,r)=>as(e,{wallet_id:t,action_id:r}),listActions:(t,r)=>cs(e,_({wallet_id:t},r))}),[e])};import{useMemo as ls}from"react";var us=()=>{let e=Wt();return ls(()=>({users:e}),[e])};import{useMemo as ps}from"react";var ms=()=>{let e=W();return ps(()=>({switchUser:r=>l(void 0,[r],function*({userId:t}){return yield e.user.switchActiveUser({userId:t})})}),[e])};import{useCallback as vs}from"react";import{PrivyClientError as bs}from"@privy-io/js-sdk-core";import{getAllUserEmbeddedBitcoinWallets as ys,getUserEmbeddedEthereumWallet as fs,getUserEmbeddedSolanaWallet as gs,isEmbeddedWalletAccount as hs,isUnifiedWallet as ws}from"@privy-io/js-sdk-core";function xr(e,t){return l(this,null,function*(){var n;let r=(n=fs(t))!=null?n:gs(t);if(!r||ws(r))return{success:!0,migrated:!1};if(r.imported)throw new Error("Imported wallets cannot be migrated");if(ys(t).length>0)throw new Error("Bitcoin wallets cannot be migrated");let o=t.linked_accounts.filter(hs).filter(s=>!s.imported).filter(s=>s.chain_type==="ethereum"||s.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:o.map(s=>({address:s.address,chainType:s.chain_type,walletIndex:s.wallet_index}))}),yield e.user.get(),{success:!0,migrated:!0}})}var Pr=()=>{let e=W();return{migrate:vs(()=>l(void 0,null,function*(){var s;let r=b(),o=e.app.getConfig();if(((s=o==null?void 0:o.embedded_wallet_config)==null?void 0:s.mode)!=="user-controlled-server-wallets-only")return{success:!0};if(!r)throw new bs({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before migrating wallets"});return xr(e,r)}),[e])}};var Ur=({disabled:e})=>{let{migrate:t}=Pr(),{user:r}=lt(),o=Cs(!1);return Ss(()=>{e||r&&(o.current||(o.current=!0,t().then(n=>{n.migrated&&!o.current&&(console.info("Migrated wallets for user"),o.current=!0)}).catch(n=>{console.debug("Unable to migrate wallets: ",n)}).finally(()=>{o.current=!1})))},[t,r,e]),null};var y=_s(null),ee;function Cg(e){return ee?ee.getAccessToken():e!=null&&e.strict?Promise.reject(new Or({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 Eg=e=>{var yt,ft,gt;As();let[t,r]=L(Ir.currentState==="active");Rr(()=>{let O=Ir.addEventListener("change",jr=>{r(jr==="active")});return()=>{O.remove()}},[]),Rr(()=>Ct(e.config),[e.config]);let[o,n]=L(!1),[s,i]=L(null),[c,d]=L(!1),[a,u]=L({status:"disconnected",account:null}),[p,m]=L({status:"disconnected"}),[g,h]=L({status:"initial"}),[v,f]=L({status:"initial"}),[w,S]=L({status:"initial"}),[E,k]=L({status:"initial"}),[A,P]=L({status:"initial"}),[F,me]=L({status:"initial"}),[ye,Te]=L({status:"initial"}),te=pe({}),De=pe({}),Ne=pe({}),pt=pe({}),mt=pe({}),fe=Fe(O=>{if(O){je(O),i(null);return}je(null),h({status:"initial"}),f({status:"initial"}),u({status:"disconnected",account:null})},[]),I=Es(()=>{let O=e.storage||ge;return e.client?ee=e.client:ee=St({appId:e.appId,clientId:e.clientId,supportedChains:e.supportedChains,storage:O,baseUrl:e.baseUrl,logLevel:e.logLevel}),ee.setCallbacks({setUser:fe,setIsReady:d,setStoredUsers:kt}),ee},[e.client,e.storage,e.appId,e.clientId,e.baseUrl,e.supportedChains,e.logLevel,fe]),Lr=Fe(()=>l(void 0,null,function*(){let O=b();yield I.auth.logout(O?{userId:O==null?void 0:O.id}:void 0),fe(null)}),[fe,I]),Mr=Fe(()=>l(void 0,null,function*(){try{return yield I.getAccessToken()}catch(O){return console.debug(O),null}}),[I]),Fr=Fe(()=>I.getIdentityToken(),[I]);Ht({client:I,isUserInitialized:o,setIsUserInitialized:n,setError:i});let Tr=Vt({client:I,appId:e.appId,createWalletCallbacks:te,recoverWalletCallbacks:De,setWalletRecoveryCallbacks:Ne,setRecoveryFlowState:S,wallet:a,setWallet:u}),Dr=Ot({client:I,createSolanaWalletCallbacks:pt,recoverSolanaWalletCallbacks:mt,setSolanaRecoveryFlowState:k,solanaWallet:p,setSolanaWallet:m});qt({client:I,createWalletCallbacks:te,recoverWalletCallbacks:De,setWalletRecoveryCallbacks:Ne,recoveryFlowState:w,oAuthState:v,setRecoveryFlowState:S,setWallet:u,appStateVisible:t});let{customAuthStateIsSettled:Nr}=Gt({client:I,isReady:o}),zr=j();return Z.createElement(Z.Fragment,null,Z.createElement(y.Provider,{value:{client:I,isReady:zr&&o&&Nr,error:s,logout:Lr,getAccessToken:Mr,getIdentityToken:Fr,wallet:_(_({},a),Tr),solanaWallet:_(_({},p),Dr),oAuthState:v,recoveryFlowState:w,setRecoveryFlowState:S,solanaRecoveryFlowState:E,setSolanaRecoveryFlowState:k,createWalletCallbacks:te,recoverWalletCallbacks:De,setWalletRecoveryCallbacks:Ne,createSolanaWalletCallbacks:pt,recoverSolanaWalletCallbacks:mt,setOAuthState:f,siweState:A,setSiweState:P,otpState:g,setOtpState:h,passkeyState:F,setPasskeyState:me,farcasterState:ye,setFarcasterState:Te}},e.children,Z.createElement(Ur,{disabled:(gt=(ft=(yt=e.config)==null?void 0:yt.embedded)==null?void 0:ft.disableAutomaticMigration)!=null?gt:!1})),Z.createElement(Ws,{style:{width:0,height:0,overflow:"hidden"}},Z.createElement(At,{client:I,isClientReady:c})))},As=()=>{if(ks(y))throw new Or({code:"configuration_error",error:"Found multiple instances of PrivyProvider, ensure there is only one mounted in your application tree."})};var Rg=e=>{let{client:t,setSiweState:r,siweState:o}=xs(y),n=ut(c=>{var a;let d=C(c);return r({status:"error",error:d}),(a=e==null?void 0:e.onError)==null||a.call(e,d),d},[e==null?void 0:e.onError]),s=ut(u=>l(void 0,[u],function*({wallet:c,from:{domain:d,uri:a}}){var p;try{r({status:"generating-message"});let m=yield t.auth.siwe.init(c,d,a);return r({status:"awaiting-signature"}),(p=e==null?void 0:e.onGenerateMessage)==null||p.call(e,m.message),m.message}catch(m){throw n(m)}}),[t,n,e==null?void 0:e.onGenerateMessage]),i=ut(a=>l(void 0,[a],function*({signature:c,messageOverride:d}){var u;try{if(!b())throw new Ps({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:m}=yield t.auth.siwe.linkWithSiwe(c,void 0,d);return r({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,m),m}catch(p){throw n(p)}}),[t,n,e==null?void 0:e.onSuccess]);return{generateSiweMessage:s,linkWithSiwe:i,state:o}};export{x as a,b,Bs as c,U as d,Hs as e,Gr as f,ke as g,C as h,H as i,St as j,Rg as k,Dc as l,W as m,$c as n,nd as o,pd as p,bd as q,Wd as r,Md as s,Kd as t,Xd as u,sl as v,pl as w,Sl as x,Rl as y,Tl as z,Vl as A,Jl as B,ou as C,du as D,fu as E,Cu as F,Ou as G,ju as H,$u as I,rp as J,dp as K,hp as L,Wp as M,ot as N,Lp as O,Dp as P,Bp as Q,Xp as R,gi as S,it as T,hm as U,Em as V,xm as W,Om as X,zm as Y,ct as Z,Li as _,Di as $,lt as aa,ji as ba,Gi as ca,Sy as da,rs as ea,is as fa,ds as ga,us as ha,ms as ia,Pr as ja,y as ka,Cg as la,Eg as ma};
@@ -1 +1 @@
1
- import{b as u,m as i}from"./chunk-N6UEERFL.js";import{e as a}from"./chunk-K5SPDXVF.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,m as i}from"./chunk-SMZX5SMH.js";import{e as a}from"./chunk-K5SPDXVF.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 bt,b as Dt,c as Gt,d as jt,e as Et,f as _t,g as Bt,h as Mt}from"./chunk-QSWCX5XI.js";import{a as f,b as I}from"./chunk-EKNB3A2Z.js";import{$ as It,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 ft,L as At,M as Ot,N as ct,O as mt,P as kt,Q as lt,R as yt,V as xt,W as dt,X as Ut,Y as Pt,Z as vt,_ as wt,aa as d,ba as Tt,ca as gt,da as Ft,e as y,ea as St,f as G,fa as Lt,ga as Wt,h as x,ha as Rt,ia as Ht,j as v,ja as w,k as j,ka as a,l as E,la as Ct,m as _,ma as Nt,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-N6UEERFL.js";import{b as m,c as k,e as l,h as P}from"./chunk-K5SPDXVF.js";export*from"@privy-io/js-sdk-core";import r from"react";var Kt=({loading:t,error:e,unauthenticated:o,children:i})=>{let{isReady:u,error:p}=d(),U=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 U?r.createElement(r.Fragment,null,i):r.createElement(r.Fragment,null,o)};import{createDataSuffixPlugin as T}from"@privy-io/js-sdk-core";function g(t){return f(t)}function F(t){let{state:e,start:o}=f(k(m({},t),{action:"link"}));return{state:e,link:o}}import{useCallback as S,useContext as L,useEffect as W,useRef as R}from"react";var H=t=>{let{client:e}=L(a),o=R(t);return W(()=>{o.current=t},[t]),{unlinkOAuth:S(U=>l(void 0,[U],function*({provider:u,subject:p}){var n,A,s,O;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 c=x(h);throw(O=(s=o.current)==null?void 0:s.onError)==null||O.call(s,c),c}}),[e.auth.oauth])}};import{useContext as C,useEffect as N,useRef as b}from"react";var D=t=>{let{client:e}=C(a),o=b(t.onOAuthTokenGrant);o.current=t.onOAuthTokenGrant,N(()=>{let{unsubscribe:i}=e.addOAuthTokensListener(u=>{o.current(u)});return i},[e])};export{Kt as AuthBoundary,a as PrivyContext,Nt as PrivyProvider,P as SecureStorageAdapter,v as createPrivyClient,T as dataSuffix,Ct as getAccessToken,Bt as hasError,bt as isConnected,Gt as isConnecting,_t as isCreating,jt as isDisconnected,Et as isNotCreated,Dt as isReconnecting,Mt as needsRecovery,Tt as useAcceptTerms,gt as useAuthorizationSignature,lt as useCreateGuestAccount,et as useDepositAddress,It as useEmbeddedBitcoinWallet,vt as useEmbeddedEthereumWallet,wt as useEmbeddedSolanaWallet,ct as useEmbeddedWallet,mt as useEmbeddedWalletStateChange,Ft as useGetEncryptedAuthorizationKey,ot as useHeadlessCryptoDeposit,tt as useHeadlessDelegatedActions,kt as useIdentityToken,Pt as useImportWallet,z as useLinkEmail,Q as useLinkSMS,st as useLinkWithCrossApp,X as useLinkWithFarcaster,F as useLinkWithOAuth,j as useLinkWithSiwe,B as useLinkWithSiws,pt as useLoginWithCrossApp,K as useLoginWithEmail,Z as useLoginWithFarcaster,$ as useLoginWithFarcasterV2,I as useLoginWithOAuth,V as useLoginWithSMS,E as useLoginWithSiwe,M as useLoginWithSiws,xt as useMfa,dt as useMfaEnrollment,w as useMigrateWallets,g as useOAuthFlow,D as useOAuthTokens,G as useOnNeedsRecovery,d as usePrivy,_ as usePrivyClient,Ot as useRecoverEmbeddedWallet,yt as useRegisterMfaListener,ft as useSendTransactionWithCrossApp,rt as useSessionSigners,At as useSetEmbeddedWalletRecovery,St as useSign7702Authorization,ht as useSignMessageWithCrossApp,at as useSignTypedDataWithCrossApp,nt as useSigners,Rt as useStoredUsers,Ht as useSwitchUser,Lt as useTransfer,J as useUnlinkEmail,Y as useUnlinkFarcaster,H as useUnlinkOAuth,Ut as useUnlinkPasskey,q as useUnlinkWallet,ut as useUpdateEmail,it as useUpdatePhone,Wt as useWalletActions};
1
+ import{a as bt,b as Dt,c as Gt,d as jt,e as Et,f as _t,g as Bt,h as Mt}from"./chunk-QSWCX5XI.js";import{a as f,b as I}from"./chunk-N2TBAO4F.js";import{$ as It,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 ft,L as At,M as Ot,N as ct,O as mt,P as kt,Q as lt,R as yt,V as xt,W as dt,X as Ut,Y as Pt,Z as vt,_ as wt,aa as d,ba as Tt,ca as gt,da as Ft,e as y,ea as St,f as G,fa as Lt,ga as Wt,h as x,ha as Rt,ia as Ht,j as v,ja as w,k as j,ka as a,l as E,la as Ct,m as _,ma as Nt,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-SMZX5SMH.js";import{b as m,c as k,e as l,h as P}from"./chunk-K5SPDXVF.js";export*from"@privy-io/js-sdk-core";import r from"react";var Kt=({loading:t,error:e,unauthenticated:o,children:i})=>{let{isReady:u,error:p}=d(),U=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 U?r.createElement(r.Fragment,null,i):r.createElement(r.Fragment,null,o)};import{createDataSuffixPlugin as T}from"@privy-io/js-sdk-core";function g(t){return f(t)}function F(t){let{state:e,start:o}=f(k(m({},t),{action:"link"}));return{state:e,link:o}}import{useCallback as S,useContext as L,useEffect as W,useRef as R}from"react";var H=t=>{let{client:e}=L(a),o=R(t);return W(()=>{o.current=t},[t]),{unlinkOAuth:S(U=>l(void 0,[U],function*({provider:u,subject:p}){var n,A,s,O;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 c=x(h);throw(O=(s=o.current)==null?void 0:s.onError)==null||O.call(s,c),c}}),[e.auth.oauth])}};import{useContext as C,useEffect as N,useRef as b}from"react";var D=t=>{let{client:e}=C(a),o=b(t.onOAuthTokenGrant);o.current=t.onOAuthTokenGrant,N(()=>{let{unsubscribe:i}=e.addOAuthTokensListener(u=>{o.current(u)});return i},[e])};export{Kt as AuthBoundary,a as PrivyContext,Nt as PrivyProvider,P as SecureStorageAdapter,v as createPrivyClient,T as dataSuffix,Ct as getAccessToken,Bt as hasError,bt as isConnected,Gt as isConnecting,_t as isCreating,jt as isDisconnected,Et as isNotCreated,Dt as isReconnecting,Mt as needsRecovery,Tt as useAcceptTerms,gt as useAuthorizationSignature,lt as useCreateGuestAccount,et as useDepositAddress,It as useEmbeddedBitcoinWallet,vt as useEmbeddedEthereumWallet,wt as useEmbeddedSolanaWallet,ct as useEmbeddedWallet,mt as useEmbeddedWalletStateChange,Ft as useGetEncryptedAuthorizationKey,ot as useHeadlessCryptoDeposit,tt as useHeadlessDelegatedActions,kt as useIdentityToken,Pt as useImportWallet,z as useLinkEmail,Q as useLinkSMS,st as useLinkWithCrossApp,X as useLinkWithFarcaster,F as useLinkWithOAuth,j as useLinkWithSiwe,B as useLinkWithSiws,pt as useLoginWithCrossApp,K as useLoginWithEmail,Z as useLoginWithFarcaster,$ as useLoginWithFarcasterV2,I as useLoginWithOAuth,V as useLoginWithSMS,E as useLoginWithSiwe,M as useLoginWithSiws,xt as useMfa,dt as useMfaEnrollment,w as useMigrateWallets,g as useOAuthFlow,D as useOAuthTokens,G as useOnNeedsRecovery,d as usePrivy,_ as usePrivyClient,Ot as useRecoverEmbeddedWallet,yt as useRegisterMfaListener,ft as useSendTransactionWithCrossApp,rt as useSessionSigners,At as useSetEmbeddedWalletRecovery,St as useSign7702Authorization,ht as useSignMessageWithCrossApp,at as useSignTypedDataWithCrossApp,nt as useSigners,Rt as useStoredUsers,Ht as useSwitchUser,Lt as useTransfer,J as useUnlinkEmail,Y as useUnlinkFarcaster,H as useUnlinkOAuth,Ut as useUnlinkPasskey,q as useUnlinkWallet,ut as useUpdateEmail,it as useUpdatePhone,Wt as useWalletActions};
@@ -1 +1 @@
1
- import{a as K,b as N,c as V,d as D,e as F,f as T,g as M,h as j}from"./chunk-QSWCX5XI.js";import{S,T as x,U as w,a as C,b as p,h as g,ka as h}from"./chunk-N6UEERFL.js";import{e as m}from"./chunk-K5SPDXVF.js";import{useCallback as W,useContext as R}from"react";import{PrivyClientError as v}from"@privy-io/js-sdk-core";var Y=e=>{let{client:a,passkeyState:P,setPasskeyState:s}=R(h),c=W(o=>{var n;let r=g(o);return s({status:"error",error:r}),(n=e==null?void 0:e.onError)==null||n.call(e,r),r},[e==null?void 0:e.onError]);return{linkWithPasskey:W(n=>m(void 0,[n],function*({relyingParty:o,extra_options:r}){var u;try{if(!p())throw new v({code:"attempted_link_passkey_before_logged_in",error:"Must be logged in to link a passkey."});s({status:"generating-challenege"});let{options:k}=yield a.auth.passkey.generateRegistrationOptions(o);s({status:"awaiting-passkey"});let y=yield S(w(k),r);s({status:"submitting-response"});let{user:l}=yield a.auth.passkey.linkWithPasskey(y,o);return s({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,l),l}catch(t){throw c(t)}}),[a,c,e==null?void 0:e.onSuccess]),state:P}};import{useCallback as O,useContext as H}from"react";import{PrivyClientError as I}from"@privy-io/js-sdk-core";var ie=e=>{let{client:a,passkeyState:P,setPasskeyState:s}=H(h),c=O(o=>{var n;let r=g(o);return s({status:"error",error:r}),(n=e==null?void 0:e.onError)==null||n.call(e,r),r},[e==null?void 0:e.onError]);return{loginWithPasskey:O(n=>m(void 0,[n],function*({relyingParty:o,extra_options:r}){var u,t,k,y;try{if(p())throw new I({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 a.auth.passkey.generateAuthenticationOptions(o);s({status:"awaiting-passkey"});let f=yield x({challenge:i.challenge,rpId:i.rp_id,extensions:{appid:(u=i.extensions)==null?void 0:u.app_id,credProps:(t=i.extensions)==null?void 0:t.cred_props,hmacCreateSecret:(k=i.extensions)==null?void 0:k.hmac_create_secret},timeout:i.timeout,allowCredentials:i.allow_credentials,userVerification:i.user_verification},r);s({status:"submitting-response"});let _=C(),b=yield a.auth.passkey.loginWithPasskey(f,i.challenge,o,{embedded:_==null?void 0:_.embedded});return s({status:"done"}),(y=e==null?void 0:e.onSuccess)==null||y.call(e,b.user,b.is_new_user),b.user}catch(l){throw c(l)}}),[a,c,e==null?void 0:e.onSuccess]),state:P}};import{useCallback as U,useContext as L,useEffect as A,useRef as q}from"react";import{PrivyClientError as J}from"@privy-io/js-sdk-core";var pe=e=>{let{client:a,passkeyState:P,setPasskeyState:s}=L(h),c=q(e);A(()=>{c.current=e},[e]);let d=U(r=>{var u,t;let n=g(r);return s({status:"error",error:n}),(t=(u=c.current)==null?void 0:u.onError)==null||t.call(u,n),n},[s]);return{signupWithPasskey:U(u=>m(void 0,[u],function*({relyingParty:r,extra_options:n}){var t,k;try{if(p())throw new J({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:l}=yield a.auth.passkey.generateSignupOptions(r);s({status:"awaiting-passkey"});let i=yield S(w(l),n);s({status:"submitting-response"});let f=yield a.auth.passkey.signupWithPasskey(i,r);return s({status:"done"}),(k=(t=c.current)==null?void 0:t.onSuccess)==null||k.call(t,f.user,f.is_new_user),{user:f.user}}catch(y){throw d(y)}}),[a.auth.passkey,d,s]),state:P}};export{M as hasError,K as isConnected,V as isConnecting,T as isCreating,D as isDisconnected,F as isNotCreated,N as isReconnecting,j as needsRecovery,Y as useLinkWithPasskey,ie as useLoginWithPasskey,pe as useSignupWithPasskey};
1
+ import{a as K,b as N,c as V,d as D,e as F,f as T,g as M,h as j}from"./chunk-QSWCX5XI.js";import{S,T as x,U as w,a as C,b as p,h as g,ka as h}from"./chunk-SMZX5SMH.js";import{e as m}from"./chunk-K5SPDXVF.js";import{useCallback as W,useContext as R}from"react";import{PrivyClientError as v}from"@privy-io/js-sdk-core";var Y=e=>{let{client:a,passkeyState:P,setPasskeyState:s}=R(h),c=W(o=>{var n;let r=g(o);return s({status:"error",error:r}),(n=e==null?void 0:e.onError)==null||n.call(e,r),r},[e==null?void 0:e.onError]);return{linkWithPasskey:W(n=>m(void 0,[n],function*({relyingParty:o,extra_options:r}){var u;try{if(!p())throw new v({code:"attempted_link_passkey_before_logged_in",error:"Must be logged in to link a passkey."});s({status:"generating-challenege"});let{options:k}=yield a.auth.passkey.generateRegistrationOptions(o);s({status:"awaiting-passkey"});let y=yield S(w(k),r);s({status:"submitting-response"});let{user:l}=yield a.auth.passkey.linkWithPasskey(y,o);return s({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,l),l}catch(t){throw c(t)}}),[a,c,e==null?void 0:e.onSuccess]),state:P}};import{useCallback as O,useContext as H}from"react";import{PrivyClientError as I}from"@privy-io/js-sdk-core";var ie=e=>{let{client:a,passkeyState:P,setPasskeyState:s}=H(h),c=O(o=>{var n;let r=g(o);return s({status:"error",error:r}),(n=e==null?void 0:e.onError)==null||n.call(e,r),r},[e==null?void 0:e.onError]);return{loginWithPasskey:O(n=>m(void 0,[n],function*({relyingParty:o,extra_options:r}){var u,t,k,y;try{if(p())throw new I({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 a.auth.passkey.generateAuthenticationOptions(o);s({status:"awaiting-passkey"});let f=yield x({challenge:i.challenge,rpId:i.rp_id,extensions:{appid:(u=i.extensions)==null?void 0:u.app_id,credProps:(t=i.extensions)==null?void 0:t.cred_props,hmacCreateSecret:(k=i.extensions)==null?void 0:k.hmac_create_secret},timeout:i.timeout,allowCredentials:i.allow_credentials,userVerification:i.user_verification},r);s({status:"submitting-response"});let _=C(),b=yield a.auth.passkey.loginWithPasskey(f,i.challenge,o,{embedded:_==null?void 0:_.embedded});return s({status:"done"}),(y=e==null?void 0:e.onSuccess)==null||y.call(e,b.user,b.is_new_user),b.user}catch(l){throw c(l)}}),[a,c,e==null?void 0:e.onSuccess]),state:P}};import{useCallback as U,useContext as L,useEffect as A,useRef as q}from"react";import{PrivyClientError as J}from"@privy-io/js-sdk-core";var pe=e=>{let{client:a,passkeyState:P,setPasskeyState:s}=L(h),c=q(e);A(()=>{c.current=e},[e]);let d=U(r=>{var u,t;let n=g(r);return s({status:"error",error:n}),(t=(u=c.current)==null?void 0:u.onError)==null||t.call(u,n),n},[s]);return{signupWithPasskey:U(u=>m(void 0,[u],function*({relyingParty:r,extra_options:n}){var t,k;try{if(p())throw new J({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:l}=yield a.auth.passkey.generateSignupOptions(r);s({status:"awaiting-passkey"});let i=yield S(w(l),n);s({status:"submitting-response"});let f=yield a.auth.passkey.signupWithPasskey(i,r);return s({status:"done"}),(k=(t=c.current)==null?void 0:t.onSuccess)==null||k.call(t,f.user,f.is_new_user),{user:f.user}}catch(y){throw d(y)}}),[a.auth.passkey,d,s]),state:P}};export{M as hasError,K as isConnected,V as isConnecting,T as isCreating,D as isDisconnected,F as isNotCreated,N as isReconnecting,j as needsRecovery,Y as useLinkWithPasskey,ie as useLoginWithPasskey,pe as useSignupWithPasskey};
@@ -1 +1 @@
1
- import{a as M}from"./chunk-QSWCX5XI.js";import{b as _,d as g,i as v,ka as w,m as k}from"./chunk-N6UEERFL.js";import{a as h,b as A,c as I,e as m}from"./chunk-K5SPDXVF.js";import p,{createContext as x,useCallback as Z,useContext as f,useEffect as T,useState as L}from"react";import{getDataSuffixPlugin as O,getUserSmartWallet as S,PrivyClientError as u}from"@privy-io/js-sdk-core";import{createPublicClient as Y,http as H}from"viem";import{getJsonRpcEndpointFromChain as X,getUserSmartWallet as j,PrivyClientError as N}from"@privy-io/js-sdk-core";import{signerToSmartAccountClient as J}from"@privy-io/js-sdk-core/smart-wallets";var P=y=>m(void 0,[y],function*({chain:t,privyAppId:e,user:a,embeddedWallet:r,smartWalletsConfig:n,client:i,dataSuffix:c}){if(!(n!=null&&n.enabled)||!r||!M(r))return;let s=yield i.embeddedWallet.getProvider(r.account),o=n==null?void 0:n.configured_networks.find(B=>B.chain_id===`eip155:${t.id}`);if(!o)throw new N({code:"chain_not_supported",error:`The chain ${t.name} (eip155:${t.id}) must be configured in the smart wallet configuration in your dashboard`});let l=j(a),C=l?l.smart_wallet_type:n.smart_wallet_type,W=l?l.smart_wallet_version:n.smart_wallet_version,F=X(t,{rpcUrls:[]},e),G=Y({chain:t,transport:H(F)}),E=yield J({owner:s,smartWalletType:C,smartWalletVersion:W,chain:t,publicClient:G,paymasterContext:Q(o.paymaster_url,o.paymaster_context),bundlerUrl:o.bundler_url,paymasterUrl:o.paymaster_url});if(!E)throw new N({code:"smart_wallet_client_error",error:`Failed to create smart wallet client for chain ${t.name} (eip155:${t.id})`});return K(E,c)});function K(t,e){return e?t.extend(a=>({sendTransaction:r=>a.sendTransaction(I(A({},r),{dataSuffix:e}))})):t}var V=/paymaster\.biconomy\.io\/api/i;function q(t){return V.test(t)}var z={mode:"SPONSORED",calculateGasLimits:!0,expiryDuration:300,sponsorshipInfo:{webhookData:{},smartAccountInfo:{name:"BICONOMY",version:"2.0.0"}}},Q=(t,e)=>{if(t&&q(t))return z;if(e&&e.policy_id)return{policyId:e.policy_id}};var U=3,tt=500,et=({children:t})=>p.createElement(at,null,p.createElement(it,null,p.createElement(lt,null,t))),D=x({config:void 0}),b=()=>{let{config:t}=f(D);return{config:t}},R=x({smartWalletClient:void 0}),rt=()=>{let{smartWalletClient:t}=f(R);return{smartWalletClient:t}},$=x({client:void 0}),nt=()=>{let{client:t}=f($),e=ot();return{client:t,getClientForChain:e}},at=({children:t})=>{let[e,a]=L(void 0),r=k();return T(()=>{!e&&r&&(()=>m(void 0,null,function*(){try{if(!r){console.warn("No client found");return}let i=yield r.app.getSmartWalletConfig();a(i)}catch(i){console.warn("Error generating smart wallet config: ",i)}}))()},[r,e]),p.createElement(D.Provider,{value:{config:e}},t)},it=({children:t})=>{let{config:e}=b(),{client:a,wallet:r}=f(w),n=g(),[i,c]=L();return T(()=>{(()=>m(void 0,null,function*(){var l;if(!n&&i&&c(void 0),!(e!=null&&e.enabled)||!n||r.status!=="connected"||n&&i&&r.status==="connected")return;let s=a.embeddedWallet.chains.find(C=>e.configured_networks.map(W=>W.chain_id).includes(`eip155:${C.id}`));if(!s)throw new u({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 o=yield P({chain:s,privyAppId:a.app.appId,user:n,embeddedWallet:r,smartWalletsConfig:e,client:a,dataSuffix:(l=O(a.plugins))==null?void 0:l.suffix});if(!o)throw new u({error:"Could not create smart wallet client",code:"smart_wallet_client_error"});c(o)}))()},[!!(e!=null&&e.enabled),!!a,!!n,r.status]),p.createElement(R.Provider,{value:{smartWalletClient:i}},t)},lt=({children:t})=>{let{client:e,wallet:a}=f(w),r=g(),{smartWalletClient:n}=rt(),{config:i}=b();return T(()=>{let c=!1;return(()=>m(void 0,null,function*(){var d;if(!(!n||!r||S(r)||!(i!=null&&i.enabled)||a.status!=="connected"))for(let s=0;s<U;s++){if(c||S((d=_())!=null?d:r))return;let o=!1;for(let l=0;l<5;l++){if(c)return;if(yield e.embeddedWallet.ping(tt)){o=!0;break}yield v(200*h(2,l))}if(o)try{let{message:l}=yield e.auth.smartWallet.init({address:n.account.address,chainId:`eip155:${n.chain.id}`}),C=yield n.signMessage({message:l});yield e.auth.smartWallet.link(l,C,i.smart_wallet_type,i.smart_wallet_version);return}catch(l){s===U-1?console.error("Error creating smart wallet:",l):yield v(500*h(2,s))}}}))(),()=>{c=!0}},[!!n,!!r,!!S(r),i,a.status]),p.createElement($.Provider,{value:{client:S(r)?n:void 0}},t)},ot=()=>{let{client:t,wallet:e}=f(w),{config:a}=b();return Z(n=>m(void 0,[n],function*({chainId:r}){var s;let i=_();if(!i)throw new u({error:"Must be logged in to get a smart wallet client",code:"smart_wallet_client_error"});if(!a||!a.enabled)throw new u({error:"Must have smart wallets enabled to get a smart wallet client",code:"smart_wallet_client_error"});let y=t.embeddedWallet.chains.find(o=>o.id===r);if(!y)throw new u({error:`Could not find chain with id: ${r}`,code:"chain_not_supported"});let d=yield P({chain:y,privyAppId:t.app.appId,user:i,embeddedWallet:e,smartWalletsConfig:a,client:t,dataSuffix:(s=O(t.plugins))==null?void 0:s.suffix});if(!d)throw new u({error:`Could not create smart wallet client for chain ${r}`,code:"smart_wallet_client_error"});return d}),[a,e,t])};export{et as SmartWalletsProvider,nt as useSmartWallets};
1
+ import{a as M}from"./chunk-QSWCX5XI.js";import{b as _,d as g,i as v,ka as w,m as k}from"./chunk-SMZX5SMH.js";import{a as h,b as A,c as I,e as m}from"./chunk-K5SPDXVF.js";import p,{createContext as x,useCallback as Z,useContext as f,useEffect as T,useState as L}from"react";import{getDataSuffixPlugin as O,getUserSmartWallet as S,PrivyClientError as u}from"@privy-io/js-sdk-core";import{createPublicClient as Y,http as H}from"viem";import{getJsonRpcEndpointFromChain as X,getUserSmartWallet as j,PrivyClientError as N}from"@privy-io/js-sdk-core";import{signerToSmartAccountClient as J}from"@privy-io/js-sdk-core/smart-wallets";var P=y=>m(void 0,[y],function*({chain:t,privyAppId:e,user:a,embeddedWallet:r,smartWalletsConfig:n,client:i,dataSuffix:c}){if(!(n!=null&&n.enabled)||!r||!M(r))return;let s=yield i.embeddedWallet.getProvider(r.account),o=n==null?void 0:n.configured_networks.find(B=>B.chain_id===`eip155:${t.id}`);if(!o)throw new N({code:"chain_not_supported",error:`The chain ${t.name} (eip155:${t.id}) must be configured in the smart wallet configuration in your dashboard`});let l=j(a),C=l?l.smart_wallet_type:n.smart_wallet_type,W=l?l.smart_wallet_version:n.smart_wallet_version,F=X(t,{rpcUrls:[]},e),G=Y({chain:t,transport:H(F)}),E=yield J({owner:s,smartWalletType:C,smartWalletVersion:W,chain:t,publicClient:G,paymasterContext:Q(o.paymaster_url,o.paymaster_context),bundlerUrl:o.bundler_url,paymasterUrl:o.paymaster_url});if(!E)throw new N({code:"smart_wallet_client_error",error:`Failed to create smart wallet client for chain ${t.name} (eip155:${t.id})`});return K(E,c)});function K(t,e){return e?t.extend(a=>({sendTransaction:r=>a.sendTransaction(I(A({},r),{dataSuffix:e}))})):t}var V=/paymaster\.biconomy\.io\/api/i;function q(t){return V.test(t)}var z={mode:"SPONSORED",calculateGasLimits:!0,expiryDuration:300,sponsorshipInfo:{webhookData:{},smartAccountInfo:{name:"BICONOMY",version:"2.0.0"}}},Q=(t,e)=>{if(t&&q(t))return z;if(e&&e.policy_id)return{policyId:e.policy_id}};var U=3,tt=500,et=({children:t})=>p.createElement(at,null,p.createElement(it,null,p.createElement(lt,null,t))),D=x({config:void 0}),b=()=>{let{config:t}=f(D);return{config:t}},R=x({smartWalletClient:void 0}),rt=()=>{let{smartWalletClient:t}=f(R);return{smartWalletClient:t}},$=x({client:void 0}),nt=()=>{let{client:t}=f($),e=ot();return{client:t,getClientForChain:e}},at=({children:t})=>{let[e,a]=L(void 0),r=k();return T(()=>{!e&&r&&(()=>m(void 0,null,function*(){try{if(!r){console.warn("No client found");return}let i=yield r.app.getSmartWalletConfig();a(i)}catch(i){console.warn("Error generating smart wallet config: ",i)}}))()},[r,e]),p.createElement(D.Provider,{value:{config:e}},t)},it=({children:t})=>{let{config:e}=b(),{client:a,wallet:r}=f(w),n=g(),[i,c]=L();return T(()=>{(()=>m(void 0,null,function*(){var l;if(!n&&i&&c(void 0),!(e!=null&&e.enabled)||!n||r.status!=="connected"||n&&i&&r.status==="connected")return;let s=a.embeddedWallet.chains.find(C=>e.configured_networks.map(W=>W.chain_id).includes(`eip155:${C.id}`));if(!s)throw new u({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 o=yield P({chain:s,privyAppId:a.app.appId,user:n,embeddedWallet:r,smartWalletsConfig:e,client:a,dataSuffix:(l=O(a.plugins))==null?void 0:l.suffix});if(!o)throw new u({error:"Could not create smart wallet client",code:"smart_wallet_client_error"});c(o)}))()},[!!(e!=null&&e.enabled),!!a,!!n,r.status]),p.createElement(R.Provider,{value:{smartWalletClient:i}},t)},lt=({children:t})=>{let{client:e,wallet:a}=f(w),r=g(),{smartWalletClient:n}=rt(),{config:i}=b();return T(()=>{let c=!1;return(()=>m(void 0,null,function*(){var d;if(!(!n||!r||S(r)||!(i!=null&&i.enabled)||a.status!=="connected"))for(let s=0;s<U;s++){if(c||S((d=_())!=null?d:r))return;let o=!1;for(let l=0;l<5;l++){if(c)return;if(yield e.embeddedWallet.ping(tt)){o=!0;break}yield v(200*h(2,l))}if(o)try{let{message:l}=yield e.auth.smartWallet.init({address:n.account.address,chainId:`eip155:${n.chain.id}`}),C=yield n.signMessage({message:l});yield e.auth.smartWallet.link(l,C,i.smart_wallet_type,i.smart_wallet_version);return}catch(l){s===U-1?console.error("Error creating smart wallet:",l):yield v(500*h(2,s))}}}))(),()=>{c=!0}},[!!n,!!r,!!S(r),i,a.status]),p.createElement($.Provider,{value:{client:S(r)?n:void 0}},t)},ot=()=>{let{client:t,wallet:e}=f(w),{config:a}=b();return Z(n=>m(void 0,[n],function*({chainId:r}){var s;let i=_();if(!i)throw new u({error:"Must be logged in to get a smart wallet client",code:"smart_wallet_client_error"});if(!a||!a.enabled)throw new u({error:"Must have smart wallets enabled to get a smart wallet client",code:"smart_wallet_client_error"});let y=t.embeddedWallet.chains.find(o=>o.id===r);if(!y)throw new u({error:`Could not find chain with id: ${r}`,code:"chain_not_supported"});let d=yield P({chain:y,privyAppId:t.app.appId,user:i,embeddedWallet:e,smartWalletsConfig:a,client:t,dataSuffix:(s=O(t.plugins))==null?void 0:s.suffix});if(!d)throw new u({error:`Could not create smart wallet client for chain ${r}`,code:"smart_wallet_client_error"});return d}),[a,e,t])};export{et as SmartWalletsProvider,nt as useSmartWallets};