@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.
- package/lib/commonjs/components/OnairosButton.js +13 -15
- package/lib/commonjs/components/OnairosButton.js.map +1 -1
- package/lib/commonjs/components/Overlay.js +8 -15
- package/lib/commonjs/components/Overlay.js.map +1 -1
- package/lib/commonjs/hooks/useConnections.js +18 -36
- package/lib/commonjs/hooks/useConnections.js.map +1 -1
- package/lib/commonjs/utils/secureStorage.js +14 -103
- package/lib/commonjs/utils/secureStorage.js.map +1 -1
- package/lib/module/components/OnairosButton.js +13 -15
- package/lib/module/components/OnairosButton.js.map +1 -1
- package/lib/module/components/Overlay.js +8 -13
- package/lib/module/components/Overlay.js.map +1 -1
- package/lib/module/hooks/useConnections.js +19 -37
- package/lib/module/hooks/useConnections.js.map +1 -1
- package/lib/module/utils/secureStorage.js +14 -102
- package/lib/module/utils/secureStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/components/OnairosButton.tsx +3 -15
- package/src/components/Overlay.tsx +8 -13
- package/src/hooks/useConnections.ts +26 -44
- package/src/utils/secureStorage.ts +14 -104
|
@@ -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
|
-
|
|
26
|
+
// Temporary in-memory storage
|
|
27
|
+
let mockStorage: { [key: string]: string } = {};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Store credentials
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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);
|