@onairos/react-native 3.0.1 → 3.0.4
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/README.md +23 -3
- package/lib/commonjs/api/index.js +109 -86
- package/lib/commonjs/api/index.js.map +1 -1
- package/lib/commonjs/components/OnairosButton.js +20 -13
- package/lib/commonjs/components/OnairosButton.js.map +1 -1
- package/lib/commonjs/components/Overlay.js +260 -108
- package/lib/commonjs/components/Overlay.js.map +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +30 -0
- package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
- package/lib/commonjs/components/onboarding/OAuthWebView.js +28 -9
- package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/commonjs/components/onboarding/PlatformConnector.js +6 -1
- package/lib/commonjs/components/onboarding/PlatformConnector.js.map +1 -1
- package/lib/commonjs/components/screens/ConnectorScreen.js +3 -2
- package/lib/commonjs/components/screens/ConnectorScreen.js.map +1 -1
- package/lib/commonjs/constants/index.js +1 -1
- package/lib/commonjs/hooks/useConnections.js +77 -15
- package/lib/commonjs/hooks/useConnections.js.map +1 -1
- package/lib/commonjs/hooks/useCredentials.js +2 -0
- package/lib/commonjs/hooks/useCredentials.js.map +1 -1
- package/lib/commonjs/index.js +38 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/oauthService.js +26 -51
- package/lib/commonjs/services/oauthService.js.map +1 -1
- package/lib/commonjs/types/ambient.d.js +2 -0
- package/lib/commonjs/types/ambient.d.js.map +1 -0
- package/lib/commonjs/types/node-fix.d.js +2 -0
- package/lib/commonjs/types/node-fix.d.js.map +1 -0
- package/lib/commonjs/types/node-override.d.js +2 -0
- package/lib/commonjs/types/node-override.d.js.map +1 -0
- package/lib/commonjs/types/types.d.js +2 -0
- package/lib/commonjs/types/types.d.js.map +1 -0
- package/lib/commonjs/utils/encryption.js +8 -2
- package/lib/commonjs/utils/encryption.js.map +1 -1
- package/lib/commonjs/utils/secureStorage.js +148 -42
- package/lib/commonjs/utils/secureStorage.js.map +1 -1
- package/lib/module/api/index.js +109 -86
- package/lib/module/api/index.js.map +1 -1
- package/lib/module/components/OnairosButton.js +21 -14
- package/lib/module/components/OnairosButton.js.map +1 -1
- package/lib/module/components/Overlay.js +260 -110
- package/lib/module/components/Overlay.js.map +1 -1
- package/lib/module/components/UniversalOnboarding.js +31 -1
- package/lib/module/components/UniversalOnboarding.js.map +1 -1
- package/lib/module/components/onboarding/OAuthWebView.js +28 -9
- package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/module/components/onboarding/PlatformConnector.js +6 -1
- package/lib/module/components/onboarding/PlatformConnector.js.map +1 -1
- package/lib/module/components/screens/ConnectorScreen.js +3 -2
- package/lib/module/components/screens/ConnectorScreen.js.map +1 -1
- package/lib/module/constants/index.js +1 -1
- package/lib/module/hooks/useConnections.js +77 -14
- package/lib/module/hooks/useConnections.js.map +1 -1
- package/lib/module/hooks/useCredentials.js +2 -0
- package/lib/module/hooks/useCredentials.js.map +1 -1
- package/lib/module/index.js +27 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/oauthService.js +26 -33
- package/lib/module/services/oauthService.js.map +1 -1
- package/lib/module/types/ambient.d.js +2 -0
- package/lib/module/types/ambient.d.js.map +1 -0
- package/lib/module/types/node-fix.d.js +2 -0
- package/lib/module/types/node-fix.d.js.map +1 -0
- package/lib/module/types/node-override.d.js +2 -0
- package/lib/module/types/node-override.d.js.map +1 -0
- package/lib/module/types/types.d.js +2 -0
- package/lib/module/types/types.d.js.map +1 -0
- package/lib/module/utils/encryption.js +8 -2
- package/lib/module/utils/encryption.js.map +1 -1
- package/lib/module/utils/secureStorage.js +149 -42
- package/lib/module/utils/secureStorage.js.map +1 -1
- package/lib/typescript/api/index.d.ts +8 -0
- package/lib/typescript/api/index.d.ts.map +1 -0
- package/lib/typescript/components/DataRequestModal.d.ts +11 -0
- package/lib/typescript/components/DataRequestModal.d.ts.map +1 -0
- package/lib/typescript/components/Onairos.d.ts +29 -0
- package/lib/typescript/components/Onairos.d.ts.map +1 -0
- package/lib/typescript/components/OnairosButton.d.ts +7 -0
- package/lib/typescript/components/OnairosButton.d.ts.map +1 -0
- package/lib/typescript/components/Overlay.d.ts +18 -0
- package/lib/typescript/components/Overlay.d.ts.map +1 -0
- package/lib/typescript/components/PinInput.d.ts +4 -0
- package/lib/typescript/components/PinInput.d.ts.map +1 -0
- package/lib/typescript/components/PlatformList.d.ts +4 -0
- package/lib/typescript/components/PlatformList.d.ts.map +1 -0
- package/lib/typescript/components/TrainingModal.d.ts +4 -0
- package/lib/typescript/components/TrainingModal.d.ts.map +1 -0
- package/lib/typescript/components/UniversalOnboarding.d.ts +4 -0
- package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -0
- package/lib/typescript/components/onboarding/OAuthWebView.d.ts +4 -0
- package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -0
- package/lib/typescript/components/onboarding/OnboardingHeader.d.ts +11 -0
- package/lib/typescript/components/onboarding/OnboardingHeader.d.ts.map +1 -0
- package/lib/typescript/components/onboarding/PinInput.d.ts +4 -0
- package/lib/typescript/components/onboarding/PinInput.d.ts.map +1 -0
- package/lib/typescript/components/onboarding/PlatformConnector.d.ts +13 -0
- package/lib/typescript/components/onboarding/PlatformConnector.d.ts.map +1 -0
- package/lib/typescript/components/screens/ConnectorScreen.d.ts +9 -0
- package/lib/typescript/components/screens/ConnectorScreen.d.ts.map +1 -0
- package/lib/typescript/components/screens/LoadingScreen.d.ts +9 -0
- package/lib/typescript/components/screens/LoadingScreen.d.ts.map +1 -0
- package/lib/typescript/components/screens/PinCreationScreen.d.ts +10 -0
- package/lib/typescript/components/screens/PinCreationScreen.d.ts.map +1 -0
- package/lib/typescript/constants/index.d.ts +52 -0
- package/lib/typescript/constants/index.d.ts.map +1 -0
- package/lib/typescript/hooks/useConnections.d.ts +9 -0
- package/lib/typescript/hooks/useConnections.d.ts.map +1 -0
- package/lib/typescript/hooks/useCredentials.d.ts +9 -0
- package/lib/typescript/hooks/useCredentials.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +45 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/services/oauthService.d.ts +50 -0
- package/lib/typescript/services/oauthService.d.ts.map +1 -0
- package/lib/typescript/types/index.d.ts +145 -0
- package/lib/typescript/types/index.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +135 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils/api.d.ts +6 -0
- package/lib/typescript/utils/api.d.ts.map +1 -0
- package/lib/typescript/utils/auth.d.ts +6 -0
- package/lib/typescript/utils/auth.d.ts.map +1 -0
- package/lib/typescript/utils/crypto.d.ts +4 -0
- package/lib/typescript/utils/crypto.d.ts.map +1 -0
- package/lib/typescript/utils/debugHelper.d.ts +29 -0
- package/lib/typescript/utils/debugHelper.d.ts.map +1 -0
- package/lib/typescript/utils/encryption.d.ts +19 -0
- package/lib/typescript/utils/encryption.d.ts.map +1 -0
- package/lib/typescript/utils/onairosApi.d.ts +72 -0
- package/lib/typescript/utils/onairosApi.d.ts.map +1 -0
- package/lib/typescript/utils/secureStorage.d.ts +63 -0
- package/lib/typescript/utils/secureStorage.d.ts.map +1 -0
- package/package.json +16 -4
- package/src/api/index.ts +86 -101
- package/src/components/OnairosButton.tsx +22 -14
- package/src/components/Overlay.tsx +303 -138
- package/src/components/UniversalOnboarding.tsx +25 -0
- package/src/components/onboarding/OAuthWebView.tsx +27 -7
- package/src/components/onboarding/PlatformConnector.tsx +5 -0
- package/src/components/screens/ConnectorScreen.tsx +3 -2
- package/src/constants/index.ts +81 -81
- package/src/hooks/useConnections.ts +76 -16
- package/src/hooks/useCredentials.ts +5 -1
- package/src/index.ts +30 -3
- package/src/services/oauthService.ts +412 -419
- package/src/types/ambient.d.ts +29 -0
- package/src/types/index.d.ts +48 -8
- package/src/types/index.ts +21 -15
- package/src/types/node-fix.d.ts +19 -0
- package/src/types/node-override.d.ts +24 -0
- package/src/types/types.d.ts +18 -0
- package/src/types.ts +121 -1
- package/src/utils/encryption.ts +7 -2
- package/src/utils/secureStorage.ts +155 -56
- package/types/index.d.ts +210 -0
- package/types/node-env.d.ts +15 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient type declarations to fix Node.js module conflicts
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// These modules are not used directly in React Native, but are referenced by types
|
|
6
|
+
// Providing empty declarations prevents TypeScript from trying to use Node.js types
|
|
7
|
+
declare module 'https' {
|
|
8
|
+
interface Server {
|
|
9
|
+
prependListener(event: string, listener: (...args: any[]) => void): any;
|
|
10
|
+
once(event: string, listener: (...args: any[]) => void): any;
|
|
11
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): any;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module 'node:https' {}
|
|
16
|
+
declare module 'node:http' {}
|
|
17
|
+
declare module 'node:crypto' {}
|
|
18
|
+
declare module 'process' {
|
|
19
|
+
global {
|
|
20
|
+
namespace NodeJS {
|
|
21
|
+
interface Process {
|
|
22
|
+
env: {
|
|
23
|
+
NODE_ENV?: string;
|
|
24
|
+
[key: string]: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -9,27 +9,47 @@ declare module '@onairos/react-native' {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface OnairosButtonProps {
|
|
12
|
+
/** Return link after authentication (used for web-based flows) */
|
|
12
13
|
returnLink?: string;
|
|
14
|
+
/** Prefill URL for the authentication process */
|
|
13
15
|
prefillUrl?: string;
|
|
14
|
-
|
|
16
|
+
/** Application name to display in dialogs */
|
|
17
|
+
AppName?: string;
|
|
18
|
+
/** Button type - 'normal' or 'pill' */
|
|
15
19
|
buttonType?: 'normal' | 'pill';
|
|
20
|
+
/** Data requests for user consent */
|
|
16
21
|
requestData?: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
[key: string]: {
|
|
23
|
+
type: string;
|
|
24
|
+
descriptions: string;
|
|
25
|
+
reward: string;
|
|
26
|
+
};
|
|
20
27
|
};
|
|
21
|
-
|
|
28
|
+
/** Button width in pixels or percentage */
|
|
29
|
+
buttonWidth?: number | string;
|
|
30
|
+
/** Button height in pixels */
|
|
22
31
|
buttonHeight?: number;
|
|
32
|
+
/** Whether to show stroke/border around button */
|
|
23
33
|
hasStroke?: boolean;
|
|
34
|
+
/** Whether the button is enabled */
|
|
24
35
|
enabled?: boolean;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
/** Button form/shape style */
|
|
37
|
+
buttonForm?: 'default' | 'rounded' | 'square';
|
|
38
|
+
/** Callback when user rejects or cancels */
|
|
39
|
+
onRejection?: (reason: string) => void;
|
|
40
|
+
/** Callback when authentication is resolved */
|
|
41
|
+
onResolved?: (apiUrl: string, accessToken: string, data: any) => void;
|
|
42
|
+
/** Function to check before starting authentication */
|
|
28
43
|
preCheck?: () => Promise<boolean>;
|
|
44
|
+
/** Button background color */
|
|
29
45
|
color?: string;
|
|
46
|
+
/** Whether to apply a slight rotation effect */
|
|
30
47
|
swerv?: boolean;
|
|
48
|
+
/** Enable debug mode */
|
|
31
49
|
debug?: boolean;
|
|
50
|
+
/** Preferred platform for authentication */
|
|
32
51
|
preferredPlatform?: string;
|
|
52
|
+
/** Enable test mode */
|
|
33
53
|
testMode?: boolean;
|
|
34
54
|
}
|
|
35
55
|
|
|
@@ -110,4 +130,24 @@ declare module '@onairos/react-native' {
|
|
|
110
130
|
export class PinInput extends Component<PinInputProps> {}
|
|
111
131
|
export class TrainingModal extends Component<TrainingModalProps> {}
|
|
112
132
|
export class OAuthWebView extends Component<OAuthWebViewProps> {}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Fix for Node.js type conflicts
|
|
136
|
+
declare module 'https' {
|
|
137
|
+
interface Server {
|
|
138
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Override any problematic Node.js types
|
|
143
|
+
declare module 'node:https' {
|
|
144
|
+
export * from 'https';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
declare module 'node:http' {
|
|
148
|
+
export * from 'http';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
declare module 'node:crypto' {
|
|
152
|
+
export * from 'crypto';
|
|
113
153
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,14 +7,16 @@ export interface DataTier {
|
|
|
7
7
|
export interface OnairosButtonProps {
|
|
8
8
|
returnLink?: string;
|
|
9
9
|
prefillUrl?: string;
|
|
10
|
-
AppName
|
|
10
|
+
AppName?: string;
|
|
11
11
|
buttonType?: 'normal' | 'pill';
|
|
12
12
|
requestData?: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
[key: string]: {
|
|
14
|
+
type: string;
|
|
15
|
+
descriptions: string;
|
|
16
|
+
reward: string;
|
|
17
|
+
};
|
|
16
18
|
};
|
|
17
|
-
buttonWidth?: number;
|
|
19
|
+
buttonWidth?: number | string;
|
|
18
20
|
buttonHeight?: number;
|
|
19
21
|
hasStroke?: boolean;
|
|
20
22
|
enabled?: boolean;
|
|
@@ -34,9 +36,11 @@ export interface UniversalOnboardingProps {
|
|
|
34
36
|
onClose: () => void;
|
|
35
37
|
AppName: string;
|
|
36
38
|
requestData?: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
[key: string]: {
|
|
40
|
+
type: string;
|
|
41
|
+
descriptions: string;
|
|
42
|
+
reward: string;
|
|
43
|
+
};
|
|
40
44
|
};
|
|
41
45
|
returnLink?: string;
|
|
42
46
|
onComplete: (apiUrl: string, token: string, userData: any) => void;
|
|
@@ -81,6 +85,13 @@ export interface OAuthWebViewProps {
|
|
|
81
85
|
onClose: () => void;
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
export interface PlatformConfig {
|
|
89
|
+
name: string;
|
|
90
|
+
icon: string;
|
|
91
|
+
color: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
84
95
|
export interface OnairosCredentials {
|
|
85
96
|
username: string;
|
|
86
97
|
accessToken?: string;
|
|
@@ -106,13 +117,8 @@ export interface OverlayProps {
|
|
|
106
117
|
username: string;
|
|
107
118
|
modelKey: string;
|
|
108
119
|
onResolved: (apiUrl: string, accessToken: string, loginDetails: any) => void;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
export interface PlatformConfig {
|
|
112
|
-
name: string;
|
|
113
|
-
icon: string;
|
|
114
|
-
color: string;
|
|
115
|
-
description?: string;
|
|
120
|
+
appName?: string;
|
|
121
|
+
darkMode?: boolean;
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
export interface BiometricOptions {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Fix for Node.js type conflicts
|
|
2
|
+
declare module 'https' {
|
|
3
|
+
interface Server {
|
|
4
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Override any problematic Node.js types
|
|
9
|
+
declare module 'node:https' {
|
|
10
|
+
export * from 'https';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module 'node:http' {
|
|
14
|
+
export * from 'http';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module 'node:crypto' {
|
|
18
|
+
export * from 'crypto';
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Override for Node.js HTTPS module to fix type errors
|
|
2
|
+
declare module 'node:https' {
|
|
3
|
+
import * as http from 'http';
|
|
4
|
+
import * as tls from 'tls';
|
|
5
|
+
|
|
6
|
+
interface ServerOptions {
|
|
7
|
+
// Define simplified options
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class Server extends tls.Server {
|
|
11
|
+
// Override problematic methods with any type
|
|
12
|
+
prependListener(event: string, listener: any): this;
|
|
13
|
+
prependOnceListener(event: string, listener: any): this;
|
|
14
|
+
once(event: string, listener: any): this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function createServer(options?: ServerOptions, requestListener?: any): Server;
|
|
18
|
+
function createServer(requestListener?: any): Server;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Also override node:http
|
|
22
|
+
declare module 'node:http' {
|
|
23
|
+
export * from 'http';
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare module '@onairos/react-native' {
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
import { ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
// Re-export all the types from our index.ts
|
|
6
|
+
export * from '../types';
|
|
7
|
+
|
|
8
|
+
// Components
|
|
9
|
+
export class Onairos extends Component<any> {}
|
|
10
|
+
export class OnairosButton extends Component<import('../types').OnairosButtonProps> {}
|
|
11
|
+
export class OnairosOverlay extends Component<import('../types').OverlayProps> {}
|
|
12
|
+
export class UniversalOnboarding extends Component<import('../types').UniversalOnboardingProps> {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Fix for Node.js type conflicts by providing empty declarations
|
|
16
|
+
declare module 'node:https' {}
|
|
17
|
+
declare module 'node:http' {}
|
|
18
|
+
declare module 'node:crypto' {}
|
package/src/types.ts
CHANGED
|
@@ -20,10 +20,130 @@ export interface UniversalOnboardingProps {
|
|
|
20
20
|
test?: boolean;
|
|
21
21
|
buttonType?: 'default' | 'pill';
|
|
22
22
|
buttonForm?: 'signup' | 'login';
|
|
23
|
+
preferredPlatform?: string;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export interface ConnectionStatus {
|
|
26
|
-
[key: string]:
|
|
27
|
+
[key: string]: {
|
|
28
|
+
userName: string;
|
|
29
|
+
connected: boolean;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface OnairosButtonProps {
|
|
34
|
+
returnLink?: string;
|
|
35
|
+
prefillUrl?: string;
|
|
36
|
+
AppName: string;
|
|
37
|
+
buttonType?: 'normal' | 'pill';
|
|
38
|
+
requestData?: {
|
|
39
|
+
Small: DataTier;
|
|
40
|
+
Medium: DataTier;
|
|
41
|
+
Large: DataTier;
|
|
42
|
+
};
|
|
43
|
+
buttonWidth?: number;
|
|
44
|
+
buttonHeight?: number;
|
|
45
|
+
hasStroke?: boolean;
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
buttonForm?: 'default' | 'login' | 'signup';
|
|
48
|
+
onRejection?: (error?: string) => void;
|
|
49
|
+
onResolved?: (apiUrl: string, token: string, userData: any) => void;
|
|
50
|
+
preCheck?: () => Promise<boolean>;
|
|
51
|
+
color?: string;
|
|
52
|
+
swerv?: boolean;
|
|
53
|
+
debug?: boolean;
|
|
54
|
+
preferredPlatform?: string;
|
|
55
|
+
testMode?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PlatformListProps {
|
|
59
|
+
platforms?: string[];
|
|
60
|
+
onSelect?: (platform: string) => void;
|
|
61
|
+
selectedPlatform?: string;
|
|
62
|
+
connections?: ConnectionStatus;
|
|
63
|
+
onToggle?: (platform: string, connect: boolean) => void;
|
|
64
|
+
isLoading?: boolean;
|
|
65
|
+
canProceed?: boolean;
|
|
66
|
+
onProceed?: () => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface PinInputProps {
|
|
70
|
+
onComplete?: (pin: string) => void;
|
|
71
|
+
length?: number;
|
|
72
|
+
secure?: boolean;
|
|
73
|
+
title?: string;
|
|
74
|
+
subtitle?: string;
|
|
75
|
+
verification?: boolean;
|
|
76
|
+
initialPin?: string;
|
|
77
|
+
onSubmit: (pin: string) => void;
|
|
78
|
+
minLength?: number;
|
|
79
|
+
requireSpecialChar?: boolean;
|
|
80
|
+
requireNumber?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface TrainingModalProps {
|
|
84
|
+
visible: boolean;
|
|
85
|
+
onClose: () => void;
|
|
86
|
+
onComplete: () => void;
|
|
87
|
+
modelKey: string;
|
|
88
|
+
username: string;
|
|
89
|
+
progress?: number;
|
|
90
|
+
eta?: string;
|
|
91
|
+
onCancel?: () => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface OAuthWebViewProps {
|
|
95
|
+
url: string;
|
|
96
|
+
onClose: () => void;
|
|
97
|
+
onSuccess: (code: string) => void;
|
|
98
|
+
platform?: string;
|
|
99
|
+
onComplete?: () => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface PlatformConfig {
|
|
103
|
+
name: string;
|
|
104
|
+
icon: string;
|
|
105
|
+
color: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ApiResponse<T> {
|
|
110
|
+
success: boolean;
|
|
111
|
+
data?: T;
|
|
112
|
+
error?: string;
|
|
113
|
+
publicKey?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CredentialsResult {
|
|
117
|
+
success: boolean;
|
|
118
|
+
credentials?: any;
|
|
119
|
+
error?: string;
|
|
120
|
+
isValid?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface OverlayProps {
|
|
124
|
+
data: {
|
|
125
|
+
[key: string]: {
|
|
126
|
+
type: string;
|
|
127
|
+
descriptions: string;
|
|
128
|
+
reward: string;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
username: string;
|
|
132
|
+
modelKey: string;
|
|
133
|
+
onResolved: (apiUrl: string, accessToken: string, loginDetails: any) => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface BiometricOptions {
|
|
137
|
+
enableBiometrics?: boolean;
|
|
138
|
+
biometricPrompt?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface PinRequirements {
|
|
142
|
+
minLength: number;
|
|
143
|
+
requireUppercase: boolean;
|
|
144
|
+
requireLowercase: boolean;
|
|
145
|
+
requireNumber: boolean;
|
|
146
|
+
requireSpecialChar: boolean;
|
|
27
147
|
}
|
|
28
148
|
|
|
29
149
|
// ... rest of the existing types ...
|
package/src/utils/encryption.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { onairosApi } from '../api';
|
|
2
2
|
import RSA from 'react-native-rsa-native';
|
|
3
|
+
import { ApiResponse } from '../types';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Encrypt a model key using RSA with a public key
|
|
@@ -33,10 +34,14 @@ export const encryptModelKey = (publicKey: string, modelKey: string): string =>
|
|
|
33
34
|
*/
|
|
34
35
|
export const getServerPublicKey = async (): Promise<string> => {
|
|
35
36
|
try {
|
|
37
|
+
// Use the API without generics to prevent TypeScript errors
|
|
36
38
|
const response = await onairosApi.get('public/getPublicKey');
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
// Check for the public key in the response data
|
|
41
|
+
if (response?.data?.data?.publicKey) {
|
|
42
|
+
return response.data.data.publicKey;
|
|
43
|
+
} else if (response?.data?.publicKey) {
|
|
44
|
+
return response.data.publicKey;
|
|
40
45
|
} else {
|
|
41
46
|
throw new Error('No public key found in response');
|
|
42
47
|
}
|
|
@@ -1,41 +1,153 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import { sha256 } from './crypto';
|
|
3
|
+
import { STORAGE_KEYS } from '../constants';
|
|
3
4
|
|
|
5
|
+
// Define OnairosCredentials interface locally to avoid circular dependencies
|
|
4
6
|
export interface OnairosCredentials {
|
|
5
7
|
username: string;
|
|
6
|
-
accessToken
|
|
8
|
+
accessToken?: string;
|
|
7
9
|
refreshToken?: string;
|
|
8
10
|
userPin?: string;
|
|
9
11
|
platforms?: {
|
|
10
|
-
instagram?: { token: string; username: string };
|
|
11
|
-
youtube?: { token: string; username: string };
|
|
12
|
-
pinterest?: { token: string; username: string };
|
|
13
|
-
reddit?: { token: string; username: string };
|
|
12
|
+
instagram?: { token: string; username: string; userId?: string };
|
|
13
|
+
youtube?: { token: string; username: string; userId?: string };
|
|
14
|
+
pinterest?: { token: string; username: string; userId?: string };
|
|
15
|
+
reddit?: { token: string; username: string; userId?: string };
|
|
14
16
|
};
|
|
15
17
|
createdAt: number;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export interface StorageOptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
service?: string;
|
|
22
|
+
accessControl?: any;
|
|
23
|
+
accessible?: any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Create a mock storage for environments without Keychain access (like Expo Go)
|
|
27
|
+
const mockStorage: Record<string, { username: string; password: string }> = {};
|
|
28
|
+
|
|
29
|
+
// Try to import Keychain, but provide fallbacks if not available
|
|
30
|
+
let Keychain: any = null;
|
|
31
|
+
try {
|
|
32
|
+
// This import might fail in Expo Go or environments without native modules
|
|
33
|
+
Keychain = require('react-native-keychain');
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn('react-native-keychain module not available, using mock storage');
|
|
36
|
+
// Create minimal mock implementation
|
|
37
|
+
Keychain = {
|
|
38
|
+
ACCESS_CONTROL: { BIOMETRY_ANY_OR_DEVICE_PASSCODE: 'mock' },
|
|
39
|
+
ACCESSIBLE: { WHEN_UNLOCKED: 'mock' },
|
|
40
|
+
getGenericPassword: async () => null,
|
|
41
|
+
setGenericPassword: async () => true,
|
|
42
|
+
resetGenericPassword: async () => true,
|
|
23
43
|
};
|
|
24
44
|
}
|
|
25
45
|
|
|
26
|
-
//
|
|
27
|
-
|
|
46
|
+
// Check if Keychain is properly initialized and available
|
|
47
|
+
const isKeychainAvailable = () => {
|
|
48
|
+
try {
|
|
49
|
+
return Keychain && typeof Keychain.getGenericPassword === 'function';
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Wrapper for getGenericPassword that falls back to mock storage
|
|
56
|
+
const safeGetGenericPassword = async (options: any) => {
|
|
57
|
+
try {
|
|
58
|
+
if (isKeychainAvailable()) {
|
|
59
|
+
return await Keychain.getGenericPassword(options);
|
|
60
|
+
} else {
|
|
61
|
+
// Fall back to mock storage in memory
|
|
62
|
+
const key = options?.service || 'default';
|
|
63
|
+
return mockStorage[key] || null;
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.warn('Keychain access failed, using mock storage', error);
|
|
67
|
+
// Fall back to mock storage on error
|
|
68
|
+
const key = options?.service || 'default';
|
|
69
|
+
return mockStorage[key] || null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Wrapper for setGenericPassword that falls back to mock storage
|
|
74
|
+
const safeSetGenericPassword = async (
|
|
75
|
+
username: string,
|
|
76
|
+
password: string,
|
|
77
|
+
options?: any
|
|
78
|
+
) => {
|
|
79
|
+
try {
|
|
80
|
+
if (isKeychainAvailable()) {
|
|
81
|
+
return await Keychain.setGenericPassword(username, password, options);
|
|
82
|
+
} else {
|
|
83
|
+
// Fall back to mock storage in memory
|
|
84
|
+
const key = options?.service || 'default';
|
|
85
|
+
mockStorage[key] = { username, password };
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.warn('Keychain access failed, using mock storage', error);
|
|
90
|
+
// Fall back to mock storage on error
|
|
91
|
+
const key = options?.service || 'default';
|
|
92
|
+
mockStorage[key] = { username, password };
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Wrapper for resetGenericPassword that falls back to mock storage
|
|
98
|
+
const safeResetGenericPassword = async (options?: any) => {
|
|
99
|
+
try {
|
|
100
|
+
if (isKeychainAvailable()) {
|
|
101
|
+
return await Keychain.resetGenericPassword(options);
|
|
102
|
+
} else {
|
|
103
|
+
// Fall back to mock storage in memory
|
|
104
|
+
const key = options?.service || 'default';
|
|
105
|
+
delete mockStorage[key];
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.warn('Keychain access failed, using mock storage', error);
|
|
110
|
+
// Fall back to mock storage on error
|
|
111
|
+
const key = options?.service || 'default';
|
|
112
|
+
delete mockStorage[key];
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
28
116
|
|
|
29
117
|
/**
|
|
30
118
|
* Store credentials in memory (temporary solution)
|
|
31
119
|
*/
|
|
32
120
|
export const storeCredentials = async (
|
|
33
|
-
credentials: OnairosCredentials
|
|
34
|
-
options: StorageOptions = {}
|
|
121
|
+
credentials: Partial<OnairosCredentials>
|
|
35
122
|
): Promise<boolean> => {
|
|
36
123
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
124
|
+
const existingCredentials = await getCredentials();
|
|
125
|
+
const updatedCredentials: OnairosCredentials = {
|
|
126
|
+
...existingCredentials,
|
|
127
|
+
...credentials,
|
|
128
|
+
createdAt: existingCredentials?.createdAt || Date.now(),
|
|
129
|
+
} as OnairosCredentials;
|
|
130
|
+
|
|
131
|
+
const username = updatedCredentials.username;
|
|
132
|
+
if (!username) {
|
|
133
|
+
throw new Error('Username is required for storing credentials');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const options: any = {
|
|
137
|
+
service: STORAGE_KEYS.credentials,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// Only use secure storage options on real devices
|
|
141
|
+
if (Platform.OS !== 'web' && isKeychainAvailable()) {
|
|
142
|
+
options.accessControl = Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE;
|
|
143
|
+
options.accessible = Keychain.ACCESSIBLE.WHEN_UNLOCKED;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await safeSetGenericPassword(
|
|
147
|
+
username,
|
|
148
|
+
JSON.stringify(updatedCredentials),
|
|
149
|
+
options
|
|
150
|
+
);
|
|
39
151
|
return true;
|
|
40
152
|
} catch (error) {
|
|
41
153
|
console.error('Error storing credentials:', error);
|
|
@@ -46,18 +158,17 @@ export const storeCredentials = async (
|
|
|
46
158
|
/**
|
|
47
159
|
* Retrieve credentials from memory (temporary solution)
|
|
48
160
|
*/
|
|
49
|
-
export const getCredentials = async (
|
|
50
|
-
options: StorageOptions = {}
|
|
51
|
-
): Promise<OnairosCredentials | null> => {
|
|
161
|
+
export const getCredentials = async (): Promise<OnairosCredentials | null> => {
|
|
52
162
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
163
|
+
const credentials = await safeGetGenericPassword({
|
|
164
|
+
service: STORAGE_KEYS.credentials,
|
|
165
|
+
});
|
|
166
|
+
if (credentials) {
|
|
167
|
+
return JSON.parse(credentials.password);
|
|
57
168
|
}
|
|
58
|
-
return
|
|
169
|
+
return null;
|
|
59
170
|
} catch (error) {
|
|
60
|
-
console.error('Error
|
|
171
|
+
console.error('Error getting credentials:', error);
|
|
61
172
|
return null;
|
|
62
173
|
}
|
|
63
174
|
};
|
|
@@ -67,9 +178,12 @@ export const getCredentials = async (
|
|
|
67
178
|
*/
|
|
68
179
|
export const hasCredentials = async (): Promise<boolean> => {
|
|
69
180
|
try {
|
|
70
|
-
|
|
181
|
+
const credentials = await safeGetGenericPassword({
|
|
182
|
+
service: STORAGE_KEYS.credentials,
|
|
183
|
+
});
|
|
184
|
+
return !!credentials;
|
|
71
185
|
} catch (error) {
|
|
72
|
-
console.error('Error checking
|
|
186
|
+
console.error('Error checking credentials:', error);
|
|
73
187
|
return false;
|
|
74
188
|
}
|
|
75
189
|
};
|
|
@@ -79,7 +193,9 @@ export const hasCredentials = async (): Promise<boolean> => {
|
|
|
79
193
|
*/
|
|
80
194
|
export const deleteCredentials = async (): Promise<boolean> => {
|
|
81
195
|
try {
|
|
82
|
-
|
|
196
|
+
await safeResetGenericPassword({
|
|
197
|
+
service: STORAGE_KEYS.credentials,
|
|
198
|
+
});
|
|
83
199
|
return true;
|
|
84
200
|
} catch (error) {
|
|
85
201
|
console.error('Error deleting credentials:', error);
|
|
@@ -91,47 +207,30 @@ export const deleteCredentials = async (): Promise<boolean> => {
|
|
|
91
207
|
* Update specific fields in the stored credentials
|
|
92
208
|
*/
|
|
93
209
|
export const updateCredentials = async (
|
|
94
|
-
|
|
95
|
-
options: StorageOptions = {}
|
|
210
|
+
credentials: Partial<OnairosCredentials>
|
|
96
211
|
): Promise<boolean> => {
|
|
97
|
-
|
|
98
|
-
const currentCredentials = await getCredentials(options);
|
|
99
|
-
if (!currentCredentials) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
const updatedCredentials: OnairosCredentials = {
|
|
103
|
-
...currentCredentials,
|
|
104
|
-
...updates,
|
|
105
|
-
};
|
|
106
|
-
return await storeCredentials(updatedCredentials, options);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error('Error updating credentials:', error);
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
212
|
+
return storeCredentials(credentials);
|
|
111
213
|
};
|
|
112
214
|
|
|
113
215
|
/**
|
|
114
216
|
* Generate a device-specific unique username
|
|
115
217
|
*/
|
|
116
|
-
export const generateDeviceUsername =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const username = `onairos_${sha256(deviceInfo).substring(0, 10)}`;
|
|
120
|
-
return username;
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.error('Error generating device username:', error);
|
|
123
|
-
return `onairos_${Date.now().toString(36)}`;
|
|
124
|
-
}
|
|
218
|
+
export const generateDeviceUsername = (): string => {
|
|
219
|
+
const randomId = Math.random().toString(36).substring(2, 10);
|
|
220
|
+
return `dev_${randomId}`;
|
|
125
221
|
};
|
|
126
222
|
|
|
127
223
|
/**
|
|
128
224
|
* Verify credentials (temporary mock implementation)
|
|
129
225
|
*/
|
|
130
|
-
export const verifyCredentials = async (
|
|
131
|
-
credentials: OnairosCredentials
|
|
132
|
-
): Promise<boolean> => {
|
|
226
|
+
export const verifyCredentials = async (username: string): Promise<boolean> => {
|
|
133
227
|
try {
|
|
134
|
-
|
|
228
|
+
// For Expo Go or development, always return true
|
|
229
|
+
if (!isKeychainAvailable()) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// TODO: Implement actual verification with API
|
|
135
234
|
return true;
|
|
136
235
|
} catch (error) {
|
|
137
236
|
console.error('Error verifying credentials:', error);
|