@openfort/react-native 0.1.20 → 0.1.21

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.
Files changed (43) hide show
  1. package/dist/components/AuthBoundary.js +4 -1
  2. package/dist/core/index.js +1 -1
  3. package/dist/core/provider.js +0 -1
  4. package/dist/hooks/auth/useEmailAuth.js +90 -3
  5. package/dist/hooks/core/useOpenfort.js +3 -17
  6. package/dist/hooks/wallet/index.js +4 -2
  7. package/dist/hooks/wallet/solanaProvider.js +77 -0
  8. package/dist/hooks/wallet/useEmbeddedEthereumWallet.js +465 -0
  9. package/dist/hooks/wallet/useEmbeddedSolanaWallet.js +391 -0
  10. package/dist/hooks/wallet/utils.js +75 -0
  11. package/dist/lib/hookConsistency.js +6 -0
  12. package/dist/native/oauth.js +13 -0
  13. package/dist/native/storage.js +4 -0
  14. package/dist/native/webview.js +15 -1
  15. package/dist/types/components/AuthBoundary.d.ts +1 -0
  16. package/dist/types/core/index.d.ts +1 -1
  17. package/dist/types/hooks/auth/useEmailAuth.d.ts +6 -7
  18. package/dist/types/hooks/auth/useGuestAuth.d.ts +1 -2
  19. package/dist/types/hooks/auth/useOAuth.d.ts +1 -2
  20. package/dist/types/hooks/core/useOpenfort.d.ts +2 -13
  21. package/dist/types/hooks/wallet/index.d.ts +2 -1
  22. package/dist/types/hooks/wallet/solanaProvider.d.ts +75 -0
  23. package/dist/types/hooks/wallet/useEmbeddedEthereumWallet.d.ts +53 -0
  24. package/dist/types/hooks/wallet/useEmbeddedSolanaWallet.d.ts +47 -0
  25. package/dist/types/hooks/wallet/utils.d.ts +17 -0
  26. package/dist/types/index.js +1 -2
  27. package/dist/types/lib/hookConsistency.d.ts +6 -0
  28. package/dist/types/native/oauth.d.ts +13 -0
  29. package/dist/types/native/storage.d.ts +4 -0
  30. package/dist/types/native/webview.d.ts +14 -0
  31. package/dist/types/types/auth.d.ts +0 -41
  32. package/dist/types/types/index.d.ts +3 -30
  33. package/dist/types/types/oauth.d.ts +0 -38
  34. package/dist/types/types/wallet.d.ts +120 -216
  35. package/package.json +1 -1
  36. package/dist/hooks/auth/useCreateWalletPostAuth.js +0 -34
  37. package/dist/hooks/wallet/useWallets.js +0 -436
  38. package/dist/types/config.js +0 -1
  39. package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +0 -1
  40. package/dist/types/hooks/wallet/useWallets.d.ts +0 -78
  41. package/dist/types/predicates.js +0 -120
  42. package/dist/types/types/config.d.ts +0 -39
  43. package/dist/types/types/predicates.d.ts +0 -118
@@ -1,3 +1,4 @@
1
+ import { useUser } from '../hooks';
1
2
  import { useOpenfort } from '../hooks/core/useOpenfort';
2
3
  /**
3
4
  * Authentication boundary component that renders content based on authentication state.
@@ -9,6 +10,7 @@ import { useOpenfort } from '../hooks/core/useOpenfort';
9
10
  * 3. **Unauthenticated** – the user is not logged in.
10
11
  * 4. **Authenticated** – the user is logged in and the SDK is ready.
11
12
  *
13
+ * @param props - Component props, see {@link AuthBoundaryProps}
12
14
  * @example
13
15
  * ```tsx
14
16
  * import { AuthBoundary } from '@openfort/react-native';
@@ -59,7 +61,8 @@ import { useOpenfort } from '../hooks/core/useOpenfort';
59
61
  * ```
60
62
  */
61
63
  export const AuthBoundary = ({ loading, unauthenticated, error: errorComponent, children, }) => {
62
- const { user, isReady, error } = useOpenfort();
64
+ const { isReady, error } = useOpenfort();
65
+ const { user } = useUser();
63
66
  // SDK encountered an error during initialization
64
67
  if (error && errorComponent) {
65
68
  if (typeof errorComponent === 'function') {
@@ -1,7 +1,7 @@
1
1
  // Client creation and configuration
2
2
  // Re-export important types and enums from openfort-js
3
3
  export { RecoveryMethod } from '@openfort/openfort-js';
4
- export { createOpenfortClient, getDefaultClient, setDefaultClient } from './client';
4
+ export { createOpenfortClient } from './client';
5
5
  // React context and hooks
6
6
  export { isOpenfortContextValue, OpenfortContext, useOpenfortContext, useOpenfortContextSafe } from './context';
7
7
  // Main provider component
@@ -227,7 +227,6 @@ export const OpenfortProvider = ({ children, publishableKey, supportedChains, wa
227
227
  error,
228
228
  supportedChains,
229
229
  walletConfig,
230
- embeddedWallet: walletConfig,
231
230
  embeddedState,
232
231
  // Flow states
233
232
  passwordState,
@@ -1,6 +1,7 @@
1
1
  import { useCallback } from 'react';
2
2
  import { useOpenfortContext } from '../../core/context';
3
3
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
+ import { createOAuthRedirectUri } from '../../native/oauth';
4
5
  import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
5
6
  const mapStatus = (status) => {
6
7
  return {
@@ -185,9 +186,95 @@ export const useEmailAuth = (hookOptions = {}) => {
185
186
  });
186
187
  }
187
188
  }, [client, setPasswordState, _internal, hookOptions]);
188
- const verifyEmail = () => { }; // TODO
189
- const resetPassword = () => { }; // TODO
190
- const requestResetPassword = () => { }; // TODO
189
+ const requestResetPassword = useCallback(async (options) => {
190
+ try {
191
+ setPasswordState({ status: 'sending-verification-code' });
192
+ // Request password reset email
193
+ await client.auth.requestResetPassword({
194
+ email: options.email,
195
+ redirectUrl: options.emailVerificationRedirectTo || createOAuthRedirectUri('/password/reset'),
196
+ });
197
+ setPasswordState({ status: 'awaiting-code-input' });
198
+ return onSuccess({
199
+ hookOptions,
200
+ options,
201
+ data: { requiresEmailVerification: true },
202
+ });
203
+ }
204
+ catch (e) {
205
+ const error = new OpenfortError('Failed to request password reset', OpenfortErrorType.AUTHENTICATION_ERROR, {
206
+ error: e,
207
+ });
208
+ setPasswordState({
209
+ status: 'error',
210
+ error,
211
+ });
212
+ return onError({
213
+ hookOptions,
214
+ options,
215
+ error,
216
+ });
217
+ }
218
+ }, [client, setPasswordState, hookOptions]);
219
+ const resetPassword = useCallback(async (options) => {
220
+ try {
221
+ setPasswordState({ status: 'submitting-code' });
222
+ // Reset password with new password and state token
223
+ await client.auth.resetPassword({
224
+ email: options.email,
225
+ password: options.password,
226
+ state: options.state,
227
+ });
228
+ setPasswordState({ status: 'done' });
229
+ return onSuccess({
230
+ hookOptions,
231
+ options,
232
+ data: {},
233
+ });
234
+ }
235
+ catch (e) {
236
+ const error = new OpenfortError('Failed to reset password', OpenfortErrorType.AUTHENTICATION_ERROR, {
237
+ error: e,
238
+ });
239
+ setPasswordState({
240
+ status: 'error',
241
+ error,
242
+ });
243
+ return onError({
244
+ hookOptions,
245
+ options,
246
+ error,
247
+ });
248
+ }
249
+ }, [client, setPasswordState, hookOptions]);
250
+ const verifyEmail = useCallback(async (options) => {
251
+ try {
252
+ setPasswordState({ status: 'submitting-code' });
253
+ // Verify email with state token
254
+ await client.auth.verifyEmail({
255
+ email: options.email,
256
+ state: options.state,
257
+ });
258
+ setPasswordState({ status: 'done' });
259
+ return onSuccess({
260
+ hookOptions,
261
+ options,
262
+ data: { email: options.email },
263
+ });
264
+ }
265
+ catch (e) {
266
+ const error = new OpenfortError('Failed to verify email', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
267
+ setPasswordState({
268
+ status: 'error',
269
+ error,
270
+ });
271
+ return onError({
272
+ hookOptions,
273
+ options,
274
+ error,
275
+ });
276
+ }
277
+ }, [client, setPasswordState, hookOptions]);
191
278
  const reset = () => {
192
279
  setPasswordState({ status: 'initial' });
193
280
  };
@@ -2,7 +2,7 @@ import { useOpenfortContext } from '../../core/context';
2
2
  /**
3
3
  * Hook that exposes the core state of the Openfort SDK.
4
4
  *
5
- * This hook provides access to the current authenticated user object, SDK initialization status, and core authentication methods.
5
+ * This hook provides access to the current SDK initialization status.
6
6
  *
7
7
  * @returns The Openfort SDK's core state and methods.
8
8
  *
@@ -12,7 +12,7 @@ import { useOpenfortContext } from '../../core/context';
12
12
  * import { useOpenfort } from '@openfort/react-native/hooks';
13
13
  *
14
14
  * export function HomeScreen() {
15
- * const { user, isReady, error, logout } = useOpenfort();
15
+ * const { isReady, error } = useOpenfort();
16
16
  *
17
17
  * if (!isReady) {
18
18
  * return <ActivityIndicator size="large" />;
@@ -22,26 +22,12 @@ import { useOpenfortContext } from '../../core/context';
22
22
  * return <Text>{`Failed to initialise: ${error.message}`}</Text>;
23
23
  * }
24
24
  *
25
- * if (!user) {
26
- * return <Text>Please sign in</Text>;
27
- * }
28
- *
29
- * return (
30
- * <View>
31
- * <Text>{`Welcome, ${user.id}`}</Text>
32
- * <Button title="Log out" onPress={() => void logout()} />
33
- * </View>
34
- * );
35
- * }
36
25
  * ```
37
26
  */
38
27
  export function useOpenfort() {
39
- const { user, isReady, error, logout, getAccessToken } = useOpenfortContext();
28
+ const { isReady, error } = useOpenfortContext();
40
29
  return {
41
- user,
42
30
  isReady,
43
31
  error,
44
- logout,
45
- getAccessToken,
46
32
  };
47
33
  }
@@ -3,5 +3,7 @@
3
3
  *
4
4
  * This module re-exports all wallet-related hooks for convenient importing.
5
5
  */
6
- // Embedded wallet hooks
7
- export { useWallets } from './useWallets';
6
+ // Embedded Ethereum wallet hook
7
+ export { useEmbeddedEthereumWallet } from './useEmbeddedEthereumWallet';
8
+ // Embedded Solana wallet hook
9
+ export { useEmbeddedSolanaWallet } from './useEmbeddedSolanaWallet';
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Embedded Solana wallet provider implementation for Openfort.
3
+ *
4
+ * This provider implements the request-based API pattern similar to EIP-1193
5
+ * but adapted for Solana operations.
6
+ */
7
+ export class OpenfortSolanaProvider {
8
+ _account;
9
+ _signTransaction;
10
+ _signAllTransactions;
11
+ _signMessage;
12
+ /**
13
+ * Legacy API for reading the public key for this provider.
14
+ * @deprecated Use publicKey getter instead
15
+ */
16
+ _publicKey;
17
+ /**
18
+ * Creates a new OpenfortSolanaProvider instance
19
+ * @param params - Provider configuration
20
+ * @param params.account - The embedded account to use for this provider
21
+ * @param params.signTransaction - Function to sign a single transaction
22
+ * @param params.signAllTransactions - Function to sign multiple transactions
23
+ * @param params.signMessage - Function to sign a message
24
+ */
25
+ constructor(params) {
26
+ this._account = params.account;
27
+ this._publicKey = params.account.address;
28
+ this._signTransaction = params.signTransaction;
29
+ this._signAllTransactions = params.signAllTransactions;
30
+ this._signMessage = params.signMessage;
31
+ }
32
+ /**
33
+ * The public key of the wallet (Solana address)
34
+ */
35
+ get publicKey() {
36
+ return this._account.address;
37
+ }
38
+ async request(args) {
39
+ switch (args.method) {
40
+ case 'signMessage': {
41
+ // Convert message string to Uint8Array
42
+ const signature = await this._signMessage(args.params.message);
43
+ return { signature: signature };
44
+ }
45
+ case 'signTransaction': {
46
+ const signedTransaction = await this._signTransaction(args.params.transaction);
47
+ return { signedTransaction };
48
+ }
49
+ default:
50
+ throw new Error(`Unsupported method: ${args.method}`);
51
+ }
52
+ }
53
+ /**
54
+ * Sign a single transaction (direct method)
55
+ */
56
+ async signTransaction(transaction) {
57
+ return await this._signTransaction(transaction);
58
+ }
59
+ /**
60
+ * Sign multiple transactions (direct method)
61
+ */
62
+ async signAllTransactions(transactions) {
63
+ return await this._signAllTransactions(transactions);
64
+ }
65
+ /**
66
+ * Sign a message (direct method)
67
+ */
68
+ async signMessage(message) {
69
+ return await this._signMessage(message);
70
+ }
71
+ /**
72
+ * Pretty log output for when an instance of this class is `console.log`'d
73
+ */
74
+ toJSON() {
75
+ return `OpenfortSolanaProvider(${this.publicKey})`;
76
+ }
77
+ }