@openfort/react-native 0.1.20 → 0.1.22
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/dist/components/AuthBoundary.js +4 -1
- package/dist/core/index.js +1 -1
- package/dist/core/provider.js +20 -7
- package/dist/hooks/auth/useEmailAuth.js +108 -8
- package/dist/hooks/auth/useGuestAuth.js +16 -6
- package/dist/hooks/auth/useOAuth.js +14 -5
- package/dist/hooks/auth/useWalletAuth.js +29 -10
- package/dist/hooks/core/useOpenfort.js +3 -17
- package/dist/hooks/wallet/index.js +4 -2
- package/dist/hooks/wallet/solanaProvider.js +77 -0
- package/dist/hooks/wallet/useEmbeddedEthereumWallet.js +517 -0
- package/dist/hooks/wallet/useEmbeddedSolanaWallet.js +455 -0
- package/dist/hooks/wallet/utils.js +75 -0
- package/dist/lib/hookConsistency.js +6 -0
- package/dist/native/oauth.js +13 -0
- package/dist/native/storage.js +4 -0
- package/dist/native/webview.js +15 -1
- package/dist/types/components/AuthBoundary.d.ts +1 -0
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/provider.d.ts +20 -6
- package/dist/types/hooks/auth/useEmailAuth.d.ts +24 -12
- package/dist/types/hooks/auth/useGuestAuth.d.ts +17 -8
- package/dist/types/hooks/auth/useOAuth.d.ts +15 -7
- package/dist/types/hooks/auth/useWalletAuth.d.ts +29 -10
- package/dist/types/hooks/core/useOpenfort.d.ts +2 -13
- package/dist/types/hooks/wallet/index.d.ts +2 -1
- package/dist/types/hooks/wallet/solanaProvider.d.ts +75 -0
- package/dist/types/hooks/wallet/useEmbeddedEthereumWallet.d.ts +104 -0
- package/dist/types/hooks/wallet/useEmbeddedSolanaWallet.d.ts +111 -0
- package/dist/types/hooks/wallet/utils.d.ts +17 -0
- package/dist/types/index.js +1 -2
- package/dist/types/lib/hookConsistency.d.ts +6 -0
- package/dist/types/native/oauth.d.ts +13 -0
- package/dist/types/native/storage.d.ts +4 -0
- package/dist/types/native/webview.d.ts +14 -0
- package/dist/types/types/auth.d.ts +0 -41
- package/dist/types/types/index.d.ts +3 -30
- package/dist/types/types/oauth.d.ts +0 -38
- package/dist/types/types/wallet.d.ts +120 -216
- package/package.json +1 -1
- package/dist/hooks/auth/useCreateWalletPostAuth.js +0 -34
- package/dist/hooks/wallet/useWallets.js +0 -436
- package/dist/types/config.js +0 -1
- package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +0 -1
- package/dist/types/hooks/wallet/useWallets.d.ts +0 -78
- package/dist/types/predicates.js +0 -120
- package/dist/types/types/config.d.ts +0 -39
- package/dist/types/types/predicates.d.ts +0 -118
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useUser } from '../hooks';
|
|
1
2
|
import { useOpenfort } from '../hooks/core/useOpenfort';
|
|
2
3
|
/**
|
|
3
4
|
* Authentication boundary component that renders content based on authentication state.
|
|
@@ -9,6 +10,7 @@ import { useOpenfort } from '../hooks/core/useOpenfort';
|
|
|
9
10
|
* 3. **Unauthenticated** – the user is not logged in.
|
|
10
11
|
* 4. **Authenticated** – the user is logged in and the SDK is ready.
|
|
11
12
|
*
|
|
13
|
+
* @param props - Component props, see {@link AuthBoundaryProps}
|
|
12
14
|
* @example
|
|
13
15
|
* ```tsx
|
|
14
16
|
* import { AuthBoundary } from '@openfort/react-native';
|
|
@@ -59,7 +61,8 @@ import { useOpenfort } from '../hooks/core/useOpenfort';
|
|
|
59
61
|
* ```
|
|
60
62
|
*/
|
|
61
63
|
export const AuthBoundary = ({ loading, unauthenticated, error: errorComponent, children, }) => {
|
|
62
|
-
const {
|
|
64
|
+
const { isReady, error } = useOpenfort();
|
|
65
|
+
const { user } = useUser();
|
|
63
66
|
// SDK encountered an error during initialization
|
|
64
67
|
if (error && errorComponent) {
|
|
65
68
|
if (typeof errorComponent === 'function') {
|
package/dist/core/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Client creation and configuration
|
|
2
2
|
// Re-export important types and enums from openfort-js
|
|
3
3
|
export { RecoveryMethod } from '@openfort/openfort-js';
|
|
4
|
-
export { createOpenfortClient
|
|
4
|
+
export { createOpenfortClient } from './client';
|
|
5
5
|
// React context and hooks
|
|
6
6
|
export { isOpenfortContextValue, OpenfortContext, useOpenfortContext, useOpenfortContextSafe } from './context';
|
|
7
7
|
// Main provider component
|
package/dist/core/provider.js
CHANGED
|
@@ -39,13 +39,22 @@ function startEmbeddedStatePolling(client, onChange, intervalMs = 1000) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Root provider component that initializes the Openfort SDK and makes it available throughout your app.
|
|
43
43
|
*
|
|
44
|
-
* This component must wrap your React Native
|
|
45
|
-
* It initializes the SDK
|
|
44
|
+
* This component must wrap your React Native application to enable Openfort functionality.
|
|
45
|
+
* It initializes the SDK, manages authentication state, handles embedded wallet connections,
|
|
46
|
+
* and provides context to all child components through {@link OpenfortContext}.
|
|
46
47
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
48
|
+
* **Key Features:**
|
|
49
|
+
* - Initializes Openfort client with platform-specific configuration
|
|
50
|
+
* - Manages user authentication state and session persistence
|
|
51
|
+
* - Polls embedded wallet state for real-time status updates
|
|
52
|
+
* - Provides hidden WebView for embedded wallet communication
|
|
53
|
+
* - Supports multiple blockchain networks via supportedChains
|
|
54
|
+
* - Integrates Shield for secure embedded wallet management
|
|
55
|
+
*
|
|
56
|
+
* @param props - Provider configuration, see {@link OpenfortProviderProps}
|
|
57
|
+
* @returns React element that provides Openfort context to all children
|
|
49
58
|
*
|
|
50
59
|
* @example
|
|
51
60
|
* ```tsx
|
|
@@ -59,7 +68,12 @@ function startEmbeddedStatePolling(client, onChange, intervalMs = 1000) {
|
|
|
59
68
|
* supportedChains={[polygon, polygonMumbai]}
|
|
60
69
|
* walletConfig={{
|
|
61
70
|
* shieldPublishableKey: "shield_pk_...",
|
|
62
|
-
* getEncryptionSession: () =>
|
|
71
|
+
* getEncryptionSession: async () => {
|
|
72
|
+
* // Fetch session from your backend
|
|
73
|
+
* const response = await fetch('/api/encryption-session');
|
|
74
|
+
* return response.text();
|
|
75
|
+
* },
|
|
76
|
+
* recoveryMethod: 'automatic',
|
|
63
77
|
* }}
|
|
64
78
|
* verbose={true}
|
|
65
79
|
* >
|
|
@@ -227,7 +241,6 @@ export const OpenfortProvider = ({ children, publishableKey, supportedChains, wa
|
|
|
227
241
|
error,
|
|
228
242
|
supportedChains,
|
|
229
243
|
walletConfig,
|
|
230
|
-
embeddedWallet: walletConfig,
|
|
231
244
|
embeddedState,
|
|
232
245
|
// Flow states
|
|
233
246
|
passwordState,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { useOpenfortContext } from '../../core/context';
|
|
3
3
|
import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
4
|
+
import { createOAuthRedirectUri } from '../../native/oauth';
|
|
4
5
|
import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
|
|
5
6
|
const mapStatus = (status) => {
|
|
6
7
|
return {
|
|
@@ -14,12 +15,23 @@ const mapStatus = (status) => {
|
|
|
14
15
|
/**
|
|
15
16
|
* Hook for email and password authentication.
|
|
16
17
|
*
|
|
17
|
-
* This hook provides email/password authentication flows including sign-in,
|
|
18
|
-
* account linking
|
|
19
|
-
* (TODOs) until the SDK wiring is complete.
|
|
18
|
+
* This hook provides comprehensive email/password authentication flows including sign-in,
|
|
19
|
+
* sign-up, account linking, password reset, and email verification functionality.
|
|
20
20
|
*
|
|
21
|
-
* @param hookOptions - Optional configuration with callback functions and email verification settings
|
|
22
|
-
* @returns Email authentication state and methods with flow status indicators
|
|
21
|
+
* @param hookOptions - Optional configuration with callback functions and email verification settings
|
|
22
|
+
* @returns Email authentication state and methods with flow status indicators including:
|
|
23
|
+
* - `signInEmail` - Sign in with email and password
|
|
24
|
+
* - `signUpEmail` - Create new account with email and password
|
|
25
|
+
* - `linkEmail` - Link email/password to existing authenticated account
|
|
26
|
+
* - `requestResetPassword` - Request password reset email
|
|
27
|
+
* - `resetPassword` - Complete password reset with token from email
|
|
28
|
+
* - `verifyEmail` - Verify email address with verification code
|
|
29
|
+
* - `reset` - Reset flow state to initial
|
|
30
|
+
* - `isLoading` - Whether an operation is in progress
|
|
31
|
+
* - `isError` - Whether the last operation failed
|
|
32
|
+
* - `isSuccess` - Whether the last operation succeeded
|
|
33
|
+
* - `requiresEmailVerification` - Whether email verification is pending
|
|
34
|
+
* - `error` - Error from the last failed operation
|
|
23
35
|
*
|
|
24
36
|
* @example
|
|
25
37
|
* ```tsx
|
|
@@ -28,12 +40,14 @@ const mapStatus = (status) => {
|
|
|
28
40
|
* onError: ({ error }) => console.error('Email auth failed:', error?.message),
|
|
29
41
|
* });
|
|
30
42
|
*
|
|
43
|
+
* // Sign up a new user
|
|
31
44
|
* await signUpEmail({ email: 'user@example.com', password: 'securePassword123' });
|
|
32
45
|
*
|
|
33
46
|
* if (requiresEmailVerification) {
|
|
34
47
|
* console.log('Check email for verification code');
|
|
35
48
|
* }
|
|
36
49
|
*
|
|
50
|
+
* // Sign in existing user
|
|
37
51
|
* await signInEmail({ email: 'user@example.com', password: 'securePassword123' });
|
|
38
52
|
* ```
|
|
39
53
|
*/
|
|
@@ -185,9 +199,95 @@ export const useEmailAuth = (hookOptions = {}) => {
|
|
|
185
199
|
});
|
|
186
200
|
}
|
|
187
201
|
}, [client, setPasswordState, _internal, hookOptions]);
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
202
|
+
const requestResetPassword = useCallback(async (options) => {
|
|
203
|
+
try {
|
|
204
|
+
setPasswordState({ status: 'sending-verification-code' });
|
|
205
|
+
// Request password reset email
|
|
206
|
+
await client.auth.requestResetPassword({
|
|
207
|
+
email: options.email,
|
|
208
|
+
redirectUrl: options.emailVerificationRedirectTo || createOAuthRedirectUri('/password/reset'),
|
|
209
|
+
});
|
|
210
|
+
setPasswordState({ status: 'awaiting-code-input' });
|
|
211
|
+
return onSuccess({
|
|
212
|
+
hookOptions,
|
|
213
|
+
options,
|
|
214
|
+
data: { requiresEmailVerification: true },
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
const error = new OpenfortError('Failed to request password reset', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
219
|
+
error: e,
|
|
220
|
+
});
|
|
221
|
+
setPasswordState({
|
|
222
|
+
status: 'error',
|
|
223
|
+
error,
|
|
224
|
+
});
|
|
225
|
+
return onError({
|
|
226
|
+
hookOptions,
|
|
227
|
+
options,
|
|
228
|
+
error,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}, [client, setPasswordState, hookOptions]);
|
|
232
|
+
const resetPassword = useCallback(async (options) => {
|
|
233
|
+
try {
|
|
234
|
+
setPasswordState({ status: 'submitting-code' });
|
|
235
|
+
// Reset password with new password and state token
|
|
236
|
+
await client.auth.resetPassword({
|
|
237
|
+
email: options.email,
|
|
238
|
+
password: options.password,
|
|
239
|
+
state: options.state,
|
|
240
|
+
});
|
|
241
|
+
setPasswordState({ status: 'done' });
|
|
242
|
+
return onSuccess({
|
|
243
|
+
hookOptions,
|
|
244
|
+
options,
|
|
245
|
+
data: {},
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
const error = new OpenfortError('Failed to reset password', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
250
|
+
error: e,
|
|
251
|
+
});
|
|
252
|
+
setPasswordState({
|
|
253
|
+
status: 'error',
|
|
254
|
+
error,
|
|
255
|
+
});
|
|
256
|
+
return onError({
|
|
257
|
+
hookOptions,
|
|
258
|
+
options,
|
|
259
|
+
error,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}, [client, setPasswordState, hookOptions]);
|
|
263
|
+
const verifyEmail = useCallback(async (options) => {
|
|
264
|
+
try {
|
|
265
|
+
setPasswordState({ status: 'submitting-code' });
|
|
266
|
+
// Verify email with state token
|
|
267
|
+
await client.auth.verifyEmail({
|
|
268
|
+
email: options.email,
|
|
269
|
+
state: options.state,
|
|
270
|
+
});
|
|
271
|
+
setPasswordState({ status: 'done' });
|
|
272
|
+
return onSuccess({
|
|
273
|
+
hookOptions,
|
|
274
|
+
options,
|
|
275
|
+
data: { email: options.email },
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
catch (e) {
|
|
279
|
+
const error = new OpenfortError('Failed to verify email', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
280
|
+
setPasswordState({
|
|
281
|
+
status: 'error',
|
|
282
|
+
error,
|
|
283
|
+
});
|
|
284
|
+
return onError({
|
|
285
|
+
hookOptions,
|
|
286
|
+
options,
|
|
287
|
+
error,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}, [client, setPasswordState, hookOptions]);
|
|
191
291
|
const reset = () => {
|
|
192
292
|
setPasswordState({ status: 'initial' });
|
|
193
293
|
};
|
|
@@ -4,24 +4,34 @@ import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
|
4
4
|
import { mapStatus } from '../../types/baseFlowState';
|
|
5
5
|
import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
|
|
6
6
|
/**
|
|
7
|
-
* Hook for
|
|
7
|
+
* Hook for guest account authentication.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* This hook provides functionality for creating anonymous guest accounts that allow
|
|
10
|
+
* users to access features without full authentication. Guest accounts can later be
|
|
11
|
+
* upgraded to permanent accounts by linking email, OAuth, or wallet authentication.
|
|
11
12
|
*
|
|
12
|
-
* @param hookOptions - Configuration options including success and error callbacks
|
|
13
|
-
* @returns
|
|
13
|
+
* @param hookOptions - Configuration options including success and error callbacks
|
|
14
|
+
* @returns Guest authentication method and flow state including:
|
|
15
|
+
* - `signUpGuest` - Create anonymous guest account
|
|
16
|
+
* - `isLoading` - Whether guest account creation is in progress
|
|
17
|
+
* - `isError` - Whether guest account creation failed
|
|
18
|
+
* - `isSuccess` - Whether guest account was created successfully
|
|
19
|
+
* - `error` - Error from the last failed operation
|
|
14
20
|
*
|
|
15
21
|
* @example
|
|
16
22
|
* ```tsx
|
|
17
23
|
* const { signUpGuest, isLoading } = useGuestAuth({
|
|
18
|
-
* onSuccess: ({ user }) => console.log('Guest account created:', user),
|
|
24
|
+
* onSuccess: ({ user }) => console.log('Guest account created:', user?.id),
|
|
19
25
|
* onError: ({ error }) => console.error('Failed to create guest account:', error),
|
|
20
26
|
* });
|
|
21
27
|
*
|
|
28
|
+
* // Create guest account for anonymous access
|
|
22
29
|
* if (!isLoading) {
|
|
23
30
|
* await signUpGuest();
|
|
24
31
|
* }
|
|
32
|
+
*
|
|
33
|
+
* // Later, upgrade to permanent account by linking authentication
|
|
34
|
+
* // Use linkEmail, linkOauth, or linkSiwe from other hooks
|
|
25
35
|
* ```
|
|
26
36
|
*/
|
|
27
37
|
export const useGuestAuth = (hookOptions = {}) => {
|
|
@@ -8,15 +8,24 @@ import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
|
|
|
8
8
|
/**
|
|
9
9
|
* Hook for OAuth-based authentication with supported providers.
|
|
10
10
|
*
|
|
11
|
-
* This hook provides
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* This hook provides OAuth authentication flows including login and account linking
|
|
12
|
+
* for various OAuth providers (Google, Apple, Discord, Twitter, Facebook, etc.).
|
|
13
|
+
* Supports both web-based OAuth flows and native Apple Sign-In on iOS.
|
|
14
14
|
*
|
|
15
|
-
* @param hookOptions - Configuration options including success and error callbacks
|
|
16
|
-
* @returns OAuth
|
|
15
|
+
* @param hookOptions - Configuration options including success and error callbacks
|
|
16
|
+
* @returns OAuth authentication methods and flow state including:
|
|
17
|
+
* - `initOAuth` - Start OAuth login flow for authentication
|
|
18
|
+
* - `linkOauth` - Link additional OAuth provider to authenticated account
|
|
19
|
+
* - `storeCredentials` - (Reserved for future use)
|
|
20
|
+
* - `isLoading` - Whether OAuth flow is in progress
|
|
21
|
+
* - `isError` - Whether the last OAuth flow failed
|
|
22
|
+
* - `isSuccess` - Whether the last OAuth flow succeeded
|
|
23
|
+
* - `error` - Error from the last failed OAuth operation
|
|
17
24
|
*
|
|
18
25
|
* @example
|
|
19
26
|
* ```tsx
|
|
27
|
+
* import { OAuthProvider } from '@openfort/openfort-js';
|
|
28
|
+
*
|
|
20
29
|
* const { initOAuth, linkOauth, isLoading, isError, error } = useOAuth({
|
|
21
30
|
* onSuccess: ({ user }) => console.log('OAuth completed for', user?.id),
|
|
22
31
|
* });
|
|
@@ -16,28 +16,47 @@ const mapStatus = (status) => {
|
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* Hook for
|
|
19
|
+
* Hook for Sign-In With Ethereum (SIWE) authentication flows.
|
|
20
20
|
*
|
|
21
|
-
* This hook
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* This hook provides SIWE authentication functionality allowing users to authenticate
|
|
22
|
+
* or link accounts using their external Ethereum wallets. It handles message generation,
|
|
23
|
+
* signature verification, and state management throughout the authentication flow.
|
|
24
24
|
*
|
|
25
|
-
* @param hookOptions - Optional callbacks for handling success or error events from
|
|
26
|
-
* @returns SIWE
|
|
25
|
+
* @param hookOptions - Optional callbacks for handling success or error events from SIWE flows
|
|
26
|
+
* @returns SIWE authentication methods and flow state including:
|
|
27
|
+
* - `generateSiweMessage` - Generate SIWE message for wallet to sign
|
|
28
|
+
* - `signInWithSiwe` - Authenticate user with signed SIWE message
|
|
29
|
+
* - `linkSiwe` - Link external wallet to existing authenticated account
|
|
30
|
+
* - `isLoading` - Whether a SIWE operation is in progress
|
|
31
|
+
* - `isError` - Whether the last SIWE operation failed
|
|
32
|
+
* - `isSuccess` - Whether the last SIWE operation succeeded
|
|
33
|
+
* - `isAwaitingSignature` - Whether waiting for user to sign message
|
|
34
|
+
* - `isGeneratingMessage` - Whether generating SIWE message
|
|
35
|
+
* - `isSubmittingSignature` - Whether submitting signature to server
|
|
36
|
+
* - `error` - Error from the last failed operation
|
|
27
37
|
*
|
|
28
38
|
* @example
|
|
29
39
|
* ```tsx
|
|
30
|
-
*
|
|
31
|
-
*
|
|
40
|
+
* // Using with an external wallet like WalletConnect or MetaMask
|
|
41
|
+
* const { generateSiweMessage, signInWithSiwe, isAwaitingSignature } = useWalletAuth({
|
|
42
|
+
* onSuccess: ({ user }) => console.log('SIWE authentication successful:', user?.id),
|
|
32
43
|
* });
|
|
33
44
|
*
|
|
45
|
+
* // Step 1: Generate SIWE message
|
|
34
46
|
* const { message } = await generateSiweMessage({
|
|
35
47
|
* wallet: connectedWallet.address,
|
|
36
|
-
* from: { domain: '
|
|
48
|
+
* from: { domain: 'myapp.com', uri: 'https://myapp.com' },
|
|
37
49
|
* });
|
|
38
50
|
*
|
|
51
|
+
* // Step 2: Request signature from user's wallet
|
|
39
52
|
* const signature = await connectedWallet.signMessage(message);
|
|
40
|
-
*
|
|
53
|
+
*
|
|
54
|
+
* // Step 3: Authenticate with signed message
|
|
55
|
+
* await signInWithSiwe({
|
|
56
|
+
* walletAddress: connectedWallet.address,
|
|
57
|
+
* signature,
|
|
58
|
+
* messageOverride: message
|
|
59
|
+
* });
|
|
41
60
|
* ```
|
|
42
61
|
*/
|
|
43
62
|
export function useWalletAuth(hookOptions) {
|
|
@@ -2,7 +2,7 @@ import { useOpenfortContext } from '../../core/context';
|
|
|
2
2
|
/**
|
|
3
3
|
* Hook that exposes the core state of the Openfort SDK.
|
|
4
4
|
*
|
|
5
|
-
* This hook provides access to the current
|
|
5
|
+
* This hook provides access to the current SDK initialization status.
|
|
6
6
|
*
|
|
7
7
|
* @returns The Openfort SDK's core state and methods.
|
|
8
8
|
*
|
|
@@ -12,7 +12,7 @@ import { useOpenfortContext } from '../../core/context';
|
|
|
12
12
|
* import { useOpenfort } from '@openfort/react-native/hooks';
|
|
13
13
|
*
|
|
14
14
|
* export function HomeScreen() {
|
|
15
|
-
* const {
|
|
15
|
+
* const { isReady, error } = useOpenfort();
|
|
16
16
|
*
|
|
17
17
|
* if (!isReady) {
|
|
18
18
|
* return <ActivityIndicator size="large" />;
|
|
@@ -22,26 +22,12 @@ import { useOpenfortContext } from '../../core/context';
|
|
|
22
22
|
* return <Text>{`Failed to initialise: ${error.message}`}</Text>;
|
|
23
23
|
* }
|
|
24
24
|
*
|
|
25
|
-
* if (!user) {
|
|
26
|
-
* return <Text>Please sign in</Text>;
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* return (
|
|
30
|
-
* <View>
|
|
31
|
-
* <Text>{`Welcome, ${user.id}`}</Text>
|
|
32
|
-
* <Button title="Log out" onPress={() => void logout()} />
|
|
33
|
-
* </View>
|
|
34
|
-
* );
|
|
35
|
-
* }
|
|
36
25
|
* ```
|
|
37
26
|
*/
|
|
38
27
|
export function useOpenfort() {
|
|
39
|
-
const {
|
|
28
|
+
const { isReady, error } = useOpenfortContext();
|
|
40
29
|
return {
|
|
41
|
-
user,
|
|
42
30
|
isReady,
|
|
43
31
|
error,
|
|
44
|
-
logout,
|
|
45
|
-
getAccessToken,
|
|
46
32
|
};
|
|
47
33
|
}
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module re-exports all wallet-related hooks for convenient importing.
|
|
5
5
|
*/
|
|
6
|
-
// Embedded wallet
|
|
7
|
-
export {
|
|
6
|
+
// Embedded Ethereum wallet hook
|
|
7
|
+
export { useEmbeddedEthereumWallet } from './useEmbeddedEthereumWallet';
|
|
8
|
+
// Embedded Solana wallet hook
|
|
9
|
+
export { useEmbeddedSolanaWallet } from './useEmbeddedSolanaWallet';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedded Solana wallet provider implementation for Openfort.
|
|
3
|
+
*
|
|
4
|
+
* This provider implements the request-based API pattern similar to EIP-1193
|
|
5
|
+
* but adapted for Solana operations.
|
|
6
|
+
*/
|
|
7
|
+
export class OpenfortSolanaProvider {
|
|
8
|
+
_account;
|
|
9
|
+
_signTransaction;
|
|
10
|
+
_signAllTransactions;
|
|
11
|
+
_signMessage;
|
|
12
|
+
/**
|
|
13
|
+
* Legacy API for reading the public key for this provider.
|
|
14
|
+
* @deprecated Use publicKey getter instead
|
|
15
|
+
*/
|
|
16
|
+
_publicKey;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new OpenfortSolanaProvider instance
|
|
19
|
+
* @param params - Provider configuration
|
|
20
|
+
* @param params.account - The embedded account to use for this provider
|
|
21
|
+
* @param params.signTransaction - Function to sign a single transaction
|
|
22
|
+
* @param params.signAllTransactions - Function to sign multiple transactions
|
|
23
|
+
* @param params.signMessage - Function to sign a message
|
|
24
|
+
*/
|
|
25
|
+
constructor(params) {
|
|
26
|
+
this._account = params.account;
|
|
27
|
+
this._publicKey = params.account.address;
|
|
28
|
+
this._signTransaction = params.signTransaction;
|
|
29
|
+
this._signAllTransactions = params.signAllTransactions;
|
|
30
|
+
this._signMessage = params.signMessage;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The public key of the wallet (Solana address)
|
|
34
|
+
*/
|
|
35
|
+
get publicKey() {
|
|
36
|
+
return this._account.address;
|
|
37
|
+
}
|
|
38
|
+
async request(args) {
|
|
39
|
+
switch (args.method) {
|
|
40
|
+
case 'signMessage': {
|
|
41
|
+
// Convert message string to Uint8Array
|
|
42
|
+
const signature = await this._signMessage(args.params.message);
|
|
43
|
+
return { signature: signature };
|
|
44
|
+
}
|
|
45
|
+
case 'signTransaction': {
|
|
46
|
+
const signedTransaction = await this._signTransaction(args.params.transaction);
|
|
47
|
+
return { signedTransaction };
|
|
48
|
+
}
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`Unsupported method: ${args.method}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sign a single transaction (direct method)
|
|
55
|
+
*/
|
|
56
|
+
async signTransaction(transaction) {
|
|
57
|
+
return await this._signTransaction(transaction);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Sign multiple transactions (direct method)
|
|
61
|
+
*/
|
|
62
|
+
async signAllTransactions(transactions) {
|
|
63
|
+
return await this._signAllTransactions(transactions);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sign a message (direct method)
|
|
67
|
+
*/
|
|
68
|
+
async signMessage(message) {
|
|
69
|
+
return await this._signMessage(message);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Pretty log output for when an instance of this class is `console.log`'d
|
|
73
|
+
*/
|
|
74
|
+
toJSON() {
|
|
75
|
+
return `OpenfortSolanaProvider(${this.publicKey})`;
|
|
76
|
+
}
|
|
77
|
+
}
|