@onairos/react-native 2.0.6 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import * as Keychain from 'react-native-keychain';
2
1
  import { Platform } from 'react-native';
3
2
  import { sha256 } from './crypto';
4
3
 
@@ -24,56 +23,19 @@ export interface StorageOptions {
24
23
  };
25
24
  }
26
25
 
27
- const CREDENTIALS_KEY = 'onairos_credentials';
26
+ // Temporary in-memory storage
27
+ let mockStorage: { [key: string]: string } = {};
28
28
 
29
29
  /**
30
- * Store credentials securely in the device keychain with optional biometric protection
30
+ * Store credentials in memory (temporary solution)
31
31
  */
32
32
  export const storeCredentials = async (
33
33
  credentials: OnairosCredentials,
34
34
  options: StorageOptions = {}
35
35
  ): Promise<boolean> => {
36
36
  try {
37
- const { useBiometrics = true, biometricPrompt } = options;
38
-
39
- // Create a JSON string of the credentials
40
- const credentialsString = JSON.stringify(credentials);
41
-
42
- // Configure security options based on platform
43
- const securityOptions: Keychain.Options = {
44
- service: CREDENTIALS_KEY,
45
- accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
46
- };
47
-
48
- // Add biometric protection if requested
49
- if (useBiometrics) {
50
- // iOS specific options
51
- if (Platform.OS === 'ios') {
52
- securityOptions.accessControl = Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE;
53
- }
54
-
55
- // Android specific options
56
- if (Platform.OS === 'android') {
57
- securityOptions.accessControl = Keychain.ACCESS_CONTROL.BIOMETRY_ANY;
58
- if (biometricPrompt) {
59
- securityOptions.authenticationType = Keychain.AUTHENTICATION_TYPE.BIOMETRIC;
60
- securityOptions.authenticationPrompt = {
61
- title: biometricPrompt.title || 'Biometric Authentication',
62
- subtitle: biometricPrompt.subtitle,
63
- description: 'Please authenticate to access your Onairos credentials',
64
- cancel: 'Cancel',
65
- };
66
- }
67
- }
68
- }
69
-
70
- // Store in the secure keychain
71
- await Keychain.setGenericPassword(
72
- credentials.username,
73
- credentialsString,
74
- securityOptions
75
- );
76
-
37
+ console.log('[Mock] Storing credentials:', credentials.username);
38
+ mockStorage[credentials.username] = JSON.stringify(credentials);
77
39
  return true;
78
40
  } catch (error) {
79
41
  console.error('Error storing credentials:', error);
@@ -82,39 +44,18 @@ export const storeCredentials = async (
82
44
  };
83
45
 
84
46
  /**
85
- * Retrieve credentials from secure storage, potentially requiring biometric authentication
47
+ * Retrieve credentials from memory (temporary solution)
86
48
  */
87
49
  export const getCredentials = async (
88
50
  options: StorageOptions = {}
89
51
  ): Promise<OnairosCredentials | null> => {
90
52
  try {
91
- const { useBiometrics = true, biometricPrompt } = options;
92
-
93
- // Configure security options
94
- const securityOptions: Keychain.Options = {
95
- service: CREDENTIALS_KEY,
96
- };
97
-
98
- // Add biometric prompt if required
99
- if (useBiometrics && biometricPrompt) {
100
- securityOptions.authenticationPrompt = {
101
- title: biometricPrompt.title || 'Biometric Authentication',
102
- subtitle: biometricPrompt.subtitle,
103
- description: 'Please authenticate to access your Onairos credentials',
104
- cancel: 'Cancel',
105
- };
106
- }
107
-
108
- // Retrieve from keychain
109
- const result = await Keychain.getGenericPassword(securityOptions);
110
-
111
- if (!result) {
53
+ // Get the first stored credential (temporary solution)
54
+ const storedCredential = Object.values(mockStorage)[0];
55
+ if (!storedCredential) {
112
56
  return null;
113
57
  }
114
-
115
- // Parse the stored JSON
116
- const credentials: OnairosCredentials = JSON.parse(result.password);
117
- return credentials;
58
+ return JSON.parse(storedCredential);
118
59
  } catch (error) {
119
60
  console.error('Error retrieving credentials:', error);
120
61
  return null;
@@ -126,11 +67,7 @@ export const getCredentials = async (
126
67
  */
127
68
  export const hasCredentials = async (): Promise<boolean> => {
128
69
  try {
129
- const result = await Keychain.getGenericPassword({
130
- service: CREDENTIALS_KEY,
131
- });
132
-
133
- return !!result;
70
+ return Object.keys(mockStorage).length > 0;
134
71
  } catch (error) {
135
72
  console.error('Error checking for credentials:', error);
136
73
  return false;
@@ -142,7 +79,7 @@ export const hasCredentials = async (): Promise<boolean> => {
142
79
  */
143
80
  export const deleteCredentials = async (): Promise<boolean> => {
144
81
  try {
145
- await Keychain.resetGenericPassword({ service: CREDENTIALS_KEY });
82
+ mockStorage = {};
146
83
  return true;
147
84
  } catch (error) {
148
85
  console.error('Error deleting credentials:', error);
@@ -158,20 +95,14 @@ export const updateCredentials = async (
158
95
  options: StorageOptions = {}
159
96
  ): Promise<boolean> => {
160
97
  try {
161
- // Get current credentials
162
98
  const currentCredentials = await getCredentials(options);
163
-
164
99
  if (!currentCredentials) {
165
100
  return false;
166
101
  }
167
-
168
- // Merge updates with current credentials
169
102
  const updatedCredentials: OnairosCredentials = {
170
103
  ...currentCredentials,
171
104
  ...updates,
172
105
  };
173
-
174
- // Store updated credentials
175
106
  return await storeCredentials(updatedCredentials, options);
176
107
  } catch (error) {
177
108
  console.error('Error updating credentials:', error);
@@ -184,44 +115,23 @@ export const updateCredentials = async (
184
115
  */
185
116
  export const generateDeviceUsername = async (): Promise<string> => {
186
117
  try {
187
- // Get a device-specific identifier that we can use
188
- // This is a simplified example - in production you might want to use
189
- // a more robust device identifier method
190
118
  const deviceInfo = `${Platform.OS}-${Platform.Version}-${Date.now()}`;
191
-
192
- // Hash it to create a unique identifier
193
119
  const username = `onairos_${sha256(deviceInfo).substring(0, 10)}`;
194
-
195
120
  return username;
196
121
  } catch (error) {
197
122
  console.error('Error generating device username:', error);
198
- // Fallback to a timestamp-based username if there's an error
199
123
  return `onairos_${Date.now().toString(36)}`;
200
124
  }
201
125
  };
202
126
 
203
127
  /**
204
- * Verify if credentials are valid (not expired, etc.)
128
+ * Verify credentials (temporary mock implementation)
205
129
  */
206
130
  export const verifyCredentials = async (
207
131
  credentials: OnairosCredentials
208
132
  ): Promise<boolean> => {
209
133
  try {
210
- // Basic verification - check if credentials exist and aren't too old
211
- if (!credentials || !credentials.accessToken || !credentials.username) {
212
- return false;
213
- }
214
-
215
- // Check for expiration (example: credentials expire after 30 days)
216
- const thirtyDaysMs = 30 * 24 * 60 * 60 * 1000;
217
- const isExpired = Date.now() - credentials.createdAt > thirtyDaysMs;
218
-
219
- if (isExpired) {
220
- return false;
221
- }
222
-
223
- // Add any additional verification logic here
224
-
134
+ console.log('[Mock] Verifying credentials for:', credentials.username);
225
135
  return true;
226
136
  } catch (error) {
227
137
  console.error('Error verifying credentials:', error);