@openfort/react-native 0.0.2 → 0.1.0

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 (91) hide show
  1. package/README.md +0 -85
  2. package/dist/components/AuthBoundary.js +83 -0
  3. package/dist/components/index.js +10 -0
  4. package/dist/constants/config.js +9 -0
  5. package/dist/constants/index.js +1 -0
  6. package/dist/core/client.js +78 -0
  7. package/dist/core/context.js +37 -0
  8. package/dist/core/index.js +10 -0
  9. package/dist/core/provider.js +224 -0
  10. package/dist/core/storage.js +141 -0
  11. package/dist/hooks/auth/index.js +13 -0
  12. package/dist/hooks/auth/useAuthCallback.js +1 -0
  13. package/dist/hooks/auth/useCreateWalletPostAuth.js +22 -0
  14. package/dist/hooks/auth/useEmailAuth.js +169 -0
  15. package/dist/hooks/auth/useGuestAuth.js +52 -0
  16. package/dist/hooks/auth/useOAuth.js +292 -0
  17. package/dist/hooks/auth/useSignOut.js +48 -0
  18. package/dist/hooks/auth/useUser.js +1 -0
  19. package/dist/hooks/auth/useWalletAuth.js +122 -0
  20. package/dist/hooks/core/index.js +10 -0
  21. package/dist/hooks/core/useOpenfort.js +50 -0
  22. package/dist/hooks/core/useOpenfortClient.js +29 -0
  23. package/dist/hooks/core/useSignOut.js +7 -0
  24. package/dist/hooks/core/useUser.js +10 -0
  25. package/dist/hooks/index.js +15 -0
  26. package/dist/hooks/wallet/index.js +7 -0
  27. package/dist/hooks/wallet/useWallets.js +389 -0
  28. package/dist/index.js +24 -1
  29. package/dist/lib/hookConsistency.js +16 -0
  30. package/dist/native/index.js +6 -0
  31. package/dist/native/oauth.js +183 -0
  32. package/dist/native/storage.js +178 -0
  33. package/dist/native/webview.js +157 -0
  34. package/dist/types/auth.js +1 -0
  35. package/dist/types/baseFlowState.js +8 -0
  36. package/dist/types/components/AuthBoundary.d.ts +85 -0
  37. package/dist/types/components/index.d.ts +10 -0
  38. package/dist/types/config.js +1 -0
  39. package/dist/types/constants/config.d.ts +9 -0
  40. package/dist/types/constants/index.d.ts +1 -0
  41. package/dist/types/core/client.d.ts +24 -0
  42. package/dist/types/core/context.d.ts +61 -0
  43. package/dist/types/core/index.d.ts +8 -0
  44. package/dist/types/core/provider.d.ts +126 -0
  45. package/dist/types/core/storage.d.ts +34 -0
  46. package/dist/types/hex.js +1 -0
  47. package/dist/types/hookOption.js +1 -0
  48. package/dist/types/hooks/auth/index.d.ts +9 -0
  49. package/dist/types/hooks/auth/useAuthCallback.d.ts +0 -0
  50. package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +6 -0
  51. package/dist/types/hooks/auth/useEmailAuth.d.ts +54 -0
  52. package/dist/types/hooks/auth/useGuestAuth.d.ts +39 -0
  53. package/dist/types/hooks/auth/useOAuth.d.ts +62 -0
  54. package/dist/types/hooks/auth/useSignOut.d.ts +9 -0
  55. package/dist/types/hooks/auth/useUser.d.ts +0 -0
  56. package/dist/types/hooks/auth/useWalletAuth.d.ts +42 -0
  57. package/dist/types/hooks/core/index.d.ts +9 -0
  58. package/dist/types/hooks/core/useOpenfort.d.ts +38 -0
  59. package/dist/types/hooks/core/useOpenfortClient.d.ts +29 -0
  60. package/dist/types/hooks/core/useSignOut.d.ts +3 -0
  61. package/dist/types/hooks/core/useUser.d.ts +5 -0
  62. package/dist/types/hooks/index.d.ts +12 -0
  63. package/dist/types/hooks/wallet/index.d.ts +6 -0
  64. package/dist/types/hooks/wallet/useWallets.d.ts +74 -0
  65. package/dist/types/index.d.ts +18 -1
  66. package/dist/types/index.js +2 -0
  67. package/dist/types/lib/hookConsistency.d.ts +14 -0
  68. package/dist/types/native/index.d.ts +5 -0
  69. package/dist/types/native/oauth.d.ts +91 -0
  70. package/dist/types/native/storage.d.ts +50 -0
  71. package/dist/types/native/webview.d.ts +50 -0
  72. package/dist/types/oauth.js +8 -0
  73. package/dist/types/openfortError.js +27 -0
  74. package/dist/types/predicates.js +101 -0
  75. package/dist/types/state.js +1 -0
  76. package/dist/types/types/auth.d.ts +168 -0
  77. package/dist/types/types/baseFlowState.d.ts +14 -0
  78. package/dist/types/types/config.d.ts +71 -0
  79. package/dist/types/types/hex.d.ts +1 -0
  80. package/dist/types/types/hookOption.d.ts +9 -0
  81. package/dist/types/types/index.d.ts +38 -0
  82. package/dist/types/types/oauth.d.ts +74 -0
  83. package/dist/types/types/openfortError.d.ts +13 -0
  84. package/dist/types/types/predicates.d.ts +64 -0
  85. package/dist/types/types/state.d.ts +0 -0
  86. package/dist/types/types/wallet.d.ts +262 -0
  87. package/dist/types/wallet.js +1 -0
  88. package/package.json +33 -20
  89. package/dist/Iframe.js +0 -72
  90. package/dist/types/Iframe.d.ts +0 -6
  91. package/polyfills/index.ts +0 -88
@@ -0,0 +1,74 @@
1
+ import type { OAuthProvider } from '@openfort/openfort-js';
2
+ import type { AuthSuccessCallback, ErrorCallback } from './auth';
3
+ /**
4
+ * OAuth authentication flow state
5
+ */
6
+ export type OAuthFlowState = {
7
+ status: 'initial' | 'loading' | 'awaiting-redirect' | 'done';
8
+ error?: never;
9
+ } | {
10
+ status: 'error';
11
+ error: Error | null;
12
+ };
13
+ export declare const mapOAuthStatus: (status: OAuthFlowState) => {
14
+ isLoading: boolean;
15
+ isError: boolean;
16
+ isSuccess: boolean;
17
+ error: Error | null | undefined;
18
+ };
19
+ /**
20
+ * OAuth tokens interface
21
+ */
22
+ export interface OAuthTokens {
23
+ [key: string]: any;
24
+ }
25
+ /**
26
+ * OAuth tokens hook options
27
+ */
28
+ export interface UseOAuthTokensOptions {
29
+ /**
30
+ * Callback function triggered when OAuth tokens are granted to the user after any OAuth Authorization flow.
31
+ * @param tokens - The set of OAuth tokens granted to the user.
32
+ */
33
+ onOAuthTokenGrant: (tokens: OAuthTokens) => void;
34
+ }
35
+ /**
36
+ * Login with OAuth input parameters
37
+ */
38
+ export type LoginWithOAuthInput = LinkWithOAuthInput;
39
+ /**
40
+ * Link with OAuth input parameters
41
+ */
42
+ export type LinkWithOAuthInput = {
43
+ provider: OAuthProvider;
44
+ redirectUri?: string | undefined;
45
+ isLegacyAppleIosBehaviorEnabled?: boolean;
46
+ };
47
+ /**
48
+ * Login with OAuth hook interface
49
+ */
50
+ export interface UseLoginWithOAuth {
51
+ state: OAuthFlowState;
52
+ login: (input: LoginWithOAuthInput) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | undefined>;
53
+ }
54
+ /**
55
+ * Link with OAuth hook interface
56
+ */
57
+ export interface UseLinkWithOAuth {
58
+ state: OAuthFlowState;
59
+ link: (input: LinkWithOAuthInput) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | undefined>;
60
+ }
61
+ /**
62
+ * Unlink OAuth hook options
63
+ */
64
+ export interface UnlinkOAuthOptions {
65
+ onError?: ErrorCallback;
66
+ onSuccess?: AuthSuccessCallback;
67
+ }
68
+ /**
69
+ * Unlink OAuth parameters
70
+ */
71
+ export interface UnlinkOAuthParams {
72
+ provider: OAuthProvider;
73
+ subject: string;
74
+ }
@@ -0,0 +1,13 @@
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 {};
@@ -0,0 +1,64 @@
1
+ import type { EmbeddedEthereumWalletState, EmbeddedSolanaWalletState, EmbeddedSolanaWalletConnectedState, EmbeddedSolanaWalletConnectingState, EmbeddedSolanaWalletReconnectingState, EmbeddedSolanaWalletDisconnectedState, EmbeddedSolanaWalletNeedsRecoveryState, EmbeddedSolanaWalletCreatingState, EmbeddedSolanaWalletErrorState } from './wallet';
2
+ /**
3
+ * Type guard to check if embedded wallet is connected
4
+ */
5
+ export declare function isConnected(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletConnectedState;
6
+ /**
7
+ * Type guard to check if embedded wallet is reconnecting
8
+ */
9
+ export declare function isReconnecting(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletReconnectingState;
10
+ /**
11
+ * Type guard to check if embedded wallet is connecting
12
+ */
13
+ export declare function isConnecting(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletConnectingState;
14
+ /**
15
+ * Type guard to check if embedded wallet is disconnected
16
+ */
17
+ export declare function isDisconnected(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletDisconnectedState;
18
+ /**
19
+ * Type guard to check if embedded wallet is not created
20
+ */
21
+ export declare function isNotCreated(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletDisconnectedState;
22
+ /**
23
+ * Type guard to check if embedded wallet is being created
24
+ */
25
+ export declare function isCreating(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletCreatingState;
26
+ /**
27
+ * Type guard to check if embedded wallet has an error
28
+ */
29
+ export declare function hasError(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletErrorState;
30
+ /**
31
+ * Type guard to check if embedded wallet needs recovery
32
+ */
33
+ export declare function needsRecovery(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletNeedsRecoveryState;
34
+ /**
35
+ * Additional utility predicates
36
+ */
37
+ /**
38
+ * Type guard to check if wallet is in a loading state (connecting, creating, reconnecting)
39
+ */
40
+ export declare function isLoading(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
41
+ /**
42
+ * Type guard to check if wallet is ready for use
43
+ */
44
+ export declare function isReady(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
45
+ /**
46
+ * Type guard to check if wallet needs user action
47
+ */
48
+ export declare function needsUserAction(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
49
+ /**
50
+ * Type guard to check if wallet state is stable (not in transition)
51
+ */
52
+ export declare function isStable(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
53
+ /**
54
+ * Type guard to check if wallet can perform transactions
55
+ */
56
+ export declare function canTransact(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
57
+ /**
58
+ * Gets a human-readable description of the wallet state
59
+ */
60
+ export declare function getStateDescription(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): string;
61
+ /**
62
+ * Gets appropriate action text for the current state
63
+ */
64
+ export declare function getActionText(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): string;
File without changes
@@ -0,0 +1,262 @@
1
+ export interface OpenfortEmbeddedEthereumWalletProvider {
2
+ request: (args: {
3
+ method: string;
4
+ params?: any[];
5
+ }) => Promise<any>;
6
+ on: (event: string, handler: (...args: any[]) => void) => void;
7
+ removeListener: (event: string, handler: (...args: any[]) => void) => void;
8
+ [key: string]: any;
9
+ }
10
+ export interface OpenfortEmbeddedSolanaWalletProvider {
11
+ signTransaction: (transaction: any) => Promise<any>;
12
+ signAllTransactions: (transactions: any[]) => Promise<any[]>;
13
+ publicKey: string;
14
+ [key: string]: any;
15
+ }
16
+ export interface OpenfortEthereumEmbeddedWalletAccount {
17
+ address: string;
18
+ ownerAddress?: string;
19
+ implementationType?: string;
20
+ chainType: 'ethereum';
21
+ walletIndex: number;
22
+ }
23
+ export interface OpenfortSolanaEmbeddedWalletAccount {
24
+ address: string;
25
+ chainType: 'solana';
26
+ walletIndex: number;
27
+ }
28
+ import { ChainTypeEnum } from '@openfort/openfort-js';
29
+ import type { ErrorCallback } from './auth';
30
+ import { Hex } from './hex';
31
+ /**
32
+ * Openfort embedded wallet account union type
33
+ */
34
+ export type OpenfortEmbeddedWalletAccount = OpenfortEthereumEmbeddedWalletAccount | OpenfortSolanaEmbeddedWalletAccount;
35
+ /**
36
+ * Wallet recovery callbacks
37
+ */
38
+ export type WalletRecoveryCallbacks = {
39
+ onError?: ErrorCallback;
40
+ onSuccess?: (provider: OpenfortEmbeddedEthereumWalletProvider) => void;
41
+ };
42
+ /**
43
+ * Solana wallet recovery callbacks
44
+ */
45
+ export type SolanaWalletRecoveryCallbacks = {
46
+ onError?: ErrorCallback;
47
+ onSuccess?: (provider: OpenfortEmbeddedSolanaWalletProvider) => void;
48
+ };
49
+ /**
50
+ * Recovery method options
51
+ */
52
+ export type RecoveryMethodOptions = string | undefined | {
53
+ recoveryMethod: 'automatic';
54
+ } | {
55
+ recoveryMethod: 'password';
56
+ password: string;
57
+ };
58
+ /**
59
+ * Solana wallet creation options
60
+ */
61
+ export type CreateSolanaEmbeddedWalletOpts = (undefined | {
62
+ recoveryMethod: 'automatic';
63
+ }) & {
64
+ createAdditional?: boolean;
65
+ };
66
+ /**
67
+ * Solana wallet recovery options
68
+ */
69
+ export type RecoverSolanaEmbeddedWalletOpts = undefined | {
70
+ recoveryMethod: 'automatic';
71
+ } | {
72
+ recoveryMethod: 'password';
73
+ password: string;
74
+ };
75
+ export type UserWallet = {
76
+ address: Hex;
77
+ ownerAddress?: string;
78
+ implementationType?: string;
79
+ chainType: ChainTypeEnum;
80
+ isActive?: boolean;
81
+ isConnecting?: boolean;
82
+ getProvider: () => Promise<OpenfortEmbeddedEthereumWalletProvider>;
83
+ };
84
+ /**
85
+ * Connected embedded wallet state
86
+ */
87
+ interface IEmbeddedEthereumWalletConnectedState {
88
+ status: 'connected';
89
+ provider: OpenfortEmbeddedEthereumWalletProvider;
90
+ activeWallet: UserWallet;
91
+ }
92
+ /**
93
+ * Connecting embedded wallet state
94
+ */
95
+ interface IEmbeddedEthereumWalletConnectingState {
96
+ status: 'connecting';
97
+ activeWallet: UserWallet;
98
+ }
99
+ /**
100
+ * Reconnecting embedded wallet state
101
+ */
102
+ interface IEmbeddedEthereumWalletReconnectingState {
103
+ status: 'reconnecting';
104
+ activeWallet: UserWallet;
105
+ }
106
+ /**
107
+ * Disconnected embedded wallet state
108
+ */
109
+ interface IEmbeddedEthereumWalletDisconnectedState {
110
+ status: 'disconnected';
111
+ activeWallet: null;
112
+ }
113
+ /**
114
+ * Needs recovery embedded wallet state
115
+ */
116
+ interface IEmbeddedEthereumWalletNeedsRecoveryState {
117
+ status: 'needs-recovery';
118
+ activeWallet: UserWallet;
119
+ }
120
+ /**
121
+ * Creating embedded wallet state
122
+ */
123
+ interface IEmbeddedEthereumWalletCreatingState {
124
+ status: 'creating';
125
+ activeWallet: null;
126
+ }
127
+ /**
128
+ * Error embedded wallet state
129
+ */
130
+ interface IEmbeddedEthereumWalletErrorState {
131
+ status: 'error';
132
+ activeWallet: UserWallet | null;
133
+ error: string;
134
+ }
135
+ /**
136
+ * Embedded wallet actions
137
+ */
138
+ export type EmbeddedEthereumWalletActions = {
139
+ /**
140
+ * Configure an embedded wallet for this user.
141
+ */
142
+ create: (args?: {
143
+ chainId?: number;
144
+ recoveryPassword?: string;
145
+ policyId?: string;
146
+ }) => Promise<import('@openfort/openfort-js').EmbeddedAccount>;
147
+ /**
148
+ * List of embedded ethereum wallets at each derived HD index.
149
+ */
150
+ wallets: ConnectedEmbeddedEthereumWallet[];
151
+ };
152
+ export type EthereumWalletState = IEmbeddedEthereumWalletConnectedState | IEmbeddedEthereumWalletConnectingState | IEmbeddedEthereumWalletReconnectingState | IEmbeddedEthereumWalletDisconnectedState | IEmbeddedEthereumWalletNeedsRecoveryState | IEmbeddedEthereumWalletCreatingState | IEmbeddedEthereumWalletErrorState;
153
+ /**
154
+ * Main embedded wallet state union
155
+ */
156
+ export type EmbeddedEthereumWalletState = EthereumWalletState & EmbeddedEthereumWalletActions;
157
+ /**
158
+ * Embedded wallet status
159
+ */
160
+ export type EmbeddedWalletStatus = EmbeddedEthereumWalletState['status'];
161
+ /**
162
+ * Connected embedded Solana wallet state
163
+ */
164
+ interface IEmbeddedSolanaWalletConnectedState {
165
+ status: 'connected';
166
+ activeWallet: OpenfortSolanaEmbeddedWalletAccount;
167
+ provider: OpenfortEmbeddedEthereumWalletProvider;
168
+ }
169
+ /**
170
+ * Connecting embedded Solana wallet state
171
+ */
172
+ interface IEmbeddedSolanaWalletConnectingState {
173
+ status: 'connecting';
174
+ }
175
+ /**
176
+ * Reconnecting embedded Solana wallet state
177
+ */
178
+ interface IEmbeddedSolanaWalletReconnectingState {
179
+ status: 'reconnecting';
180
+ activeWallet: OpenfortSolanaEmbeddedWalletAccount;
181
+ }
182
+ /**
183
+ * Disconnected embedded Solana wallet state
184
+ */
185
+ interface IEmbeddedSolanaWalletDisconnectedState {
186
+ status: 'disconnected';
187
+ activeWallet: null;
188
+ }
189
+ /**
190
+ * Needs recovery embedded Solana wallet state
191
+ */
192
+ interface IEmbeddedSolanaWalletNeedsRecoveryState {
193
+ status: 'needs-recovery';
194
+ activeWallet: OpenfortSolanaEmbeddedWalletAccount;
195
+ }
196
+ /**
197
+ * Creating embedded Solana wallet state
198
+ */
199
+ interface IEmbeddedSolanaWalletCreatingState {
200
+ status: 'creating';
201
+ activeWallet: null;
202
+ }
203
+ /**
204
+ * Error embedded Solana wallet state
205
+ */
206
+ interface IEmbeddedSolanaWalletErrorState {
207
+ status: 'error';
208
+ activeWallet: OpenfortSolanaEmbeddedWalletAccount | null;
209
+ error: string;
210
+ }
211
+ /**
212
+ * Connected embedded Solana wallet
213
+ */
214
+ export type ConnectedEmbeddedSolanaWallet = {
215
+ address: string;
216
+ chainType: 'solana';
217
+ walletIndex: number;
218
+ getProvider: () => Promise<OpenfortEmbeddedSolanaWalletProvider>;
219
+ };
220
+ /**
221
+ * Embedded Solana wallet actions
222
+ */
223
+ export type EmbeddedSolanaWalletActions = {
224
+ /**
225
+ * Configure an embedded wallet for this user.
226
+ */
227
+ create: (args?: {
228
+ chainId?: number;
229
+ recoveryPassword?: string;
230
+ }) => Promise<import('@openfort/openfort-js').EmbeddedAccount>;
231
+ /**
232
+ * List of embedded solana wallets
233
+ */
234
+ wallets: ConnectedEmbeddedSolanaWallet[];
235
+ };
236
+ export type EmbeddedSolanaWalletConnectedState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletConnectedState;
237
+ export type EmbeddedSolanaWalletConnectingState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletConnectingState;
238
+ export type EmbeddedSolanaWalletReconnectingState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletReconnectingState;
239
+ export type EmbeddedSolanaWalletDisconnectedState = Partial<EmbeddedSolanaWalletActions> & IEmbeddedSolanaWalletDisconnectedState;
240
+ export type EmbeddedSolanaWalletNeedsRecoveryState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletNeedsRecoveryState;
241
+ export type EmbeddedSolanaWalletCreatingState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletCreatingState;
242
+ export type EmbeddedSolanaWalletErrorState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletErrorState;
243
+ /**
244
+ * Main embedded Solana wallet state union
245
+ */
246
+ export type EmbeddedSolanaWalletState = EmbeddedSolanaWalletConnectedState | EmbeddedSolanaWalletConnectingState | EmbeddedSolanaWalletReconnectingState | EmbeddedSolanaWalletDisconnectedState | EmbeddedSolanaWalletNeedsRecoveryState | EmbeddedSolanaWalletCreatingState | EmbeddedSolanaWalletErrorState;
247
+ /**
248
+ * Embedded Solana wallet status
249
+ */
250
+ export type EmbeddedSolanaWalletStatus = EmbeddedSolanaWalletState['status'];
251
+ /**
252
+ * Connected Ethereum wallet
253
+ */
254
+ export type ConnectedEmbeddedEthereumWallet = {
255
+ address: string;
256
+ ownerAddress?: string;
257
+ implementationType?: string;
258
+ chainType: 'ethereum';
259
+ walletIndex: number;
260
+ getProvider: () => Promise<OpenfortEmbeddedEthereumWalletProvider>;
261
+ };
262
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,44 +1,57 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.2",
4
+ "version": "0.1.0",
5
5
  "license": "MIT",
6
+ "description": "React Native SDK for Openfort platform integration",
6
7
  "scripts": {
7
8
  "build": "rimraf dist && tsc",
8
- "lint": "eslint . --ignore-pattern dist"
9
+ "lint": "eslint . --ignore-pattern dist",
10
+ "link": "yarn link",
11
+ "unlink": "yarn unlink"
9
12
  },
10
13
  "types": "dist/types/index.d.ts",
11
14
  "files": [
12
- "dist",
13
- "polyfills"
15
+ "dist"
14
16
  ],
17
+ "exports": {
18
+ ".": {
19
+ "require": "./dist/index.js",
20
+ "import": "./dist/index.js",
21
+ "types": "./dist/types/index.d.ts"
22
+ }
23
+ },
15
24
  "dependencies": {
16
- "events": "^3.3.0",
17
- "jsrsasign": "^11.1.0",
18
- "react-native-get-random-values": "^1.11.0",
19
- "react-native-mmkv": "^3.2.0",
20
- "react-native-randombytes": "^3.6.1",
21
- "react-native-webview": "13.12.5",
22
- "text-encoding": "^0.7.0",
23
- "uuid": "^11.1.0"
25
+ "@openfort/openfort-js": "^0.9.8"
24
26
  },
25
27
  "peerDependencies": {
26
- "@openfort/openfort-js": "^0.8.31",
28
+ "expo-apple-authentication": "*",
29
+ "expo-crypto": "*",
30
+ "expo-linking": "*",
31
+ "expo-secure-store": "*",
32
+ "expo-web-browser": "*",
27
33
  "react": "*",
28
- "react-native": "*"
34
+ "expo-application": "*",
35
+ "react-native": "*",
36
+ "react-native-webview": "*"
29
37
  },
30
38
  "devDependencies": {
31
39
  "@eslint/js": "^9.17.0",
32
- "@openfort/openfort-js": "^0.8.31",
33
- "@types/jsrsasign": "^10.5.15",
34
40
  "@types/react": "~18.3.12",
35
41
  "@types/react-test-renderer": "^18.3.0",
42
+ "buffer": "^5.4.3",
36
43
  "eslint": "^9.17.0",
37
44
  "eslint-plugin-react": "^7.37.3",
38
- "globals": "^15.14.0",
39
- "react": "18.3.1",
40
- "react-native": "0.76.5",
41
- "typescript": "^5.3.3",
45
+ "expo-apple-authentication": "^7.2.4",
46
+ "expo-application": "^6.1.4",
47
+ "expo-crypto": "14.0.2",
48
+ "expo-linking": "^7.1.5",
49
+ "expo-secure-store": "^14.2.3",
50
+ "expo-web-browser": "^14.1.6",
51
+ "react": "^18.3.1",
52
+ "react-native": "0.77.1",
53
+ "react-native-webview": "^13.15.0",
54
+ "typescript": "^5.5.3",
42
55
  "typescript-eslint": "^8.19.0"
43
56
  },
44
57
  "private": false,
package/dist/Iframe.js DELETED
@@ -1,72 +0,0 @@
1
- import React from 'react';
2
- import { useEffect, useRef, useState } from "react";
3
- import { View } from "react-native";
4
- import WebView from "react-native-webview";
5
- const debugInjectedCode = `
6
- console.log = function(...message) {
7
- const safeMessage = JSON.stringify({ ...message, type: "log" });
8
- window.ReactNativeWebView.postMessage(safeMessage);
9
- };
10
-
11
- console.warn = console.log;
12
- console.error = console.log;
13
- console.info = console.log;
14
- console.debug = console.log;
15
-
16
- console.log("injecting Code");
17
- `;
18
- const injectedCode = `
19
- window.parent = {};
20
- window.parent.postMessage = (msg) => {console.log("---", msg); window.ReactNativeWebView.postMessage(JSON.stringify(msg))}
21
- `;
22
- export default function Iframe({ customUri, debug, debugVisible }) {
23
- const webViewRef = useRef(null);
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- const fnCallbackRef = useRef(null); // Ref to store the callback
26
- const [loaded, setLoaded] = useState(false);
27
- useEffect(() => {
28
- global.openfortListener = (fn) => {
29
- fnCallbackRef.current = fn; // Store the callback in the ref
30
- };
31
- global.openfortPostMessage = (message) => {
32
- webViewRef?.current?.postMessage(JSON.stringify(message));
33
- if (debug)
34
- console.log("[Send message to web view]", message);
35
- setLoaded(true);
36
- };
37
- }, [webViewRef?.current]);
38
- const handleMessage = (event) => {
39
- // Trigger the stored callback, if any
40
- if (fnCallbackRef.current) {
41
- const origin = event.nativeEvent.url.endsWith('/') ? event.nativeEvent.url.slice(0, -1) : event.nativeEvent.url;
42
- try {
43
- const data = JSON.parse(event.nativeEvent.data);
44
- if (data?.type === "log") {
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
- const { type, ...dataWithoutType } = data;
47
- if (debug)
48
- console.log("[Webview LOG]", Object.values(dataWithoutType).join(", "));
49
- }
50
- else {
51
- if (debug)
52
- console.log("[Webview message received]", data);
53
- }
54
- }
55
- catch {
56
- if (debug)
57
- console.log("[Webview message received]", event.nativeEvent.data);
58
- }
59
- fnCallbackRef.current({ origin, data: event.nativeEvent.data });
60
- }
61
- };
62
- if (!loaded)
63
- return null;
64
- const uri = customUri ? customUri : "https://embedded.openfort.xyz";
65
- const finalUri = new URL(uri);
66
- if (debug) {
67
- finalUri.searchParams.set('debug', 'true');
68
- }
69
- const uriWithParams = finalUri.toString();
70
- return (React.createElement(View, { style: { flex: debugVisible ? 1 : 0 } },
71
- React.createElement(WebView, { ref: webViewRef, source: { uri: uriWithParams }, onMessage: handleMessage, injectedJavaScript: injectedCode + (debug ? debugInjectedCode : "") })));
72
- }
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- export default function Iframe({ customUri, debug, debugVisible }: {
3
- customUri?: string;
4
- debug?: boolean;
5
- debugVisible?: boolean;
6
- }): React.JSX.Element | null;
@@ -1,88 +0,0 @@
1
- import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions"
2
- import { KEYUTIL, KJUR } from 'jsrsasign';
3
-
4
- // This is a workaround to fix the issue with process.version
5
- if (process.version === undefined) {
6
- Object.defineProperty(process, 'version', {
7
- value: "", // Set the desired version (you can use any string)
8
- writable: false,
9
- });
10
- }
11
-
12
- // Crypto module needs getRandomValues
13
- import 'react-native-get-random-values';
14
-
15
- crypto.randomUUID = require('uuid').v4;
16
-
17
- const MMKVStorage = require("react-native-mmkv").MMKV;
18
-
19
- // Initialize MMKVStorage
20
- const MMKV = new MMKVStorage();
21
-
22
- const localStorage: Storage = {
23
- getItem: (key: string): string | null => {
24
- try {
25
- const value = MMKV.getString(key);
26
- // console.log("getItem", key, value);
27
- return value !== undefined ? value : null; // Ensure it returns string or null
28
- } catch (e) {
29
- console.error('Error reading value from localStorage polyfill', e);
30
- return null;
31
- }
32
- },
33
- setItem: (key: string, value: string) => {
34
- try {
35
- // console.log("setItem", key, value);
36
- MMKV.set(key, value); // Sets value synchronously
37
- } catch (e) {
38
- console.error('Error saving value to localStorage polyfill', e);
39
- }
40
- },
41
- removeItem: (key: string) => {
42
- try {
43
- // console.log("removeItem", key);
44
- MMKV.delete(key); // Removes item synchronously
45
- } catch (e) {
46
- console.error('Error removing value from localStorage polyfill', e);
47
- }
48
- },
49
- clear: () => {
50
- try {
51
- // console.log("clear");
52
- MMKV.clearAll(); // Clears store synchronously
53
- } catch (e) {
54
- console.error('Error clearing localStorage polyfill', e);
55
- }
56
- },
57
- key: (index: number): string | null => {
58
- return MMKV.getAllKeys()[index] || null;
59
- },
60
- get length(): number {
61
- try {
62
- return MMKV.getAllKeys().length;
63
- } catch {
64
- console.error('Error: localStorage.length is not supported');
65
- return -1;
66
- }
67
- }
68
- };
69
-
70
- global.localStorage = localStorage;
71
- global.sessionStorage = localStorage;
72
-
73
- global.JWK_UTILS = {
74
- getKey: KEYUTIL.getKey,
75
- parse: KJUR.jws.JWS.parse,
76
- verifyJWT: KJUR.jws.JWS.verifyJWT,
77
- getNow: KJUR.jws.IntDate.getNow,
78
- };
79
-
80
- // for TextEncoder and TextDecoder
81
- const applyGlobalPolyfills = () => {
82
- const { TextEncoder, TextDecoder } = require("text-encoding")
83
-
84
- polyfillGlobal("TextEncoder", () => TextEncoder)
85
- polyfillGlobal("TextDecoder", () => TextDecoder)
86
- }
87
-
88
- applyGlobalPolyfills()