@privy-io/expo 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +6 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -125,24 +125,6 @@ export const hasError: (s: EmbeddedWalletState) => s is EmbeddedWalletErrorState
|
|
|
125
125
|
* )}
|
|
126
126
|
*/
|
|
127
127
|
export const needsRecovery: (s: EmbeddedWalletState) => s is EmbeddedWalletNeedsRecoveryState;
|
|
128
|
-
export type EmbeddedWallet = Extract<PrivyAuthenticatedUser['user']['linked_accounts'][number], {
|
|
129
|
-
wallet_client_type: 'privy';
|
|
130
|
-
connector_type: 'embedded';
|
|
131
|
-
}>;
|
|
132
|
-
export type User = PrivyAuthenticatedUser['user'];
|
|
133
|
-
/**
|
|
134
|
-
* @description Finds the embedded walet account (if it exists) for a given user.
|
|
135
|
-
*
|
|
136
|
-
* @param user A privy user object
|
|
137
|
-
*
|
|
138
|
-
* @returns The user's embedded wallet account
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* const { user } = usePrivy();
|
|
142
|
-
* const account = getUserEmbeddedWallet(user)
|
|
143
|
-
* console.log(account.address)
|
|
144
|
-
*/
|
|
145
|
-
export const getUserEmbeddedWallet: (user: User | null) => EmbeddedWallet | null;
|
|
146
128
|
export type OAuthFlowState = {
|
|
147
129
|
status: 'initial';
|
|
148
130
|
} | {
|
|
@@ -302,6 +284,11 @@ export interface PrivyProviderProps {
|
|
|
302
284
|
supportedChains?: [Chain, ...Chain[]];
|
|
303
285
|
}
|
|
304
286
|
export const PrivyProvider: (props: PrivyProviderProps) => React.JSX.Element;
|
|
287
|
+
export type EmbeddedWallet = Extract<PrivyAuthenticatedUser['user']['linked_accounts'][number], {
|
|
288
|
+
wallet_client_type: 'privy';
|
|
289
|
+
connector_type: 'embedded';
|
|
290
|
+
}>;
|
|
291
|
+
export type User = PrivyAuthenticatedUser['user'];
|
|
305
292
|
export * from '@privy-io/js-sdk-core';
|
|
306
293
|
|
|
307
294
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;ACEA,oCAAoC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,2BAA2B,CAAC;CACvC,CAAC;AAEF,qCAAqC;IACnC,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,uCAAuC;IACrC,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,wCAAwC;IACtC,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;OAIG;IACH,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,qCAAqC;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,mCAAmC;IACjC,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,gCAAgC;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,kCACI,4BAA4B,GAC5B,6BAA6B,GAC7B,+BAA+B,GAC/B,gCAAgC,GAChC,2BAA2B,GAC3B,6BAA6B,GAC7B,wBAAwB,CAAC;AAE7B,mCAAmC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,OAAO,MAAM,iBAAkB,mBAAmB,sCACxB,CAAC;AAE3B;;;;;;;;;;;;GAYG;AACH,OAAO,MAAM,kBAAmB,mBAAmB,uCACxB,CAAC;AAG5B,OAAO,MAAM,oBAAqB,mBAAmB,yCACxB,CAAC;AAE9B;;;;;;;;;;;;GAYG;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C;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,MAAM,QAAQ,CAAC,MAAM,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;IAChE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,OAAO,MAAM,yCAAgD,CAAC;AAE9D;IACE,QAAQ,EAAE,MAAM,SAAS,CAAC;IAE1B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;CAUvC;AAED,OAAO,MAAM,uBAAwB,kBAAkB,sBAmFtD,CAAC;ACvLF,6BAA6B,OAAO,CAClC,sBAAsB,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,EACzD;IAAC,kBAAkB,EAAE,OAAO,CAAC;IAAC,cAAc,EAAE,UAAU,CAAA;CAAC,CAC1D,CAAC;AAEF,mBAAmB,sBAAsB,CAAC,MAAM,CAAC,CAAC;ACPlD,cAAc,uBAAuB,CAAC","sources":["packages-js-public/expo/src/src/context/EmbeddedWalletWebView.tsx","packages-js-public/expo/src/src/models/EmbeddedWalletState.ts","packages-js-public/expo/src/src/models/index.ts","packages-js-public/expo/src/src/context/useConnectEmbeddedWallet.ts","packages-js-public/expo/src/src/context/useInitializeUser.ts","packages-js-public/expo/src/src/utils/toStableSetter.ts","packages-js-public/expo/src/src/utils/toErrorState.ts","packages-js-public/expo/src/src/utils/index.ts","packages-js-public/expo/src/src/expo.ts","packages-js-public/expo/src/src/hooks/hooks.types.ts","packages-js-public/expo/src/src/hooks/useLoginWithEmail.ts","packages-js-public/expo/src/src/hooks/useLinkEmail.ts","packages-js-public/expo/src/src/hooks/useLoginWithSMS.ts","packages-js-public/expo/src/src/hooks/useLinkSMS.ts","packages-js-public/expo/src/src/hooks/useEmbeddedWallet.ts","packages-js-public/expo/src/src/hooks/usePrivyClient.ts","packages-js-public/expo/src/src/hooks/usePrivy.ts","packages-js-public/expo/src/src/hooks/index.ts","packages-js-public/expo/src/src/PrivyProvider.tsx","packages-js-public/expo/src/src/types.ts","packages-js-public/expo/src/src/index.ts","packages-js-public/expo/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"export * from '@privy-io/js-sdk-core';\nexport * from './PrivyProvider';\nexport * from './types';\nexport * from './models';\nexport * from './hooks';\nexport {SecureStorageAdapter, useOAuthFlow} from './expo';\nexport type {OAuthFlowState} from './expo';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var e=require("@privy-io/js-sdk-core"),t=require("react"),s=require("react-native"),a=require("react-native-webview"),r=require("
|
|
2
|
-
return s?c(t).createElement(c(a),{style:{flex:1},ref:n,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>i(!0),onMessage:o}):null},y=
|
|
1
|
+
var e=require("@privy-io/js-sdk-core"),t=require("react"),s=require("react-native"),a=require("react-native-webview"),r=require("expo-application"),i=require("expo-linking"),n=require("expo-secure-store"),o=require("react-fast-compare");function l(e,t){return Object.keys(t).forEach(function(s){"default"===s||"__esModule"===s||e.hasOwnProperty(s)||Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[s]}})}),e}function u(e,t,s,a){Object.defineProperty(e,t,{get:s,set:a,enumerable:!0,configurable:!0})}function c(e){return e&&e.__esModule?e.default:e}u(module.exports,"SecureStorageAdapter",()=>k),u(module.exports,"useOAuthFlow",()=>v);var d={};u(d,"PrivyContext",()=>S),u(d,"PrivyProvider",()=>E);var p={};p=JSON.parse('{"name":"@privy-io/expo","version":"0.5.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":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.11.1","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","parcel":"2.10.1","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');const h=({client:e,isClientReady:s,isWebViewReady:r,setIsWebViewReady:i})=>{let n=(0,t.useRef)(null);(0,t.useEffect)(()=>{r&&n.current&&e.setMessagePoster(n.current)},[r,e]);let o=(0,t.useCallback)(async t=>{let{data:s}=t.nativeEvent,a=e.embeddedWallet.getMessageHandler();a?.(JSON.parse(s))},[e]);// Ensure we only render the webview once the client is initialized
|
|
2
|
+
return s?c(t).createElement(c(a),{style:{flex:1},ref:n,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>i(!0),onMessage:o}):null},y=({client:s,user:a,wallet:r,setWallet:i,isWebViewReady:n})=>{let o=(0,t.useMemo)(()=>(0,e.getUserEmbeddedWallet)(a),[a]),l=(0,t.useCallback)(async e=>{i({status:"creating"});try{let t=await s.embeddedWallet.create(e);i({status:"connected",provider:t})}catch(e){i({status:"error",error:"Error creating embedded wallet"})}},[s]),u=(0,t.useCallback)(async e=>{if(o){i({status:"connecting"});try{let t=await s.embeddedWallet.getProvider(o,e);i({status:"connected",provider:t})}catch(e){i({status:"needs-recovery",recover:u})}}},[s,o]);return(0,t.useEffect)(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
|
|
3
3
|
// the wallet returns to disconnected state along with a logged out user
|
|
4
4
|
if(!a&&"disconnected"!==r.status)return i({status:"disconnected"});async function t(){// There is a user but no embedded wallet account
|
|
5
5
|
// We need to create an embedded walert for this user
|
|
@@ -8,8 +8,8 @@ if(!o)return i({status:"not-created",create:l});// There is definitely a user wi
|
|
|
8
8
|
// `getProvider` will internally attempt recovery of `pinless` wallets
|
|
9
9
|
// Otherwise, let the user know they need to prompt for recovery
|
|
10
10
|
i({status:"connecting"});try{let e=await s.embeddedWallet.getProvider(o);i({status:"connected",provider:e})}catch(t){(0,e.errorIndicatesRecoveryIsNeeded)(t)?i({status:"needs-recovery",recover:u}):t instanceof Error?i({status:"error",error:t.toString()}):i({status:"error",error:"Error loading embedded wallet"})}}// Automatically run on first load, once we know the iframe is loaded
|
|
11
|
-
n&&t()},[n,a,o])},
|
|
12
|
-
}finally{a(!0)}};s||t()},[s])},
|
|
11
|
+
n&&t()},[n,a,o])},g=({client:e,isUserInitialized:s,setIsUserInitialized:a})=>{(0,t.useEffect)(()=>{let t=async()=>{try{await e.user.get()}catch(e){// Explicitly swallow this error
|
|
12
|
+
}finally{a(!0)}};s||t()},[s])},m=e=>t=>e(e=>c(o)(e,t)?e:t),C=e=>"object"==typeof e&&!!(e?.error&&e?.code),b=e=>t=>e instanceof Error?{status:"error",error:e}:C(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,f=e=>"loading"!==e.status,v=()=>{let{oAuthState:e,client:s}=(0,t.useContext)(S),a=(0,t.useCallback)(async function({provider:e,redirectUri:t}){let{url:a}=await s.auth.oauth.generateURL(e,i.createURL(t||"/"));return i.openURL(a)},[s]);return{start:a,state:e}},w=({client:e,user:s,isUserInitialized:a,setOAuthState:r})=>{let n=i.useURL();return(0,t.useEffect)(()=>{let t=async()=>{if(!n){r({status:"done"});return}let{queryParams:t}=i.parse(n),{privy_oauth_state:a,privy_oauth_code:o}=t;if(!o||!a){r({status:"done"});return}r({status:"loading"});try{s?await e.auth.oauth.linkWithCode(o,a):await e.auth.oauth.loginWithCode(o,a),r({status:"done"})}catch(e){r(b(e))}// Since stripping query params off the url in place is not possible
|
|
13
13
|
// navigating to the currentUrl less the query params should accomplish the same
|
|
14
|
-
return
|
|
15
|
-
nativeAppIdentifier:
|
|
14
|
+
return i.openURL(n.split("?")[0])};a&&t()},[n,a])},x=()=>r.applicationId,k={get:e=>n.getItemAsync(e.replace(":","-")),put:(e,t)=>n.setItemAsync(e.replace(":","-"),t),del:e=>n.deleteItemAsync(e.replace(":","-")),getKeys:async()=>[]},S=/*#__PURE__*/(0,t.createContext)({}),E=a=>{let[r,i]=(0,t.useState)(!1),[n,o]=(0,t.useState)(!1),[l,u]=(0,t.useState)(!1),[d,C]=(0,t.useState)(null),[b,v]=(0,t.useState)({status:"disconnected"}),[E,W]=(0,t.useState)({status:"initial"}),[I,R]=(0,t.useState)({status:"initial"}),A=(0,t.useCallback)(e=>{if(e)return m(C)(e);C(null),W({status:"initial"}),R({status:"initial"}),v({status:"disconnected"})},[]),U=(0,t.useMemo)(()=>new(c(e))({storage:a.storage||k,appId:a.appId,supportedChains:a.supportedChains,// @ts-expect-error config for internal use only
|
|
15
|
+
nativeAppIdentifier:x(),baseUrl:a.baseUrl,sdkVersion:`expo:${/*@__PURE__*/c(p).version}`,callbacks:{setUser:A,setIsReady:u},logLevel:a.logLevel}),[a.storage,a.appId,a.baseUrl,a.supportedChains,a.logLevel,A]),L=(0,t.useCallback)(()=>(A(null),U.auth.logout()),[A,U]),M=(0,t.useCallback)(()=>U.getAccessToken(),[U]);return g({client:U,isUserInitialized:r,setIsUserInitialized:i}),y({client:U,user:d,isWebViewReady:n,wallet:b,setWallet:v}),w({client:U,isUserInitialized:r,user:d,setOAuthState:R}),c(t).createElement(c(t).Fragment,null,c(t).createElement(S.Provider,{value:{client:U,user:d,isReady:n&&r&&f(I),logout:L,getAccessToken:M,wallet:b,oAuthState:I,otpState:E,setOtpState:W}},a.children),c(t).createElement(s.View,{style:{width:0,height:0,overflow:"hidden"}},c(t).createElement(h,{client:U,isClientReady:l,isWebViewReady:n,setIsWebViewReady:o})))};var W={},I={};u(I,"isConnected",()=>R),u(I,"isConnecting",()=>A),u(I,"isDisconnected",()=>U),u(I,"isNotCreated",()=>L),u(I,"isCreating",()=>M),u(I,"hasError",()=>j),u(I,"needsRecovery",()=>P);const R=e=>"connected"===e.status,A=e=>"connecting"===e.status,U=e=>"disconnected"===e.status,L=e=>"not-created"===e.status,M=e=>"creating"===e.status,j=e=>"error"===e.status,P=e=>"needs-recovery"===e.status;l(W,I);var O={};u(O,"useLoginWithEmail",()=>q),u(O,"useLinkEmail",()=>z),u(O,"useLoginWithSMS",()=>V),u(O,"useLinkSMS",()=>_),u(O,"useEmbeddedWallet",()=>N),u(O,"usePrivyClient",()=>D),u(O,"usePrivy",()=>T);const q=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(S),n=(0,t.useCallback)(async({email:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `loginWithCode`");try{i({status:"submitting-code"});let e=await a.auth.email.loginWithCode(r,t);return i({status:"done"}),e}catch(e){i(b(e))}},[a,e]);return{sendCode:n,loginWithCode:o,state:r}},z=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(S),n=(0,t.useCallback)(async({email:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.email.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `linkWithCode`");try{i({status:"submitting-code"});let e=await a.auth.email.linkWithCode(r,t);return i({status:"done"}),e}catch(e){i(b(e))}},[a,e]);return{sendCode:n,linkWithCode:o,state:r}},V=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(S),n=(0,t.useCallback)(async({phone:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `loginWithCode`");try{i({status:"submitting-code"});let r=await a.auth.phone.loginWithCode(s||e,t);return i({status:"done"}),r}catch(e){i(b(e))}},[a,e]);return{sendCode:n,loginWithCode:o,state:r}},_=()=>{let[e,s]=(0,t.useState)(""),{client:a,otpState:r,setOtpState:i}=(0,t.useContext)(S),n=(0,t.useCallback)(async({phone:e})=>{s(e);try{i({status:"sending-code"}),await a.auth.phone.sendCode(e),i({status:"awaiting-code-input"})}catch(e){i(b(e))}},[a]),o=(0,t.useCallback)(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `linkWithCode`");try{i({status:"submitting-code"});let r=await a.auth.phone.linkWithCode(s||e,t);return i({status:"done"}),r}catch(e){i(b(e))}},[a,e]);return{sendCode:n,linkWithCode:o,state:r}},N=()=>{let{wallet:e}=(0,t.useContext)(S);return e},D=()=>{let{client:e}=(0,t.useContext)(S);return e},T=()=>{let{user:e,isReady:s,logout:a,getAccessToken:r}=(0,t.useContext)(S);return{user:e,isReady:s,logout:a,getAccessToken:r}};l(module.exports,e),l(module.exports,d),l(module.exports,{}),l(module.exports,W),l(module.exports,O);
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import e from"@privy-io/js-sdk-core";import t,{createContext as a,useState as s,useCallback as r,useMemo as i,useRef as n,useEffect as o,useContext as c}from"react";import{View as d}from"react-native";import l from"react-native-webview";import
|
|
2
|
-
return a?t.createElement(l,{style:{flex:1},ref:c,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>i(!0),onMessage:d}):null},E=
|
|
1
|
+
import e from"@privy-io/js-sdk-core";import t,{createContext as a,useState as s,useCallback as r,useMemo as i,useRef as n,useEffect as o,useContext as c}from"react";import{View as d}from"react-native";import l from"react-native-webview";import{applicationId as u}from"expo-application";import{createURL as p,openURL as h,useURL as f,parse as y}from"expo-linking";import{getItemAsync as b,setItemAsync as g,deleteItemAsync as m}from"expo-secure-store";import v from"react-fast-compare";function $(e,t,a,s){Object.defineProperty(e,t,{get:a,set:s,enumerable:!0,configurable:!0})}var w,x={};$(x,"PrivyContext",()=>j),$(x,"PrivyProvider",()=>O);var C={};C=JSON.parse('{"name":"@privy-io/expo","version":"0.5.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":"*"},"dependencies":{"@privy-io/js-sdk-core":"0.11.1","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","parcel":"2.10.1","typescript":"^4.9.5"},"author":"privy.io","publishConfig":{"access":"public"}}');let W=({client:e,isClientReady:a,isWebViewReady:s,setIsWebViewReady:i})=>{let c=n(null);o(()=>{s&&c.current&&e.setMessagePoster(c.current)},[s,e]);let d=r(async t=>{let{data:a}=t.nativeEvent,s=e.embeddedWallet.getMessageHandler();s?.(JSON.parse(a))},[e]);// Ensure we only render the webview once the client is initialized
|
|
2
|
+
return a?t.createElement(l,{style:{flex:1},ref:c,source:{uri:e.embeddedWallet.getURL()},onLoad:()=>i(!0),onMessage:d}):null},E=({client:e,user:t,wallet:a,setWallet:s,isWebViewReady:n})=>{let c=i(()=>$diYGi$getUserEmbeddedWallet(t),[t]),d=r(async t=>{s({status:"creating"});try{let a=await e.embeddedWallet.create(t);s({status:"connected",provider:a})}catch(e){s({status:"error",error:"Error creating embedded wallet"})}},[e]),l=r(async t=>{if(c){s({status:"connecting"});try{let a=await e.embeddedWallet.getProvider(c,t);s({status:"connected",provider:a})}catch(e){s({status:"needs-recovery",recover:l})}}},[e,c]);return o(()=>{// Ensures that in the event of an expiring session or otherwise bad token,
|
|
3
3
|
// the wallet returns to disconnected state along with a logged out user
|
|
4
4
|
if(!t&&"disconnected"!==a.status)return s({status:"disconnected"});async function r(){// There is a user but no embedded wallet account
|
|
5
5
|
// We need to create an embedded walert for this user
|
|
@@ -8,8 +8,8 @@ if(!c)return s({status:"not-created",create:d});// There is definitely a user wi
|
|
|
8
8
|
// `getProvider` will internally attempt recovery of `pinless` wallets
|
|
9
9
|
// Otherwise, let the user know they need to prompt for recovery
|
|
10
10
|
s({status:"connecting"});try{let t=await e.embeddedWallet.getProvider(c);s({status:"connected",provider:t})}catch(e){$diYGi$errorIndicatesRecoveryIsNeeded(e)?s({status:"needs-recovery",recover:l}):e instanceof Error?s({status:"error",error:e.toString()}):s({status:"error",error:"Error loading embedded wallet"})}}// Automatically run on first load, once we know the iframe is loaded
|
|
11
|
-
n&&r()},[n,t,c])},
|
|
12
|
-
}finally{a(!0)}};t||s()},[t])},
|
|
11
|
+
n&&r()},[n,t,c])},S=({client:e,isUserInitialized:t,setIsUserInitialized:a})=>{o(()=>{let s=async()=>{try{await e.user.get()}catch(e){// Explicitly swallow this error
|
|
12
|
+
}finally{a(!0)}};t||s()},[t])},k=e=>t=>e(e=>v(e,t)?e:t),I=e=>"object"==typeof e&&!!(e?.error&&e?.code),R=e=>t=>e instanceof Error?{status:"error",error:e}:I(e)?{status:"error",error:Error(e.error)}:"string"==typeof e?{status:"error",error:Error(e)}:t,L=e=>"loading"!==e.status,P=()=>{let{oAuthState:e,client:t}=c(j),a=r(async function({provider:e,redirectUri:a}){let{url:s}=await t.auth.oauth.generateURL(e,p(a||"/"));return h(s)},[t]);return{start:a,state:e}},A=({client:e,user:t,isUserInitialized:a,setOAuthState:s})=>{let r=f();return o(()=>{let i=async()=>{if(!r){s({status:"done"});return}let{queryParams:a}=y(r),{privy_oauth_state:i,privy_oauth_code:n}=a;if(!n||!i){s({status:"done"});return}s({status:"loading"});try{t?await e.auth.oauth.linkWithCode(n,i):await e.auth.oauth.loginWithCode(n,i),s({status:"done"})}catch(e){s(R(e))}// Since stripping query params off the url in place is not possible
|
|
13
13
|
// navigating to the currentUrl less the query params should accomplish the same
|
|
14
|
-
return h(r.split("?")[0])};a&&i()},[r,a])},
|
|
15
|
-
nativeAppIdentifier:
|
|
14
|
+
return h(r.split("?")[0])};a&&i()},[r,a])},M=()=>u,U={get:e=>b(e.replace(":","-")),put:(e,t)=>g(e.replace(":","-"),t),del:e=>m(e.replace(":","-")),getKeys:async()=>[]},j=a({}),O=a=>{let[n,o]=s(!1),[c,l]=s(!1),[u,p]=s(!1),[h,f]=s(null),[y,b]=s({status:"disconnected"}),[g,m]=s({status:"initial"}),[v,$]=s({status:"initial"}),w=r(e=>{if(e)return k(f)(e);f(null),m({status:"initial"}),$({status:"initial"}),b({status:"disconnected"})},[]),x=i(()=>{var t;return new e({storage:a.storage||U,appId:a.appId,supportedChains:a.supportedChains,// @ts-expect-error config for internal use only
|
|
15
|
+
nativeAppIdentifier:M(),baseUrl:a.baseUrl,sdkVersion:`expo:${((t=C)&&t.__esModule?t.default:t).version}`,callbacks:{setUser:w,setIsReady:p},logLevel:a.logLevel})},[a.storage,a.appId,a.baseUrl,a.supportedChains,a.logLevel,w]),I=r(()=>(w(null),x.auth.logout()),[w,x]),R=r(()=>x.getAccessToken(),[x]);return S({client:x,isUserInitialized:n,setIsUserInitialized:o}),E({client:x,user:h,isWebViewReady:c,wallet:y,setWallet:b}),A({client:x,isUserInitialized:n,user:h,setOAuthState:$}),t.createElement(t.Fragment,null,t.createElement(j.Provider,{value:{client:x,user:h,isReady:c&&n&&L(v),logout:I,getAccessToken:R,wallet:y,oAuthState:v,otpState:g,setOtpState:m}},a.children),t.createElement(d,{style:{width:0,height:0,overflow:"hidden"}},t.createElement(W,{client:x,isClientReady:u,isWebViewReady:c,setIsWebViewReady:l})))};var z={};$(z,"isConnected",()=>V),$(z,"isConnecting",()=>_),$(z,"isDisconnected",()=>N),$(z,"isNotCreated",()=>D),$(z,"isCreating",()=>T),$(z,"hasError",()=>q),$(z,"needsRecovery",()=>F);let V=e=>"connected"===e.status,_=e=>"connecting"===e.status,N=e=>"disconnected"===e.status,D=e=>"not-created"===e.status,T=e=>"creating"===e.status,q=e=>"error"===e.status,F=e=>"needs-recovery"===e.status;w={},Object.keys(z).forEach(function(e){"default"===e||"__esModule"===e||w.hasOwnProperty(e)||Object.defineProperty(w,e,{enumerable:!0,get:function(){return z[e]}})});var G={};$(G,"useLoginWithEmail",()=>J),$(G,"useLinkEmail",()=>Y),$(G,"useLoginWithSMS",()=>H),$(G,"useLinkSMS",()=>K),$(G,"useEmbeddedWallet",()=>B),$(G,"usePrivyClient",()=>Q),$(G,"usePrivy",()=>X);let J=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(j),o=r(async({email:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.email.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(R(e))}},[a]),d=r(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `loginWithCode`");try{n({status:"submitting-code"});let e=await a.auth.email.loginWithCode(r,t);return n({status:"done"}),e}catch(e){n(R(e))}},[a,e]);return{sendCode:o,loginWithCode:d,state:i}},Y=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(j),o=r(async({email:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.email.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(R(e))}},[a]),d=r(async({code:t,email:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid email before calling `linkWithCode`");try{n({status:"submitting-code"});let e=await a.auth.email.linkWithCode(r,t);return n({status:"done"}),e}catch(e){n(R(e))}},[a,e]);return{sendCode:o,linkWithCode:d,state:i}},H=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(j),o=r(async({phone:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.phone.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(R(e))}},[a]),d=r(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `loginWithCode`");try{n({status:"submitting-code"});let r=await a.auth.phone.loginWithCode(s||e,t);return n({status:"done"}),r}catch(e){n(R(e))}},[a,e]);return{sendCode:o,loginWithCode:d,state:i}},K=()=>{let[e,t]=s(""),{client:a,otpState:i,setOtpState:n}=c(j),o=r(async({phone:e})=>{t(e);try{n({status:"sending-code"}),await a.auth.phone.sendCode(e),n({status:"awaiting-code-input"})}catch(e){n(R(e))}},[a]),d=r(async({code:t,phone:s})=>{let r=s||e;if(!r)throw Error("Must `sendCode` with a valid phone number before calling `linkWithCode`");try{n({status:"submitting-code"});let r=await a.auth.phone.linkWithCode(s||e,t);return n({status:"done"}),r}catch(e){n(R(e))}},[a,e]);return{sendCode:o,linkWithCode:d,state:i}},B=()=>{let{wallet:e}=c(j);return e},Q=()=>{let{client:e}=c(j);return e},X=()=>{let{user:e,isReady:t,logout:a,getAccessToken:s}=c(j);return{user:e,isReady:t,logout:a,getAccessToken:s}};export{U as SecureStorageAdapter,P as useOAuthFlow,j as PrivyContext,O as PrivyProvider,V as isConnected,_ as isConnecting,N as isDisconnected,D as isNotCreated,T as isCreating,q as hasError,F as needsRecovery,J as useLoginWithEmail,Y as useLinkEmail,H as useLoginWithSMS,K as useLinkSMS,B as useEmbeddedWallet,Q as usePrivyClient,X as usePrivy};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privy-io/expo",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Expo client for the Privy Auth API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"expo-application": "*"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@privy-io/js-sdk-core": "0.11.
|
|
64
|
+
"@privy-io/js-sdk-core": "0.11.1",
|
|
65
65
|
"react-fast-compare": "^3.2.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|