@privy-io/expo 0.8.1 → 0.8.2-beta-20240304190232

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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var e=require("@privy-io/js-sdk-core"),t=require("react"),r=require("react-native"),s=require("react-native-webview"),a=require("expo-linking"),n=require("react-fast-compare"),o=require("expo-application"),i=require("expo-secure-store"),l=require("expo-web-browser");function u(e,t){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e}function d(e,t,r,s){Object.defineProperty(e,t,{get:r,set:s,enumerable:!0,configurable:!0})}function c(e){return e&&e.__esModule?e.default:e}d(module.exports,"SecureStorageAdapter",()=>x),d(module.exports,"useOAuthFlow",()=>S),d(module.exports,"useLinkWithOAuth",()=>E),d(module.exports,"useLoginWithOAuth",()=>f);var h={};d(h,"PrivyContext",()=>P),d(h,"PrivyProvider",()=>W);var g={};g=JSON.parse('{"name":"@privy-io/expo","version":"0.8.1","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*","expo-web-browser":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.13.3","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');const w=({client:e,isClientReady:a,setWebViewState:n,webViewState:o})=>{let i=(0,t.useRef)(null);(0,t.useEffect)(()=>{i.current&&"loaded"===o&&e.setMessagePoster(i.current)},[e,i.current,"loaded"===o]),(0,t.useEffect)(()=>{let e=(0,r.AppState).addEventListener("change",e=>{i.current&&"active"===e&&(i.current.reload(),n("reloading"))});return e.remove},[]);let l=(0,t.useCallback)(async t=>{let{data:r}=t.nativeEvent,s=e.embeddedWallet.getMessageHandler();s?.(JSON.parse(r))},[e]);// Ensure we only render the webview once the client is initialized
1
+ var e=require("@privy-io/js-sdk-core"),t=require("react"),r=require("react-native"),s=require("react-native-webview"),a=require("expo-linking"),n=require("react-fast-compare"),o=require("expo-application"),i=require("expo-secure-store"),l=require("expo-web-browser");function u(e,t){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e}function d(e,t,r,s){Object.defineProperty(e,t,{get:r,set:s,enumerable:!0,configurable:!0})}function c(e){return e&&e.__esModule?e.default:e}d(module.exports,"SecureStorageAdapter",()=>x),d(module.exports,"useOAuthFlow",()=>S),d(module.exports,"useLinkWithOAuth",()=>E),d(module.exports,"useLoginWithOAuth",()=>f);var h={};d(h,"PrivyContext",()=>P),d(h,"PrivyProvider",()=>W);var g={};g=JSON.parse('{"name":"@privy-io/expo","version":"0.8.2-beta-20240304190232","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*","expo-web-browser":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.13.4-beta-20240304190232","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');const w=({client:e,isClientReady:a,setWebViewState:n,webViewState:o})=>{let i=(0,t.useRef)(null);(0,t.useEffect)(()=>{i.current&&"loaded"===o&&e.setMessagePoster(i.current)},[e,i.current,"loaded"===o]),(0,t.useEffect)(()=>{let e=(0,r.AppState).addEventListener("change",e=>{i.current&&"active"===e&&(i.current.reload(),n("reloading"))});return e.remove},[]);let l=(0,t.useCallback)(async t=>{let{data:r}=t.nativeEvent,s=e.embeddedWallet.getMessageHandler();s?.(JSON.parse(r))},[e]);// Ensure we only render the webview once the client is initialized
2
2
  return a?c(t).createElement(c(s),{style:{flex:1},ref:i,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>n("loaded"),onError:console.error,onMessage:l}):null},p=({client:r,user:s,wallet:a,setWallet:n,webViewState:o})=>{let i=(0,t.useMemo)(()=>(0,e.getUserEmbeddedWallet)(s),[s]),l=(0,t.useCallback)(async t=>{n({status:"creating"});try{let e=await r.embeddedWallet.create(t);return n({status:"connected",provider:e}),e}catch(r){let t=r instanceof Error?r.message:"Error creating embedded wallet";throw n({status:"error",error:t}),new e.PrivyClientError({code:"embedded_wallet_creation_error",error:t})}},[r]),u=(0,t.useCallback)(async t=>{if("connected"!==a.status)throw new e.PrivyClientError({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"});if(!i)throw new e.PrivyClientError({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if("user-passcode"===i.recovery_method)throw new e.PrivyClientError({code:"attempted_to_set_password_but_password_already_set",error:"Embedded wallet already has a recovery password"});try{let e=await r.embeddedWallet.setPassword(i,t);return n({status:"connected",provider:e}),e}catch(t){throw new e.PrivyClientError({code:"embedded_wallet_set_password_error",error:t instanceof Error?t.message:"Error setting password on embedded wallet"})}},[r,i,a.status]),d=(0,t.useCallback)(async t=>{if(!i)throw new e.PrivyClientError({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});n({status:"connecting"});try{let e=await r.embeddedWallet.getProvider(i,t);return n({status:"connected",provider:e}),e}catch(t){throw n({status:"needs-recovery"}),new e.PrivyClientError({code:"embedded_wallet_recovery_error",error:t instanceof Error?t.message:"Error recovering embedded wallet"})}},[r,i]),c=(0,t.useCallback)(async()=>{// There is a user but no embedded wallet account
3
3
  // We need to create an embedded walert for this user
4
4
  if(!i)throw n({status:"not-created"}),new e.PrivyClientError({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});// There is definitely a user with an embedded wallet so we try to connect
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import e from"@privy-io/js-sdk-core";import t,{createContext as r,useState as i,useRef as a,useCallback as s,useMemo as o,useEffect as n,useContext as d}from"react";import{View as c,AppState as l,Platform as u}from"react-native";import h from"react-native-webview";import{useURL as g,parse as w,openURL as p,createURL as m}from"expo-linking";import y from"react-fast-compare";import{applicationId as b}from"expo-application";import{getItemAsync as f,setItemAsync as _,deleteItemAsync as $}from"expo-secure-store";import{openAuthSessionAsync as v}from"expo-web-browser";function E(e,t,r,i){Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0})}function S(e,t){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e}var C={};E(C,"PrivyContext",()=>z),E(C,"PrivyProvider",()=>V);var x={};x=JSON.parse('{"name":"@privy-io/expo","version":"0.8.1","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*","expo-web-browser":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.13.3","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');let k=({client:e,isClientReady:r,setWebViewState:i,webViewState:o})=>{let d=a(null);n(()=>{d.current&&"loaded"===o&&e.setMessagePoster(d.current)},[e,d.current,"loaded"===o]),n(()=>{let e=l.addEventListener("change",e=>{d.current&&"active"===e&&(d.current.reload(),i("reloading"))});return e.remove},[]);let c=s(async t=>{let{data:r}=t.nativeEvent,i=e.embeddedWallet.getMessageHandler();i?.(JSON.parse(r))},[e]);// Ensure we only render the webview once the client is initialized
1
+ import e from"@privy-io/js-sdk-core";import t,{createContext as r,useState as i,useRef as a,useCallback as s,useMemo as o,useEffect as n,useContext as d}from"react";import{View as c,AppState as l,Platform as u}from"react-native";import h from"react-native-webview";import{useURL as g,parse as w,openURL as p,createURL as m}from"expo-linking";import b from"react-fast-compare";import{applicationId as y}from"expo-application";import{getItemAsync as f,setItemAsync as _,deleteItemAsync as $}from"expo-secure-store";import{openAuthSessionAsync as v}from"expo-web-browser";function E(e,t,r,i){Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0})}function S(e,t){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e}var C={};E(C,"PrivyContext",()=>z),E(C,"PrivyProvider",()=>V);var x={};x=JSON.parse('{"name":"@privy-io/expo","version":"0.8.2-beta-20240304190232","description":"Expo client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","react-native","expo","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true,"sourceMap":false,"optimize":true},"module":{"isLibrary":true,"sourceMap":false,"optimize":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build --no-cache","clean":"rm -rf dist .turbo","dev":"npx parcel watch -p 4234","test":"jest --testMatch \\"**/test/**/*.test.ts\\"","test:ci":"npm run test","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"peerDependencies":{"react":"*","react-native":"*","react-native-webview":"*","expo-constants":"*","expo-linking":"*","expo-secure-store":"*","expo-application":"*","expo-web-browser":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.13.4-beta-20240304190232","react-fast-compare":"^3.2.2"},"devDependencies":{"@privy-io/eslint-config-custom":"*","@privy-io/parcel-config":"*","@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');let k=({client:e,isClientReady:r,setWebViewState:i,webViewState:o})=>{let d=a(null);n(()=>{d.current&&"loaded"===o&&e.setMessagePoster(d.current)},[e,d.current,"loaded"===o]),n(()=>{let e=l.addEventListener("change",e=>{d.current&&"active"===e&&(d.current.reload(),i("reloading"))});return e.remove},[]);let c=s(async t=>{let{data:r}=t.nativeEvent,i=e.embeddedWallet.getMessageHandler();i?.(JSON.parse(r))},[e]);// Ensure we only render the webview once the client is initialized
2
2
  return r?t.createElement(h,{style:{flex:1},ref:d,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>i("loaded"),onError:console.error,onMessage:c}):null},P=({client:e,user:t,wallet:r,setWallet:i,webViewState:a})=>{let d=o(()=>$diYGi$getUserEmbeddedWallet(t),[t]),c=s(async t=>{i({status:"creating"});try{let r=await e.embeddedWallet.create(t);return i({status:"connected",provider:r}),r}catch(t){let e=t instanceof Error?t.message:"Error creating embedded wallet";throw i({status:"error",error:e}),new $diYGi$PrivyClientError({code:"embedded_wallet_creation_error",error:e})}},[e]),l=s(async t=>{if("connected"!==r.status)throw new $diYGi$PrivyClientError({code:"attempted_to_set_password_before_connected",error:"Embedded wallet must be connected before setting password"});if(!d)throw new $diYGi$PrivyClientError({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});if("user-passcode"===d.recovery_method)throw new $diYGi$PrivyClientError({code:"attempted_to_set_password_but_password_already_set",error:"Embedded wallet already has a recovery password"});try{let r=await e.embeddedWallet.setPassword(d,t);return i({status:"connected",provider:r}),r}catch(e){throw new $diYGi$PrivyClientError({code:"embedded_wallet_set_password_error",error:e instanceof Error?e.message:"Error setting password on embedded wallet"})}},[e,d,r.status]),u=s(async t=>{if(!d)throw new $diYGi$PrivyClientError({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});i({status:"connecting"});try{let r=await e.embeddedWallet.getProvider(d,t);return i({status:"connected",provider:r}),r}catch(e){throw i({status:"needs-recovery"}),new $diYGi$PrivyClientError({code:"embedded_wallet_recovery_error",error:e instanceof Error?e.message:"Error recovering embedded wallet"})}},[e,d]),h=s(async()=>{// There is a user but no embedded wallet account
3
3
  // We need to create an embedded walert for this user
4
4
  if(!d)throw i({status:"not-created"}),new $diYGi$PrivyClientError({code:"embedded_wallet_does_not_exist",error:"Embedded wallet does not exist"});// There is definitely a user with an embedded wallet so we try to connect
@@ -8,7 +8,7 @@ if(!d)throw i({status:"not-created"}),new $diYGi$PrivyClientError({code:"embedde
8
8
  i(e=>"connected"===e.status?{status:"reconnecting"}:{status:"connecting"});try{let t=await e.embeddedWallet.getProvider(d);return i({status:"connected",provider:t}),t}catch(e){if($diYGi$errorIndicatesRecoveryIsNeeded(e))throw i({status:"needs-recovery"}),new $diYGi$PrivyClientError({code:"embedded_wallet_needs_recovery",error:"Embedded wallet not loaded on device"});if(e instanceof Error)throw i({status:"error",error:e.message}),new $diYGi$PrivyClientError({code:"unknown_embedded_wallet_error",error:e.message});throw i({status:"error",error:"Error loading embedded wallet"}),new $diYGi$PrivyClientError({code:"unknown_embedded_wallet_error",error:"Error loading embedded wallet"})}},[e,d]);return n(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
9
9
  // the wallet returns to disconnected state along with a logged out user
10
10
  if(!t&&"disconnected"!==r.status)return i({status:"disconnected"});// Automatically anytime the iframe reloads
11
- "loaded"===a&&h().catch(()=>void 0)},[a,t,d]),{create:c,recover:u,setPassword:l,getProvider:h}},W=e=>t=>e(e=>y(e,t)?e:t);function A(e){return e instanceof Error||e instanceof $diYGi$PrivyApiError||e instanceof $diYGi$PrivyClientError?e:"string"==typeof e?Error(e):Error("Unknown error")}let L=({client:e,user:t,isUserInitialized:r,oAuthState:i,oAuthCallbacks:a,setOAuthState:o})=>{let d=g(),c=s(e=>{let t=A(e);o({status:"error",error:t}),a.current.onError?.(t)},[o]);return n(()=>{async function s(){if(!d||"loading"!==i.status)return;let{queryParams:r}=w(d),{privy_oauth_state:s,privy_oauth_code:n}=r;if(!n||!s){o({status:"done"});return}try{let r;if(t)r=await e.auth.oauth.linkWithCode(n,s);else{let t=await e.auth.oauth.loginWithCode(n,s);r=t.user}// Since stripping query params off the url in place is not possible
11
+ "loaded"===a&&h().catch(()=>void 0)},[a,t,d]),{create:c,recover:u,setPassword:l,getProvider:h}},W=e=>t=>e(e=>b(e,t)?e:t);function A(e){return e instanceof Error||e instanceof $diYGi$PrivyApiError||e instanceof $diYGi$PrivyClientError?e:"string"==typeof e?Error(e):Error("Unknown error")}let L=({client:e,user:t,isUserInitialized:r,oAuthState:i,oAuthCallbacks:a,setOAuthState:o})=>{let d=g(),c=s(e=>{let t=A(e);o({status:"error",error:t}),a.current.onError?.(t)},[o]);return n(()=>{async function s(){if(!d||"loading"!==i.status)return;let{queryParams:r}=w(d),{privy_oauth_state:s,privy_oauth_code:n}=r;if(!n||!s){o({status:"done"});return}try{let r;if(t)r=await e.auth.oauth.linkWithCode(n,s);else{let t=await e.auth.oauth.loginWithCode(n,s);r=t.user}// Since stripping query params off the url in place is not possible
12
12
  // navigating to the currentUrl less the query params should accomplish the same
13
13
  return a.current.onSuccess?.(r),o({status:"done"}),await p(d.split("?")[0])}catch(e){c(e)}}// On ios, the WebBrowser authSession result will be used directly to complete oauth flow
14
14
  // from with login/link hooks. On android, this will not work due to
@@ -34,5 +34,5 @@ await p(d.url.split("?")[0]),i({status:"done"}),s??void 0}catch(e){l(e)}},[t,o,i
34
34
  * <Button onPress={() => link({ provider: 'google' })} />
35
35
  */link:r}}function U(e){// this omits `action` so that the link/login behavior is driven by whether a valid session exists
36
36
  // for backwards compatibility reasons
37
- return Y(e)}let R=()=>b,j={get:e=>f(e),put:(e,t)=>_(e,t),del:e=>$(e),getKeys:async()=>[]},z=r({}),V=r=>{let[n,d]=i(!1),[l,u]=i("loading"),[h,g]=i(!1),[w,p]=i(null),[m,y]=i({status:"disconnected"}),[b,f]=i({status:"initial"}),[_,$]=i({status:"initial"}),[v,E]=i({status:"initial"}),S=a({}),C=s(e=>{if(e)return W(p)(e);p(null),f({status:"initial"}),$({status:"initial"}),y({status:"disconnected"})},[]),A=o(()=>{var t;let i=r.storage||j;return new e({storage:{get:e=>i.get(e.replace(":","-")),put:(e,t)=>i.put(e.replace(":","-"),t),del:e=>i.del(e.replace(":","-")),getKeys:async()=>[]},appId:r.appId,supportedChains:r.supportedChains,// @ts-expect-error config for internal use only
38
- nativeAppIdentifier:R(),baseUrl:r.baseUrl,sdkVersion:`expo:${((t=x)&&t.__esModule?t.default:t).version}`,callbacks:{setUser:C,setIsReady:g},logLevel:r.logLevel})},[r.storage,r.appId,r.baseUrl,r.supportedChains,r.logLevel,C]),Y=s(()=>(C(null),A.auth.logout()),[C,A]),M=s(()=>A.getAccessToken(),[A]);G({client:A,isUserInitialized:n,setIsUserInitialized:d});let I=P({client:A,user:w,webViewState:l,wallet:m,setWallet:y});return L({client:A,isUserInitialized:n,user:w,oAuthState:_,setOAuthState:$,oAuthCallbacks:S}),t.createElement(t.Fragment,null,t.createElement(z.Provider,{value:{client:A,user:w,isReady:"loading"!==l&&n&&O(_),logout:Y,getAccessToken:M,wallet:{...m,...I},oAuthState:_,oAuthCallbacks:S,setOAuthState:$,siweState:v,setSiweState:E,otpState:b,setOtpState:f}},r.children),t.createElement(c,{style:{width:0,height:0,overflow:"hidden"}},t.createElement(k,{client:A,isClientReady:h,setWebViewState:u,webViewState:l})))};var N={};E(N,"isConnected",()=>D),E(N,"isReconnecting",()=>T),E(N,"isConnecting",()=>q),E(N,"isDisconnected",()=>F),E(N,"isNotCreated",()=>J),E(N,"isCreating",()=>K),E(N,"hasError",()=>H),E(N,"needsRecovery",()=>B);let D=e=>"connected"===e.status,T=e=>"reconnecting"===e.status,q=e=>"connecting"===e.status,F=e=>"disconnected"===e.status,J=e=>"not-created"===e.status,K=e=>"creating"===e.status,H=e=>"error"===e.status,B=e=>"needs-recovery"===e.status;S({},N);var Q={};E(Q,"useEmbeddedWallet",()=>el),E(Q,"usePrivyClient",()=>eu),E(Q,"usePrivy",()=>eh);var X={};E(X,"useLinkWithSiwe",()=>Z);let Z=e=>{let{user:t,client:r,setSiweState:i,siweState:a}=d(z),o=s(t=>{let r=A(t);return i({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),n=s(async({wallet:t,from:{domain:a,uri:s}})=>{try{i({status:"generating-message"});let o=await r.auth.siwe.init(t,a,s);return i({status:"awaiting-signature"}),e?.onGenerateMessage?.(o.message),o.message}catch(e){throw o(e)}},[r,o]),c=s(async({signature:a,messageOverride:s})=>{try{if(!t)throw new $diYGi$PrivyClientError({code:"attempted_link_siwe_before_logged_in",error:"Must be logged in to link a wallet, Use `useLoginWithSiwe` to login with a wallet"});i({status:"submitting-signature"});let o=await r.auth.siwe.linkWithSiwe(a,void 0,s);return i({status:"done"}),e?.onSuccess?.(o),o}catch(e){o(e)}},[t,r,o]);return{generateSiweMessage:n,linkWithSiwe:c,state:a}};var ee={};E(ee,"useLoginWithSiwe",()=>et);let et=e=>{let{user:t,client:r,setSiweState:i,siweState:a}=d(z),o=s(t=>{let r=A(t);return i({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),n=s(async({wallet:t,from:{domain:a,uri:s}})=>{try{i({status:"generating-message"});let o=await r.auth.siwe.init(t,a,s);return i({status:"awaiting-signature"}),e?.onGenerateMessage?.(o.message),o.message}catch(e){throw o(e)}},[r,o]),c=s(async({signature:a,messageOverride:s})=>{try{if(t)throw new $diYGi$PrivyClientError({code:"attempted_login_with_siwe_while_already_logged_in",error:"Already logged in, use `useLinkWithSiwe` if you are trying to link a wallet to an existing account"});i({status:"submitting-signature"});let o=await r.auth.siwe.loginWithSiwe(a,void 0,s);return i({status:"done"}),e?.onSuccess?.(o.user),o.user}catch(e){o(e)}},[t,r,o]);return{loginWithSiwe:c,generateSiweMessage:n,state:a}};var er={};E(er,"useLinkEmail",()=>ei);let ei=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({email:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.email.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({email:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,email:i})=>{try{if(!a)throw new $diYGi$PrivyClientError({code:"attempted_link_email_before_logged_in",error:"Must be logged in to link an email, Use `useLoginWithEmail` to login with email"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});c({status:"submitting-code"});let n=await o.auth.email.linkWithCode(s,r);return c({status:"done"}),e?.onLinkSuccess?.(n),n}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,linkWithCode:h,state:n}};var ea={};E(ea,"useLoginWithEmail",()=>es);let es=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({email:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.email.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({email:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,email:i})=>{try{if(a)throw new $diYGi$PrivyClientError({code:"attempted_login_with_email_while_already_logged_in",error:"Already logged in, use `useLinkWithEmail` if you are trying to link an email to an existing account"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `loginWithCode`"});c({status:"submitting-code"});let n=await o.auth.email.loginWithCode(s,r);return c({status:"done"}),e?.onLoginSuccess?.(n.user),n?.user}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,loginWithCode:h,state:n}};var eo={};E(eo,"useLinkSMS",()=>en);let en=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({phone:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.phone.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({phone:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,phone:i})=>{try{if(!a)throw new $diYGi$PrivyClientError({code:"attempted_link_sms_before_logged_in",error:"Must be logged in to link a phone number, Use `useLoginWithSMS` to login with a phone number"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});c({status:"submitting-code"});let n=await o.auth.phone.linkWithCode(i||t,r);return c({status:"done"}),e?.onLinkSuccess?.(n),n}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,linkWithCode:h,state:n}};var ed={};E(ed,"useLoginWithSMS",()=>ec);let ec=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({phone:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.phone.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({phone:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,phone:i})=>{try{if(a)throw new $diYGi$PrivyClientError({code:"attempted_login_with_sms_while_already_logged_in",error:"Already logged in, use `useLinkWithSMS` if you are trying to link a phone number to an existing account"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});c({status:"submitting-code"});let n=await o.auth.phone.loginWithCode(i||t,r);return c({status:"done"}),e?.onLoginSuccess?.(n.user),n?.user}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,loginWithCode:h,state:n}},el=()=>{let{wallet:e}=d(z);return e},eu=()=>{let{client:e}=d(z);return e},eh=()=>{let{user:e,isReady:t,logout:r,getAccessToken:i}=d(z);return{user:e,isReady:t,logout:r,getAccessToken:i}};S(Q,X),S(Q,ee),S(Q,er),S(Q,ea),S(Q,eo),S(Q,ed);export{j as SecureStorageAdapter,U as useOAuthFlow,I as useLinkWithOAuth,M as useLoginWithOAuth,z as PrivyContext,V as PrivyProvider,D as isConnected,T as isReconnecting,q as isConnecting,F as isDisconnected,J as isNotCreated,K as isCreating,H as hasError,B as needsRecovery,el as useEmbeddedWallet,eu as usePrivyClient,eh as usePrivy,Z as useLinkWithSiwe,et as useLoginWithSiwe,ei as useLinkEmail,es as useLoginWithEmail,en as useLinkSMS,ec as useLoginWithSMS};
37
+ return Y(e)}let R=()=>y,j={get:e=>f(e),put:(e,t)=>_(e,t),del:e=>$(e),getKeys:async()=>[]},z=r({}),V=r=>{let[n,d]=i(!1),[l,u]=i("loading"),[h,g]=i(!1),[w,p]=i(null),[m,b]=i({status:"disconnected"}),[y,f]=i({status:"initial"}),[_,$]=i({status:"initial"}),[v,E]=i({status:"initial"}),S=a({}),C=s(e=>{if(e)return W(p)(e);p(null),f({status:"initial"}),$({status:"initial"}),b({status:"disconnected"})},[]),A=o(()=>{var t;let i=r.storage||j;return new e({storage:{get:e=>i.get(e.replace(":","-")),put:(e,t)=>i.put(e.replace(":","-"),t),del:e=>i.del(e.replace(":","-")),getKeys:async()=>[]},appId:r.appId,supportedChains:r.supportedChains,// @ts-expect-error config for internal use only
38
+ nativeAppIdentifier:R(),baseUrl:r.baseUrl,sdkVersion:`expo:${((t=x)&&t.__esModule?t.default:t).version}`,callbacks:{setUser:C,setIsReady:g},logLevel:r.logLevel})},[r.storage,r.appId,r.baseUrl,r.supportedChains,r.logLevel,C]),Y=s(()=>(C(null),A.auth.logout()),[C,A]),M=s(()=>A.getAccessToken(),[A]);G({client:A,isUserInitialized:n,setIsUserInitialized:d});let I=P({client:A,user:w,webViewState:l,wallet:m,setWallet:b});return L({client:A,isUserInitialized:n,user:w,oAuthState:_,setOAuthState:$,oAuthCallbacks:S}),t.createElement(t.Fragment,null,t.createElement(z.Provider,{value:{client:A,user:w,isReady:"loading"!==l&&n&&O(_),logout:Y,getAccessToken:M,wallet:{...m,...I},oAuthState:_,oAuthCallbacks:S,setOAuthState:$,siweState:v,setSiweState:E,otpState:y,setOtpState:f}},r.children),t.createElement(c,{style:{width:0,height:0,overflow:"hidden"}},t.createElement(k,{client:A,isClientReady:h,setWebViewState:u,webViewState:l})))};var N={};E(N,"isConnected",()=>D),E(N,"isReconnecting",()=>T),E(N,"isConnecting",()=>q),E(N,"isDisconnected",()=>F),E(N,"isNotCreated",()=>J),E(N,"isCreating",()=>K),E(N,"hasError",()=>H),E(N,"needsRecovery",()=>B);let D=e=>"connected"===e.status,T=e=>"reconnecting"===e.status,q=e=>"connecting"===e.status,F=e=>"disconnected"===e.status,J=e=>"not-created"===e.status,K=e=>"creating"===e.status,H=e=>"error"===e.status,B=e=>"needs-recovery"===e.status;S({},N);var Q={};E(Q,"useEmbeddedWallet",()=>el),E(Q,"usePrivyClient",()=>eu),E(Q,"usePrivy",()=>eh);var X={};E(X,"useLinkWithSiwe",()=>Z);let Z=e=>{let{user:t,client:r,setSiweState:i,siweState:a}=d(z),o=s(t=>{let r=A(t);return i({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),n=s(async({wallet:t,from:{domain:a,uri:s}})=>{try{i({status:"generating-message"});let o=await r.auth.siwe.init(t,a,s);return i({status:"awaiting-signature"}),e?.onGenerateMessage?.(o.message),o.message}catch(e){throw o(e)}},[r,o]),c=s(async({signature:a,messageOverride:s})=>{try{if(!t)throw new $diYGi$PrivyClientError({code:"attempted_link_siwe_before_logged_in",error:"Must be logged in to link a wallet, Use `useLoginWithSiwe` to login with a wallet"});i({status:"submitting-signature"});let o=await r.auth.siwe.linkWithSiwe(a,void 0,s);return i({status:"done"}),e?.onSuccess?.(o),o}catch(e){o(e)}},[t,r,o]);return{generateSiweMessage:n,linkWithSiwe:c,state:a}};var ee={};E(ee,"useLoginWithSiwe",()=>et);let et=e=>{let{user:t,client:r,setSiweState:i,siweState:a}=d(z),o=s(t=>{let r=A(t);return i({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),n=s(async({wallet:t,from:{domain:a,uri:s}})=>{try{i({status:"generating-message"});let o=await r.auth.siwe.init(t,a,s);return i({status:"awaiting-signature"}),e?.onGenerateMessage?.(o.message),o.message}catch(e){throw o(e)}},[r,o]),c=s(async({signature:a,messageOverride:s})=>{try{if(t)throw new $diYGi$PrivyClientError({code:"attempted_login_with_siwe_while_already_logged_in",error:"Already logged in, use `useLinkWithSiwe` if you are trying to link a wallet to an existing account"});i({status:"submitting-signature"});let o=await r.auth.siwe.loginWithSiwe(a,void 0,s);return i({status:"done"}),e?.onSuccess?.(o.user),o.user}catch(e){o(e)}},[t,r,o]);return{loginWithSiwe:c,generateSiweMessage:n,state:a}};var er={};E(er,"useLinkEmail",()=>ei);let ei=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({email:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.email.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({email:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,email:i})=>{try{if(!a)throw new $diYGi$PrivyClientError({code:"attempted_link_email_before_logged_in",error:"Must be logged in to link an email, Use `useLoginWithEmail` to login with email"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `linkWithCode`"});c({status:"submitting-code"});let n=await o.auth.email.linkWithCode(s,r);return c({status:"done"}),e?.onLinkSuccess?.(n),n}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,linkWithCode:h,state:n}};var ea={};E(ea,"useLoginWithEmail",()=>es);let es=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({email:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.email.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({email:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,email:i})=>{try{if(a)throw new $diYGi$PrivyClientError({code:"attempted_login_with_email_while_already_logged_in",error:"Already logged in, use `useLinkWithEmail` if you are trying to link an email to an existing account"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid email before calling `loginWithCode`"});c({status:"submitting-code"});let n=await o.auth.email.loginWithCode(s,r);return c({status:"done"}),e?.onLoginSuccess?.(n.user),n?.user}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,loginWithCode:h,state:n}};var eo={};E(eo,"useLinkSMS",()=>en);let en=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({phone:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.phone.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({phone:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,phone:i})=>{try{if(!a)throw new $diYGi$PrivyClientError({code:"attempted_link_sms_before_logged_in",error:"Must be logged in to link a phone number, Use `useLoginWithSMS` to login with a phone number"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `linkWithCode`"});c({status:"submitting-code"});let n=await o.auth.phone.linkWithCode(i||t,r);return c({status:"done"}),e?.onLinkSuccess?.(n),n}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,linkWithCode:h,state:n}};var ed={};E(ed,"useLoginWithSMS",()=>ec);let ec=e=>{let[t,r]=i(""),{user:a,client:o,otpState:n,setOtpState:c}=d(z),l=s(t=>{let r=A(t);return c({status:"error",error:r}),e?.onError?.(r),r},[e?.onError]),u=s(async({phone:t})=>{r(t);try{c({status:"sending-code"});let r=await o.auth.phone.sendCode(t);return c({status:"awaiting-code-input"}),e?.onSendCodeSuccess?.({phone:t}),r}catch(e){return l(e),{success:!1}}},[o,l]),h=s(async({code:r,phone:i})=>{try{if(a)throw new $diYGi$PrivyClientError({code:"attempted_login_with_sms_while_already_logged_in",error:"Already logged in, use `useLinkWithSMS` if you are trying to link a phone number to an existing account"});let s=i||t;if(!s)throw new $diYGi$PrivyClientError({code:"attempted_submit_otp_before_sending",error:"Must `sendCode` with a valid phone number before calling `loginWithCode`"});c({status:"submitting-code"});let n=await o.auth.phone.loginWithCode(i||t,r);return c({status:"done"}),e?.onLoginSuccess?.(n.user),n?.user}catch(e){l(e)}},[a,o,t,l]);return{sendCode:u,loginWithCode:h,state:n}},el=()=>{let{wallet:e}=d(z);return e},eu=()=>{let{client:e}=d(z);return e},eh=()=>{let{user:e,isReady:t,logout:r,getAccessToken:i}=d(z);return{user:e,isReady:t,logout:r,getAccessToken:i}};S(Q,X),S(Q,ee),S(Q,er),S(Q,ea),S(Q,eo),S(Q,ed);export{j as SecureStorageAdapter,U as useOAuthFlow,I as useLinkWithOAuth,M as useLoginWithOAuth,z as PrivyContext,V as PrivyProvider,D as isConnected,T as isReconnecting,q as isConnecting,F as isDisconnected,J as isNotCreated,K as isCreating,H as hasError,B as needsRecovery,el as useEmbeddedWallet,eu as usePrivyClient,eh as usePrivy,Z as useLinkWithSiwe,et as useLoginWithSiwe,ei as useLinkEmail,es as useLoginWithEmail,en as useLinkSMS,ec as useLoginWithSMS};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/expo",
3
- "version": "0.8.1",
3
+ "version": "0.8.2-beta-20240304190232",
4
4
  "description": "Expo client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",
@@ -62,7 +62,7 @@
62
62
  "expo-web-browser": "*"
63
63
  },
64
64
  "dependencies": {
65
- "@privy-io/js-sdk-core": "0.13.3",
65
+ "@privy-io/js-sdk-core": "0.13.4-beta-20240304190232",
66
66
  "react-fast-compare": "^3.2.2"
67
67
  },
68
68
  "devDependencies": {