@openfort/react-native 0.0.3 → 0.1.1
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 +0 -85
- package/dist/components/AuthBoundary.js +83 -0
- package/dist/components/index.js +10 -0
- package/dist/constants/config.js +9 -0
- package/dist/constants/index.js +1 -0
- package/dist/core/client.js +78 -0
- package/dist/core/context.js +37 -0
- package/dist/core/index.js +10 -0
- package/dist/core/provider.js +224 -0
- package/dist/core/storage.js +141 -0
- package/dist/hooks/auth/index.js +14 -0
- package/dist/hooks/auth/useAuthCallback.js +1 -0
- package/dist/hooks/auth/useCreateWalletPostAuth.js +22 -0
- package/dist/hooks/auth/useEmailAuth.js +176 -0
- package/dist/hooks/auth/useGuestAuth.js +52 -0
- package/dist/hooks/auth/useOAuth.js +292 -0
- package/dist/hooks/auth/useSignOut.js +48 -0
- package/dist/hooks/auth/useWalletAuth.js +133 -0
- package/dist/hooks/core/index.js +9 -0
- package/dist/hooks/core/useOpenfort.js +50 -0
- package/dist/hooks/core/useOpenfortClient.js +29 -0
- package/dist/hooks/core/useUser.js +10 -0
- package/dist/hooks/index.js +15 -0
- package/dist/hooks/wallet/index.js +7 -0
- package/dist/hooks/wallet/useWallets.js +389 -0
- package/dist/index.js +24 -1
- package/dist/lib/hookConsistency.js +16 -0
- package/dist/native/index.js +6 -0
- package/dist/native/oauth.js +183 -0
- package/dist/native/storage.js +178 -0
- package/dist/native/webview.js +157 -0
- package/dist/types/auth.js +1 -0
- package/dist/types/baseFlowState.js +8 -0
- package/dist/types/components/AuthBoundary.d.ts +85 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/config.js +1 -0
- package/dist/types/constants/config.d.ts +9 -0
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/core/client.d.ts +24 -0
- package/dist/types/core/context.d.ts +61 -0
- package/dist/types/core/index.d.ts +8 -0
- package/dist/types/core/provider.d.ts +126 -0
- package/dist/types/core/storage.d.ts +34 -0
- package/dist/types/hex.js +1 -0
- package/dist/types/hookOption.js +1 -0
- package/dist/types/hooks/auth/index.d.ts +10 -0
- package/dist/types/hooks/auth/useAuthCallback.d.ts +0 -0
- package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +6 -0
- package/dist/types/hooks/auth/useEmailAuth.d.ts +59 -0
- package/dist/types/hooks/auth/useGuestAuth.d.ts +39 -0
- package/dist/types/hooks/auth/useOAuth.d.ts +62 -0
- package/dist/types/hooks/auth/useSignOut.d.ts +9 -0
- package/dist/types/hooks/auth/useWalletAuth.d.ts +48 -0
- package/dist/types/hooks/core/index.d.ts +8 -0
- package/dist/types/hooks/core/useOpenfort.d.ts +38 -0
- package/dist/types/hooks/core/useOpenfortClient.d.ts +29 -0
- package/dist/types/hooks/core/useUser.d.ts +5 -0
- package/dist/types/hooks/index.d.ts +12 -0
- package/dist/types/hooks/wallet/index.d.ts +6 -0
- package/dist/types/hooks/wallet/useWallets.d.ts +74 -0
- package/dist/types/index.d.ts +18 -1
- package/dist/types/index.js +2 -0
- package/dist/types/lib/hookConsistency.d.ts +14 -0
- package/dist/types/native/index.d.ts +5 -0
- package/dist/types/native/oauth.d.ts +91 -0
- package/dist/types/native/storage.d.ts +50 -0
- package/dist/types/native/webview.d.ts +50 -0
- package/dist/types/oauth.js +8 -0
- package/dist/types/openfortError.js +27 -0
- package/dist/types/predicates.js +101 -0
- package/dist/types/state.js +1 -0
- package/dist/types/types/auth.d.ts +168 -0
- package/dist/types/types/baseFlowState.d.ts +14 -0
- package/dist/types/types/config.d.ts +71 -0
- package/dist/types/types/hex.d.ts +1 -0
- package/dist/types/types/hookOption.d.ts +9 -0
- package/dist/types/types/index.d.ts +38 -0
- package/dist/types/types/oauth.d.ts +74 -0
- package/dist/types/types/openfortError.d.ts +13 -0
- package/dist/types/types/predicates.d.ts +64 -0
- package/dist/types/types/state.d.ts +0 -0
- package/dist/types/types/wallet.d.ts +262 -0
- package/dist/types/wallet.js +1 -0
- package/package.json +33 -19
- package/dist/Iframe.js +0 -84
- package/dist/types/Iframe.d.ts +0 -6
- package/polyfills/index.ts +0 -89
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Openfort as OpenfortClient, EmbeddedState } from '@openfort/openfort-js';
|
|
3
|
+
import { OAuthFlowState, PasswordFlowState, RecoveryFlowState, SiweFlowState } from '../types';
|
|
4
|
+
import type { Chain, EmbeddedWalletConfiguration } from './provider';
|
|
5
|
+
/**
|
|
6
|
+
* Core Openfort context interface containing all SDK state and methods
|
|
7
|
+
*/
|
|
8
|
+
export interface OpenfortContextValue {
|
|
9
|
+
/** The Openfort client instance */
|
|
10
|
+
client: OpenfortClient;
|
|
11
|
+
/** The current authenticated user, or null when unauthenticated */
|
|
12
|
+
user: import('@openfort/openfort-js').AuthPlayerResponse | null;
|
|
13
|
+
/** Whether the SDK has initialized and is ready for use */
|
|
14
|
+
isReady: boolean;
|
|
15
|
+
/** Any error encountered during SDK initialization */
|
|
16
|
+
error: Error | null;
|
|
17
|
+
/** Supported chains configuration */
|
|
18
|
+
supportedChains?: [Chain, ...Chain[]];
|
|
19
|
+
/** Embedded wallet configuration for Shield integration */
|
|
20
|
+
walletConfig?: EmbeddedWalletConfiguration;
|
|
21
|
+
/** Current embedded wallet state */
|
|
22
|
+
embeddedState: EmbeddedState;
|
|
23
|
+
/** Password (email/SMS) authentication flow state */
|
|
24
|
+
passwordState: PasswordFlowState;
|
|
25
|
+
/** OAuth authentication flow state */
|
|
26
|
+
oAuthState: OAuthFlowState;
|
|
27
|
+
/** Sign-in with Ethereum flow state */
|
|
28
|
+
siweState: SiweFlowState;
|
|
29
|
+
/** Recovery flow state */
|
|
30
|
+
recoveryFlowState: RecoveryFlowState;
|
|
31
|
+
setPasswordState: React.Dispatch<React.SetStateAction<PasswordFlowState>>;
|
|
32
|
+
setOAuthState: React.Dispatch<React.SetStateAction<OAuthFlowState>>;
|
|
33
|
+
setSiweState: React.Dispatch<React.SetStateAction<SiweFlowState>>;
|
|
34
|
+
setRecoveryFlowState: React.Dispatch<React.SetStateAction<RecoveryFlowState>>;
|
|
35
|
+
/** Logs the current user out and clears any stored tokens */
|
|
36
|
+
logout: () => Promise<void>;
|
|
37
|
+
/** Gets the current authenticated user's access token */
|
|
38
|
+
getAccessToken: () => Promise<string | null>;
|
|
39
|
+
/** @internal Refreshes user state after authentication changes */
|
|
40
|
+
_internal: {
|
|
41
|
+
refreshUserState: (user?: import('@openfort/openfort-js').AuthPlayerResponse) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | null>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* React context for sharing Openfort SDK state throughout the component tree
|
|
46
|
+
*/
|
|
47
|
+
export declare const OpenfortContext: React.Context<OpenfortContextValue | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Hook to access the Openfort context
|
|
50
|
+
* Throws an error if used outside of a OpenfortProvider
|
|
51
|
+
*/
|
|
52
|
+
export declare function useOpenfortContext(): OpenfortContextValue;
|
|
53
|
+
/**
|
|
54
|
+
* Hook to safely access the Openfort context
|
|
55
|
+
* Returns null if used outside of a OpenfortProvider
|
|
56
|
+
*/
|
|
57
|
+
export declare function useOpenfortContextSafe(): OpenfortContextValue | null;
|
|
58
|
+
/**
|
|
59
|
+
* Type guard to check if a value is a valid OpenfortContextValue
|
|
60
|
+
*/
|
|
61
|
+
export declare function isOpenfortContextValue(value: unknown): value is OpenfortContextValue;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createOpenfortClient, getDefaultClient, setDefaultClient } from './client';
|
|
2
|
+
export { RecoveryMethod } from '@openfort/openfort-js';
|
|
3
|
+
export type { SDKOverrides } from '@openfort/openfort-js';
|
|
4
|
+
export { OpenfortContext, useOpenfortContext, useOpenfortContextSafe, isOpenfortContextValue } from './context';
|
|
5
|
+
export type { OpenfortContextValue } from './context';
|
|
6
|
+
export { OpenfortProvider } from './provider';
|
|
7
|
+
export type { OpenfortProviderProps, EmbeddedWalletConfiguration, CommonEmbeddedWalletConfiguration, EncryptionSession, AutomaticRecoveryEmbeddedWalletConfiguration, PasswordRecoveryEmbeddedWalletConfiguration } from './provider';
|
|
8
|
+
export { SecureStorageAdapter, createNormalizedStorage } from './storage';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RecoveryMethod, SDKOverrides } from '@openfort/openfort-js';
|
|
3
|
+
/**
|
|
4
|
+
* Custom auth configuration
|
|
5
|
+
*/
|
|
6
|
+
interface CustomAuthConfig {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
getCustomAccessToken: () => Promise<string | null>;
|
|
10
|
+
}
|
|
11
|
+
export type CommonEmbeddedWalletConfiguration = {
|
|
12
|
+
/** Publishable key for the Shield API */
|
|
13
|
+
shieldPublishableKey: string;
|
|
14
|
+
/** Policy ID (pol_...) for the embedded signer */
|
|
15
|
+
ethereumProviderPolicyId?: string;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type EncryptionSession = {
|
|
19
|
+
/** Function to retrieve an encryption session using a session ID */
|
|
20
|
+
getEncryptionSession: () => Promise<string>;
|
|
21
|
+
createEncryptedSessionEndpoint?: never;
|
|
22
|
+
} | {
|
|
23
|
+
/** API endpoint for creating an encrypted session */
|
|
24
|
+
createEncryptedSessionEndpoint: string;
|
|
25
|
+
getEncryptionSession?: never;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for automatic recovery, which requires an encryption session.
|
|
29
|
+
*/
|
|
30
|
+
export type AutomaticRecoveryEmbeddedWalletConfiguration = {
|
|
31
|
+
/** Specifies that the recovery method is automatic */
|
|
32
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC;
|
|
33
|
+
} & EncryptionSession;
|
|
34
|
+
export type PasswordRecoveryEmbeddedWalletConfiguration = {
|
|
35
|
+
/** Specifies that the recovery method is password-based */
|
|
36
|
+
recoveryMethod: RecoveryMethod.PASSWORD;
|
|
37
|
+
} & ((EncryptionSession & {
|
|
38
|
+
shieldEncryptionKey?: never;
|
|
39
|
+
}) | {
|
|
40
|
+
/** Required shield encryption key when no encryption session is used */
|
|
41
|
+
shieldEncryptionKey: string;
|
|
42
|
+
createEncryptedSessionEndpoint?: never;
|
|
43
|
+
getEncryptionSession?: never;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Configuration for automatic recovery.
|
|
47
|
+
* - An encryption session is required.
|
|
48
|
+
*
|
|
49
|
+
* Configuration for password-based recovery.
|
|
50
|
+
* - An encryption session, OR
|
|
51
|
+
* - A `shieldEncryptionKey` without an encryption session.
|
|
52
|
+
*
|
|
53
|
+
* Encryption session can be created using either:
|
|
54
|
+
* - `createEncryptedSessionEndpoint` as a string, OR
|
|
55
|
+
* - `getEncryptionSession.` as a function that returns a promise.
|
|
56
|
+
*/
|
|
57
|
+
export type EmbeddedWalletConfiguration = CommonEmbeddedWalletConfiguration & (AutomaticRecoveryEmbeddedWalletConfiguration | PasswordRecoveryEmbeddedWalletConfiguration);
|
|
58
|
+
/**
|
|
59
|
+
* These types are fully compatible with WAGMI chain types, in case
|
|
60
|
+
* we need interop in the future.
|
|
61
|
+
*/
|
|
62
|
+
type RpcUrls = {
|
|
63
|
+
http: readonly string[];
|
|
64
|
+
webSocket?: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
type NativeCurrency = {
|
|
67
|
+
name: string;
|
|
68
|
+
/** 2-6 characters long */
|
|
69
|
+
symbol: string;
|
|
70
|
+
decimals: number;
|
|
71
|
+
};
|
|
72
|
+
type BlockExplorer = {
|
|
73
|
+
name: string;
|
|
74
|
+
url: string;
|
|
75
|
+
};
|
|
76
|
+
/** A subset of WAGMI's chain type
|
|
77
|
+
* https://github.com/wagmi-dev/references/blob/6aea7ee9c65cfac24f33173ab3c98176b8366f05/packages/chains/src/types.ts#L8
|
|
78
|
+
*/
|
|
79
|
+
export type Chain = {
|
|
80
|
+
/** Id in number form */
|
|
81
|
+
id: number;
|
|
82
|
+
/** Human readable name */
|
|
83
|
+
name: string;
|
|
84
|
+
/** Internal network name */
|
|
85
|
+
network?: string;
|
|
86
|
+
/** Currency used by chain */
|
|
87
|
+
nativeCurrency: NativeCurrency;
|
|
88
|
+
/** Collection of block explorers */
|
|
89
|
+
blockExplorers?: {
|
|
90
|
+
[key: string]: BlockExplorer;
|
|
91
|
+
default: BlockExplorer;
|
|
92
|
+
};
|
|
93
|
+
/** Collection of RPC endpoints */
|
|
94
|
+
rpcUrls: {
|
|
95
|
+
[key: string]: RpcUrls;
|
|
96
|
+
default: RpcUrls;
|
|
97
|
+
};
|
|
98
|
+
/** Flag for test networks */
|
|
99
|
+
testnet?: boolean;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Props for the OpenfortProvider component
|
|
103
|
+
*/
|
|
104
|
+
export interface OpenfortProviderProps {
|
|
105
|
+
children: React.ReactNode;
|
|
106
|
+
customAuth?: CustomAuthConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Openfort application ID (can be found in openfort developer dashboard)
|
|
109
|
+
*/
|
|
110
|
+
publishableKey: string;
|
|
111
|
+
supportedChains?: [Chain, ...Chain[]];
|
|
112
|
+
/**
|
|
113
|
+
* Embedded signer configuration for Shield integration
|
|
114
|
+
*/
|
|
115
|
+
walletConfig?: EmbeddedWalletConfiguration;
|
|
116
|
+
/**
|
|
117
|
+
* SDK overrides configuration for advanced customization
|
|
118
|
+
*/
|
|
119
|
+
overrides?: SDKOverrides;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Main provider component that wraps the entire application and provides
|
|
123
|
+
* Openfort SDK functionality through React context
|
|
124
|
+
*/
|
|
125
|
+
export declare const OpenfortProvider: ({ children, publishableKey, customAuth, supportedChains, walletConfig, overrides, }: OpenfortProviderProps) => React.JSX.Element;
|
|
126
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare enum StorageKeys {
|
|
2
|
+
AUTHENTICATION = "openfort.authentication",
|
|
3
|
+
SIGNER = "openfort.signer",
|
|
4
|
+
CONFIGURATION = "openfort.configuration",
|
|
5
|
+
ACCOUNT = "openfort.account",
|
|
6
|
+
TEST = "openfort.test",
|
|
7
|
+
RECOVERY = "openfort.recovery",
|
|
8
|
+
SESSION = "openfort.session",
|
|
9
|
+
PKCE_STATE = "openfort.pkce_state",
|
|
10
|
+
PKCE_VERIFIER = "openfort.pkce_verifier"
|
|
11
|
+
}
|
|
12
|
+
interface OpenfortStorage {
|
|
13
|
+
get(key: StorageKeys): Promise<string | null>;
|
|
14
|
+
save(key: StorageKeys, value: string): Promise<void>;
|
|
15
|
+
remove(key: StorageKeys): Promise<void>;
|
|
16
|
+
flush(): void;
|
|
17
|
+
keyExists(key: StorageKeys): Promise<boolean>;
|
|
18
|
+
getStorageInfo(): Promise<{
|
|
19
|
+
isAvailable: boolean;
|
|
20
|
+
platform: string;
|
|
21
|
+
keychainAccessible: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Storage adapter using `expo-secure-store` intended for
|
|
26
|
+
* use with `Openfort` class from `@openfort/openfort-js`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SecureStorageAdapter: OpenfortStorage;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a type-safe storage adapter that bridges between the Openfort SDK's
|
|
31
|
+
* expected Storage interface and our React Native implementation
|
|
32
|
+
*/
|
|
33
|
+
export declare function createNormalizedStorage(customStorage?: OpenfortStorage): import('@openfort/openfort-js').Storage;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication hooks index
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports all authentication-related hooks for convenient importing.
|
|
5
|
+
*/
|
|
6
|
+
export { useEmailAuth } from './useEmailAuth';
|
|
7
|
+
export { useOAuth } from './useOAuth';
|
|
8
|
+
export { useWalletAuth } from './useWalletAuth';
|
|
9
|
+
export { useGuestAuth } from './useGuestAuth';
|
|
10
|
+
export { useSignOut } from './useSignOut';
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
2
|
+
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
3
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
4
|
+
import { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
5
|
+
export type EmailAuthResult = {
|
|
6
|
+
error?: OpenfortError;
|
|
7
|
+
user?: OpenfortUser;
|
|
8
|
+
requiresEmailVerification?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type SignInEmailOptions = {
|
|
11
|
+
email: string;
|
|
12
|
+
password: string;
|
|
13
|
+
emailVerificationRedirectTo?: string;
|
|
14
|
+
} & OpenfortHookOptions<EmailAuthResult> & CreateWalletPostAuthOptions;
|
|
15
|
+
export type SignUpEmailOptions = {
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
emailVerificationRedirectTo?: string;
|
|
20
|
+
} & OpenfortHookOptions<EmailAuthResult> & CreateWalletPostAuthOptions;
|
|
21
|
+
export type RequestResetPasswordOptions = {
|
|
22
|
+
email: string;
|
|
23
|
+
emailVerificationRedirectTo?: string;
|
|
24
|
+
} & OpenfortHookOptions<EmailAuthResult>;
|
|
25
|
+
export type ResetPasswordOptions = {
|
|
26
|
+
email: string;
|
|
27
|
+
password: string;
|
|
28
|
+
state: string;
|
|
29
|
+
} & OpenfortHookOptions<EmailAuthResult>;
|
|
30
|
+
export type LinkEmailOptions = {
|
|
31
|
+
email: string;
|
|
32
|
+
password: string;
|
|
33
|
+
emailVerificationRedirectTo?: string;
|
|
34
|
+
} & OpenfortHookOptions<EmailAuthResult>;
|
|
35
|
+
export type VerifyEmailOptions = {
|
|
36
|
+
email: string;
|
|
37
|
+
state: string;
|
|
38
|
+
} & OpenfortHookOptions<EmailVerificationResult>;
|
|
39
|
+
export type EmailVerificationResult = {
|
|
40
|
+
email?: string;
|
|
41
|
+
error?: OpenfortError;
|
|
42
|
+
};
|
|
43
|
+
export type UseEmailHookOptions = {
|
|
44
|
+
emailVerificationRedirectTo?: string;
|
|
45
|
+
} & OpenfortHookOptions<EmailAuthResult | EmailVerificationResult> & CreateWalletPostAuthOptions;
|
|
46
|
+
export declare const useEmailAuth: (hookOptions?: UseEmailHookOptions) => {
|
|
47
|
+
isLoading: boolean;
|
|
48
|
+
isError: boolean;
|
|
49
|
+
isSuccess: boolean;
|
|
50
|
+
requiresEmailVerification: boolean;
|
|
51
|
+
error: Error | null;
|
|
52
|
+
signInEmail: (options: SignInEmailOptions) => Promise<EmailAuthResult>;
|
|
53
|
+
signUpEmail: (options: SignUpEmailOptions) => Promise<EmailAuthResult>;
|
|
54
|
+
verifyEmail: () => void;
|
|
55
|
+
linkEmail: (options: LinkEmailOptions) => Promise<EmailAuthResult>;
|
|
56
|
+
requestResetPassword: () => void;
|
|
57
|
+
resetPassword: () => void;
|
|
58
|
+
reset: () => void;
|
|
59
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for creating guest accounts
|
|
3
|
+
*/
|
|
4
|
+
import type { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
5
|
+
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
6
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
7
|
+
import { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
8
|
+
/**
|
|
9
|
+
* Hook for creating guest accounts
|
|
10
|
+
*
|
|
11
|
+
* Guest accounts allow users to access certain features without full authentication.
|
|
12
|
+
* These accounts can later be upgraded to full accounts by linking authentication methods.
|
|
13
|
+
*
|
|
14
|
+
* @param opts - Configuration options including success/error callbacks
|
|
15
|
+
* @returns Object with create function
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const { create } = useGuestAuth({
|
|
20
|
+
* onSuccess: (user) => console.log('Guest account created:', user),
|
|
21
|
+
* onError: (error) => console.error('Failed to create guest account:', error),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Create a guest account
|
|
25
|
+
* const guestUser = await create();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type GuestHookResult = {
|
|
29
|
+
error?: OpenfortError;
|
|
30
|
+
user?: OpenfortUser;
|
|
31
|
+
};
|
|
32
|
+
export type GuestHookOptions = OpenfortHookOptions<GuestHookResult> & CreateWalletPostAuthOptions;
|
|
33
|
+
export declare const useGuestAuth: (hookOptions?: GuestHookOptions) => {
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
isError: boolean;
|
|
36
|
+
isSuccess: boolean;
|
|
37
|
+
error: OpenfortError | null | undefined;
|
|
38
|
+
signUpGuest: (options?: GuestHookOptions) => Promise<GuestHookResult>;
|
|
39
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for OAuth-based login functionality
|
|
3
|
+
*/
|
|
4
|
+
import { OAuthProvider, type AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
5
|
+
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
6
|
+
import { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
7
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
8
|
+
export type InitializeOAuthOptions = {
|
|
9
|
+
provider: OAuthProvider;
|
|
10
|
+
redirectTo?: string;
|
|
11
|
+
isLegacyAppleIosBehaviorEnabled?: boolean;
|
|
12
|
+
} & OpenfortHookOptions<InitOAuthReturnType>;
|
|
13
|
+
export type StoreCredentialsResult = {
|
|
14
|
+
user?: OpenfortUser;
|
|
15
|
+
error?: OpenfortError;
|
|
16
|
+
};
|
|
17
|
+
export type InitOAuthReturnType = {
|
|
18
|
+
error?: OpenfortError;
|
|
19
|
+
user?: OpenfortUser;
|
|
20
|
+
};
|
|
21
|
+
export type AuthHookOptions = {
|
|
22
|
+
redirectTo?: string;
|
|
23
|
+
} & OpenfortHookOptions<StoreCredentialsResult | InitOAuthReturnType> & CreateWalletPostAuthOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Hook for OAuth-based authentication with supported providers
|
|
26
|
+
*
|
|
27
|
+
* This hook provides OAuth authentication flow for various providers (Google, Apple, Discord, etc.).
|
|
28
|
+
* It opens the provider's web authentication page and handles the OAuth flow automatically.
|
|
29
|
+
*
|
|
30
|
+
* @param opts - Configuration options including success/error callbacks
|
|
31
|
+
* @returns Object with login function and current OAuth flow state
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* const { login, state } = useLoginWithOAuth({
|
|
36
|
+
* onSuccess: (user) => console.log('OAuth login successful:', user),
|
|
37
|
+
* onError: (error) => console.error('OAuth login failed:', error),
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Login with Google
|
|
41
|
+
* const user = await login({ provider: 'google' });
|
|
42
|
+
*
|
|
43
|
+
* // Login with Apple (using legacy web flow on iOS if needed)
|
|
44
|
+
* const user = await login({
|
|
45
|
+
* provider: 'apple',
|
|
46
|
+
* isLegacyAppleIosBehaviorEnabled: true
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Other supported providers
|
|
50
|
+
* await login({ provider: 'discord' });
|
|
51
|
+
* await login({ provider: 'twitter' });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const useOAuth: (hookOptions?: AuthHookOptions) => {
|
|
55
|
+
isLoading: boolean;
|
|
56
|
+
isError: boolean;
|
|
57
|
+
isSuccess: boolean;
|
|
58
|
+
error: Error | null | undefined;
|
|
59
|
+
initOAuth: (options: InitializeOAuthOptions) => Promise<InitOAuthReturnType>;
|
|
60
|
+
linkOauth: (options: InitializeOAuthOptions) => Promise<InitOAuthReturnType>;
|
|
61
|
+
storeCredentials: () => void;
|
|
62
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OpenfortHookOptions } from "../../types/hookOption";
|
|
2
|
+
import { OpenfortError } from "../../types/openfortError";
|
|
3
|
+
export declare function useSignOut(hookOptions?: OpenfortHookOptions): {
|
|
4
|
+
signOut: (options?: OpenfortHookOptions) => Promise<{} | undefined>;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
isError: boolean;
|
|
7
|
+
isSuccess: boolean;
|
|
8
|
+
error: OpenfortError | null | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for linking Ethereum accounts using SIWE to existing users
|
|
3
|
+
*/
|
|
4
|
+
import { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
5
|
+
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
6
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
7
|
+
export type WalletHookResult = {
|
|
8
|
+
error?: OpenfortError;
|
|
9
|
+
user?: OpenfortUser;
|
|
10
|
+
};
|
|
11
|
+
export type WalletHookOptions = OpenfortHookOptions<WalletHookResult | GenerateSiweMessageResult>;
|
|
12
|
+
type SiweOptions = {
|
|
13
|
+
signature: string;
|
|
14
|
+
walletAddress: string;
|
|
15
|
+
messageOverride?: string;
|
|
16
|
+
disableSignup?: boolean;
|
|
17
|
+
} & OpenfortHookOptions<WalletHookResult>;
|
|
18
|
+
type LinkSiweOptions = {
|
|
19
|
+
signature: string;
|
|
20
|
+
walletAddress: string;
|
|
21
|
+
messageOverride?: string;
|
|
22
|
+
} & OpenfortHookOptions<WalletHookResult>;
|
|
23
|
+
type GenerateSiweMessageOptions = {
|
|
24
|
+
wallet: string | {
|
|
25
|
+
address: string;
|
|
26
|
+
};
|
|
27
|
+
from: {
|
|
28
|
+
domain: string;
|
|
29
|
+
uri: string;
|
|
30
|
+
};
|
|
31
|
+
} & OpenfortHookOptions<GenerateSiweMessageResult>;
|
|
32
|
+
type GenerateSiweMessageResult = {
|
|
33
|
+
error?: OpenfortError;
|
|
34
|
+
message?: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function useWalletAuth(hookOptions?: WalletHookOptions): {
|
|
37
|
+
isLoading: boolean;
|
|
38
|
+
isError: boolean;
|
|
39
|
+
isSuccess: boolean;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
isAwaitingSignature: boolean;
|
|
42
|
+
isGeneratingMessage: boolean;
|
|
43
|
+
isSubmittingSignature: boolean;
|
|
44
|
+
generateSiweMessage: (args: GenerateSiweMessageOptions) => Promise<GenerateSiweMessageResult>;
|
|
45
|
+
signInWithSiwe: (opts: SiweOptions) => Promise<WalletHookResult>;
|
|
46
|
+
linkSiwe: (opts: LinkSiweOptions) => Promise<WalletHookResult>;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { UseOpenfort } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that exposes the core state of the Openfort SDK
|
|
4
|
+
*
|
|
5
|
+
* This hook provides access to the current authenticated user object,
|
|
6
|
+
* SDK initialization status, and core authentication methods.
|
|
7
|
+
*
|
|
8
|
+
* @returns The Openfort SDK's core state and methods
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { user, isReady, error, logout, getAccessToken } = useOpenfort();
|
|
13
|
+
*
|
|
14
|
+
* // Check if SDK is ready
|
|
15
|
+
* if (!isReady) {
|
|
16
|
+
* return <LoadingSpinner />;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* // Handle initialization errors
|
|
20
|
+
* if (error) {
|
|
21
|
+
* return <ErrorDisplay error={error} />;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // Check authentication status
|
|
25
|
+
* if (!user) {
|
|
26
|
+
* return <LoginScreen />;
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // User is authenticated
|
|
30
|
+
* return (
|
|
31
|
+
* <div>
|
|
32
|
+
* <h1>Welcome, {user.id}!</h1>
|
|
33
|
+
* <button onClick={logout}>Logout</button>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function useOpenfort(): UseOpenfort;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for accessing the Openfort client instance
|
|
3
|
+
*/
|
|
4
|
+
import type { Openfort as OpenfortClient } from '@openfort/openfort-js';
|
|
5
|
+
/**
|
|
6
|
+
* Hook for accessing the Openfort client instance directly
|
|
7
|
+
*
|
|
8
|
+
* This hook provides access to the underlying Openfort client for advanced use cases
|
|
9
|
+
* where you need direct access to the client methods.
|
|
10
|
+
*
|
|
11
|
+
* @returns The Openfort client instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const client = useOpenfortClient();
|
|
16
|
+
*
|
|
17
|
+
* // Use client methods directly
|
|
18
|
+
* const customResult = await client.auth.customMethod();
|
|
19
|
+
*
|
|
20
|
+
* // Access client configuration
|
|
21
|
+
* console.log('App ID:', client.config.appId);
|
|
22
|
+
*
|
|
23
|
+
* // Check client status
|
|
24
|
+
* if (client.isInitialized) {
|
|
25
|
+
* // Perform operations that require initialization
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function useOpenfortClient(): OpenfortClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Openfort React Native SDK Hooks
|
|
3
|
+
*
|
|
4
|
+
* This module provides a comprehensive set of React hooks for integrating
|
|
5
|
+
* with the Openfort platform in React Native applications.
|
|
6
|
+
*
|
|
7
|
+
* The hooks are organized into the following categories:
|
|
8
|
+
* - Core: Core SDK functionality hooks
|
|
9
|
+
*/
|
|
10
|
+
export * from './core';
|
|
11
|
+
export * from './auth';
|
|
12
|
+
export * from './wallet';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for embedded Ethereum wallet functionality
|
|
3
|
+
*/
|
|
4
|
+
import { ChainTypeEnum, Provider, RecoveryMethod } from '@openfort/openfort-js';
|
|
5
|
+
import { Hex } from '../../types/hex';
|
|
6
|
+
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
7
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
8
|
+
import { UserWallet } from '../../types/wallet';
|
|
9
|
+
type SetActiveWalletResult = {
|
|
10
|
+
error?: OpenfortError;
|
|
11
|
+
wallet?: UserWallet;
|
|
12
|
+
provider?: Provider;
|
|
13
|
+
};
|
|
14
|
+
type SetActiveWalletOptions = {
|
|
15
|
+
address?: Hex | undefined;
|
|
16
|
+
chainId?: number;
|
|
17
|
+
recoveryPassword?: string;
|
|
18
|
+
} & OpenfortHookOptions<SetActiveWalletResult>;
|
|
19
|
+
type CreateWalletResult = SetActiveWalletResult;
|
|
20
|
+
type CreateWalletOptions = {
|
|
21
|
+
chainType?: ChainTypeEnum;
|
|
22
|
+
chainId?: number;
|
|
23
|
+
policyId?: string;
|
|
24
|
+
recoveryPassword?: string;
|
|
25
|
+
} & OpenfortHookOptions<CreateWalletResult>;
|
|
26
|
+
type RecoverEmbeddedWalletResult = SetActiveWalletResult;
|
|
27
|
+
type SetRecoveryOptions = {
|
|
28
|
+
recoveryMethod: RecoveryMethod;
|
|
29
|
+
recoveryPassword?: string;
|
|
30
|
+
} & OpenfortHookOptions<CreateWalletResult>;
|
|
31
|
+
type WalletOptions = OpenfortHookOptions<SetActiveWalletResult | CreateWalletResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Hook for interacting with embedded Ethereum wallets
|
|
34
|
+
*
|
|
35
|
+
* This hook manages embedded Ethereum wallets based on the user's state from the provider.
|
|
36
|
+
* Wallet state is determined by polling in the provider, not by local state management.
|
|
37
|
+
*
|
|
38
|
+
* @param props - Optional configuration with callback functions
|
|
39
|
+
* @returns Current embedded Ethereum wallet state with actions
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const ethereumWallet = useEmbeddedEthereumWallet({
|
|
44
|
+
* onCreateWalletSuccess: (provider) => console.log('Ethereum wallet created:', provider),
|
|
45
|
+
* onCreateWalletError: (error) => console.error('Ethereum wallet creation failed:', error),
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Check wallet status and create if needed
|
|
49
|
+
* if (ethereumWallet.status === 'disconnected') {
|
|
50
|
+
* await ethereumWallet.create(); // Uses default chain
|
|
51
|
+
* // Or with specific chain: await ethereumWallet.create({ chainId: 1 });
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* // Use connected wallets
|
|
55
|
+
* if (ethereumWallet.status === 'connected' && ethereumWallet.wallets.length > 0) {
|
|
56
|
+
* const provider = await ethereumWallet.wallets[0].getProvider();
|
|
57
|
+
* // Use provider for Ethereum transactions
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function useWallets(hookOptions?: WalletOptions): {
|
|
62
|
+
exportPrivateKey: () => Promise<string>;
|
|
63
|
+
error: OpenfortError | null | undefined;
|
|
64
|
+
isError: boolean;
|
|
65
|
+
isSuccess: boolean;
|
|
66
|
+
isCreating: boolean;
|
|
67
|
+
isConnecting: boolean;
|
|
68
|
+
wallets: UserWallet[];
|
|
69
|
+
activeWallet: UserWallet | null;
|
|
70
|
+
setRecovery: (params: SetRecoveryOptions) => Promise<RecoverEmbeddedWalletResult>;
|
|
71
|
+
setActiveWallet: (options?: SetActiveWalletOptions) => Promise<SetActiveWalletResult>;
|
|
72
|
+
createWallet: (options?: CreateWalletOptions) => Promise<CreateWalletResult>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|