@openfort/react-native 0.1.9 → 0.1.10
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 +7 -8
- package/dist/components/index.js +3 -6
- package/dist/constants/config.js +2 -2
- package/dist/core/client.js +31 -10
- package/dist/core/context.js +41 -4
- package/dist/core/provider.js +35 -4
- package/dist/core/storage.js +17 -7
- package/dist/hooks/auth/index.js +1 -1
- package/dist/hooks/auth/useCreateWalletPostAuth.js +9 -1
- package/dist/hooks/auth/useEmailAuth.js +26 -0
- package/dist/hooks/auth/useGuestAuth.js +21 -0
- package/dist/hooks/auth/useOAuth.js +15 -21
- package/dist/hooks/auth/useSignOut.js +32 -0
- package/dist/hooks/auth/useWalletAuth.js +25 -0
- package/dist/hooks/core/index.js +1 -1
- package/dist/hooks/core/useOpenfort.js +24 -27
- package/dist/hooks/core/useOpenfortClient.js +8 -13
- package/dist/hooks/core/useUser.js +28 -0
- package/dist/hooks/index.js +7 -6
- package/dist/hooks/wallet/index.js +1 -1
- package/dist/hooks/wallet/useWallet.js +27 -0
- package/dist/hooks/wallet/useWallets.js +21 -19
- package/dist/index.js +5 -6
- package/dist/lib/hookConsistency.js +42 -0
- package/dist/native/oauth.js +38 -1
- package/dist/native/storage.js +23 -8
- package/dist/types/components/AuthBoundary.d.ts +7 -8
- package/dist/types/components/index.d.ts +3 -6
- package/dist/types/constants/config.d.ts +2 -2
- package/dist/types/core/client.d.ts +22 -6
- package/dist/types/core/context.d.ts +56 -19
- package/dist/types/core/provider.d.ts +55 -29
- package/dist/types/core/storage.d.ts +7 -4
- package/dist/types/hooks/auth/index.d.ts +1 -1
- package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +9 -0
- package/dist/types/hooks/auth/useEmailAuth.d.ts +26 -0
- package/dist/types/hooks/auth/useGuestAuth.d.ts +16 -18
- package/dist/types/hooks/auth/useOAuth.d.ts +15 -21
- package/dist/types/hooks/auth/useSignOut.d.ts +32 -0
- package/dist/types/hooks/auth/useWalletAuth.d.ts +25 -3
- package/dist/types/hooks/core/index.d.ts +1 -1
- package/dist/types/hooks/core/useOpenfort.d.ts +24 -24
- package/dist/types/hooks/core/useOpenfortClient.d.ts +8 -16
- package/dist/types/hooks/core/useUser.d.ts +28 -0
- package/dist/types/hooks/index.d.ts +7 -6
- package/dist/types/hooks/wallet/index.d.ts +1 -1
- package/dist/types/hooks/wallet/useWallet.d.ts +27 -0
- package/dist/types/hooks/wallet/useWallets.d.ts +21 -19
- package/dist/types/index.d.ts +5 -6
- package/dist/types/lib/hookConsistency.d.ts +42 -0
- package/dist/types/native/oauth.d.ts +38 -1
- package/dist/types/native/storage.d.ts +21 -9
- package/dist/types/predicates.js +20 -1
- package/dist/types/types/index.d.ts +8 -8
- package/dist/types/types/predicates.d.ts +55 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SDKOverrides, AccountTypeEnum, ThirdPartyAuthConfiguration } from '@openfort/openfort-js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Shape for configuring custom authentication synchronisation behaviour.
|
|
5
5
|
*/
|
|
6
6
|
interface CustomAuthConfig {
|
|
7
7
|
enabled: boolean;
|
|
@@ -10,9 +10,9 @@ interface CustomAuthConfig {
|
|
|
10
10
|
}
|
|
11
11
|
type PolicyConfig = string | Record<number, string>;
|
|
12
12
|
export type CommonEmbeddedWalletConfiguration = {
|
|
13
|
-
/** Publishable key for the Shield API */
|
|
13
|
+
/** Publishable key for the Shield API. */
|
|
14
14
|
shieldPublishableKey: string;
|
|
15
|
-
/** Policy ID (pol_...) for the embedded signer */
|
|
15
|
+
/** Policy ID (pol_...) for the embedded signer. */
|
|
16
16
|
ethereumProviderPolicyId?: PolicyConfig;
|
|
17
17
|
accountType?: AccountTypeEnum;
|
|
18
18
|
debug?: boolean;
|
|
@@ -27,16 +27,13 @@ export type EncryptionSession = {
|
|
|
27
27
|
getEncryptionSession?: never;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* Configuration for
|
|
31
|
-
* - An encryption session is required.
|
|
30
|
+
* Configuration for enabling embedded wallet recovery flows.
|
|
32
31
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* - `createEncryptedSessionEndpoint` as a string, OR
|
|
39
|
-
* - `getEncryptionSession.` as a function that returns a promise.
|
|
32
|
+
* Automatic recovery requires an encryption session, while password-based recovery may either use
|
|
33
|
+
* an encryption session or a Shield encryption key. Provide a
|
|
34
|
+
* {@link EncryptionSession.getEncryptionSession | getEncryptionSession} callback to surface the
|
|
35
|
+
* session identifier. TODO: add support for `createEncryptedSessionEndpoint` once the native
|
|
36
|
+
* hooks implement that pathway.
|
|
40
37
|
*/
|
|
41
38
|
export type EmbeddedWalletConfiguration = CommonEmbeddedWalletConfiguration & EncryptionSession;
|
|
42
39
|
/**
|
|
@@ -49,7 +46,7 @@ type RpcUrls = {
|
|
|
49
46
|
};
|
|
50
47
|
type NativeCurrency = {
|
|
51
48
|
name: string;
|
|
52
|
-
/** 2-6 characters long */
|
|
49
|
+
/** 2-6 characters long. */
|
|
53
50
|
symbol: string;
|
|
54
51
|
decimals: number;
|
|
55
52
|
};
|
|
@@ -57,62 +54,91 @@ type BlockExplorer = {
|
|
|
57
54
|
name: string;
|
|
58
55
|
url: string;
|
|
59
56
|
};
|
|
60
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* A subset of WAGMI's chain type.
|
|
59
|
+
*
|
|
61
60
|
* https://github.com/wagmi-dev/references/blob/6aea7ee9c65cfac24f33173ab3c98176b8366f05/packages/chains/src/types.ts#L8
|
|
62
61
|
*/
|
|
63
62
|
export type Chain = {
|
|
64
|
-
/**
|
|
63
|
+
/** Chain identifier in number form. */
|
|
65
64
|
id: number;
|
|
66
|
-
/** Human readable name */
|
|
65
|
+
/** Human readable name. */
|
|
67
66
|
name: string;
|
|
68
|
-
/** Internal network name */
|
|
67
|
+
/** Internal network name. */
|
|
69
68
|
network?: string;
|
|
70
|
-
/** Currency used by chain */
|
|
69
|
+
/** Currency used by chain. */
|
|
71
70
|
nativeCurrency: NativeCurrency;
|
|
72
|
-
/** Collection of block explorers */
|
|
71
|
+
/** Collection of block explorers. */
|
|
73
72
|
blockExplorers?: {
|
|
74
73
|
[key: string]: BlockExplorer;
|
|
75
74
|
default: BlockExplorer;
|
|
76
75
|
};
|
|
77
|
-
/** Collection of RPC endpoints */
|
|
76
|
+
/** Collection of RPC endpoints. */
|
|
78
77
|
rpcUrls: {
|
|
79
78
|
[key: string]: RpcUrls;
|
|
80
79
|
default: RpcUrls;
|
|
81
80
|
};
|
|
82
|
-
/** Flag for test networks */
|
|
81
|
+
/** Flag for test networks. */
|
|
83
82
|
testnet?: boolean;
|
|
84
83
|
};
|
|
85
84
|
/**
|
|
86
|
-
* Props for the OpenfortProvider component
|
|
85
|
+
* Props for the {@link OpenfortProvider} component.
|
|
87
86
|
*/
|
|
88
87
|
export interface OpenfortProviderProps {
|
|
89
88
|
children: React.ReactNode;
|
|
90
89
|
customAuth?: CustomAuthConfig;
|
|
91
90
|
/**
|
|
92
|
-
* Openfort application ID (can be found in
|
|
91
|
+
* Openfort application ID (can be found in the Openfort developer dashboard).
|
|
93
92
|
*/
|
|
94
93
|
publishableKey: string;
|
|
95
94
|
supportedChains?: [Chain, ...Chain[]];
|
|
96
95
|
/**
|
|
97
|
-
* Embedded signer configuration for Shield integration
|
|
96
|
+
* Embedded signer configuration for Shield integration.
|
|
98
97
|
*/
|
|
99
98
|
walletConfig?: EmbeddedWalletConfiguration;
|
|
100
99
|
/**
|
|
101
|
-
* SDK overrides configuration for advanced customization
|
|
100
|
+
* SDK overrides configuration for advanced customization.
|
|
102
101
|
*/
|
|
103
102
|
overrides?: SDKOverrides;
|
|
104
103
|
/**
|
|
105
|
-
* Third party auth configuration for integrating with external auth providers
|
|
104
|
+
* Third party auth configuration for integrating with external auth providers.
|
|
106
105
|
*/
|
|
107
106
|
thirdPartyAuth?: ThirdPartyAuthConfiguration;
|
|
108
107
|
/**
|
|
109
|
-
* Enable verbose logging for debugging purposes
|
|
108
|
+
* Enable verbose logging for debugging purposes.
|
|
110
109
|
*/
|
|
111
110
|
verbose?: boolean;
|
|
112
111
|
}
|
|
113
112
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
113
|
+
* Provider component that initialises the Openfort SDK and exposes its state via {@link OpenfortContext}
|
|
114
|
+
*
|
|
115
|
+
* This component must wrap your React Native app to provide Openfort functionality to all child components.
|
|
116
|
+
* It initializes the SDK with the provided configuration and manages authentication state.
|
|
117
|
+
*
|
|
118
|
+
* @param props - Provider configuration including the publishable key and optional overrides
|
|
119
|
+
* @returns A React element that provides the Openfort context to its children
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```tsx
|
|
123
|
+
* import { OpenfortProvider } from '@openfort/react-native';
|
|
124
|
+
* import { polygon, polygonMumbai } from 'viem/chains';
|
|
125
|
+
*
|
|
126
|
+
* function App() {
|
|
127
|
+
* return (
|
|
128
|
+
* <OpenfortProvider
|
|
129
|
+
* publishableKey="pk_test_..."
|
|
130
|
+
* supportedChains={[polygon, polygonMumbai]}
|
|
131
|
+
* walletConfig={{
|
|
132
|
+
* shieldPublishableKey: "shield_pk_...",
|
|
133
|
+
* getEncryptionSession: () => fetchEncryptionSession(),
|
|
134
|
+
* }}
|
|
135
|
+
* verbose={true}
|
|
136
|
+
* >
|
|
137
|
+
* <YourAppContent />
|
|
138
|
+
* </OpenfortProvider>
|
|
139
|
+
* );
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
116
142
|
*/
|
|
117
143
|
export declare const OpenfortProvider: ({ children, publishableKey, customAuth, supportedChains, walletConfig, overrides, thirdPartyAuth, verbose, }: OpenfortProviderProps) => React.JSX.Element;
|
|
118
144
|
export {};
|
|
@@ -23,13 +23,16 @@ interface OpenfortStorage {
|
|
|
23
23
|
}>;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Storage adapter
|
|
27
|
-
*
|
|
26
|
+
* Storage adapter backed by {@link SecureStore} that matches the {@link Storage} interface expected by `@openfort/openfort-js`.
|
|
27
|
+
*
|
|
28
|
+
* The adapter normalises the keys provided by the Openfort SDK so they can be safely persisted via Expo Secure Store.
|
|
28
29
|
*/
|
|
29
30
|
export declare const SecureStorageAdapter: OpenfortStorage;
|
|
30
31
|
/**
|
|
31
|
-
* Creates a type-safe storage adapter that bridges
|
|
32
|
-
*
|
|
32
|
+
* Creates a type-safe storage adapter that bridges the Openfort SDK storage API with the React Native implementation.
|
|
33
|
+
*
|
|
34
|
+
* @param customStorage - Optional custom storage implementation. When omitted the {@link SecureStorageAdapter} is used.
|
|
35
|
+
* @returns An object that satisfies the {@link Storage} interface expected by `@openfort/openfort-js`.
|
|
33
36
|
*/
|
|
34
37
|
export declare function createNormalizedStorage(customStorage?: OpenfortStorage): Storage;
|
|
35
38
|
export {};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export type CreateWalletPostAuthOptions = {};
|
|
2
|
+
/**
|
|
3
|
+
* Hook for creating wallets after user authentication.
|
|
4
|
+
*
|
|
5
|
+
* TODO: the implementation is currently a placeholder that always returns an
|
|
6
|
+
* undefined wallet. Once the post-auth wallet flow is wired up, this helper will
|
|
7
|
+
* attempt to provision or connect an embedded wallet automatically.
|
|
8
|
+
*
|
|
9
|
+
* @returns Object containing wallet creation utilities (placeholder for now).
|
|
10
|
+
*/
|
|
2
11
|
export declare const useCreateWalletPostAuth: () => {
|
|
3
12
|
tryUseWallet: ({}: CreateWalletPostAuthOptions) => Promise<{
|
|
4
13
|
wallet: undefined;
|
|
@@ -43,6 +43,32 @@ export type EmailVerificationResult = {
|
|
|
43
43
|
export type UseEmailHookOptions = {
|
|
44
44
|
emailVerificationRedirectTo?: string;
|
|
45
45
|
} & OpenfortHookOptions<EmailAuthResult | EmailVerificationResult> & CreateWalletPostAuthOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Hook for email and password authentication.
|
|
48
|
+
*
|
|
49
|
+
* This hook provides email/password authentication flows including sign-in, sign-up, and
|
|
50
|
+
* account linking. Password reset and verification helpers are exposed but currently stubbed
|
|
51
|
+
* (TODOs) until the SDK wiring is complete.
|
|
52
|
+
*
|
|
53
|
+
* @param hookOptions - Optional configuration with callback functions and email verification settings.
|
|
54
|
+
* @returns Email authentication state and methods with flow status indicators.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const { signInEmail, signUpEmail, linkEmail, isLoading, requiresEmailVerification } = useEmailAuth({
|
|
59
|
+
* onSuccess: ({ user }) => console.log('Email auth successful:', user?.id),
|
|
60
|
+
* onError: ({ error }) => console.error('Email auth failed:', error?.message),
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* await signUpEmail({ email: 'user@example.com', password: 'securePassword123' });
|
|
64
|
+
*
|
|
65
|
+
* if (requiresEmailVerification) {
|
|
66
|
+
* console.log('Check email for verification code');
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* await signInEmail({ email: 'user@example.com', password: 'securePassword123' });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
46
72
|
export declare const useEmailAuth: (hookOptions?: UseEmailHookOptions) => {
|
|
47
73
|
isLoading: boolean;
|
|
48
74
|
isError: boolean;
|
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook for creating guest accounts
|
|
3
|
-
*/
|
|
4
1
|
import type { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
5
2
|
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
6
3
|
import { OpenfortError } from '../../types/openfortError';
|
|
7
4
|
import { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
5
|
+
export type GuestHookResult = {
|
|
6
|
+
error?: OpenfortError;
|
|
7
|
+
user?: OpenfortUser;
|
|
8
|
+
};
|
|
9
|
+
export type GuestHookOptions = OpenfortHookOptions<GuestHookResult> & CreateWalletPostAuthOptions;
|
|
8
10
|
/**
|
|
9
|
-
* Hook for creating guest accounts
|
|
11
|
+
* Hook for creating guest accounts.
|
|
10
12
|
*
|
|
11
|
-
* Guest accounts allow users to access certain features without full authentication
|
|
12
|
-
*
|
|
13
|
+
* Guest accounts allow users to access certain features without full authentication and can later be upgraded to full accounts
|
|
14
|
+
* by linking additional authentication methods.
|
|
13
15
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
16
|
+
* @param hookOptions - Configuration options including success and error callbacks.
|
|
17
|
+
* @returns Current guest authentication helpers with flow status indicators.
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
* ```tsx
|
|
19
|
-
* const {
|
|
20
|
-
* onSuccess: (user) => console.log('Guest account created:', user),
|
|
21
|
-
* onError: (error) => console.error('Failed to create guest account:', error),
|
|
21
|
+
* const { signUpGuest, isLoading } = useGuestAuth({
|
|
22
|
+
* onSuccess: ({ user }) => console.log('Guest account created:', user),
|
|
23
|
+
* onError: ({ error }) => console.error('Failed to create guest account:', error),
|
|
22
24
|
* });
|
|
23
25
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* if (!isLoading) {
|
|
27
|
+
* await signUpGuest();
|
|
28
|
+
* }
|
|
26
29
|
* ```
|
|
27
30
|
*/
|
|
28
|
-
export type GuestHookResult = {
|
|
29
|
-
error?: OpenfortError;
|
|
30
|
-
user?: OpenfortUser;
|
|
31
|
-
};
|
|
32
|
-
export type GuestHookOptions = OpenfortHookOptions<GuestHookResult> & CreateWalletPostAuthOptions;
|
|
33
31
|
export declare const useGuestAuth: (hookOptions?: GuestHookOptions) => {
|
|
34
32
|
isLoading: boolean;
|
|
35
33
|
isError: boolean;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook for OAuth-based login functionality
|
|
3
|
-
*/
|
|
4
1
|
import { OAuthProvider, type AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
5
2
|
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
6
3
|
import { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
@@ -22,33 +19,30 @@ export type AuthHookOptions = {
|
|
|
22
19
|
redirectTo?: string;
|
|
23
20
|
} & OpenfortHookOptions<StoreCredentialsResult | InitOAuthReturnType> & CreateWalletPostAuthOptions;
|
|
24
21
|
/**
|
|
25
|
-
* Hook for OAuth-based authentication with supported providers
|
|
22
|
+
* Hook for OAuth-based authentication with supported providers.
|
|
26
23
|
*
|
|
27
|
-
* This hook provides
|
|
28
|
-
*
|
|
24
|
+
* This hook provides helpers for starting OAuth login flows (`initOAuth`) and linking
|
|
25
|
+
* additional providers to an authenticated user (`linkOauth`). Some advanced flows may
|
|
26
|
+
* require manual credential storage via `storeCredentials`, which is currently a TODO.
|
|
29
27
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @returns
|
|
28
|
+
* @param hookOptions - Configuration options including success and error callbacks.
|
|
29
|
+
* @returns OAuth helpers and derived flow state flags.
|
|
32
30
|
*
|
|
33
31
|
* @example
|
|
34
32
|
* ```tsx
|
|
35
|
-
* const {
|
|
36
|
-
* onSuccess: (user) => console.log('OAuth
|
|
37
|
-
* onError: (error) => console.error('OAuth login failed:', error),
|
|
33
|
+
* const { initOAuth, linkOauth, isLoading, isError, error } = useOAuth({
|
|
34
|
+
* onSuccess: ({ user }) => console.log('OAuth completed for', user?.id),
|
|
38
35
|
* });
|
|
39
36
|
*
|
|
40
|
-
* //
|
|
41
|
-
*
|
|
37
|
+
* // Start a login flow
|
|
38
|
+
* await initOAuth({ provider: OAuthProvider.GOOGLE });
|
|
42
39
|
*
|
|
43
|
-
* //
|
|
44
|
-
*
|
|
45
|
-
* provider: 'apple',
|
|
46
|
-
* isLegacyAppleIosBehaviorEnabled: true
|
|
47
|
-
* });
|
|
40
|
+
* // Later, link another provider for the signed-in user
|
|
41
|
+
* await linkOauth({ provider: OAuthProvider.DISCORD });
|
|
48
42
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
43
|
+
* if (isError) {
|
|
44
|
+
* console.warn('Latest OAuth attempt failed', error);
|
|
45
|
+
* }
|
|
52
46
|
* ```
|
|
53
47
|
*/
|
|
54
48
|
export declare const useOAuth: (hookOptions?: AuthHookOptions) => {
|
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import { OpenfortHookOptions } from "../../types/hookOption";
|
|
2
2
|
import { OpenfortError } from "../../types/openfortError";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for user sign out functionality
|
|
5
|
+
*
|
|
6
|
+
* This hook provides secure sign out capabilities that clear user authentication state
|
|
7
|
+
* and refresh the application context to reflect the unauthenticated state.
|
|
8
|
+
*
|
|
9
|
+
* @param hookOptions - Optional configuration with callback functions for handling success and error events
|
|
10
|
+
* @returns Sign out method with loading and error state indicators
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const { signOut, isLoading, isError, error } = useSignOut({
|
|
15
|
+
* onSuccess: () => console.log('Successfully signed out'),
|
|
16
|
+
* onError: ({ error }) => console.error('Sign out failed:', error?.message),
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Sign out the current user
|
|
20
|
+
* if (!isLoading) {
|
|
21
|
+
* await signOut();
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // Handle loading states
|
|
25
|
+
* if (isLoading) {
|
|
26
|
+
* console.log('Signing out...');
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // Handle errors
|
|
30
|
+
* if (isError && error) {
|
|
31
|
+
* console.error('Sign out error:', error.message);
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
3
35
|
export declare function useSignOut(hookOptions?: OpenfortHookOptions): {
|
|
4
36
|
signOut: (options?: OpenfortHookOptions) => Promise<{} | undefined>;
|
|
5
37
|
isLoading: boolean;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook for linking Ethereum accounts using SIWE to existing users
|
|
3
|
-
*/
|
|
4
1
|
import { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
5
2
|
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
6
3
|
import { OpenfortError } from '../../types/openfortError';
|
|
@@ -33,6 +30,31 @@ type GenerateSiweMessageResult = {
|
|
|
33
30
|
error?: OpenfortError;
|
|
34
31
|
message?: string;
|
|
35
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Hook for handling Sign-In With Ethereum (SIWE) flows.
|
|
35
|
+
*
|
|
36
|
+
* This hook orchestrates SIWE message generation, signature submission, and state
|
|
37
|
+
* tracking so that external wallets can either authenticate a user (`signInWithSiwe`)
|
|
38
|
+
* or be linked to an existing account (`linkSiwe`).
|
|
39
|
+
*
|
|
40
|
+
* @param hookOptions - Optional callbacks for handling success or error events from the SIWE flows.
|
|
41
|
+
* @returns SIWE helpers for generating messages, signing in, linking wallets, and inspecting flow status.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const { generateSiweMessage, signInWithSiwe, linkSiwe, isAwaitingSignature } = useWalletAuth({
|
|
46
|
+
* onSuccess: ({ user }) => console.log('SIWE flow completed for', user?.id),
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* const { message } = await generateSiweMessage({
|
|
50
|
+
* wallet: connectedWallet.address,
|
|
51
|
+
* from: { domain: 'app.openfort.io', uri: 'https://app.openfort.io' },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const signature = await connectedWallet.signMessage(message);
|
|
55
|
+
* await signInWithSiwe({ walletAddress: connectedWallet.address, signature, messageOverride: message });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
36
58
|
export declare function useWalletAuth(hookOptions?: WalletHookOptions): {
|
|
37
59
|
isLoading: boolean;
|
|
38
60
|
isError: boolean;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { UseOpenfort } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
* Hook that exposes the core state of the Openfort SDK
|
|
3
|
+
* Hook that exposes the core state of the Openfort SDK.
|
|
4
4
|
*
|
|
5
|
-
* This hook provides access to the current authenticated user object,
|
|
6
|
-
* SDK initialization status, and core authentication methods.
|
|
5
|
+
* This hook provides access to the current authenticated user object, SDK initialization status, and core authentication methods.
|
|
7
6
|
*
|
|
8
|
-
* @returns The Openfort SDK's core state and methods
|
|
7
|
+
* @returns The Openfort SDK's core state and methods.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```tsx
|
|
12
|
-
*
|
|
11
|
+
* import { ActivityIndicator, Button, Text, View } from 'react-native';
|
|
12
|
+
* import { useOpenfort } from '@openfort/react-native/hooks';
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* return <LoadingSpinner />;
|
|
17
|
-
* }
|
|
14
|
+
* export function HomeScreen() {
|
|
15
|
+
* const { user, isReady, error, logout } = useOpenfort();
|
|
18
16
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* }
|
|
17
|
+
* if (!isReady) {
|
|
18
|
+
* return <ActivityIndicator size="large" />;
|
|
19
|
+
* }
|
|
23
20
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* }
|
|
21
|
+
* if (error) {
|
|
22
|
+
* return <Text>{`Failed to initialise: ${error.message}`}</Text>;
|
|
23
|
+
* }
|
|
28
24
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export declare function useOpenfort(): UseOpenfort;
|
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook for accessing the Openfort client instance
|
|
3
|
-
*/
|
|
4
1
|
import type { Openfort as OpenfortClient } from '@openfort/openfort-js';
|
|
5
2
|
/**
|
|
6
|
-
* Hook for accessing the Openfort client instance directly
|
|
3
|
+
* Hook for accessing the Openfort client instance directly.
|
|
7
4
|
*
|
|
8
|
-
* This hook
|
|
9
|
-
*
|
|
5
|
+
* This hook exposes the underlying {@link OpenfortClient} so that advanced consumer code can access low-level methods that are
|
|
6
|
+
* not surfaced through the convenience hooks.
|
|
10
7
|
*
|
|
11
|
-
* @returns The
|
|
8
|
+
* @returns The current {@link OpenfortClient} instance from context.
|
|
12
9
|
*
|
|
13
10
|
* @example
|
|
14
11
|
* ```tsx
|
|
15
12
|
* const client = useOpenfortClient();
|
|
16
13
|
*
|
|
17
|
-
* //
|
|
18
|
-
* const
|
|
19
|
-
*
|
|
20
|
-
* // Access client configuration
|
|
21
|
-
* console.log('App ID:', client.config.appId);
|
|
14
|
+
* // Invoke a raw SDK method
|
|
15
|
+
* const token = await client.getAccessToken();
|
|
22
16
|
*
|
|
23
|
-
* //
|
|
24
|
-
*
|
|
25
|
-
* // Perform operations that require initialization
|
|
26
|
-
* }
|
|
17
|
+
* // Access nested services
|
|
18
|
+
* await client.auth.logout();
|
|
27
19
|
* ```
|
|
28
20
|
*/
|
|
29
21
|
export declare function useOpenfortClient(): OpenfortClient;
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for accessing current user state and authentication status
|
|
3
|
+
*
|
|
4
|
+
* This hook provides access to the current user's information and authentication state.
|
|
5
|
+
* It automatically updates when the user signs in, signs out, or their profile changes.
|
|
6
|
+
*
|
|
7
|
+
* @returns Current user data, authentication status, and access token getter
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const { user, isAuthenticated, getAccessToken } = useUser();
|
|
12
|
+
*
|
|
13
|
+
* // Check if user is authenticated
|
|
14
|
+
* if (isAuthenticated && user) {
|
|
15
|
+
* console.log('Authenticated user:', user.id);
|
|
16
|
+
* console.log('User email:', user.email);
|
|
17
|
+
*
|
|
18
|
+
* // Get access token for API calls
|
|
19
|
+
* const token = await getAccessToken();
|
|
20
|
+
* console.log('Access token available:', !!token);
|
|
21
|
+
* } else {
|
|
22
|
+
* console.log('User not authenticated');
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Use in conditional rendering
|
|
26
|
+
* return isAuthenticated ? <Dashboard user={user} /> : <LoginForm />;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
1
29
|
export declare function useUser(): {
|
|
2
30
|
user: import("@openfort/openfort-js").AuthPlayerResponse | null;
|
|
3
31
|
isAuthenticated: boolean;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Openfort React Native SDK
|
|
2
|
+
* Openfort React Native SDK hooks.
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
4
|
+
* This barrel re-exports all hook collections that ship with the SDK so consumers can
|
|
5
|
+
* import from `@openfort/react-native/hooks`. The hooks are organised into the
|
|
6
|
+
* following sub-modules:
|
|
7
|
+
* - Core: Lifecycle/state helpers (e.g. `useOpenfort`)
|
|
8
|
+
* - Auth: Authentication helpers (email, OAuth, SIWE, guest)
|
|
9
|
+
* - Wallet: Embedded wallet management utilities
|
|
9
10
|
*/
|
|
10
11
|
export * from './core';
|
|
11
12
|
export * from './auth';
|
|
@@ -1 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for accessing the currently active embedded wallet
|
|
3
|
+
*
|
|
4
|
+
* This hook provides access to the currently active embedded wallet from the wallet collection.
|
|
5
|
+
* It automatically updates when the active wallet changes through other wallet operations.
|
|
6
|
+
*
|
|
7
|
+
* @returns The active embedded wallet when available, otherwise `null`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const activeWallet = useWallet();
|
|
12
|
+
*
|
|
13
|
+
* // Check if wallet is available
|
|
14
|
+
* if (activeWallet) {
|
|
15
|
+
* console.log('Active wallet address:', activeWallet.address);
|
|
16
|
+
*
|
|
17
|
+
* // Get provider for transactions
|
|
18
|
+
* const provider = await activeWallet.getProvider();
|
|
19
|
+
*
|
|
20
|
+
* // Use wallet for operations
|
|
21
|
+
* console.log('Wallet chain type:', activeWallet.chainType);
|
|
22
|
+
* console.log('Is connecting:', activeWallet.isConnecting);
|
|
23
|
+
* } else {
|
|
24
|
+
* console.log('No active wallet available');
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
1
28
|
export declare function useWallet(): import("../..").UserWallet | null;
|