@openfort/react-native 0.1.21 → 0.1.23

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.
@@ -39,13 +39,22 @@ function startEmbeddedStatePolling(client, onChange, intervalMs = 1000) {
39
39
  };
40
40
  }
41
41
  /**
42
- * Provider component that initialises the Openfort SDK and exposes its state via {@link OpenfortContext}
42
+ * Root provider component that initializes the Openfort SDK and makes it available throughout your app.
43
43
  *
44
- * This component must wrap your React Native app to provide Openfort functionality to all child components.
45
- * It initializes the SDK with the provided configuration and manages authentication state.
44
+ * This component must wrap your React Native application to enable Openfort functionality.
45
+ * It initializes the SDK, manages authentication state, handles embedded wallet connections,
46
+ * and provides context to all child components through {@link OpenfortContext}.
46
47
  *
47
- * @param props - Provider configuration including the publishable key and optional overrides
48
- * @returns A React element that provides the Openfort context to its children
48
+ * **Key Features:**
49
+ * - Initializes Openfort client with platform-specific configuration
50
+ * - Manages user authentication state and session persistence
51
+ * - Polls embedded wallet state for real-time status updates
52
+ * - Provides hidden WebView for embedded wallet communication
53
+ * - Supports multiple blockchain networks via supportedChains
54
+ * - Integrates Shield for secure embedded wallet management
55
+ *
56
+ * @param props - Provider configuration, see {@link OpenfortProviderProps}
57
+ * @returns React element that provides Openfort context to all children
49
58
  *
50
59
  * @example
51
60
  * ```tsx
@@ -59,7 +68,12 @@ function startEmbeddedStatePolling(client, onChange, intervalMs = 1000) {
59
68
  * supportedChains={[polygon, polygonMumbai]}
60
69
  * walletConfig={{
61
70
  * shieldPublishableKey: "shield_pk_...",
62
- * getEncryptionSession: () => fetchEncryptionSession(),
71
+ * getEncryptionSession: async () => {
72
+ * // Fetch session from your backend
73
+ * const response = await fetch('/api/encryption-session');
74
+ * return response.text();
75
+ * },
76
+ * recoveryMethod: 'automatic',
63
77
  * }}
64
78
  * verbose={true}
65
79
  * >
@@ -15,12 +15,23 @@ const mapStatus = (status) => {
15
15
  /**
16
16
  * Hook for email and password authentication.
17
17
  *
18
- * This hook provides email/password authentication flows including sign-in, sign-up, and
19
- * account linking. Password reset and verification helpers are exposed but currently stubbed
20
- * (TODOs) until the SDK wiring is complete.
18
+ * This hook provides comprehensive email/password authentication flows including sign-in,
19
+ * sign-up, account linking, password reset, and email verification functionality.
21
20
  *
22
- * @param hookOptions - Optional configuration with callback functions and email verification settings.
23
- * @returns Email authentication state and methods with flow status indicators.
21
+ * @param hookOptions - Optional configuration with callback functions and email verification settings
22
+ * @returns Email authentication state and methods with flow status indicators including:
23
+ * - `signInEmail` - Sign in with email and password
24
+ * - `signUpEmail` - Create new account with email and password
25
+ * - `linkEmail` - Link email/password to existing authenticated account
26
+ * - `requestResetPassword` - Request password reset email
27
+ * - `resetPassword` - Complete password reset with token from email
28
+ * - `verifyEmail` - Verify email address with verification code
29
+ * - `reset` - Reset flow state to initial
30
+ * - `isLoading` - Whether an operation is in progress
31
+ * - `isError` - Whether the last operation failed
32
+ * - `isSuccess` - Whether the last operation succeeded
33
+ * - `requiresEmailVerification` - Whether email verification is pending
34
+ * - `error` - Error from the last failed operation
24
35
  *
25
36
  * @example
26
37
  * ```tsx
@@ -29,12 +40,14 @@ const mapStatus = (status) => {
29
40
  * onError: ({ error }) => console.error('Email auth failed:', error?.message),
30
41
  * });
31
42
  *
43
+ * // Sign up a new user
32
44
  * await signUpEmail({ email: 'user@example.com', password: 'securePassword123' });
33
45
  *
34
46
  * if (requiresEmailVerification) {
35
47
  * console.log('Check email for verification code');
36
48
  * }
37
49
  *
50
+ * // Sign in existing user
38
51
  * await signInEmail({ email: 'user@example.com', password: 'securePassword123' });
39
52
  * ```
40
53
  */
@@ -4,24 +4,34 @@ import { onError, onSuccess } from '../../lib/hookConsistency';
4
4
  import { mapStatus } from '../../types/baseFlowState';
5
5
  import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
6
6
  /**
7
- * Hook for creating guest accounts.
7
+ * Hook for guest account authentication.
8
8
  *
9
- * Guest accounts allow users to access certain features without full authentication and can later be upgraded to full accounts
10
- * by linking additional authentication methods.
9
+ * This hook provides functionality for creating anonymous guest accounts that allow
10
+ * users to access features without full authentication. Guest accounts can later be
11
+ * upgraded to permanent accounts by linking email, OAuth, or wallet authentication.
11
12
  *
12
- * @param hookOptions - Configuration options including success and error callbacks.
13
- * @returns Current guest authentication helpers with flow status indicators.
13
+ * @param hookOptions - Configuration options including success and error callbacks
14
+ * @returns Guest authentication method and flow state including:
15
+ * - `signUpGuest` - Create anonymous guest account
16
+ * - `isLoading` - Whether guest account creation is in progress
17
+ * - `isError` - Whether guest account creation failed
18
+ * - `isSuccess` - Whether guest account was created successfully
19
+ * - `error` - Error from the last failed operation
14
20
  *
15
21
  * @example
16
22
  * ```tsx
17
23
  * const { signUpGuest, isLoading } = useGuestAuth({
18
- * onSuccess: ({ user }) => console.log('Guest account created:', user),
24
+ * onSuccess: ({ user }) => console.log('Guest account created:', user?.id),
19
25
  * onError: ({ error }) => console.error('Failed to create guest account:', error),
20
26
  * });
21
27
  *
28
+ * // Create guest account for anonymous access
22
29
  * if (!isLoading) {
23
30
  * await signUpGuest();
24
31
  * }
32
+ *
33
+ * // Later, upgrade to permanent account by linking authentication
34
+ * // Use linkEmail, linkOauth, or linkSiwe from other hooks
25
35
  * ```
26
36
  */
27
37
  export const useGuestAuth = (hookOptions = {}) => {
@@ -8,15 +8,24 @@ import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
8
8
  /**
9
9
  * Hook for OAuth-based authentication with supported providers.
10
10
  *
11
- * This hook provides helpers for starting OAuth login flows (`initOAuth`) and linking
12
- * additional providers to an authenticated user (`linkOauth`). Some advanced flows may
13
- * require manual credential storage via `storeCredentials`, which is currently a TODO.
11
+ * This hook provides OAuth authentication flows including login and account linking
12
+ * for various OAuth providers (Google, Apple, Discord, Twitter, Facebook, etc.).
13
+ * Supports both web-based OAuth flows and native Apple Sign-In on iOS.
14
14
  *
15
- * @param hookOptions - Configuration options including success and error callbacks.
16
- * @returns OAuth helpers and derived flow state flags.
15
+ * @param hookOptions - Configuration options including success and error callbacks
16
+ * @returns OAuth authentication methods and flow state including:
17
+ * - `initOAuth` - Start OAuth login flow for authentication
18
+ * - `linkOauth` - Link additional OAuth provider to authenticated account
19
+ * - `storeCredentials` - (Reserved for future use)
20
+ * - `isLoading` - Whether OAuth flow is in progress
21
+ * - `isError` - Whether the last OAuth flow failed
22
+ * - `isSuccess` - Whether the last OAuth flow succeeded
23
+ * - `error` - Error from the last failed OAuth operation
17
24
  *
18
25
  * @example
19
26
  * ```tsx
27
+ * import { OAuthProvider } from '@openfort/openfort-js';
28
+ *
20
29
  * const { initOAuth, linkOauth, isLoading, isError, error } = useOAuth({
21
30
  * onSuccess: ({ user }) => console.log('OAuth completed for', user?.id),
22
31
  * });
@@ -16,28 +16,47 @@ const mapStatus = (status) => {
16
16
  };
17
17
  };
18
18
  /**
19
- * Hook for handling Sign-In With Ethereum (SIWE) flows.
19
+ * Hook for Sign-In With Ethereum (SIWE) authentication flows.
20
20
  *
21
- * This hook orchestrates SIWE message generation, signature submission, and state
22
- * tracking so that external wallets can either authenticate a user (`signInWithSiwe`)
23
- * or be linked to an existing account (`linkSiwe`).
21
+ * This hook provides SIWE authentication functionality allowing users to authenticate
22
+ * or link accounts using their external Ethereum wallets. It handles message generation,
23
+ * signature verification, and state management throughout the authentication flow.
24
24
  *
25
- * @param hookOptions - Optional callbacks for handling success or error events from the SIWE flows.
26
- * @returns SIWE helpers for generating messages, signing in, linking wallets, and inspecting flow status.
25
+ * @param hookOptions - Optional callbacks for handling success or error events from SIWE flows
26
+ * @returns SIWE authentication methods and flow state including:
27
+ * - `generateSiweMessage` - Generate SIWE message for wallet to sign
28
+ * - `signInWithSiwe` - Authenticate user with signed SIWE message
29
+ * - `linkSiwe` - Link external wallet to existing authenticated account
30
+ * - `isLoading` - Whether a SIWE operation is in progress
31
+ * - `isError` - Whether the last SIWE operation failed
32
+ * - `isSuccess` - Whether the last SIWE operation succeeded
33
+ * - `isAwaitingSignature` - Whether waiting for user to sign message
34
+ * - `isGeneratingMessage` - Whether generating SIWE message
35
+ * - `isSubmittingSignature` - Whether submitting signature to server
36
+ * - `error` - Error from the last failed operation
27
37
  *
28
38
  * @example
29
39
  * ```tsx
30
- * const { generateSiweMessage, signInWithSiwe, linkSiwe, isAwaitingSignature } = useWalletAuth({
31
- * onSuccess: ({ user }) => console.log('SIWE flow completed for', user?.id),
40
+ * // Using with an external wallet like WalletConnect or MetaMask
41
+ * const { generateSiweMessage, signInWithSiwe, isAwaitingSignature } = useWalletAuth({
42
+ * onSuccess: ({ user }) => console.log('SIWE authentication successful:', user?.id),
32
43
  * });
33
44
  *
45
+ * // Step 1: Generate SIWE message
34
46
  * const { message } = await generateSiweMessage({
35
47
  * wallet: connectedWallet.address,
36
- * from: { domain: 'app.openfort.io', uri: 'https://app.openfort.io' },
48
+ * from: { domain: 'myapp.com', uri: 'https://myapp.com' },
37
49
  * });
38
50
  *
51
+ * // Step 2: Request signature from user's wallet
39
52
  * const signature = await connectedWallet.signMessage(message);
40
- * await signInWithSiwe({ walletAddress: connectedWallet.address, signature, messageOverride: message });
53
+ *
54
+ * // Step 3: Authenticate with signed message
55
+ * await signInWithSiwe({
56
+ * walletAddress: connectedWallet.address,
57
+ * signature,
58
+ * messageOverride: message
59
+ * });
41
60
  * ```
42
61
  */
43
62
  export function useWalletAuth(hookOptions) {
@@ -38,16 +38,13 @@ export class OpenfortSolanaProvider {
38
38
  async request(args) {
39
39
  switch (args.method) {
40
40
  case 'signMessage': {
41
- // Convert message string to Uint8Array
42
41
  const signature = await this._signMessage(args.params.message);
43
- return { signature: signature };
42
+ return { signature };
44
43
  }
45
44
  case 'signTransaction': {
46
45
  const signedTransaction = await this._signTransaction(args.params.transaction);
47
46
  return { signedTransaction };
48
47
  }
49
- default:
50
- throw new Error(`Unsupported method: ${args.method}`);
51
48
  }
52
49
  }
53
50
  /**
@@ -8,39 +8,90 @@ import { buildRecoveryParams } from './utils';
8
8
  /**
9
9
  * Hook for managing embedded Ethereum wallets.
10
10
  *
11
- * This hook provides comprehensive Ethereum wallet management including creation, activation,
12
- * and recovery. It returns a discriminated union state that enables type-safe wallet interactions.
11
+ * This hook provides comprehensive management of embedded Ethereum wallets including creation,
12
+ * recovery, activation, and EIP-1193 provider access. Returns a discriminated union state that
13
+ * enables type-safe wallet interactions based on connection status.
13
14
  *
14
- * @param options - Configuration with default chainId and callback functions
15
- * @returns Discriminated union state object. The `status` field determines available properties.
16
- * Possible states: 'disconnected', 'connecting', 'reconnecting', 'creating', 'needs-recovery',
17
- * 'connected', 'error'. When connected, includes `provider` and `activeWallet`. All states include
18
- * `create`, `setActive`, `setRecovery`, `exportPrivateKey`, and `wallets` methods/properties.
15
+ * **Wallet Types Supported:**
16
+ * - Smart Contract Accounts (Account Abstraction)
17
+ * - EOA (Externally Owned Accounts)
18
+ *
19
+ * **Recovery Methods:**
20
+ * - Automatic recovery (via encryption session)
21
+ * - Password-based recovery
22
+ *
23
+ * @param options - Configuration options including:
24
+ * - `chainId` - Default chain ID for wallet operations
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
+ * - `onSetRecoverySuccess` - Callback when recovery method is updated
30
+ * - `onSetRecoveryError` - Callback when recovery update fails
31
+ *
32
+ * @returns Discriminated union state based on `status` field:
33
+ * - **'disconnected'**: No active wallet. Properties: `create`, `setActive`, `wallets`, `setRecovery`, `exportPrivateKey`
34
+ * - **'connecting'**: Activating wallet. Properties: same as disconnected + `activeWallet`
35
+ * - **'reconnecting'**: Reconnecting to wallet. Properties: same as connecting
36
+ * - **'creating'**: Creating new wallet. Properties: same as disconnected
37
+ * - **'needs-recovery'**: Recovery required. Properties: same as connecting
38
+ * - **'connected'**: Wallet ready. Properties: all + `provider` (EIP-1193 provider)
39
+ * - **'error'**: Operation failed. Properties: all + `error` message
19
40
  *
20
41
  * @example
21
42
  * ```tsx
22
- * import { useEmbeddedEthereumWallet, isConnected, isLoading } from '@openfort/react-native';
43
+ * import { useEmbeddedEthereumWallet } from '@openfort/react-native';
44
+ * import { ActivityIndicator } from 'react-native';
23
45
  *
24
- * const ethereum = useEmbeddedEthereumWallet({
25
- * chainId: 1,
26
- * onCreateSuccess: (account, provider) => console.log('Wallet created:', account.address),
27
- * });
46
+ * function WalletComponent() {
47
+ * const ethereum = useEmbeddedEthereumWallet({
48
+ * chainId: 137, // Polygon
49
+ * onCreateSuccess: (account, provider) => {
50
+ * console.log('Wallet created:', account.address);
51
+ * },
52
+ * });
28
53
  *
29
- * if (isLoading(ethereum)) {
30
- * return <ActivityIndicator />;
31
- * }
54
+ * // Handle loading states
55
+ * if (ethereum.status === 'creating' || ethereum.status === 'connecting') {
56
+ * return <ActivityIndicator />;
57
+ * }
32
58
  *
33
- * if (isConnected(ethereum)) {
34
- * // TypeScript knows provider and activeWallet are available
35
- * const tx = await ethereum.provider.request({
36
- * method: 'eth_sendTransaction',
37
- * params: [{ from: ethereum.activeWallet.address, to: '0x...', value: '0x0' }]
38
- * });
39
- * }
59
+ * // Create first wallet
60
+ * if (ethereum.status === 'disconnected' && ethereum.wallets.length === 0) {
61
+ * return <Button onPress={() => ethereum.create()} title="Create Wallet" />;
62
+ * }
63
+ *
64
+ * // Activate existing wallet
65
+ * if (ethereum.status === 'disconnected' && ethereum.wallets.length > 0) {
66
+ * return (
67
+ * <Button
68
+ * onPress={() => ethereum.setActive({
69
+ * address: ethereum.wallets[0].address,
70
+ * recoveryPassword: 'optional-password'
71
+ * })}
72
+ * title="Connect Wallet"
73
+ * />
74
+ * );
75
+ * }
76
+ *
77
+ * // Use connected wallet
78
+ * if (ethereum.status === 'connected') {
79
+ * const sendTransaction = async () => {
80
+ * const tx = await ethereum.provider.request({
81
+ * method: 'eth_sendTransaction',
82
+ * params: [{
83
+ * from: ethereum.activeWallet.address,
84
+ * to: '0x...',
85
+ * value: '0x0'
86
+ * }]
87
+ * });
88
+ * console.log('Transaction hash:', tx);
89
+ * };
90
+ *
91
+ * return <Button onPress={sendTransaction} title="Send Transaction" />;
92
+ * }
40
93
  *
41
- * // Create wallet if none exist
42
- * if (ethereum.status === 'disconnected' && ethereum.wallets.length === 0) {
43
- * await ethereum.create({ chainId: 1 });
94
+ * return null;
44
95
  * }
45
96
  * ```
46
97
  */
@@ -200,10 +251,11 @@ export function useEmbeddedEthereumWallet(options = {}) {
200
251
  }
201
252
  // Build recovery params
202
253
  const recoveryParams = await buildRecoveryParams(createOptions, walletConfig);
254
+ const accountType = createOptions?.accountType || walletConfig?.accountType || AccountTypeEnum.SMART_ACCOUNT;
203
255
  // Create embedded wallet
204
256
  const embeddedAccount = await client.embeddedWallet.create({
205
- chainId,
206
- accountType: createOptions?.accountType || walletConfig?.accountType || AccountTypeEnum.SMART_ACCOUNT,
257
+ chainId: accountType === AccountTypeEnum.EOA ? undefined : chainId,
258
+ accountType,
207
259
  chainType: ChainTypeEnum.EVM,
208
260
  recoveryParams,
209
261
  });
@@ -9,36 +9,100 @@ import { buildRecoveryParams } from './utils';
9
9
  /**
10
10
  * Hook for managing embedded Solana wallets.
11
11
  *
12
- * This hook provides comprehensive Solana wallet management including creation, activation,
13
- * and recovery. It returns a discriminated union state that enables type-safe wallet interactions.
12
+ * This hook provides comprehensive management of embedded Solana (SVM) wallets including
13
+ * creation, recovery, activation, and transaction signing. Returns a discriminated union
14
+ * state that enables type-safe wallet interactions based on connection status.
14
15
  *
15
- * @param options - Configuration with callback functions
16
- * @returns Discriminated union state object. The `status` field determines available properties.
17
- * Possible states: 'disconnected', 'connecting', 'reconnecting', 'creating', 'needs-recovery',
18
- * 'connected', 'error'. When connected, includes `provider` and `activeWallet`. All states include
19
- * `create`, `setActive`, and `wallets` methods/properties.
16
+ * **Note:** Solana wallets are always EOA (Externally Owned Accounts) and work across
17
+ * all Solana networks (mainnet, devnet, testnet).
18
+ *
19
+ * **Recovery Methods:**
20
+ * - Automatic recovery (via encryption session)
21
+ * - Password-based recovery
22
+ *
23
+ * @param options - Configuration options including:
24
+ * - `onCreateSuccess` - Callback when wallet is created
25
+ * - `onCreateError` - Callback when wallet creation fails
26
+ * - `onSetActiveSuccess` - Callback when wallet is activated/recovered
27
+ * - `onSetActiveError` - Callback when wallet activation fails
28
+ *
29
+ * @returns Discriminated union state based on `status` field:
30
+ * - **'disconnected'**: No active wallet. Properties: `create`, `setActive`, `wallets`
31
+ * - **'connecting'**: Activating wallet. Properties: same as disconnected
32
+ * - **'reconnecting'**: Reconnecting to wallet. Properties: same as disconnected + `activeWallet`
33
+ * - **'creating'**: Creating new wallet. Properties: same as disconnected
34
+ * - **'needs-recovery'**: Recovery required. Properties: same as reconnecting
35
+ * - **'connected'**: Wallet ready. Properties: all + `provider` (Solana wallet adapter)
36
+ * - **'error'**: Operation failed. Properties: all + `error` message + optional `activeWallet`
20
37
  *
21
38
  * @example
22
39
  * ```tsx
23
- * import { useEmbeddedSolanaWallet, isConnected, isLoading } from '@openfort/react-native';
40
+ * import { useEmbeddedSolanaWallet } from '@openfort/react-native';
41
+ * import { Transaction } from '@solana/web3.js';
42
+ * import { ActivityIndicator } from 'react-native';
24
43
  *
25
- * const solana = useEmbeddedSolanaWallet({
26
- * onCreateSuccess: (account, provider) => console.log('Wallet created:', account.address),
27
- * });
44
+ * function SolanaWalletComponent() {
45
+ * const solana = useEmbeddedSolanaWallet({
46
+ * onCreateSuccess: (account, provider) => {
47
+ * console.log('Solana wallet created:', account.address);
48
+ * console.log('Public key:', provider.publicKey);
49
+ * },
50
+ * });
28
51
  *
29
- * if (isLoading(solana)) {
30
- * return <ActivityIndicator />;
31
- * }
52
+ * // Handle loading states
53
+ * if (solana.status === 'creating' || solana.status === 'connecting') {
54
+ * return <ActivityIndicator />;
55
+ * }
32
56
  *
33
- * if (isConnected(solana)) {
34
- * // TypeScript knows provider and activeWallet are available
35
- * const signed = await solana.provider.signTransaction(transaction);
36
- * const publicKey = solana.provider.publicKey;
37
- * }
57
+ * // Create first wallet
58
+ * if (solana.status === 'disconnected' && solana.wallets.length === 0) {
59
+ * return (
60
+ * <Button
61
+ * onPress={() => solana.create({ recoveryPassword: 'optional' })}
62
+ * title="Create Solana Wallet"
63
+ * />
64
+ * );
65
+ * }
66
+ *
67
+ * // Activate existing wallet
68
+ * if (solana.status === 'disconnected' && solana.wallets.length > 0) {
69
+ * return (
70
+ * <Button
71
+ * onPress={() => solana.setActive({
72
+ * address: solana.wallets[0].address,
73
+ * recoveryPassword: 'optional'
74
+ * })}
75
+ * title="Connect Solana Wallet"
76
+ * />
77
+ * );
78
+ * }
79
+ *
80
+ * // Use connected wallet
81
+ * if (solana.status === 'connected') {
82
+ * const signTransaction = async () => {
83
+ * const transaction = new Transaction();
84
+ * // ... add instructions to transaction
85
+ *
86
+ * const signed = await solana.provider.signTransaction(transaction);
87
+ * console.log('Signed transaction:', signed);
88
+ * };
38
89
  *
39
- * // Create wallet if none exist
40
- * if (solana.status === 'disconnected' && solana.wallets.length === 0) {
41
- * await solana.create({ recoveryMethod: 'automatic' });
90
+ * const signMessage = async () => {
91
+ * const message = 'Hello Solana!';
92
+ * const signature = await solana.provider.signMessage(message);
93
+ * console.log('Message signature:', signature);
94
+ * };
95
+ *
96
+ * return (
97
+ * <View>
98
+ * <Text>Connected: {solana.activeWallet.address}</Text>
99
+ * <Button onPress={signTransaction} title="Sign Transaction" />
100
+ * <Button onPress={signMessage} title="Sign Message" />
101
+ * </View>
102
+ * );
103
+ * }
104
+ *
105
+ * return null;
42
106
  * }
43
107
  * ```
44
108
  */
@@ -102,18 +166,18 @@ export function useEmbeddedSolanaWallet(options = {}) {
102
166
  // Extract the message bytes from the transaction
103
167
  // For @solana/kit compiledTransaction, the messageBytes property contains what needs to be signed
104
168
  let messageBytes;
105
- if (transaction.messageBytes) {
169
+ if (transaction instanceof Uint8Array) {
170
+ // Raw bytes
171
+ messageBytes = transaction;
172
+ }
173
+ else if ('messageBytes' in transaction) {
106
174
  // @solana/kit compiled transaction
107
175
  messageBytes = transaction.messageBytes;
108
176
  }
109
- else if (transaction.serializeMessage) {
177
+ else if ('serializeMessage' in transaction) {
110
178
  // @solana/web3.js Transaction
111
179
  messageBytes = transaction.serializeMessage();
112
180
  }
113
- else if (transaction instanceof Uint8Array) {
114
- // Raw bytes
115
- messageBytes = transaction;
116
- }
117
181
  else {
118
182
  throw new OpenfortError('Unsupported transaction format. Expected @solana/kit compiled transaction, @solana/web3.js Transaction, or Uint8Array', OpenfortErrorType.WALLET_ERROR);
119
183
  }
@@ -125,13 +189,12 @@ export function useEmbeddedSolanaWallet(options = {}) {
125
189
  data: Array.from(messageBytes),
126
190
  };
127
191
  // Sign the message bytes (hashMessage: false for Solana - Ed25519 signs raw bytes)
128
- // Note: We cast to any because the iframe will deserialize the Buffer format correctly,
192
+ // Note: We cast to unknown because the iframe will deserialize the Buffer format correctly,
129
193
  // but TypeScript doesn't know about this serialization detail
130
194
  const signatureBase58 = await client.embeddedWallet.signMessage(bufferFormatMessage, {
131
195
  hashMessage: false,
132
196
  });
133
197
  // Return the signature in the expected format
134
- // Different libraries expect different return formats, so we return a flexible object
135
198
  return {
136
199
  signature: signatureBase58,
137
200
  publicKey: account.address,
@@ -103,13 +103,22 @@ export interface OpenfortProviderProps {
103
103
  verbose?: boolean;
104
104
  }
105
105
  /**
106
- * Provider component that initialises the Openfort SDK and exposes its state via {@link OpenfortContext}
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 app to provide Openfort functionality to all child components.
109
- * It initializes the SDK with the provided configuration and manages authentication state.
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
- * @param props - Provider configuration including the publishable key and optional overrides
112
- * @returns A React element that provides the Openfort context to its children
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: () => fetchEncryptionSession(),
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
  * >
@@ -45,12 +45,23 @@ export type UseEmailHookOptions = {
45
45
  /**
46
46
  * Hook for email and password authentication.
47
47
  *
48
- * This hook provides email/password authentication flows including sign-in, sign-up, and
49
- * account linking. Password reset and verification helpers are exposed but currently stubbed
50
- * (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.
51
50
  *
52
- * @param hookOptions - Optional configuration with callback functions and email verification settings.
53
- * @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
54
65
  *
55
66
  * @example
56
67
  * ```tsx
@@ -59,12 +70,14 @@ export type UseEmailHookOptions = {
59
70
  * onError: ({ error }) => console.error('Email auth failed:', error?.message),
60
71
  * });
61
72
  *
73
+ * // Sign up a new user
62
74
  * await signUpEmail({ email: 'user@example.com', password: 'securePassword123' });
63
75
  *
64
76
  * if (requiresEmailVerification) {
65
77
  * console.log('Check email for verification code');
66
78
  * }
67
79
  *
80
+ * // Sign in existing user
68
81
  * await signInEmail({ email: 'user@example.com', password: 'securePassword123' });
69
82
  * ```
70
83
  */