import type { StatusUpdateData } from '@explorins/pers-signer/types'; import type { SigningStatus as SigningStatusType } from '@explorins/pers-signer/types'; type SubmissionResult = import('@explorins/pers-signer/react-native').SubmissionResult; type AuthenticatedUser = import('@explorins/pers-signer/react-native').AuthenticatedUser; type TransactionSigningResult = import('@explorins/pers-signer/react-native').TransactionSigningResult; export type { SigningStatusType as SigningStatus }; export type { StatusUpdateData }; /** * Simple status callback function type for React Native consumers * (Simplified from the signer SDK's object-based StatusCallback interface) */ export type OnStatusUpdateFn = (status: SigningStatusType, message: string, data?: StatusUpdateData) => void; /** * Return interface for the useTransactionSigner hook * * Provides secure transaction signing capabilities for EVM blockchain interactions * and error handling for React Native applications. * * @interface TransactionSignerHook * @property {Function} signAndSubmitTransactionWithJWT - Main method to sign and submit transactions * @property {Function} signPersTransaction - Sign transaction without submitting (for POS flows) * @property {boolean} isSignerInitialized - Whether the signer SDK has been initialized * @property {boolean} isSignerAvailable - Whether signing functionality is fully available * @property {SigningStatus | null} currentStatus - Current signing status for UI feedback * @property {string | null} statusMessage - Human-readable status message */ export interface TransactionSignerHook { signAndSubmitTransactionWithJWT: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise; signPersTransaction: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise; isSignerInitialized: boolean; isSignerAvailable: boolean; currentStatus: SigningStatusType | null; statusMessage: string | null; } /** * React Native hook for blockchain transaction signing using PERS Signer SDK * * This hook provides a complete blockchain transaction signing solution for React Native * applications, integrating with the PERS ecosystem for tourism loyalty and reward systems. * It automatically handles WebAuthn authentication, transaction preparation, signing, and * blockchain submission in a single convenient interface. * * **Features:** * - Automatic WebAuthn provider initialization for React Native * - 5-minute authentication caching to reduce repeated logins * - Complete transaction lifecycle management (sign + submit) * - Comprehensive error handling with detailed error messages * - Real-time status monitoring for UI feedback * - Automatic retry logic for network failures * * **Underlying SDK Methods:** * The hook uses the PERS Signer SDK which provides 5 core methods: * 1. `loginUser(jwtToken)` - Authenticate user with 5-minute caching * 2. `signTransaction(signingData, jwtToken)` - Sign transactions with auto-login * 3. `submitTransaction(signingResult, jwtToken)` - Submit signed transactions * 4. `signPersTransaction(jwtToken)` - Legacy one-liner for backward compatibility * 5. `signAndSubmitPersTransaction(jwtToken)` - Complete sign + submit flow (used by this hook) * * **Security:** * - WebAuthn-based secure authentication (no passwords stored) * - JWT token validation and expiration checking * - Secure transaction signing using device biometrics/PIN * - No sensitive data stored locally * * @returns {TransactionSignerHook} Hook interface with signing methods and status * * @example * **Basic Usage:** * ```typescript * import { useTransactionSigner } from '@explorins/pers-sdk-react-native'; * * function TransactionScreen() { * const { * signAndSubmitTransactionWithJWT, * isSignerAvailable, * isSignerInitialized * } = useTransactionSigner(); * * const handleSign = async (jwtFromRedemption: string) => { * if (!isSignerAvailable) { * console.error('Signer not available'); * return; * } * * try { * const result = await signAndSubmitTransactionWithJWT(jwtFromRedemption); * if (result.success) { * console.log('Transaction completed:', result.transactionHash); * // Handle successful transaction * if (result.shouldRedirect && result.redirectUrl) { * // Navigate to success page or external URL * } * } * } catch (error) { * console.error('Transaction failed:', error.message); * // Handle error (show user-friendly message) * } * }; * * return ( * * handleSign(redeemJWT)} * disabled={!isSignerAvailable} * style={[styles.button, !isSignerAvailable && styles.disabled]} * > * * {isSignerInitialized ? 'Sign Transaction' : 'Initializing...'} * * * * ); * } * ``` * * @example * **Advanced Usage with Error Handling:** * ```typescript * function AdvancedTransactionComponent() { * const [isLoading, setIsLoading] = useState(false); * const [error, setError] = useState(null); * const { signAndSubmitTransactionWithJWT, isSignerAvailable } = useTransactionSigner(); * * const handleTransaction = async (jwt: string) => { * setIsLoading(true); * setError(null); * * try { * const result = await signAndSubmitTransactionWithJWT(jwt); * * if (result.success) { * // Success handling * Alert.alert( * 'Success', * `Transaction completed!\nHash: ${result.transactionHash}` * ); * } else { * throw new Error(result.error || 'Transaction failed'); * } * } catch (err) { * const errorMessage = err instanceof Error ? err.message : 'Unknown error'; * setError(errorMessage); * * // Different error handling based on error type * if (errorMessage.includes('expired')) { * Alert.alert('Session Expired', 'Please log in again'); * } else if (errorMessage.includes('network')) { * Alert.alert('Network Error', 'Please check your connection'); * } else { * Alert.alert('Transaction Failed', errorMessage); * } * } finally { * setIsLoading(false); * } * }; * * return ( * * {error && ( * {error} * )} * handleTransaction(jwtToken)} * disabled={!isSignerAvailable || isLoading} * > * * {isLoading ? 'Processing...' : 'Sign & Submit Transaction'} * * * * ); * } * ``` * * @example * **Integration with PERS SDK:** * ```typescript * import { usePersSDK } from '@explorins/pers-sdk-react-native'; * import { useTransactionSigner } from '@explorins/pers-sdk-react-native'; * * function RedemptionFlow() { * const { user, redeemTokens } = usePersSDK(); * const { signAndSubmitTransactionWithJWT } = useTransactionSigner(); * * const handleRedemption = async (tokenAmount: number) => { * try { * // Step 1: Create redemption with PERS SDK * const redemption = await redeemTokens({ * tokenAmount, * destinationAddress: user?.walletAddress * }); * * // Step 2: Sign and submit transaction * const txResult = await signAndSubmitTransactionWithJWT(redemption.jwtToken); * * if (txResult.success) { * console.log('Redemption completed:', txResult.transactionHash); * } * } catch (error) { * console.error('Redemption failed:', error); * } * }; * } * ``` * * @see {@link SubmissionResult} for transaction result structure * @see {@link TransactionSigningResult} for signing result details * @see {@link AuthenticatedUser} for user authentication data * * @since 1.5.0 */ export declare const useTransactionSigner: () => TransactionSignerHook; /** * Type exports for external usage * * These types are re-exported from the PERS Signer SDK for convenience * when working with transaction signing in React Native applications. * * @see {@link SubmissionResult} - Complete transaction submission result * @see {@link AuthenticatedUser} - User authentication data structure * @see {@link TransactionSigningResult} - Transaction signing result details * @see {@link TransactionSignerHook} - Hook return interface */ export type { SubmissionResult, AuthenticatedUser, TransactionSigningResult }; //# sourceMappingURL=useTransactionSigner.d.ts.map