@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.
@@ -7,24 +7,34 @@ export type GuestHookResult = {
7
7
  };
8
8
  export type GuestHookOptions = OpenfortHookOptions<GuestHookResult>;
9
9
  /**
10
- * Hook for creating guest accounts.
10
+ * Hook for guest account authentication.
11
11
  *
12
- * Guest accounts allow users to access certain features without full authentication and can later be upgraded to full accounts
13
- * by linking additional authentication methods.
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.
14
15
  *
15
- * @param hookOptions - Configuration options including success and error callbacks.
16
- * @returns Current guest authentication helpers with flow status indicators.
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
17
23
  *
18
24
  * @example
19
25
  * ```tsx
20
26
  * const { signUpGuest, isLoading } = useGuestAuth({
21
- * onSuccess: ({ user }) => console.log('Guest account created:', user),
27
+ * onSuccess: ({ user }) => console.log('Guest account created:', user?.id),
22
28
  * onError: ({ error }) => console.error('Failed to create guest account:', error),
23
29
  * });
24
30
  *
31
+ * // Create guest account for anonymous access
25
32
  * if (!isLoading) {
26
33
  * await signUpGuest();
27
34
  * }
35
+ *
36
+ * // Later, upgrade to permanent account by linking authentication
37
+ * // Use linkEmail, linkOauth, or linkSiwe from other hooks
28
38
  * ```
29
39
  */
30
40
  export declare const useGuestAuth: (hookOptions?: GuestHookOptions) => {
@@ -20,15 +20,24 @@ export type AuthHookOptions = {
20
20
  /**
21
21
  * Hook for OAuth-based authentication with supported providers.
22
22
  *
23
- * This hook provides helpers for starting OAuth login flows (`initOAuth`) and linking
24
- * additional providers to an authenticated user (`linkOauth`). Some advanced flows may
25
- * require manual credential storage via `storeCredentials`, which is currently a TODO.
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.
26
26
  *
27
- * @param hookOptions - Configuration options including success and error callbacks.
28
- * @returns OAuth helpers and derived flow state flags.
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
29
36
  *
30
37
  * @example
31
38
  * ```tsx
39
+ * import { OAuthProvider } from '@openfort/openfort-js';
40
+ *
32
41
  * const { initOAuth, linkOauth, isLoading, isError, error } = useOAuth({
33
42
  * onSuccess: ({ user }) => console.log('OAuth completed for', user?.id),
34
43
  * });
@@ -31,28 +31,47 @@ type GenerateSiweMessageResult = {
31
31
  message?: string;
32
32
  };
33
33
  /**
34
- * Hook for handling Sign-In With Ethereum (SIWE) flows.
34
+ * Hook for Sign-In With Ethereum (SIWE) authentication flows.
35
35
  *
36
- * This hook orchestrates SIWE message generation, signature submission, and state
37
- * tracking so that external wallets can either authenticate a user (`signInWithSiwe`)
38
- * or be linked to an existing account (`linkSiwe`).
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 the SIWE flows.
41
- * @returns SIWE helpers for generating messages, signing in, linking wallets, and inspecting flow status.
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
- * const { generateSiweMessage, signInWithSiwe, linkSiwe, isAwaitingSignature } = useWalletAuth({
46
- * onSuccess: ({ user }) => console.log('SIWE flow completed for', user?.id),
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: 'app.openfort.io', uri: 'https://app.openfort.io' },
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
- * await signInWithSiwe({ walletAddress: connectedWallet.address, signature, messageOverride: message });
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): {
@@ -1,17 +1,5 @@
1
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
- };
2
+ import type { OpenfortEmbeddedSolanaWalletProvider, SignedSolanaTransaction, SolanaSignMessageRequest, SolanaSignTransactionRequest, SolanaTransaction } from '../../types/wallet';
15
3
  /**
16
4
  * Embedded Solana wallet provider implementation for Openfort.
17
5
  *
@@ -38,8 +26,8 @@ export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWal
38
26
  */
39
27
  constructor(params: {
40
28
  account: EmbeddedAccount;
41
- signTransaction: (transaction: any) => Promise<any>;
42
- signAllTransactions: (transactions: any[]) => Promise<any[]>;
29
+ signTransaction: (transaction: SolanaTransaction) => Promise<SignedSolanaTransaction>;
30
+ signAllTransactions: (transactions: SolanaTransaction[]) => Promise<SignedSolanaTransaction[]>;
43
31
  signMessage: (message: string) => Promise<string>;
44
32
  });
45
33
  /**
@@ -49,20 +37,20 @@ export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWal
49
37
  /**
50
38
  * Request-based API for wallet operations
51
39
  */
52
- request(args: SignMessageRequestArguments): Promise<{
40
+ request(args: SolanaSignMessageRequest): Promise<{
53
41
  signature: string;
54
42
  }>;
55
- request(args: SignTransactionRequestArguments): Promise<{
56
- signedTransaction: any;
43
+ request(args: SolanaSignTransactionRequest): Promise<{
44
+ signedTransaction: SignedSolanaTransaction;
57
45
  }>;
58
46
  /**
59
47
  * Sign a single transaction (direct method)
60
48
  */
61
- signTransaction(transaction: any): Promise<any>;
49
+ signTransaction(transaction: SolanaTransaction): Promise<SignedSolanaTransaction>;
62
50
  /**
63
51
  * Sign multiple transactions (direct method)
64
52
  */
65
- signAllTransactions(transactions: any[]): Promise<any[]>;
53
+ signAllTransactions(transactions: SolanaTransaction[]): Promise<SignedSolanaTransaction[]>;
66
54
  /**
67
55
  * Sign a message (direct method)
68
56
  */
@@ -72,4 +60,3 @@ export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWal
72
60
  */
73
61
  toJSON(): string;
74
62
  }
75
- export {};
@@ -13,39 +13,90 @@ type UseEmbeddedEthereumWalletOptions = {
13
13
  /**
14
14
  * Hook for managing embedded Ethereum wallets.
15
15
  *
16
- * This hook provides comprehensive Ethereum wallet management including creation, activation,
17
- * and recovery. It returns a discriminated union state that enables type-safe wallet interactions.
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.
18
19
  *
19
- * @param options - Configuration with default chainId and callback functions
20
- * @returns Discriminated union state object. The `status` field determines available properties.
21
- * Possible states: 'disconnected', 'connecting', 'reconnecting', 'creating', 'needs-recovery',
22
- * 'connected', 'error'. When connected, includes `provider` and `activeWallet`. All states include
23
- * `create`, `setActive`, `setRecovery`, `exportPrivateKey`, and `wallets` methods/properties.
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
24
45
  *
25
46
  * @example
26
47
  * ```tsx
27
- * import { useEmbeddedEthereumWallet, isConnected, isLoading } from '@openfort/react-native';
48
+ * import { useEmbeddedEthereumWallet } from '@openfort/react-native';
49
+ * import { ActivityIndicator } from 'react-native';
28
50
  *
29
- * const ethereum = useEmbeddedEthereumWallet({
30
- * chainId: 1,
31
- * onCreateSuccess: (account, provider) => console.log('Wallet created:', account.address),
32
- * });
51
+ * function WalletComponent() {
52
+ * const ethereum = useEmbeddedEthereumWallet({
53
+ * chainId: 137, // Polygon
54
+ * onCreateSuccess: (account, provider) => {
55
+ * console.log('Wallet created:', account.address);
56
+ * },
57
+ * });
33
58
  *
34
- * if (isLoading(ethereum)) {
35
- * return <ActivityIndicator />;
36
- * }
59
+ * // Handle loading states
60
+ * if (ethereum.status === 'creating' || ethereum.status === 'connecting') {
61
+ * return <ActivityIndicator />;
62
+ * }
37
63
  *
38
- * if (isConnected(ethereum)) {
39
- * // TypeScript knows provider and activeWallet are available
40
- * const tx = await ethereum.provider.request({
41
- * method: 'eth_sendTransaction',
42
- * params: [{ from: ethereum.activeWallet.address, to: '0x...', value: '0x0' }]
43
- * });
44
- * }
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
+ * }
45
98
  *
46
- * // Create wallet if none exist
47
- * if (ethereum.status === 'disconnected' && ethereum.wallets.length === 0) {
48
- * await ethereum.create({ chainId: 1 });
99
+ * return null;
49
100
  * }
50
101
  * ```
51
102
  */
@@ -10,36 +10,100 @@ type UseEmbeddedSolanaWalletOptions = {
10
10
  /**
11
11
  * Hook for managing embedded Solana wallets.
12
12
  *
13
- * This hook provides comprehensive Solana wallet management including creation, activation,
14
- * and recovery. It returns a discriminated union state that enables type-safe wallet interactions.
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.
15
16
  *
16
- * @param options - Configuration with callback functions
17
- * @returns Discriminated union state object. The `status` field determines available properties.
18
- * Possible states: 'disconnected', 'connecting', 'reconnecting', 'creating', 'needs-recovery',
19
- * 'connected', 'error'. When connected, includes `provider` and `activeWallet`. All states include
20
- * `create`, `setActive`, and `wallets` methods/properties.
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`
21
38
  *
22
39
  * @example
23
40
  * ```tsx
24
- * import { useEmbeddedSolanaWallet, isConnected, isLoading } from '@openfort/react-native';
41
+ * import { useEmbeddedSolanaWallet } from '@openfort/react-native';
42
+ * import { Transaction } from '@solana/web3.js';
43
+ * import { ActivityIndicator } from 'react-native';
25
44
  *
26
- * const solana = useEmbeddedSolanaWallet({
27
- * onCreateSuccess: (account, provider) => console.log('Wallet created:', account.address),
28
- * });
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
+ * });
29
52
  *
30
- * if (isLoading(solana)) {
31
- * return <ActivityIndicator />;
32
- * }
53
+ * // Handle loading states
54
+ * if (solana.status === 'creating' || solana.status === 'connecting') {
55
+ * return <ActivityIndicator />;
56
+ * }
33
57
  *
34
- * if (isConnected(solana)) {
35
- * // TypeScript knows provider and activeWallet are available
36
- * const signed = await solana.provider.signTransaction(transaction);
37
- * const publicKey = solana.provider.publicKey;
38
- * }
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
+ * }
39
105
  *
40
- * // Create wallet if none exist
41
- * if (solana.status === 'disconnected' && solana.wallets.length === 0) {
42
- * await solana.create({ recoveryMethod: 'automatic' });
106
+ * return null;
43
107
  * }
44
108
  * ```
45
109
  */
@@ -8,4 +8,4 @@ export interface UseOpenfort {
8
8
  }
9
9
  export type { AuthSuccessCallback, EmailLoginHookOptions, EmailLoginHookResult, ErrorCallback, GenerateSiweMessage, GenerateSiweMessageResponse, PasswordFlowState, RecoveryFlowState, SiweFlowState, SiweLoginHookOptions, SiweLoginHookResult, } from './auth';
10
10
  export type { LinkWithOAuthInput, LoginWithOAuthInput, OAuthFlowState, UseLoginWithOAuth, } from './oauth';
11
- export type { ConnectedEmbeddedEthereumWallet, ConnectedEmbeddedSolanaWallet, CreateSolanaEmbeddedWalletOpts, EmbeddedEthereumWalletState, EmbeddedSolanaWalletState, OpenfortEmbeddedEthereumWalletProvider, OpenfortEmbeddedSolanaWalletProvider, } from './wallet';
11
+ export type { ConnectedEmbeddedEthereumWallet, ConnectedEmbeddedSolanaWallet, CreateEthereumWalletOptions, CreateEthereumWalletResult, CreateSolanaEmbeddedWalletOpts, CreateSolanaWalletOptions, CreateSolanaWalletResult, EIP1193EventHandler, EIP1193EventName, EIP1193RequestArguments, EmbeddedEthereumWalletState, EmbeddedSolanaWalletState, EthereumWalletActions, OpenfortEmbeddedEthereumWalletProvider, OpenfortEmbeddedSolanaWalletProvider, SetActiveEthereumWalletOptions, SetActiveEthereumWalletResult, SetActiveSolanaWalletOptions, SetActiveSolanaWalletResult, SetRecoveryOptions, SetRecoveryResult, SignedSolanaTransaction, SolanaRequestArguments, SolanaSignMessageRequest, SolanaSignTransactionRequest, SolanaTransaction, SolanaWalletActions, } from './wallet';