@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
|
@@ -103,13 +103,22 @@ export interface OpenfortProviderProps {
|
|
|
103
103
|
verbose?: boolean;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Root provider component that initializes the Openfort SDK and makes it available throughout your app.
|
|
107
107
|
*
|
|
108
|
-
* This component must wrap your React Native
|
|
109
|
-
* It initializes the SDK
|
|
108
|
+
* This component must wrap your React Native application to enable Openfort functionality.
|
|
109
|
+
* It initializes the SDK, manages authentication state, handles embedded wallet connections,
|
|
110
|
+
* and provides context to all child components through {@link OpenfortContext}.
|
|
110
111
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
112
|
+
* **Key Features:**
|
|
113
|
+
* - Initializes Openfort client with platform-specific configuration
|
|
114
|
+
* - Manages user authentication state and session persistence
|
|
115
|
+
* - Polls embedded wallet state for real-time status updates
|
|
116
|
+
* - Provides hidden WebView for embedded wallet communication
|
|
117
|
+
* - Supports multiple blockchain networks via supportedChains
|
|
118
|
+
* - Integrates Shield for secure embedded wallet management
|
|
119
|
+
*
|
|
120
|
+
* @param props - Provider configuration, see {@link OpenfortProviderProps}
|
|
121
|
+
* @returns React element that provides Openfort context to all children
|
|
113
122
|
*
|
|
114
123
|
* @example
|
|
115
124
|
* ```tsx
|
|
@@ -123,7 +132,12 @@ export interface OpenfortProviderProps {
|
|
|
123
132
|
* supportedChains={[polygon, polygonMumbai]}
|
|
124
133
|
* walletConfig={{
|
|
125
134
|
* shieldPublishableKey: "shield_pk_...",
|
|
126
|
-
* getEncryptionSession: () =>
|
|
135
|
+
* getEncryptionSession: async () => {
|
|
136
|
+
* // Fetch session from your backend
|
|
137
|
+
* const response = await fetch('/api/encryption-session');
|
|
138
|
+
* return response.text();
|
|
139
|
+
* },
|
|
140
|
+
* recoveryMethod: 'automatic',
|
|
127
141
|
* }}
|
|
128
142
|
* verbose={true}
|
|
129
143
|
* >
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
2
2
|
import type { OpenfortHookOptions } from '../../types/hookOption';
|
|
3
3
|
import { OpenfortError } from '../../types/openfortError';
|
|
4
|
-
import type { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
5
4
|
export type EmailAuthResult = {
|
|
6
5
|
error?: OpenfortError;
|
|
7
6
|
user?: OpenfortUser;
|
|
@@ -11,13 +10,13 @@ export type SignInEmailOptions = {
|
|
|
11
10
|
email: string;
|
|
12
11
|
password: string;
|
|
13
12
|
emailVerificationRedirectTo?: string;
|
|
14
|
-
} & OpenfortHookOptions<EmailAuthResult
|
|
13
|
+
} & OpenfortHookOptions<EmailAuthResult>;
|
|
15
14
|
export type SignUpEmailOptions = {
|
|
16
15
|
email: string;
|
|
17
16
|
password: string;
|
|
18
17
|
name?: string;
|
|
19
18
|
emailVerificationRedirectTo?: string;
|
|
20
|
-
} & OpenfortHookOptions<EmailAuthResult
|
|
19
|
+
} & OpenfortHookOptions<EmailAuthResult>;
|
|
21
20
|
export type RequestResetPasswordOptions = {
|
|
22
21
|
email: string;
|
|
23
22
|
emailVerificationRedirectTo?: string;
|
|
@@ -42,16 +41,27 @@ export type EmailVerificationResult = {
|
|
|
42
41
|
};
|
|
43
42
|
export type UseEmailHookOptions = {
|
|
44
43
|
emailVerificationRedirectTo?: string;
|
|
45
|
-
} & OpenfortHookOptions<EmailAuthResult | EmailVerificationResult
|
|
44
|
+
} & OpenfortHookOptions<EmailAuthResult | EmailVerificationResult>;
|
|
46
45
|
/**
|
|
47
46
|
* Hook for email and password authentication.
|
|
48
47
|
*
|
|
49
|
-
* This hook provides email/password authentication flows including sign-in,
|
|
50
|
-
* account linking
|
|
51
|
-
* (TODOs) until the SDK wiring is complete.
|
|
48
|
+
* This hook provides comprehensive email/password authentication flows including sign-in,
|
|
49
|
+
* sign-up, account linking, password reset, and email verification functionality.
|
|
52
50
|
*
|
|
53
|
-
* @param hookOptions - Optional configuration with callback functions and email verification settings
|
|
54
|
-
* @returns Email authentication state and methods with flow status indicators
|
|
51
|
+
* @param hookOptions - Optional configuration with callback functions and email verification settings
|
|
52
|
+
* @returns Email authentication state and methods with flow status indicators including:
|
|
53
|
+
* - `signInEmail` - Sign in with email and password
|
|
54
|
+
* - `signUpEmail` - Create new account with email and password
|
|
55
|
+
* - `linkEmail` - Link email/password to existing authenticated account
|
|
56
|
+
* - `requestResetPassword` - Request password reset email
|
|
57
|
+
* - `resetPassword` - Complete password reset with token from email
|
|
58
|
+
* - `verifyEmail` - Verify email address with verification code
|
|
59
|
+
* - `reset` - Reset flow state to initial
|
|
60
|
+
* - `isLoading` - Whether an operation is in progress
|
|
61
|
+
* - `isError` - Whether the last operation failed
|
|
62
|
+
* - `isSuccess` - Whether the last operation succeeded
|
|
63
|
+
* - `requiresEmailVerification` - Whether email verification is pending
|
|
64
|
+
* - `error` - Error from the last failed operation
|
|
55
65
|
*
|
|
56
66
|
* @example
|
|
57
67
|
* ```tsx
|
|
@@ -60,12 +70,14 @@ export type UseEmailHookOptions = {
|
|
|
60
70
|
* onError: ({ error }) => console.error('Email auth failed:', error?.message),
|
|
61
71
|
* });
|
|
62
72
|
*
|
|
73
|
+
* // Sign up a new user
|
|
63
74
|
* await signUpEmail({ email: 'user@example.com', password: 'securePassword123' });
|
|
64
75
|
*
|
|
65
76
|
* if (requiresEmailVerification) {
|
|
66
77
|
* console.log('Check email for verification code');
|
|
67
78
|
* }
|
|
68
79
|
*
|
|
80
|
+
* // Sign in existing user
|
|
69
81
|
* await signInEmail({ email: 'user@example.com', password: 'securePassword123' });
|
|
70
82
|
* ```
|
|
71
83
|
*/
|
|
@@ -77,9 +89,9 @@ export declare const useEmailAuth: (hookOptions?: UseEmailHookOptions) => {
|
|
|
77
89
|
error: Error | null;
|
|
78
90
|
signInEmail: (options: SignInEmailOptions) => Promise<EmailAuthResult>;
|
|
79
91
|
signUpEmail: (options: SignUpEmailOptions) => Promise<EmailAuthResult>;
|
|
80
|
-
verifyEmail: () =>
|
|
92
|
+
verifyEmail: (options: VerifyEmailOptions) => Promise<EmailVerificationResult>;
|
|
81
93
|
linkEmail: (options: LinkEmailOptions) => Promise<EmailAuthResult>;
|
|
82
|
-
requestResetPassword: () =>
|
|
83
|
-
resetPassword: () =>
|
|
94
|
+
requestResetPassword: (options: RequestResetPasswordOptions) => Promise<EmailAuthResult>;
|
|
95
|
+
resetPassword: (options: ResetPasswordOptions) => Promise<EmailAuthResult>;
|
|
84
96
|
reset: () => void;
|
|
85
97
|
};
|
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
import type { AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
2
2
|
import type { OpenfortHookOptions } from '../../types/hookOption';
|
|
3
3
|
import { OpenfortError } from '../../types/openfortError';
|
|
4
|
-
import type { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
5
4
|
export type GuestHookResult = {
|
|
6
5
|
error?: OpenfortError;
|
|
7
6
|
user?: OpenfortUser;
|
|
8
7
|
};
|
|
9
|
-
export type GuestHookOptions = OpenfortHookOptions<GuestHookResult
|
|
8
|
+
export type GuestHookOptions = OpenfortHookOptions<GuestHookResult>;
|
|
10
9
|
/**
|
|
11
|
-
* Hook for
|
|
10
|
+
* Hook for guest account authentication.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* This hook provides functionality for creating anonymous guest accounts that allow
|
|
13
|
+
* users to access features without full authentication. Guest accounts can later be
|
|
14
|
+
* upgraded to permanent accounts by linking email, OAuth, or wallet authentication.
|
|
15
15
|
*
|
|
16
|
-
* @param hookOptions - Configuration options including success and error callbacks
|
|
17
|
-
* @returns
|
|
16
|
+
* @param hookOptions - Configuration options including success and error callbacks
|
|
17
|
+
* @returns Guest authentication method and flow state including:
|
|
18
|
+
* - `signUpGuest` - Create anonymous guest account
|
|
19
|
+
* - `isLoading` - Whether guest account creation is in progress
|
|
20
|
+
* - `isError` - Whether guest account creation failed
|
|
21
|
+
* - `isSuccess` - Whether guest account was created successfully
|
|
22
|
+
* - `error` - Error from the last failed operation
|
|
18
23
|
*
|
|
19
24
|
* @example
|
|
20
25
|
* ```tsx
|
|
21
26
|
* const { signUpGuest, isLoading } = useGuestAuth({
|
|
22
|
-
* onSuccess: ({ user }) => console.log('Guest account created:', user),
|
|
27
|
+
* onSuccess: ({ user }) => console.log('Guest account created:', user?.id),
|
|
23
28
|
* onError: ({ error }) => console.error('Failed to create guest account:', error),
|
|
24
29
|
* });
|
|
25
30
|
*
|
|
31
|
+
* // Create guest account for anonymous access
|
|
26
32
|
* if (!isLoading) {
|
|
27
33
|
* await signUpGuest();
|
|
28
34
|
* }
|
|
35
|
+
*
|
|
36
|
+
* // Later, upgrade to permanent account by linking authentication
|
|
37
|
+
* // Use linkEmail, linkOauth, or linkSiwe from other hooks
|
|
29
38
|
* ```
|
|
30
39
|
*/
|
|
31
40
|
export declare const useGuestAuth: (hookOptions?: GuestHookOptions) => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { OAuthProvider, type AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
2
2
|
import type { OpenfortHookOptions } from '../../types/hookOption';
|
|
3
3
|
import { OpenfortError } from '../../types/openfortError';
|
|
4
|
-
import type { CreateWalletPostAuthOptions } from './useCreateWalletPostAuth';
|
|
5
4
|
export type InitializeOAuthOptions = {
|
|
6
5
|
provider: OAuthProvider;
|
|
7
6
|
redirectTo?: string;
|
|
@@ -17,19 +16,28 @@ export type InitOAuthReturnType = {
|
|
|
17
16
|
};
|
|
18
17
|
export type AuthHookOptions = {
|
|
19
18
|
redirectTo?: string;
|
|
20
|
-
} & OpenfortHookOptions<StoreCredentialsResult | InitOAuthReturnType
|
|
19
|
+
} & OpenfortHookOptions<StoreCredentialsResult | InitOAuthReturnType>;
|
|
21
20
|
/**
|
|
22
21
|
* Hook for OAuth-based authentication with supported providers.
|
|
23
22
|
*
|
|
24
|
-
* This hook provides
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* This hook provides OAuth authentication flows including login and account linking
|
|
24
|
+
* for various OAuth providers (Google, Apple, Discord, Twitter, Facebook, etc.).
|
|
25
|
+
* Supports both web-based OAuth flows and native Apple Sign-In on iOS.
|
|
27
26
|
*
|
|
28
|
-
* @param hookOptions - Configuration options including success and error callbacks
|
|
29
|
-
* @returns OAuth
|
|
27
|
+
* @param hookOptions - Configuration options including success and error callbacks
|
|
28
|
+
* @returns OAuth authentication methods and flow state including:
|
|
29
|
+
* - `initOAuth` - Start OAuth login flow for authentication
|
|
30
|
+
* - `linkOauth` - Link additional OAuth provider to authenticated account
|
|
31
|
+
* - `storeCredentials` - (Reserved for future use)
|
|
32
|
+
* - `isLoading` - Whether OAuth flow is in progress
|
|
33
|
+
* - `isError` - Whether the last OAuth flow failed
|
|
34
|
+
* - `isSuccess` - Whether the last OAuth flow succeeded
|
|
35
|
+
* - `error` - Error from the last failed OAuth operation
|
|
30
36
|
*
|
|
31
37
|
* @example
|
|
32
38
|
* ```tsx
|
|
39
|
+
* import { OAuthProvider } from '@openfort/openfort-js';
|
|
40
|
+
*
|
|
33
41
|
* const { initOAuth, linkOauth, isLoading, isError, error } = useOAuth({
|
|
34
42
|
* onSuccess: ({ user }) => console.log('OAuth completed for', user?.id),
|
|
35
43
|
* });
|
|
@@ -31,28 +31,47 @@ type GenerateSiweMessageResult = {
|
|
|
31
31
|
message?: string;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Hook for
|
|
34
|
+
* Hook for Sign-In With Ethereum (SIWE) authentication flows.
|
|
35
35
|
*
|
|
36
|
-
* This hook
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* This hook provides SIWE authentication functionality allowing users to authenticate
|
|
37
|
+
* or link accounts using their external Ethereum wallets. It handles message generation,
|
|
38
|
+
* signature verification, and state management throughout the authentication flow.
|
|
39
39
|
*
|
|
40
|
-
* @param hookOptions - Optional callbacks for handling success or error events from
|
|
41
|
-
* @returns SIWE
|
|
40
|
+
* @param hookOptions - Optional callbacks for handling success or error events from SIWE flows
|
|
41
|
+
* @returns SIWE authentication methods and flow state including:
|
|
42
|
+
* - `generateSiweMessage` - Generate SIWE message for wallet to sign
|
|
43
|
+
* - `signInWithSiwe` - Authenticate user with signed SIWE message
|
|
44
|
+
* - `linkSiwe` - Link external wallet to existing authenticated account
|
|
45
|
+
* - `isLoading` - Whether a SIWE operation is in progress
|
|
46
|
+
* - `isError` - Whether the last SIWE operation failed
|
|
47
|
+
* - `isSuccess` - Whether the last SIWE operation succeeded
|
|
48
|
+
* - `isAwaitingSignature` - Whether waiting for user to sign message
|
|
49
|
+
* - `isGeneratingMessage` - Whether generating SIWE message
|
|
50
|
+
* - `isSubmittingSignature` - Whether submitting signature to server
|
|
51
|
+
* - `error` - Error from the last failed operation
|
|
42
52
|
*
|
|
43
53
|
* @example
|
|
44
54
|
* ```tsx
|
|
45
|
-
*
|
|
46
|
-
*
|
|
55
|
+
* // Using with an external wallet like WalletConnect or MetaMask
|
|
56
|
+
* const { generateSiweMessage, signInWithSiwe, isAwaitingSignature } = useWalletAuth({
|
|
57
|
+
* onSuccess: ({ user }) => console.log('SIWE authentication successful:', user?.id),
|
|
47
58
|
* });
|
|
48
59
|
*
|
|
60
|
+
* // Step 1: Generate SIWE message
|
|
49
61
|
* const { message } = await generateSiweMessage({
|
|
50
62
|
* wallet: connectedWallet.address,
|
|
51
|
-
* from: { domain: '
|
|
63
|
+
* from: { domain: 'myapp.com', uri: 'https://myapp.com' },
|
|
52
64
|
* });
|
|
53
65
|
*
|
|
66
|
+
* // Step 2: Request signature from user's wallet
|
|
54
67
|
* const signature = await connectedWallet.signMessage(message);
|
|
55
|
-
*
|
|
68
|
+
*
|
|
69
|
+
* // Step 3: Authenticate with signed message
|
|
70
|
+
* await signInWithSiwe({
|
|
71
|
+
* walletAddress: connectedWallet.address,
|
|
72
|
+
* signature,
|
|
73
|
+
* messageOverride: message
|
|
74
|
+
* });
|
|
56
75
|
* ```
|
|
57
76
|
*/
|
|
58
77
|
export declare function useWalletAuth(hookOptions?: WalletHookOptions): {
|
|
@@ -2,7 +2,7 @@ import type { UseOpenfort } from '../../types';
|
|
|
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 type { UseOpenfort } from '../../types';
|
|
|
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,17 +22,6 @@ import type { UseOpenfort } from '../../types';
|
|
|
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 declare function useOpenfort(): UseOpenfort;
|
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module re-exports all wallet-related hooks for convenient importing.
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
6
|
+
export { useEmbeddedEthereumWallet } from './useEmbeddedEthereumWallet';
|
|
7
|
+
export { useEmbeddedSolanaWallet } from './useEmbeddedSolanaWallet';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { EmbeddedAccount } from '@openfort/openfort-js';
|
|
2
|
+
import type { OpenfortEmbeddedSolanaWalletProvider } from '../../types/wallet';
|
|
3
|
+
type SignMessageRequestArguments = {
|
|
4
|
+
method: 'signMessage';
|
|
5
|
+
params: {
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type SignTransactionRequestArguments<T = any> = {
|
|
10
|
+
method: 'signTransaction';
|
|
11
|
+
params: {
|
|
12
|
+
transaction: T;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Embedded Solana wallet provider implementation for Openfort.
|
|
17
|
+
*
|
|
18
|
+
* This provider implements the request-based API pattern similar to EIP-1193
|
|
19
|
+
* but adapted for Solana operations.
|
|
20
|
+
*/
|
|
21
|
+
export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWalletProvider {
|
|
22
|
+
private _account;
|
|
23
|
+
private _signTransaction;
|
|
24
|
+
private _signAllTransactions;
|
|
25
|
+
private _signMessage;
|
|
26
|
+
/**
|
|
27
|
+
* Legacy API for reading the public key for this provider.
|
|
28
|
+
* @deprecated Use publicKey getter instead
|
|
29
|
+
*/
|
|
30
|
+
readonly _publicKey: string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new OpenfortSolanaProvider instance
|
|
33
|
+
* @param params - Provider configuration
|
|
34
|
+
* @param params.account - The embedded account to use for this provider
|
|
35
|
+
* @param params.signTransaction - Function to sign a single transaction
|
|
36
|
+
* @param params.signAllTransactions - Function to sign multiple transactions
|
|
37
|
+
* @param params.signMessage - Function to sign a message
|
|
38
|
+
*/
|
|
39
|
+
constructor(params: {
|
|
40
|
+
account: EmbeddedAccount;
|
|
41
|
+
signTransaction: (transaction: any) => Promise<any>;
|
|
42
|
+
signAllTransactions: (transactions: any[]) => Promise<any[]>;
|
|
43
|
+
signMessage: (message: string) => Promise<string>;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* The public key of the wallet (Solana address)
|
|
47
|
+
*/
|
|
48
|
+
get publicKey(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Request-based API for wallet operations
|
|
51
|
+
*/
|
|
52
|
+
request(args: SignMessageRequestArguments): Promise<{
|
|
53
|
+
signature: string;
|
|
54
|
+
}>;
|
|
55
|
+
request(args: SignTransactionRequestArguments): Promise<{
|
|
56
|
+
signedTransaction: any;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Sign a single transaction (direct method)
|
|
60
|
+
*/
|
|
61
|
+
signTransaction(transaction: any): Promise<any>;
|
|
62
|
+
/**
|
|
63
|
+
* Sign multiple transactions (direct method)
|
|
64
|
+
*/
|
|
65
|
+
signAllTransactions(transactions: any[]): Promise<any[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Sign a message (direct method)
|
|
68
|
+
*/
|
|
69
|
+
signMessage(message: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Pretty log output for when an instance of this class is `console.log`'d
|
|
72
|
+
*/
|
|
73
|
+
toJSON(): string;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type EmbeddedAccount } from '@openfort/openfort-js';
|
|
2
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
3
|
+
import type { ConnectedEmbeddedEthereumWallet, EmbeddedEthereumWalletState, OpenfortEmbeddedEthereumWalletProvider } from '../../types/wallet';
|
|
4
|
+
type UseEmbeddedEthereumWalletOptions = {
|
|
5
|
+
chainId?: number;
|
|
6
|
+
onCreateSuccess?: (account: EmbeddedAccount, provider: OpenfortEmbeddedEthereumWalletProvider) => void;
|
|
7
|
+
onCreateError?: (error: OpenfortError) => void;
|
|
8
|
+
onSetActiveSuccess?: (wallet: ConnectedEmbeddedEthereumWallet, provider: OpenfortEmbeddedEthereumWalletProvider) => void;
|
|
9
|
+
onSetActiveError?: (error: OpenfortError) => void;
|
|
10
|
+
onSetRecoverySuccess?: () => void;
|
|
11
|
+
onSetRecoveryError?: (error: OpenfortError) => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Hook for managing embedded Ethereum wallets.
|
|
15
|
+
*
|
|
16
|
+
* This hook provides comprehensive management of embedded Ethereum wallets including creation,
|
|
17
|
+
* recovery, activation, and EIP-1193 provider access. Returns a discriminated union state that
|
|
18
|
+
* enables type-safe wallet interactions based on connection status.
|
|
19
|
+
*
|
|
20
|
+
* **Wallet Types Supported:**
|
|
21
|
+
* - Smart Contract Accounts (Account Abstraction)
|
|
22
|
+
* - EOA (Externally Owned Accounts)
|
|
23
|
+
*
|
|
24
|
+
* **Recovery Methods:**
|
|
25
|
+
* - Automatic recovery (via encryption session)
|
|
26
|
+
* - Password-based recovery
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options including:
|
|
29
|
+
* - `chainId` - Default chain ID for wallet operations
|
|
30
|
+
* - `onCreateSuccess` - Callback when wallet is created
|
|
31
|
+
* - `onCreateError` - Callback when wallet creation fails
|
|
32
|
+
* - `onSetActiveSuccess` - Callback when wallet is activated/recovered
|
|
33
|
+
* - `onSetActiveError` - Callback when wallet activation fails
|
|
34
|
+
* - `onSetRecoverySuccess` - Callback when recovery method is updated
|
|
35
|
+
* - `onSetRecoveryError` - Callback when recovery update fails
|
|
36
|
+
*
|
|
37
|
+
* @returns Discriminated union state based on `status` field:
|
|
38
|
+
* - **'disconnected'**: No active wallet. Properties: `create`, `setActive`, `wallets`, `setRecovery`, `exportPrivateKey`
|
|
39
|
+
* - **'connecting'**: Activating wallet. Properties: same as disconnected + `activeWallet`
|
|
40
|
+
* - **'reconnecting'**: Reconnecting to wallet. Properties: same as connecting
|
|
41
|
+
* - **'creating'**: Creating new wallet. Properties: same as disconnected
|
|
42
|
+
* - **'needs-recovery'**: Recovery required. Properties: same as connecting
|
|
43
|
+
* - **'connected'**: Wallet ready. Properties: all + `provider` (EIP-1193 provider)
|
|
44
|
+
* - **'error'**: Operation failed. Properties: all + `error` message
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* import { useEmbeddedEthereumWallet } from '@openfort/react-native';
|
|
49
|
+
* import { ActivityIndicator } from 'react-native';
|
|
50
|
+
*
|
|
51
|
+
* function WalletComponent() {
|
|
52
|
+
* const ethereum = useEmbeddedEthereumWallet({
|
|
53
|
+
* chainId: 137, // Polygon
|
|
54
|
+
* onCreateSuccess: (account, provider) => {
|
|
55
|
+
* console.log('Wallet created:', account.address);
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // Handle loading states
|
|
60
|
+
* if (ethereum.status === 'creating' || ethereum.status === 'connecting') {
|
|
61
|
+
* return <ActivityIndicator />;
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* // Create first wallet
|
|
65
|
+
* if (ethereum.status === 'disconnected' && ethereum.wallets.length === 0) {
|
|
66
|
+
* return <Button onPress={() => ethereum.create()} title="Create Wallet" />;
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* // Activate existing wallet
|
|
70
|
+
* if (ethereum.status === 'disconnected' && ethereum.wallets.length > 0) {
|
|
71
|
+
* return (
|
|
72
|
+
* <Button
|
|
73
|
+
* onPress={() => ethereum.setActive({
|
|
74
|
+
* address: ethereum.wallets[0].address,
|
|
75
|
+
* recoveryPassword: 'optional-password'
|
|
76
|
+
* })}
|
|
77
|
+
* title="Connect Wallet"
|
|
78
|
+
* />
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* // Use connected wallet
|
|
83
|
+
* if (ethereum.status === 'connected') {
|
|
84
|
+
* const sendTransaction = async () => {
|
|
85
|
+
* const tx = await ethereum.provider.request({
|
|
86
|
+
* method: 'eth_sendTransaction',
|
|
87
|
+
* params: [{
|
|
88
|
+
* from: ethereum.activeWallet.address,
|
|
89
|
+
* to: '0x...',
|
|
90
|
+
* value: '0x0'
|
|
91
|
+
* }]
|
|
92
|
+
* });
|
|
93
|
+
* console.log('Transaction hash:', tx);
|
|
94
|
+
* };
|
|
95
|
+
*
|
|
96
|
+
* return <Button onPress={sendTransaction} title="Send Transaction" />;
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* return null;
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function useEmbeddedEthereumWallet(options?: UseEmbeddedEthereumWalletOptions): EmbeddedEthereumWalletState;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type EmbeddedAccount } from '@openfort/openfort-js';
|
|
2
|
+
import { OpenfortError } from '../../types/openfortError';
|
|
3
|
+
import type { ConnectedEmbeddedSolanaWallet, EmbeddedSolanaWalletState, OpenfortEmbeddedSolanaWalletProvider } from '../../types/wallet';
|
|
4
|
+
type UseEmbeddedSolanaWalletOptions = {
|
|
5
|
+
onCreateSuccess?: (account: EmbeddedAccount, provider: OpenfortEmbeddedSolanaWalletProvider) => void;
|
|
6
|
+
onCreateError?: (error: OpenfortError) => void;
|
|
7
|
+
onSetActiveSuccess?: (wallet: ConnectedEmbeddedSolanaWallet, provider: OpenfortEmbeddedSolanaWalletProvider) => void;
|
|
8
|
+
onSetActiveError?: (error: OpenfortError) => void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Hook for managing embedded Solana wallets.
|
|
12
|
+
*
|
|
13
|
+
* This hook provides comprehensive management of embedded Solana (SVM) wallets including
|
|
14
|
+
* creation, recovery, activation, and transaction signing. Returns a discriminated union
|
|
15
|
+
* state that enables type-safe wallet interactions based on connection status.
|
|
16
|
+
*
|
|
17
|
+
* **Note:** Solana wallets are always EOA (Externally Owned Accounts) and work across
|
|
18
|
+
* all Solana networks (mainnet, devnet, testnet).
|
|
19
|
+
*
|
|
20
|
+
* **Recovery Methods:**
|
|
21
|
+
* - Automatic recovery (via encryption session)
|
|
22
|
+
* - Password-based recovery
|
|
23
|
+
*
|
|
24
|
+
* @param options - Configuration options including:
|
|
25
|
+
* - `onCreateSuccess` - Callback when wallet is created
|
|
26
|
+
* - `onCreateError` - Callback when wallet creation fails
|
|
27
|
+
* - `onSetActiveSuccess` - Callback when wallet is activated/recovered
|
|
28
|
+
* - `onSetActiveError` - Callback when wallet activation fails
|
|
29
|
+
*
|
|
30
|
+
* @returns Discriminated union state based on `status` field:
|
|
31
|
+
* - **'disconnected'**: No active wallet. Properties: `create`, `setActive`, `wallets`
|
|
32
|
+
* - **'connecting'**: Activating wallet. Properties: same as disconnected
|
|
33
|
+
* - **'reconnecting'**: Reconnecting to wallet. Properties: same as disconnected + `activeWallet`
|
|
34
|
+
* - **'creating'**: Creating new wallet. Properties: same as disconnected
|
|
35
|
+
* - **'needs-recovery'**: Recovery required. Properties: same as reconnecting
|
|
36
|
+
* - **'connected'**: Wallet ready. Properties: all + `provider` (Solana wallet adapter)
|
|
37
|
+
* - **'error'**: Operation failed. Properties: all + `error` message + optional `activeWallet`
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { useEmbeddedSolanaWallet } from '@openfort/react-native';
|
|
42
|
+
* import { Transaction } from '@solana/web3.js';
|
|
43
|
+
* import { ActivityIndicator } from 'react-native';
|
|
44
|
+
*
|
|
45
|
+
* function SolanaWalletComponent() {
|
|
46
|
+
* const solana = useEmbeddedSolanaWallet({
|
|
47
|
+
* onCreateSuccess: (account, provider) => {
|
|
48
|
+
* console.log('Solana wallet created:', account.address);
|
|
49
|
+
* console.log('Public key:', provider.publicKey);
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Handle loading states
|
|
54
|
+
* if (solana.status === 'creating' || solana.status === 'connecting') {
|
|
55
|
+
* return <ActivityIndicator />;
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Create first wallet
|
|
59
|
+
* if (solana.status === 'disconnected' && solana.wallets.length === 0) {
|
|
60
|
+
* return (
|
|
61
|
+
* <Button
|
|
62
|
+
* onPress={() => solana.create({ recoveryPassword: 'optional' })}
|
|
63
|
+
* title="Create Solana Wallet"
|
|
64
|
+
* />
|
|
65
|
+
* );
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* // Activate existing wallet
|
|
69
|
+
* if (solana.status === 'disconnected' && solana.wallets.length > 0) {
|
|
70
|
+
* return (
|
|
71
|
+
* <Button
|
|
72
|
+
* onPress={() => solana.setActive({
|
|
73
|
+
* address: solana.wallets[0].address,
|
|
74
|
+
* recoveryPassword: 'optional'
|
|
75
|
+
* })}
|
|
76
|
+
* title="Connect Solana Wallet"
|
|
77
|
+
* />
|
|
78
|
+
* );
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* // Use connected wallet
|
|
82
|
+
* if (solana.status === 'connected') {
|
|
83
|
+
* const signTransaction = async () => {
|
|
84
|
+
* const transaction = new Transaction();
|
|
85
|
+
* // ... add instructions to transaction
|
|
86
|
+
*
|
|
87
|
+
* const signed = await solana.provider.signTransaction(transaction);
|
|
88
|
+
* console.log('Signed transaction:', signed);
|
|
89
|
+
* };
|
|
90
|
+
*
|
|
91
|
+
* const signMessage = async () => {
|
|
92
|
+
* const message = 'Hello Solana!';
|
|
93
|
+
* const signature = await solana.provider.signMessage(message);
|
|
94
|
+
* console.log('Message signature:', signature);
|
|
95
|
+
* };
|
|
96
|
+
*
|
|
97
|
+
* return (
|
|
98
|
+
* <View>
|
|
99
|
+
* <Text>Connected: {solana.activeWallet.address}</Text>
|
|
100
|
+
* <Button onPress={signTransaction} title="Sign Transaction" />
|
|
101
|
+
* <Button onPress={signMessage} title="Sign Message" />
|
|
102
|
+
* </View>
|
|
103
|
+
* );
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* return null;
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function useEmbeddedSolanaWallet(options?: UseEmbeddedSolanaWalletOptions): EmbeddedSolanaWalletState;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RecoveryParams } from '@openfort/openfort-js';
|
|
2
|
+
import type { EmbeddedWalletConfiguration } from '../../core/provider';
|
|
3
|
+
/**
|
|
4
|
+
* Builds recovery parameters from options and wallet configuration.
|
|
5
|
+
*
|
|
6
|
+
* This utility constructs the appropriate RecoveryParams object based on whether
|
|
7
|
+
* a recovery password is provided or automatic recovery should be used.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Options containing optional recovery password
|
|
10
|
+
* @param walletConfig - The embedded wallet configuration from the provider
|
|
11
|
+
* @returns A promise that resolves to RecoveryParams for the SDK
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildRecoveryParams(options: {
|
|
16
|
+
recoveryPassword?: string;
|
|
17
|
+
} | undefined, walletConfig?: EmbeddedWalletConfiguration): Promise<RecoveryParams>;
|
package/dist/types/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { canTransact, getActionText, getStateDescription, hasError, isConnected, isConnecting, isCreating, isDisconnected, isLoading, isNotCreated, isReady, isReconnecting, isStable, needsRecovery, needsUserAction, } from './predicates';
|
|
1
|
+
export {};
|
|
@@ -7,6 +7,9 @@ import type { OpenfortError } from '../types/openfortError';
|
|
|
7
7
|
* ensuring consistent callback execution across all hooks in the SDK.
|
|
8
8
|
*
|
|
9
9
|
* @param params - Object containing hook options and success data
|
|
10
|
+
* @param params.hookOptions - Primary hook options (from the hook itself)
|
|
11
|
+
* @param params.options - Secondary hook options (from the action call)
|
|
12
|
+
* @param params.data - The success data to pass to callbacks
|
|
10
13
|
* @returns The success data that was passed in
|
|
11
14
|
*
|
|
12
15
|
* @example
|
|
@@ -31,6 +34,9 @@ export declare const onSuccess: <T>({ hookOptions, options, data, }: {
|
|
|
31
34
|
* and optionally throws the error if throwOnError is configured.
|
|
32
35
|
*
|
|
33
36
|
* @param params - Object containing hook options and error information
|
|
37
|
+
* @param params.hookOptions - Primary hook options (from the hook itself)
|
|
38
|
+
* @param params.options - Secondary hook options (from the action call)
|
|
39
|
+
* @param params.error - The error that occurred during the operation
|
|
34
40
|
* @returns Object containing the error, or throws if throwOnError is enabled
|
|
35
41
|
*
|
|
36
42
|
* @example
|