@openfort/react-native 1.1.0 → 1.1.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.
Files changed (32) hide show
  1. package/dist/hooks/auth/useEmailAuth.js +12 -10
  2. package/dist/hooks/auth/useEmailAuthOtp.js +5 -9
  3. package/dist/hooks/auth/useGuestAuth.js +4 -4
  4. package/dist/hooks/auth/useOAuth.js +11 -16
  5. package/dist/hooks/auth/usePhoneAuthOtp.js +5 -9
  6. package/dist/hooks/auth/useSignOut.js +2 -2
  7. package/dist/hooks/auth/useWalletAuth.js +6 -10
  8. package/dist/hooks/wallet/useEmbeddedEthereumWallet.js +10 -17
  9. package/dist/hooks/wallet/useEmbeddedSolanaWallet.js +7 -12
  10. package/dist/hooks/wallet/utils.js +7 -10
  11. package/dist/index.js +1 -1
  12. package/dist/lib/hookConsistency.js +1 -1
  13. package/dist/native/passkey.js +2 -14
  14. package/dist/native/webview.js +19 -20
  15. package/dist/types/hooks/auth/useEmailAuth.d.ts +1 -1
  16. package/dist/types/hooks/auth/useEmailAuthOtp.d.ts +1 -1
  17. package/dist/types/hooks/auth/useGuestAuth.d.ts +1 -1
  18. package/dist/types/hooks/auth/useOAuth.d.ts +1 -2
  19. package/dist/types/hooks/auth/usePhoneAuthOtp.d.ts +1 -1
  20. package/dist/types/hooks/auth/useSignOut.d.ts +1 -1
  21. package/dist/types/hooks/auth/useWalletAuth.d.ts +1 -1
  22. package/dist/types/hooks/wallet/useEmbeddedEthereumWallet.d.ts +1 -2
  23. package/dist/types/hooks/wallet/useEmbeddedSolanaWallet.d.ts +1 -2
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/lib/hookConsistency.d.ts +2 -2
  26. package/dist/types/native/passkey.d.ts +1 -2
  27. package/dist/types/types/baseFlowState.d.ts +1 -1
  28. package/dist/types/types/hookOption.d.ts +1 -1
  29. package/dist/types/types/wallet.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/dist/types/openfortError.js +0 -27
  32. package/dist/types/types/openfortError.d.ts +0 -13
@@ -1,8 +1,8 @@
1
+ import { AuthenticationError, OpenfortError } from '@openfort/openfort-js';
1
2
  import { useCallback } from 'react';
2
3
  import { useOpenfortContext } from '../../core/context';
3
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
5
  import { createOAuthRedirectUri } from '../../native/oauth';
5
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
6
6
  const mapStatus = (status) => {
7
7
  return {
8
8
  isLoading: status.status === 'submitting-code' || status.status === 'sending-verification-code',
@@ -87,7 +87,9 @@ export const useEmailAuth = (hookOptions = {}) => {
87
87
  }
88
88
  }
89
89
  catch (e) {
90
- const error = new OpenfortError('Failed to login with email and password', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
90
+ const error = e instanceof OpenfortError
91
+ ? e
92
+ : new AuthenticationError('email_login_error', 'Failed to login with email and password');
91
93
  setPasswordState({
92
94
  status: 'error',
93
95
  error,
@@ -135,7 +137,9 @@ export const useEmailAuth = (hookOptions = {}) => {
135
137
  }
136
138
  }
137
139
  catch (e) {
138
- const error = new OpenfortError('Failed to signup with email and password', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
140
+ const error = e instanceof OpenfortError
141
+ ? e
142
+ : new AuthenticationError('email_signup_error', 'Failed to signup with email and password');
139
143
  setPasswordState({
140
144
  status: 'error',
141
145
  error,
@@ -218,9 +222,9 @@ export const useEmailAuth = (hookOptions = {}) => {
218
222
  });
219
223
  }
220
224
  catch (e) {
221
- const error = new OpenfortError('Failed to request password reset', OpenfortErrorType.AUTHENTICATION_ERROR, {
222
- error: e,
223
- });
225
+ const error = e instanceof OpenfortError
226
+ ? e
227
+ : new AuthenticationError('password_reset_error', 'Failed to request password reset');
224
228
  setPasswordState({
225
229
  status: 'error',
226
230
  error,
@@ -248,9 +252,7 @@ export const useEmailAuth = (hookOptions = {}) => {
248
252
  });
249
253
  }
250
254
  catch (e) {
251
- const error = new OpenfortError('Failed to reset password', OpenfortErrorType.AUTHENTICATION_ERROR, {
252
- error: e,
253
- });
255
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('password_reset_error', 'Failed to reset password');
254
256
  setPasswordState({
255
257
  status: 'error',
256
258
  error,
@@ -277,7 +279,7 @@ export const useEmailAuth = (hookOptions = {}) => {
277
279
  });
278
280
  }
279
281
  catch (e) {
280
- const error = new OpenfortError('Failed to verify email', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
282
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('email_verification_error', 'Failed to verify email');
281
283
  setPasswordState({
282
284
  status: 'error',
283
285
  error,
@@ -1,8 +1,8 @@
1
+ import { AuthenticationError, OpenfortError } from '@openfort/openfort-js';
1
2
  import { useCallback, useState } from 'react';
2
3
  import { useOpenfortContext } from '../../core/context';
3
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
5
  import { mapStatus } from '../../types/baseFlowState';
5
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
6
6
  export const useEmailAuthOtp = (hookOptions = {}) => {
7
7
  const { client, _internal } = useOpenfortContext();
8
8
  const [status, setStatus] = useState({
@@ -14,7 +14,7 @@ export const useEmailAuthOtp = (hookOptions = {}) => {
14
14
  status: 'loading',
15
15
  });
16
16
  if (!options.email || !options.otp) {
17
- const error = new OpenfortError('Email and OTP are required', OpenfortErrorType.AUTHENTICATION_ERROR);
17
+ const error = new AuthenticationError('validation_error', 'Email and OTP are required');
18
18
  setStatus({
19
19
  status: 'error',
20
20
  error,
@@ -41,9 +41,7 @@ export const useEmailAuthOtp = (hookOptions = {}) => {
41
41
  });
42
42
  }
43
43
  catch (e) {
44
- const error = new OpenfortError('Failed to login with email OTP', OpenfortErrorType.AUTHENTICATION_ERROR, {
45
- error: e,
46
- });
44
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('email_otp_error', 'Failed to login with email OTP');
47
45
  setStatus({
48
46
  status: 'error',
49
47
  error: error,
@@ -61,7 +59,7 @@ export const useEmailAuthOtp = (hookOptions = {}) => {
61
59
  status: 'loading',
62
60
  });
63
61
  if (!options.email) {
64
- const error = new OpenfortError('Email is required', OpenfortErrorType.AUTHENTICATION_ERROR);
62
+ const error = new AuthenticationError('validation_error', 'Email is required');
65
63
  setStatus({
66
64
  status: 'error',
67
65
  error,
@@ -85,9 +83,7 @@ export const useEmailAuthOtp = (hookOptions = {}) => {
85
83
  });
86
84
  }
87
85
  catch (e) {
88
- const error = new OpenfortError('Failed to request email OTP', OpenfortErrorType.AUTHENTICATION_ERROR, {
89
- error: e,
90
- });
86
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('email_otp_error', 'Failed to request email OTP');
91
87
  setStatus({
92
88
  status: 'error',
93
89
  error: error,
@@ -1,8 +1,8 @@
1
+ import { AuthenticationError, OpenfortError } from '@openfort/openfort-js';
1
2
  import { useCallback, useState } from 'react';
2
3
  import { useOpenfortContext } from '../../core/context';
3
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
5
  import { mapStatus } from '../../types/baseFlowState';
5
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
6
6
  /**
7
7
  * Hook for guest account authentication.
8
8
  *
@@ -64,9 +64,9 @@ export const useGuestAuth = (hookOptions = {}) => {
64
64
  return { user /* wallet */ };
65
65
  }
66
66
  catch (error) {
67
- const openfortError = new OpenfortError('Failed to signup guest', OpenfortErrorType.AUTHENTICATION_ERROR, {
68
- error,
69
- });
67
+ const openfortError = error instanceof OpenfortError
68
+ ? error
69
+ : new AuthenticationError('guest_signup_error', 'Failed to signup guest');
70
70
  setStatus({
71
71
  status: 'error',
72
72
  error: openfortError,
@@ -1,10 +1,9 @@
1
- import { OAuthProvider } from '@openfort/openfort-js';
1
+ import { AuthenticationError, OAuthProvider, OpenfortError } from '@openfort/openfort-js';
2
2
  import { useCallback } from 'react';
3
3
  import { useOpenfortContext } from '../../core/context';
4
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
5
5
  import { authenticateWithApple, createOAuthRedirectUri, isAppleSignInAvailable, OAuthUtils, openOAuthSession, parseOAuthUrl, } from '../../native';
6
6
  import { mapOAuthStatus } from '../../types/oauth';
7
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
8
7
  /**
9
8
  * Hook for OAuth-based authentication with supported providers.
10
9
  *
@@ -82,9 +81,9 @@ export const useOAuth = (hookOptions = {}) => {
82
81
  });
83
82
  }
84
83
  catch (e) {
85
- const error = new OpenfortError('Apple authentication failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
86
- error: e,
87
- });
84
+ const error = e instanceof OpenfortError
85
+ ? e
86
+ : new AuthenticationError('apple_auth_error', 'Apple authentication failed');
88
87
  setOAuthState({
89
88
  status: 'error',
90
89
  error,
@@ -125,7 +124,7 @@ export const useOAuth = (hookOptions = {}) => {
125
124
  });
126
125
  }
127
126
  else if (oauthResult.type === 'cancel') {
128
- const error = new OpenfortError('OAuth authentication was cancelled by user', OpenfortErrorType.AUTHENTICATION_ERROR);
127
+ const error = new AuthenticationError('oauth_cancelled', 'OAuth authentication was cancelled by user');
129
128
  setOAuthState({
130
129
  status: 'error',
131
130
  error,
@@ -137,7 +136,7 @@ export const useOAuth = (hookOptions = {}) => {
137
136
  });
138
137
  }
139
138
  else {
140
- const error = new OpenfortError(oauthResult.error || 'OAuth authentication failed', OpenfortErrorType.AUTHENTICATION_ERROR);
139
+ const error = new AuthenticationError('oauth_error', oauthResult.error || 'OAuth authentication failed');
141
140
  setOAuthState({
142
141
  status: 'error',
143
142
  error,
@@ -150,9 +149,7 @@ export const useOAuth = (hookOptions = {}) => {
150
149
  }
151
150
  }
152
151
  catch (e) {
153
- const error = new OpenfortError('OAuth initialization failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
154
- error: e,
155
- });
152
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('oauth_error', 'OAuth initialization failed');
156
153
  setOAuthState({
157
154
  status: 'error',
158
155
  error,
@@ -209,9 +206,7 @@ export const useOAuth = (hookOptions = {}) => {
209
206
  });
210
207
  }
211
208
  catch (e) {
212
- const error = new OpenfortError('Apple linking failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
213
- error: e,
214
- });
209
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('apple_link_error', 'Apple linking failed');
215
210
  setOAuthState({
216
211
  status: 'error',
217
212
  error,
@@ -252,7 +247,7 @@ export const useOAuth = (hookOptions = {}) => {
252
247
  });
253
248
  }
254
249
  else if (oauthResult.type === 'cancel') {
255
- const error = new OpenfortError('OAuth linking was cancelled by user', OpenfortErrorType.AUTHENTICATION_ERROR);
250
+ const error = new AuthenticationError('oauth_cancelled', 'OAuth linking was cancelled by user');
256
251
  setOAuthState({
257
252
  status: 'error',
258
253
  error,
@@ -264,7 +259,7 @@ export const useOAuth = (hookOptions = {}) => {
264
259
  });
265
260
  }
266
261
  else {
267
- const error = new OpenfortError(oauthResult.error || 'OAuth linking failed', OpenfortErrorType.AUTHENTICATION_ERROR);
262
+ const error = new AuthenticationError('oauth_error', oauthResult.error || 'OAuth linking failed');
268
263
  setOAuthState({
269
264
  status: 'error',
270
265
  error,
@@ -277,7 +272,7 @@ export const useOAuth = (hookOptions = {}) => {
277
272
  }
278
273
  }
279
274
  catch (e) {
280
- const error = new OpenfortError('OAuth linking failed', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
275
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('oauth_error', 'OAuth linking failed');
281
276
  setOAuthState({
282
277
  status: 'error',
283
278
  error,
@@ -1,8 +1,8 @@
1
+ import { AuthenticationError, OpenfortError } from '@openfort/openfort-js';
1
2
  import { useCallback, useState } from 'react';
2
3
  import { useOpenfortContext } from '../../core/context';
3
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
5
  import { mapStatus } from '../../types/baseFlowState';
5
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
6
6
  export const usePhoneAuthOtp = (hookOptions = {}) => {
7
7
  const { client, _internal } = useOpenfortContext();
8
8
  const [status, setStatus] = useState({
@@ -14,7 +14,7 @@ export const usePhoneAuthOtp = (hookOptions = {}) => {
14
14
  status: 'loading',
15
15
  });
16
16
  if (!options.phone || !options.otp) {
17
- const error = new OpenfortError('Phone and OTP are required', OpenfortErrorType.AUTHENTICATION_ERROR);
17
+ const error = new AuthenticationError('validation_error', 'Phone and OTP are required');
18
18
  setStatus({
19
19
  status: 'error',
20
20
  error,
@@ -41,9 +41,7 @@ export const usePhoneAuthOtp = (hookOptions = {}) => {
41
41
  });
42
42
  }
43
43
  catch (e) {
44
- const error = new OpenfortError('Failed to login with phone OTP', OpenfortErrorType.AUTHENTICATION_ERROR, {
45
- error: e,
46
- });
44
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('phone_otp_error', 'Failed to login with phone OTP');
47
45
  setStatus({
48
46
  status: 'error',
49
47
  error: error,
@@ -61,7 +59,7 @@ export const usePhoneAuthOtp = (hookOptions = {}) => {
61
59
  status: 'loading',
62
60
  });
63
61
  if (!options.phone) {
64
- const error = new OpenfortError('Phone is required', OpenfortErrorType.AUTHENTICATION_ERROR);
62
+ const error = new AuthenticationError('validation_error', 'Phone is required');
65
63
  setStatus({
66
64
  status: 'error',
67
65
  error,
@@ -85,9 +83,7 @@ export const usePhoneAuthOtp = (hookOptions = {}) => {
85
83
  });
86
84
  }
87
85
  catch (e) {
88
- const error = new OpenfortError('Failed to request phone OTP', OpenfortErrorType.AUTHENTICATION_ERROR, {
89
- error: e,
90
- });
86
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('phone_otp_error', 'Failed to request phone OTP');
91
87
  setStatus({
92
88
  status: 'error',
93
89
  error: error,
@@ -1,8 +1,8 @@
1
+ import { AuthenticationError, OpenfortError } from '@openfort/openfort-js';
1
2
  import { useCallback, useRef, useState } from 'react';
2
3
  import { useOpenfortContext } from '../../core';
3
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
5
  import { mapStatus } from '../../types/baseFlowState';
5
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
6
6
  import { useOpenfortClient } from '../core';
7
7
  /**
8
8
  * Hook for user sign out functionality
@@ -64,7 +64,7 @@ export function useSignOut(hookOptions = {}) {
64
64
  });
65
65
  }
66
66
  catch (e) {
67
- const error = new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
67
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('sign_out_error', 'Failed to sign out');
68
68
  setStatus({ status: 'error', error });
69
69
  return onError({
70
70
  hookOptions: hookOptionsRef.current,
@@ -1,7 +1,7 @@
1
+ import { AuthenticationError, OpenfortError } from '@openfort/openfort-js';
1
2
  import { useCallback } from 'react';
2
3
  import { useOpenfortContext } from '../../core/context';
3
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
5
5
  const mapStatus = (status) => {
6
6
  return {
7
7
  isLoading: status.status === 'generating-message' ||
@@ -89,9 +89,9 @@ export function useWalletAuth(hookOptions) {
89
89
  return onError({
90
90
  hookOptions,
91
91
  options: args,
92
- error: new OpenfortError('Failed to generate SIWE message', OpenfortErrorType.AUTHENTICATION_ERROR, {
93
- error: errorObj,
94
- }),
92
+ error: errorObj instanceof OpenfortError
93
+ ? errorObj
94
+ : new AuthenticationError('siwe_error', 'Failed to generate SIWE message'),
95
95
  });
96
96
  }
97
97
  }, [client, setSiweState]);
@@ -125,9 +125,7 @@ export function useWalletAuth(hookOptions) {
125
125
  });
126
126
  }
127
127
  catch (e) {
128
- const error = new OpenfortError('Failed to link in with Ethereum', OpenfortErrorType.AUTHENTICATION_ERROR, {
129
- error: e,
130
- });
128
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('siwe_error', 'Failed to link in with Ethereum');
131
129
  setSiweState({
132
130
  status: 'error',
133
131
  error,
@@ -164,9 +162,7 @@ export function useWalletAuth(hookOptions) {
164
162
  });
165
163
  }
166
164
  catch (e) {
167
- const error = new OpenfortError('Failed to sign in with Ethereum', OpenfortErrorType.AUTHENTICATION_ERROR, {
168
- error: e,
169
- });
165
+ const error = e instanceof OpenfortError ? e : new AuthenticationError('siwe_error', 'Failed to sign in with Ethereum');
170
166
  setSiweState({
171
167
  status: 'error',
172
168
  error,
@@ -1,9 +1,8 @@
1
- import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, RecoveryMethod, } from '@openfort/openfort-js';
1
+ import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, OpenfortError, RecoveryMethod, SignerError, } from '@openfort/openfort-js';
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { useOpenfortContext } from '../../core/context';
4
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
5
5
  import { logger } from '../../lib/logger';
6
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
7
6
  import { buildRecoveryParams } from './utils';
8
7
  /**
9
8
  * Hook for managing embedded Ethereum wallets.
@@ -223,7 +222,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
223
222
  catch (e) {
224
223
  const error = e instanceof OpenfortError
225
224
  ? e
226
- : new OpenfortError('Failed to initialize provider for active Ethereum wallet', OpenfortErrorType.WALLET_ERROR, { error: e });
225
+ : new SignerError('wallet_error', 'Failed to initialize provider for active Ethereum wallet');
227
226
  logger.error('Ethereum provider initialization failed', error);
228
227
  setStatus({ status: 'error', error });
229
228
  }
@@ -275,7 +274,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
275
274
  let chainId;
276
275
  if (createOptions?.chainId) {
277
276
  if (!supportedChains || !supportedChains.some((chain) => chain.id === createOptions.chainId)) {
278
- throw new OpenfortError(`Chain ID ${createOptions.chainId} is not supported. Supported chains: ${supportedChains?.map((c) => c.id).join(', ') || 'none'}`, OpenfortErrorType.WALLET_ERROR);
277
+ throw new SignerError('unsupported_chain', `Chain ID ${createOptions.chainId} is not supported. Supported chains: ${supportedChains?.map((c) => c.id).join(', ') || 'none'}`);
279
278
  }
280
279
  chainId = createOptions.chainId;
281
280
  }
@@ -286,7 +285,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
286
285
  chainId = supportedChains[0].id;
287
286
  }
288
287
  else {
289
- throw new OpenfortError('No supported chains available for wallet creation', OpenfortErrorType.WALLET_ERROR);
288
+ throw new SignerError('unsupported_chain', 'No supported chains available for wallet creation');
290
289
  }
291
290
  // Build recovery params
292
291
  const recoveryParams = await buildRecoveryParams({ ...createOptions, userId: user?.id }, walletConfig);
@@ -326,9 +325,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
326
325
  return embeddedAccount;
327
326
  }
328
327
  catch (e) {
329
- const error = e instanceof OpenfortError
330
- ? e
331
- : new OpenfortError('Failed to create Ethereum wallet', OpenfortErrorType.WALLET_ERROR, { error: e });
328
+ const error = e instanceof OpenfortError ? e : new SignerError('wallet_error', 'Failed to create Ethereum wallet');
332
329
  setStatus({ status: 'error', error });
333
330
  onError({
334
331
  options: createOptions,
@@ -351,7 +348,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
351
348
  return;
352
349
  }
353
350
  if (wallets.length === 0) {
354
- const error = new OpenfortError('No embedded Ethereum wallets available to set as active', OpenfortErrorType.WALLET_ERROR);
351
+ const error = new SignerError('wallet_error', 'No embedded Ethereum wallets available to set as active');
355
352
  onError({
356
353
  options: setActiveOptions,
357
354
  error,
@@ -371,7 +368,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
371
368
  let chainId;
372
369
  if (setActiveOptions.chainId) {
373
370
  if (!supportedChains || !supportedChains.some((chain) => chain.id === setActiveOptions.chainId)) {
374
- throw new OpenfortError(`Chain ID ${setActiveOptions.chainId} is not supported. Supported chains: ${supportedChains?.map((c) => c.id).join(', ') || 'none'}`, OpenfortErrorType.WALLET_ERROR);
371
+ throw new SignerError('unsupported_chain', `Chain ID ${setActiveOptions.chainId} is not supported. Supported chains: ${supportedChains?.map((c) => c.id).join(', ') || 'none'}`);
375
372
  }
376
373
  chainId = setActiveOptions.chainId;
377
374
  }
@@ -395,7 +392,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
395
392
  const errorMsg = walletConfig?.accountType === AccountTypeEnum.EOA
396
393
  ? `No embedded EOA account found for address ${setActiveOptions.address}`
397
394
  : `No embedded smart account found for address ${setActiveOptions.address} on chain ID ${chainId}`;
398
- throw new OpenfortError(errorMsg, OpenfortErrorType.WALLET_ERROR);
395
+ throw new SignerError('wallet_error', errorMsg);
399
396
  }
400
397
  // Auto-detect recovery method from account if not explicitly provided
401
398
  let effectiveRecoveryMethod = setActiveOptions.recoveryMethod;
@@ -470,9 +467,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
470
467
  }
471
468
  catch (e) {
472
469
  recoverPromiseRef.current = null;
473
- const error = e instanceof OpenfortError
474
- ? e
475
- : new OpenfortError('Failed to set active Ethereum wallet', OpenfortErrorType.WALLET_ERROR);
470
+ const error = e instanceof OpenfortError ? e : new SignerError('wallet_error', 'Failed to set active Ethereum wallet');
476
471
  setStatus({ status: 'error', error });
477
472
  onError({
478
473
  options: setActiveOptions,
@@ -507,9 +502,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
507
502
  }
508
503
  }
509
504
  catch (e) {
510
- const error = new OpenfortError('Failed to set wallet recovery', OpenfortErrorType.WALLET_ERROR, {
511
- error: e instanceof Error ? e : new Error('Unknown error'),
512
- });
505
+ const error = e instanceof OpenfortError ? e : new SignerError('wallet_error', 'Failed to set wallet recovery');
513
506
  setStatus({ status: 'error', error });
514
507
  onError({
515
508
  options: params,
@@ -1,9 +1,8 @@
1
- import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, RecoveryMethod, } from '@openfort/openfort-js';
1
+ import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, OpenfortError, RecoveryMethod, SignerError, } from '@openfort/openfort-js';
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { useOpenfortContext } from '../../core/context';
4
4
  import { onError, onSuccess } from '../../lib/hookConsistency';
5
5
  import { logger } from '../../lib/logger';
6
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
7
6
  import { OpenfortSolanaProvider } from './solanaProvider';
8
7
  import { buildRecoveryParams } from './utils';
9
8
  /**
@@ -189,7 +188,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
189
188
  messageBytes = transaction.serializeMessage();
190
189
  }
191
190
  else {
192
- throw new OpenfortError('Unsupported transaction format. Expected @solana/kit compiled transaction, @solana/web3.js Transaction, or Uint8Array', OpenfortErrorType.WALLET_ERROR);
191
+ throw new SignerError('wallet_error', 'Unsupported transaction format. Expected @solana/kit compiled transaction, @solana/web3.js Transaction, or Uint8Array');
193
192
  }
194
193
  // Convert Uint8Array to Buffer JSON format for React Native WebView serialization
195
194
  // This is necessary because React Native's postMessage only accepts strings,
@@ -258,7 +257,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
258
257
  catch (e) {
259
258
  const error = e instanceof OpenfortError
260
259
  ? e
261
- : new OpenfortError('Failed to initialize provider for active Solana wallet', OpenfortErrorType.WALLET_ERROR, { error: e });
260
+ : new SignerError('wallet_error', 'Failed to initialize provider for active Solana wallet');
262
261
  logger.error('Solana provider initialization failed', error);
263
262
  setStatus({ status: 'error', error });
264
263
  }
@@ -324,9 +323,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
324
323
  return embeddedAccount;
325
324
  }
326
325
  catch (e) {
327
- const error = e instanceof OpenfortError
328
- ? e
329
- : new OpenfortError('Failed to create Solana wallet', OpenfortErrorType.WALLET_ERROR, { error: e });
326
+ const error = e instanceof OpenfortError ? e : new SignerError('wallet_error', 'Failed to create Solana wallet');
330
327
  setStatus({ status: 'error', error });
331
328
  onError({
332
329
  options: createOptions,
@@ -349,7 +346,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
349
346
  return;
350
347
  }
351
348
  if (wallets.length === 0) {
352
- const error = new OpenfortError('No embedded Solana wallets available to set as active', OpenfortErrorType.WALLET_ERROR);
349
+ const error = new SignerError('wallet_error', 'No embedded Solana wallets available to set as active');
353
350
  onError({
354
351
  options: setActiveOptions,
355
352
  error,
@@ -368,7 +365,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
368
365
  // Find account to recover by address only
369
366
  const embeddedAccountToRecover = embeddedAccounts.find((account) => account.address.toLowerCase() === setActiveOptions.address.toLowerCase());
370
367
  if (!embeddedAccountToRecover) {
371
- throw new OpenfortError(`No embedded Solana account found for address ${setActiveOptions.address}`, OpenfortErrorType.WALLET_ERROR);
368
+ throw new SignerError('wallet_error', `No embedded Solana account found for address ${setActiveOptions.address}`);
372
369
  }
373
370
  // Auto-detect recovery method from account if not explicitly provided
374
371
  let effectiveRecoveryMethod = setActiveOptions.recoveryMethod;
@@ -435,9 +432,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
435
432
  }
436
433
  catch (e) {
437
434
  recoverPromiseRef.current = null;
438
- const error = e instanceof OpenfortError
439
- ? e
440
- : new OpenfortError('Failed to set active Solana wallet', OpenfortErrorType.WALLET_ERROR);
435
+ const error = e instanceof OpenfortError ? e : new SignerError('wallet_error', 'Failed to set active Solana wallet');
441
436
  setStatus({ status: 'error', error });
442
437
  onError({
443
438
  options: setActiveOptions,
@@ -1,5 +1,4 @@
1
- import { RecoveryMethod } from '@openfort/openfort-js';
2
- import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
1
+ import { OpenfortError, RecoveryMethod, SignerError } from '@openfort/openfort-js';
3
2
  /**
4
3
  * Resolves an encryption session from wallet configuration.
5
4
  *
@@ -16,7 +15,7 @@ import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
16
15
  */
17
16
  async function resolveEncryptionSession(walletConfig, otpCode, userId) {
18
17
  if (!walletConfig) {
19
- throw new OpenfortError('Encryption session configuration is required', OpenfortErrorType.WALLET_ERROR);
18
+ throw new SignerError('missing_encryption_session', 'Encryption session configuration is required');
20
19
  }
21
20
  // Try callback-based session retrieval first
22
21
  if (walletConfig.getEncryptionSession) {
@@ -33,13 +32,11 @@ async function resolveEncryptionSession(walletConfig, otpCode, userId) {
33
32
  body: JSON.stringify({ otp_code: otpCode, user_id: userId }),
34
33
  });
35
34
  if (!response.ok) {
36
- throw new OpenfortError('Failed to create encryption session', OpenfortErrorType.WALLET_ERROR, {
37
- status: response.status,
38
- });
35
+ throw new SignerError('encryption_session_error', 'Failed to create encryption session');
39
36
  }
40
37
  const body = (await response.json());
41
38
  if (!body?.session || typeof body.session !== 'string') {
42
- throw new OpenfortError('Encryption session response is missing the `session` property', OpenfortErrorType.WALLET_ERROR);
39
+ throw new SignerError('encryption_session_error', 'Encryption session response is missing the `session` property');
43
40
  }
44
41
  return body.session;
45
42
  }
@@ -47,10 +44,10 @@ async function resolveEncryptionSession(walletConfig, otpCode, userId) {
47
44
  if (error instanceof OpenfortError) {
48
45
  throw error;
49
46
  }
50
- throw new OpenfortError('Failed to create encryption session', OpenfortErrorType.WALLET_ERROR, { error });
47
+ throw new SignerError('encryption_session_error', 'Failed to create encryption session');
51
48
  }
52
49
  }
53
- throw new OpenfortError('Encryption session configuration is required', OpenfortErrorType.WALLET_ERROR);
50
+ throw new SignerError('missing_encryption_session', 'Encryption session configuration is required');
54
51
  }
55
52
  /**
56
53
  * Builds recovery parameters from options and wallet configuration.
@@ -84,7 +81,7 @@ export async function buildRecoveryParams(options, walletConfig) {
84
81
  // If password recovery method is explicitly requested or password is provided
85
82
  if (options?.recoveryMethod === 'password' || options?.recoveryPassword) {
86
83
  if (!options?.recoveryPassword) {
87
- throw new OpenfortError('Recovery password is required when using password recovery method', OpenfortErrorType.WALLET_ERROR);
84
+ throw new SignerError('missing_recovery_password', 'Recovery password is required when using password recovery method');
88
85
  }
89
86
  return {
90
87
  recoveryMethod: RecoveryMethod.PASSWORD,
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // Re-export commonly used types from @openfort/openfort-js
12
12
  // Re-export enums and values from @openfort/openfort-js
13
13
  // Re-export event listener functionality from @openfort/openfort-js
14
- export { AccountTypeEnum, ChainTypeEnum, EmbeddedState, OAuthProvider, Openfort as OpenfortClient, OpenfortConfiguration, OpenfortError, OpenfortEvents, openfortEvents, RecoveryMethod, ShieldConfiguration, ThirdPartyOAuthProvider, } from '@openfort/openfort-js';
14
+ export { AccountTypeEnum, AuthenticationError, ChainTypeEnum, EmbeddedState, OAuthProvider, Openfort as OpenfortClient, OpenfortConfiguration, OpenfortError, OpenfortEvents, openfortEvents, RecoveryError, RecoveryMethod, SessionError, ShieldConfiguration, SignerError, ThirdPartyOAuthProvider, } from '@openfort/openfort-js';
15
15
  // Re-export all components and UI elements
16
16
  export * from './components';
17
17
  // Re-export constants
@@ -42,7 +42,7 @@ export const onSuccess = ({ hookOptions, options, data, }) => {
42
42
  * try {
43
43
  * await someAsyncOperation();
44
44
  * } catch (e) {
45
- * const error = new OpenfortError('Operation failed', OpenfortErrorType.GENERIC);
45
+ * const error = new AuthenticationError('operation_failed', 'Operation failed');
46
46
  * return onError({
47
47
  * hookOptions,
48
48
  * options,
@@ -6,17 +6,6 @@ import { logger } from '../lib/logger';
6
6
  * Handles base64/base64url encoding, key extraction, and challenge generation.
7
7
  */
8
8
  const PasskeyUtils = {
9
- /** Valid byte lengths for derived keys (AES-128, AES-192, AES-256) */
10
- validByteLengths: [16, 24, 32],
11
- /**
12
- * Validates that the key byte length is valid for AES encryption.
13
- * @throws Error if length is not 16, 24, or 32
14
- */
15
- validateKeyByteLength(length) {
16
- if (!this.validByteLengths.includes(length)) {
17
- throw new Error(`Invalid key byte length ${length}. Must be 16, 24, or 32.`);
18
- }
19
- },
20
9
  /**
21
10
  * Generates a random 32-byte challenge for WebAuthn operations.
22
11
  */
@@ -148,9 +137,8 @@ export class NativePasskeyHandler {
148
137
  constructor(config) {
149
138
  this.rpId = config.rpId;
150
139
  this.rpName = config.rpName;
151
- this.timeout = config.timeout ?? 60_000;
152
- this.derivedKeyLengthBytes = config.derivedKeyLengthBytes ?? 32;
153
- PasskeyUtils.validateKeyByteLength(this.derivedKeyLengthBytes);
140
+ this.timeout = 60_000;
141
+ this.derivedKeyLengthBytes = 32;
154
142
  }
155
143
  /**
156
144
  * Normalizes prf.results.first from the native module to Uint8Array.
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  // biome-ignore lint: need to import react
3
3
  import React, { useCallback, useEffect, useRef } from 'react';
4
- import { AppState, Platform, View } from 'react-native';
4
+ import { Platform, View } from 'react-native';
5
5
  import WebView from 'react-native-webview';
6
6
  import { logger } from '../lib/logger';
7
7
  import { handleSecureStorageMessage, isSecureStorageMessage } from './storage';
@@ -15,25 +15,24 @@ import { handleSecureStorageMessage, isSecureStorageMessage } from './storage';
15
15
  export const EmbeddedWalletWebView = ({ client, onProxyStatusChange, debug }) => {
16
16
  const webViewRef = useRef(null);
17
17
  // Handle app state changes to monitor WebView health
18
- useEffect(() => {
19
- const handleAppStateChange = async (nextAppState) => {
20
- if (nextAppState === 'active') {
21
- // Check if embedded wallet is still responsive
22
- try {
23
- await client.embeddedWallet.ping(500);
24
- // if (!isResponsive) {
25
- // onProxyStatusChange?.('reloading');
26
- // // client.embeddedWallet.reload();
27
- // }
28
- }
29
- catch (error) {
30
- logger.warn('Failed to ping embedded wallet', error);
31
- }
32
- }
33
- };
34
- const subscription = AppState.addEventListener('change', handleAppStateChange);
35
- return () => subscription?.remove();
36
- }, [client, onProxyStatusChange]);
18
+ // useEffect(() => {
19
+ // const handleAppStateChange = async (nextAppState: string) => {
20
+ // if (nextAppState === 'active') {
21
+ // // Check if embedded wallet is still responsive
22
+ // try {
23
+ // await client.embeddedWallet.ping(500)
24
+ // // if (!isResponsive) {
25
+ // // onProxyStatusChange?.('reloading');
26
+ // // // client.embeddedWallet.reload();
27
+ // // }
28
+ // } catch (error) {
29
+ // logger.warn('Failed to ping embedded wallet', error)
30
+ // }
31
+ // }
32
+ // }
33
+ // const subscription = AppState.addEventListener('change', handleAppStateChange)
34
+ // return () => subscription?.remove()
35
+ // }, [client, onProxyStatusChange])
37
36
  // Handle WebView load events
38
37
  const handleLoad = useCallback(() => {
39
38
  onProxyStatusChange?.('loaded');
@@ -1,6 +1,6 @@
1
1
  import type { User as OpenfortUser } from '@openfort/openfort-js';
2
+ import { OpenfortError } from '@openfort/openfort-js';
2
3
  import type { OpenfortHookOptions } from '../../types/hookOption';
3
- import { OpenfortError } from '../../types/openfortError';
4
4
  export type EmailAuthResult = {
5
5
  error?: OpenfortError;
6
6
  user?: OpenfortUser;
@@ -1,6 +1,6 @@
1
1
  import type { User } from '@openfort/openfort-js';
2
+ import { OpenfortError } from '@openfort/openfort-js';
2
3
  import type { OpenfortHookOptions } from '../../types/hookOption';
3
- import { OpenfortError } from '../../types/openfortError';
4
4
  export type EmailOtpAuthResult = {
5
5
  error?: OpenfortError;
6
6
  user?: User;
@@ -1,6 +1,6 @@
1
1
  import type { User as OpenfortUser } from '@openfort/openfort-js';
2
+ import { OpenfortError } from '@openfort/openfort-js';
2
3
  import type { OpenfortHookOptions } from '../../types/hookOption';
3
- import { OpenfortError } from '../../types/openfortError';
4
4
  export type GuestHookResult = {
5
5
  error?: OpenfortError;
6
6
  user?: OpenfortUser;
@@ -1,6 +1,5 @@
1
- import { OAuthProvider, type User as OpenfortUser } from '@openfort/openfort-js';
1
+ import { OAuthProvider, OpenfortError, type User as OpenfortUser } from '@openfort/openfort-js';
2
2
  import type { OpenfortHookOptions } from '../../types/hookOption';
3
- import { OpenfortError } from '../../types/openfortError';
4
3
  export type InitializeOAuthOptions = {
5
4
  provider: OAuthProvider;
6
5
  redirectTo?: string;
@@ -1,6 +1,6 @@
1
1
  import type { User } from '@openfort/openfort-js';
2
+ import { OpenfortError } from '@openfort/openfort-js';
2
3
  import type { OpenfortHookOptions } from '../../types/hookOption';
3
- import { OpenfortError } from '../../types/openfortError';
4
4
  export type PhoneOtpAuthResult = {
5
5
  error?: OpenfortError;
6
6
  user?: User;
@@ -1,5 +1,5 @@
1
+ import { OpenfortError } from '@openfort/openfort-js';
1
2
  import type { OpenfortHookOptions } from '../../types/hookOption';
2
- import { OpenfortError } from '../../types/openfortError';
3
3
  /**
4
4
  * Hook for user sign out functionality
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import type { User as OpenfortUser } from '@openfort/openfort-js';
2
+ import { OpenfortError } from '@openfort/openfort-js';
2
3
  import type { OpenfortHookOptions } from '../../types/hookOption';
3
- import { OpenfortError } from '../../types/openfortError';
4
4
  export type WalletHookResult = {
5
5
  error?: OpenfortError;
6
6
  user?: OpenfortUser;
@@ -1,5 +1,4 @@
1
- import { type EmbeddedAccount } from '@openfort/openfort-js';
2
- import { OpenfortError } from '../../types/openfortError';
1
+ import { type EmbeddedAccount, OpenfortError } from '@openfort/openfort-js';
3
2
  import type { ConnectedEmbeddedEthereumWallet, EmbeddedEthereumWalletState, OpenfortEmbeddedEthereumWalletProvider } from '../../types/wallet';
4
3
  type UseEmbeddedEthereumWalletOptions = {
5
4
  chainId?: number;
@@ -1,5 +1,4 @@
1
- import { type EmbeddedAccount } from '@openfort/openfort-js';
2
- import { OpenfortError } from '../../types/openfortError';
1
+ import { type EmbeddedAccount, OpenfortError } from '@openfort/openfort-js';
3
2
  import type { ConnectedEmbeddedSolanaWallet, EmbeddedSolanaWalletState, OpenfortEmbeddedSolanaWalletProvider } from '../../types/wallet';
4
3
  type UseEmbeddedSolanaWalletOptions = {
5
4
  onCreateSuccess?: (account: EmbeddedAccount, provider: OpenfortEmbeddedSolanaWalletProvider) => void;
@@ -7,7 +7,7 @@
7
7
  * required to integrate Openfort authentication and embedded wallets into React Native and
8
8
  * Expo applications.
9
9
  */
10
- export { AccountTypeEnum, AuthInitPayload, AuthResponse, ChainTypeEnum, EmbeddedAccount, EmbeddedState, OAuthProvider, Openfort as OpenfortClient, OpenfortConfiguration, OpenfortError, OpenfortEventMap, OpenfortEvents, openfortEvents, Provider, RecoveryMethod, RecoveryParams, ShieldConfiguration, SignedMessagePayload, ThirdPartyOAuthProvider, } from '@openfort/openfort-js';
10
+ export { AccountTypeEnum, AuthenticationError, AuthInitPayload, AuthResponse, ChainTypeEnum, EmbeddedAccount, EmbeddedState, OAuthProvider, Openfort as OpenfortClient, OpenfortConfiguration, OpenfortError, OpenfortEventMap, OpenfortEvents, openfortEvents, Provider, RecoveryError, RecoveryMethod, RecoveryParams, SessionError, ShieldConfiguration, SignedMessagePayload, SignerError, ThirdPartyOAuthProvider, } from '@openfort/openfort-js';
11
11
  export * from './components';
12
12
  export * from './constants';
13
13
  export * from './core';
@@ -1,5 +1,5 @@
1
+ import type { OpenfortError } from '@openfort/openfort-js';
1
2
  import type { OpenfortHookOptions } from '../types/hookOption';
2
- import type { OpenfortError } from '../types/openfortError';
3
3
  /**
4
4
  * Handles successful hook operation callbacks
5
5
  *
@@ -44,7 +44,7 @@ export declare const onSuccess: <T>({ hookOptions, options, data, }: {
44
44
  * try {
45
45
  * await someAsyncOperation();
46
46
  * } catch (e) {
47
- * const error = new OpenfortError('Operation failed', OpenfortErrorType.GENERIC);
47
+ * const error = new AuthenticationError('operation_failed', 'Operation failed');
48
48
  * return onError({
49
49
  * hookOptions,
50
50
  * options,
@@ -56,8 +56,7 @@ export declare function isPasskeyPrfSupported(): Promise<boolean>;
56
56
  export interface NativePasskeyHandlerConfig {
57
57
  rpId?: string;
58
58
  rpName?: string;
59
- timeout?: number;
60
- derivedKeyLengthBytes?: number;
59
+ displayName?: string;
61
60
  }
62
61
  interface PublicKeyCredentialCreationOptions {
63
62
  challenge: string;
@@ -1,4 +1,4 @@
1
- import type { OpenfortError } from './openfortError';
1
+ import type { OpenfortError } from '@openfort/openfort-js';
2
2
  export type BaseFlowState = {
3
3
  status: 'idle' | 'awaiting-input' | 'loading' | 'success';
4
4
  error?: never;
@@ -1,4 +1,4 @@
1
- import type { OpenfortError } from './openfortError';
1
+ import type { OpenfortError } from '@openfort/openfort-js';
2
2
  export type OpenfortHookOptions<T = {
3
3
  error?: OpenfortError;
4
4
  }> = {
@@ -3,9 +3,9 @@ import type { AccountTypeEnum, ChainTypeEnum, EmbeddedAccount, RecoveryMethod, R
3
3
  * Recovery method details extracted from EmbeddedAccount
4
4
  */
5
5
  export type RecoveryMethodDetails = EmbeddedAccount['recoveryMethodDetails'];
6
+ import type { OpenfortError } from '@openfort/openfort-js';
6
7
  import type { Hex } from './hex';
7
8
  import type { OpenfortHookOptions } from './hookOption';
8
- import type { OpenfortError } from './openfortError';
9
9
  /**
10
10
  * JSON-RPC request arguments following EIP-1193 spec
11
11
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "license": "MIT",
6
6
  "description": "React Native SDK for Openfort platform integration",
7
7
  "repository": {
@@ -1,27 +0,0 @@
1
- export var OpenfortErrorType;
2
- (function (OpenfortErrorType) {
3
- OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
4
- OpenfortErrorType["WALLET_ERROR"] = "WALLET_ERROR";
5
- })(OpenfortErrorType || (OpenfortErrorType = {}));
6
- export class OpenfortError extends Error {
7
- type;
8
- data;
9
- constructor(message, type, data) {
10
- if (data?.error instanceof OpenfortError) {
11
- super(data.error.message);
12
- this.data = data.error.data;
13
- this.type = data.error.type;
14
- this.name = data.error.name;
15
- return;
16
- }
17
- else if (data?.error instanceof Error) {
18
- super(data.error.message);
19
- }
20
- else {
21
- super(message);
22
- }
23
- this.type = type;
24
- this.data = data || {};
25
- this.name = 'OpenfortError';
26
- }
27
- }
@@ -1,13 +0,0 @@
1
- export declare enum OpenfortErrorType {
2
- AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
3
- WALLET_ERROR = "WALLET_ERROR"
4
- }
5
- interface Data {
6
- [key: string]: any;
7
- }
8
- export declare class OpenfortError extends Error {
9
- type: OpenfortErrorType;
10
- data: Data;
11
- constructor(message: string, type: OpenfortErrorType, data?: Data);
12
- }
13
- export {};