@varity-labs/ui-kit 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +31 -0
- package/README.md +248 -0
- package/dist/components/AI/ChatbotWidget.d.ts +53 -0
- package/dist/components/AI/ChatbotWidget.d.ts.map +1 -0
- package/dist/components/AI/ChatbotWidget.js +126 -0
- package/dist/components/AI/ChatbotWidget.js.map +1 -0
- package/dist/components/AI/InputBar.d.ts +25 -0
- package/dist/components/AI/InputBar.d.ts.map +1 -0
- package/dist/components/AI/InputBar.js +126 -0
- package/dist/components/AI/InputBar.js.map +1 -0
- package/dist/components/AI/MessageBubble.d.ts +37 -0
- package/dist/components/AI/MessageBubble.d.ts.map +1 -0
- package/dist/components/AI/MessageBubble.js +124 -0
- package/dist/components/AI/MessageBubble.js.map +1 -0
- package/dist/components/AI/index.d.ts +12 -0
- package/dist/components/AI/index.d.ts.map +1 -0
- package/dist/components/AI/index.js +9 -0
- package/dist/components/AI/index.js.map +1 -0
- package/dist/components/Analytics/AnalyticsCard.d.ts +48 -0
- package/dist/components/Analytics/AnalyticsCard.d.ts.map +1 -0
- package/dist/components/Analytics/AnalyticsCard.js +156 -0
- package/dist/components/Analytics/AnalyticsCard.js.map +1 -0
- package/dist/components/Analytics/ChartContainer.d.ts +53 -0
- package/dist/components/Analytics/ChartContainer.d.ts.map +1 -0
- package/dist/components/Analytics/ChartContainer.js +128 -0
- package/dist/components/Analytics/ChartContainer.js.map +1 -0
- package/dist/components/Analytics/DataTable.d.ts +62 -0
- package/dist/components/Analytics/DataTable.d.ts.map +1 -0
- package/dist/components/Analytics/DataTable.js +165 -0
- package/dist/components/Analytics/DataTable.js.map +1 -0
- package/dist/components/Analytics/MetricDisplay.d.ts +42 -0
- package/dist/components/Analytics/MetricDisplay.d.ts.map +1 -0
- package/dist/components/Analytics/MetricDisplay.js +110 -0
- package/dist/components/Analytics/MetricDisplay.js.map +1 -0
- package/dist/components/Analytics/index.d.ts +14 -0
- package/dist/components/Analytics/index.d.ts.map +1 -0
- package/dist/components/Analytics/index.js +10 -0
- package/dist/components/Analytics/index.js.map +1 -0
- package/dist/components/Branding/Attribution.d.ts +39 -0
- package/dist/components/Branding/Attribution.d.ts.map +1 -0
- package/dist/components/Branding/Attribution.js +124 -0
- package/dist/components/Branding/Attribution.js.map +1 -0
- package/dist/components/Branding/Logo.d.ts +39 -0
- package/dist/components/Branding/Logo.d.ts.map +1 -0
- package/dist/components/Branding/Logo.js +67 -0
- package/dist/components/Branding/Logo.js.map +1 -0
- package/dist/components/Branding/ThemeProvider.d.ts +85 -0
- package/dist/components/Branding/ThemeProvider.d.ts.map +1 -0
- package/dist/components/Branding/ThemeProvider.js +186 -0
- package/dist/components/Branding/ThemeProvider.js.map +1 -0
- package/dist/components/Branding/index.d.ts +12 -0
- package/dist/components/Branding/index.d.ts.map +1 -0
- package/dist/components/Branding/index.js +9 -0
- package/dist/components/Branding/index.js.map +1 -0
- package/dist/components/Dashboard/DashboardFooter.d.ts +30 -0
- package/dist/components/Dashboard/DashboardFooter.d.ts.map +1 -0
- package/dist/components/Dashboard/DashboardFooter.js +68 -0
- package/dist/components/Dashboard/DashboardFooter.js.map +1 -0
- package/dist/components/Dashboard/DashboardHeader.d.ts +24 -0
- package/dist/components/Dashboard/DashboardHeader.d.ts.map +1 -0
- package/dist/components/Dashboard/DashboardHeader.js +87 -0
- package/dist/components/Dashboard/DashboardHeader.js.map +1 -0
- package/dist/components/Dashboard/DashboardLayout.d.ts +71 -0
- package/dist/components/Dashboard/DashboardLayout.d.ts.map +1 -0
- package/dist/components/Dashboard/DashboardLayout.js +52 -0
- package/dist/components/Dashboard/DashboardLayout.js.map +1 -0
- package/dist/components/Dashboard/DashboardSidebar.d.ts +26 -0
- package/dist/components/Dashboard/DashboardSidebar.d.ts.map +1 -0
- package/dist/components/Dashboard/DashboardSidebar.js +146 -0
- package/dist/components/Dashboard/DashboardSidebar.js.map +1 -0
- package/dist/components/Dashboard/EmptyState.d.ts +84 -0
- package/dist/components/Dashboard/EmptyState.d.ts.map +1 -0
- package/dist/components/Dashboard/EmptyState.js +99 -0
- package/dist/components/Dashboard/EmptyState.js.map +1 -0
- package/dist/components/Dashboard/KPICard.d.ts +58 -0
- package/dist/components/Dashboard/KPICard.d.ts.map +1 -0
- package/dist/components/Dashboard/KPICard.js +82 -0
- package/dist/components/Dashboard/KPICard.js.map +1 -0
- package/dist/components/Dashboard/LoadingSkeleton.d.ts +58 -0
- package/dist/components/Dashboard/LoadingSkeleton.d.ts.map +1 -0
- package/dist/components/Dashboard/LoadingSkeleton.js +105 -0
- package/dist/components/Dashboard/LoadingSkeleton.js.map +1 -0
- package/dist/components/Dashboard/StatusBadge.d.ts +57 -0
- package/dist/components/Dashboard/StatusBadge.d.ts.map +1 -0
- package/dist/components/Dashboard/StatusBadge.js +149 -0
- package/dist/components/Dashboard/StatusBadge.js.map +1 -0
- package/dist/components/Dashboard/index.d.ts +19 -0
- package/dist/components/Dashboard/index.d.ts.map +1 -0
- package/dist/components/Dashboard/index.js +18 -0
- package/dist/components/Dashboard/index.js.map +1 -0
- package/dist/components/InAppWallet/EmailLoginButton.d.ts +27 -0
- package/dist/components/InAppWallet/EmailLoginButton.d.ts.map +1 -0
- package/dist/components/InAppWallet/EmailLoginButton.js +84 -0
- package/dist/components/InAppWallet/EmailLoginButton.js.map +1 -0
- package/dist/components/InAppWallet/InAppWalletProvider.d.ts +54 -0
- package/dist/components/InAppWallet/InAppWalletProvider.d.ts.map +1 -0
- package/dist/components/InAppWallet/InAppWalletProvider.js +238 -0
- package/dist/components/InAppWallet/InAppWalletProvider.js.map +1 -0
- package/dist/components/InAppWallet/OnboardingFlow.d.ts +25 -0
- package/dist/components/InAppWallet/OnboardingFlow.d.ts.map +1 -0
- package/dist/components/InAppWallet/OnboardingFlow.js +159 -0
- package/dist/components/InAppWallet/OnboardingFlow.js.map +1 -0
- package/dist/components/InAppWallet/SocialLoginButtons.d.ts +28 -0
- package/dist/components/InAppWallet/SocialLoginButtons.d.ts.map +1 -0
- package/dist/components/InAppWallet/SocialLoginButtons.js +128 -0
- package/dist/components/InAppWallet/SocialLoginButtons.js.map +1 -0
- package/dist/components/InAppWallet/index.d.ts +15 -0
- package/dist/components/InAppWallet/index.d.ts.map +1 -0
- package/dist/components/InAppWallet/index.js +14 -0
- package/dist/components/InAppWallet/index.js.map +1 -0
- package/dist/components/Onramp/BuyUSDCButton.d.ts +27 -0
- package/dist/components/Onramp/BuyUSDCButton.d.ts.map +1 -0
- package/dist/components/Onramp/BuyUSDCButton.js +70 -0
- package/dist/components/Onramp/BuyUSDCButton.js.map +1 -0
- package/dist/components/Onramp/OnrampWidget.d.ts +38 -0
- package/dist/components/Onramp/OnrampWidget.d.ts.map +1 -0
- package/dist/components/Onramp/OnrampWidget.js +105 -0
- package/dist/components/Onramp/OnrampWidget.js.map +1 -0
- package/dist/components/Onramp/index.d.ts +14 -0
- package/dist/components/Onramp/index.d.ts.map +1 -0
- package/dist/components/Onramp/index.js +12 -0
- package/dist/components/Onramp/index.js.map +1 -0
- package/dist/components/Payments/CheckoutModal.d.ts +19 -0
- package/dist/components/Payments/CheckoutModal.d.ts.map +1 -0
- package/dist/components/Payments/CheckoutModal.js +183 -0
- package/dist/components/Payments/CheckoutModal.js.map +1 -0
- package/dist/components/Payments/SubscriptionWidget.d.ts +17 -0
- package/dist/components/Payments/SubscriptionWidget.d.ts.map +1 -0
- package/dist/components/Payments/SubscriptionWidget.js +89 -0
- package/dist/components/Payments/SubscriptionWidget.js.map +1 -0
- package/dist/components/Payments/constants.d.ts +59 -0
- package/dist/components/Payments/constants.d.ts.map +1 -0
- package/dist/components/Payments/constants.js +145 -0
- package/dist/components/Payments/constants.js.map +1 -0
- package/dist/components/Payments/index.d.ts +10 -0
- package/dist/components/Payments/index.d.ts.map +1 -0
- package/dist/components/Payments/index.js +12 -0
- package/dist/components/Payments/index.js.map +1 -0
- package/dist/components/Payments/types.d.ts +119 -0
- package/dist/components/Payments/types.d.ts.map +1 -0
- package/dist/components/Payments/types.js +27 -0
- package/dist/components/Payments/types.js.map +1 -0
- package/dist/components/Payments/usePayments.d.ts +33 -0
- package/dist/components/Payments/usePayments.d.ts.map +1 -0
- package/dist/components/Payments/usePayments.js +249 -0
- package/dist/components/Payments/usePayments.js.map +1 -0
- package/dist/components/Privy/InitTimeoutScreen.d.ts +62 -0
- package/dist/components/Privy/InitTimeoutScreen.d.ts.map +1 -0
- package/dist/components/Privy/InitTimeoutScreen.js +64 -0
- package/dist/components/Privy/InitTimeoutScreen.js.map +1 -0
- package/dist/components/Privy/InitializingScreen.d.ts +56 -0
- package/dist/components/Privy/InitializingScreen.d.ts.map +1 -0
- package/dist/components/Privy/InitializingScreen.js +60 -0
- package/dist/components/Privy/InitializingScreen.js.map +1 -0
- package/dist/components/Privy/PrivyLoginButton.d.ts +27 -0
- package/dist/components/Privy/PrivyLoginButton.d.ts.map +1 -0
- package/dist/components/Privy/PrivyLoginButton.js +48 -0
- package/dist/components/Privy/PrivyLoginButton.js.map +1 -0
- package/dist/components/Privy/PrivyProtectedRoute.d.ts +22 -0
- package/dist/components/Privy/PrivyProtectedRoute.d.ts.map +1 -0
- package/dist/components/Privy/PrivyProtectedRoute.js +46 -0
- package/dist/components/Privy/PrivyProtectedRoute.js.map +1 -0
- package/dist/components/Privy/PrivyReadyGate.d.ts +69 -0
- package/dist/components/Privy/PrivyReadyGate.d.ts.map +1 -0
- package/dist/components/Privy/PrivyReadyGate.js +83 -0
- package/dist/components/Privy/PrivyReadyGate.js.map +1 -0
- package/dist/components/Privy/PrivyUserProfile.d.ts +25 -0
- package/dist/components/Privy/PrivyUserProfile.d.ts.map +1 -0
- package/dist/components/Privy/PrivyUserProfile.js +98 -0
- package/dist/components/Privy/PrivyUserProfile.js.map +1 -0
- package/dist/components/Privy/index.d.ts +21 -0
- package/dist/components/Privy/index.d.ts.map +1 -0
- package/dist/components/Privy/index.js +16 -0
- package/dist/components/Privy/index.js.map +1 -0
- package/dist/components/SIWE/AuthStatus.d.ts +15 -0
- package/dist/components/SIWE/AuthStatus.d.ts.map +1 -0
- package/dist/components/SIWE/AuthStatus.js +47 -0
- package/dist/components/SIWE/AuthStatus.js.map +1 -0
- package/dist/components/SIWE/ProtectedRoute.d.ts +17 -0
- package/dist/components/SIWE/ProtectedRoute.d.ts.map +1 -0
- package/dist/components/SIWE/ProtectedRoute.js +52 -0
- package/dist/components/SIWE/ProtectedRoute.js.map +1 -0
- package/dist/components/SIWE/SIWEButton.d.ts +22 -0
- package/dist/components/SIWE/SIWEButton.d.ts.map +1 -0
- package/dist/components/SIWE/SIWEButton.js +106 -0
- package/dist/components/SIWE/SIWEButton.js.map +1 -0
- package/dist/components/SIWE/SIWEModal.d.ts +19 -0
- package/dist/components/SIWE/SIWEModal.d.ts.map +1 -0
- package/dist/components/SIWE/SIWEModal.js +75 -0
- package/dist/components/SIWE/SIWEModal.js.map +1 -0
- package/dist/components/SIWE/SIWEProvider.d.ts +38 -0
- package/dist/components/SIWE/SIWEProvider.d.ts.map +1 -0
- package/dist/components/SIWE/SIWEProvider.js +227 -0
- package/dist/components/SIWE/SIWEProvider.js.map +1 -0
- package/dist/components/SIWE/index.d.ts +15 -0
- package/dist/components/SIWE/index.d.ts.map +1 -0
- package/dist/components/SIWE/index.js +10 -0
- package/dist/components/SIWE/index.js.map +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +16 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/templates/Finance/FinanceDashboard.d.ts +15 -0
- package/dist/components/templates/Finance/FinanceDashboard.d.ts.map +1 -0
- package/dist/components/templates/Finance/FinanceDashboard.js +112 -0
- package/dist/components/templates/Finance/FinanceDashboard.js.map +1 -0
- package/dist/components/templates/Healthcare/HealthcareDashboard.d.ts +15 -0
- package/dist/components/templates/Healthcare/HealthcareDashboard.d.ts.map +1 -0
- package/dist/components/templates/Healthcare/HealthcareDashboard.js +121 -0
- package/dist/components/templates/Healthcare/HealthcareDashboard.js.map +1 -0
- package/dist/components/templates/ISO/ISODashboard.d.ts +15 -0
- package/dist/components/templates/ISO/ISODashboard.d.ts.map +1 -0
- package/dist/components/templates/ISO/ISODashboard.js +184 -0
- package/dist/components/templates/ISO/ISODashboard.js.map +1 -0
- package/dist/components/templates/Retail/RetailDashboard.d.ts +15 -0
- package/dist/components/templates/Retail/RetailDashboard.d.ts.map +1 -0
- package/dist/components/templates/Retail/RetailDashboard.js +151 -0
- package/dist/components/templates/Retail/RetailDashboard.js.map +1 -0
- package/dist/components/templates/index.d.ts +14 -0
- package/dist/components/templates/index.d.ts.map +1 -0
- package/dist/components/templates/index.js +14 -0
- package/dist/components/templates/index.js.map +1 -0
- package/dist/config/chains.d.ts +23 -0
- package/dist/config/chains.d.ts.map +1 -0
- package/dist/config/chains.js +55 -0
- package/dist/config/chains.js.map +1 -0
- package/dist/core/VarityClient.d.ts +76 -0
- package/dist/core/VarityClient.d.ts.map +1 -0
- package/dist/core/VarityClient.js +99 -0
- package/dist/core/VarityClient.js.map +1 -0
- package/dist/core/config.d.ts +136 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +156 -0
- package/dist/core/config.js.map +1 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +18 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAnalytics.d.ts +94 -0
- package/dist/hooks/useAnalytics.d.ts.map +1 -0
- package/dist/hooks/useAnalytics.js +116 -0
- package/dist/hooks/useAnalytics.js.map +1 -0
- package/dist/hooks/useAuth.d.ts +71 -0
- package/dist/hooks/useAuth.d.ts.map +1 -0
- package/dist/hooks/useAuth.js +198 -0
- package/dist/hooks/useAuth.js.map +1 -0
- package/dist/hooks/useDashboard.d.ts +110 -0
- package/dist/hooks/useDashboard.d.ts.map +1 -0
- package/dist/hooks/useDashboard.js +201 -0
- package/dist/hooks/useDashboard.js.map +1 -0
- package/dist/hooks/useVarityAPI.d.ts +88 -0
- package/dist/hooks/useVarityAPI.d.ts.map +1 -0
- package/dist/hooks/useVarityAPI.js +138 -0
- package/dist/hooks/useVarityAPI.js.map +1 -0
- package/dist/hooks/useWalletAuth.d.ts +108 -0
- package/dist/hooks/useWalletAuth.d.ts.map +1 -0
- package/dist/hooks/useWalletAuth.js +415 -0
- package/dist/hooks/useWalletAuth.js.map +1 -0
- package/dist/hooks/web3/index.d.ts +5 -0
- package/dist/hooks/web3/index.d.ts.map +1 -0
- package/dist/hooks/web3/index.js +6 -0
- package/dist/hooks/web3/index.js.map +1 -0
- package/dist/hooks/web3/useAddressValidation.d.ts +37 -0
- package/dist/hooks/web3/useAddressValidation.d.ts.map +1 -0
- package/dist/hooks/web3/useAddressValidation.js +59 -0
- package/dist/hooks/web3/useAddressValidation.js.map +1 -0
- package/dist/hooks/web3/useBlockExplorer.d.ts +37 -0
- package/dist/hooks/web3/useBlockExplorer.d.ts.map +1 -0
- package/dist/hooks/web3/useBlockExplorer.js +59 -0
- package/dist/hooks/web3/useBlockExplorer.js.map +1 -0
- package/dist/hooks/web3/useUSDCFormat.d.ts +34 -0
- package/dist/hooks/web3/useUSDCFormat.d.ts.map +1 -0
- package/dist/hooks/web3/useUSDCFormat.js +43 -0
- package/dist/hooks/web3/useUSDCFormat.js.map +1 -0
- package/dist/hooks/web3/useVarityWallet.d.ts +48 -0
- package/dist/hooks/web3/useVarityWallet.d.ts.map +1 -0
- package/dist/hooks/web3/useVarityWallet.js +70 -0
- package/dist/hooks/web3/useVarityWallet.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/analytics/AnalyticsClient.d.ts +72 -0
- package/dist/modules/analytics/AnalyticsClient.d.ts.map +1 -0
- package/dist/modules/analytics/AnalyticsClient.js +56 -0
- package/dist/modules/analytics/AnalyticsClient.js.map +1 -0
- package/dist/modules/analytics/index.d.ts +2 -0
- package/dist/modules/analytics/index.d.ts.map +1 -0
- package/dist/modules/analytics/index.js +2 -0
- package/dist/modules/analytics/index.js.map +1 -0
- package/dist/modules/auth/AuthClient.d.ts +41 -0
- package/dist/modules/auth/AuthClient.d.ts.map +1 -0
- package/dist/modules/auth/AuthClient.js +36 -0
- package/dist/modules/auth/AuthClient.js.map +1 -0
- package/dist/modules/auth/index.d.ts +2 -0
- package/dist/modules/auth/index.d.ts.map +1 -0
- package/dist/modules/auth/index.js +2 -0
- package/dist/modules/auth/index.js.map +1 -0
- package/dist/modules/cache/CacheClient.d.ts +48 -0
- package/dist/modules/cache/CacheClient.d.ts.map +1 -0
- package/dist/modules/cache/CacheClient.js +59 -0
- package/dist/modules/cache/CacheClient.js.map +1 -0
- package/dist/modules/cache/index.d.ts +2 -0
- package/dist/modules/cache/index.d.ts.map +1 -0
- package/dist/modules/cache/index.js +2 -0
- package/dist/modules/cache/index.js.map +1 -0
- package/dist/modules/compute/ComputeClient.d.ts +54 -0
- package/dist/modules/compute/ComputeClient.d.ts.map +1 -0
- package/dist/modules/compute/ComputeClient.js +39 -0
- package/dist/modules/compute/ComputeClient.js.map +1 -0
- package/dist/modules/compute/index.d.ts +2 -0
- package/dist/modules/compute/index.d.ts.map +1 -0
- package/dist/modules/compute/index.js +2 -0
- package/dist/modules/compute/index.js.map +1 -0
- package/dist/modules/export/ExportClient.d.ts +56 -0
- package/dist/modules/export/ExportClient.d.ts.map +1 -0
- package/dist/modules/export/ExportClient.js +42 -0
- package/dist/modules/export/ExportClient.js.map +1 -0
- package/dist/modules/export/index.d.ts +2 -0
- package/dist/modules/export/index.d.ts.map +1 -0
- package/dist/modules/export/index.js +2 -0
- package/dist/modules/export/index.js.map +1 -0
- package/dist/modules/forecasting/ForecastingClient.d.ts +112 -0
- package/dist/modules/forecasting/ForecastingClient.d.ts.map +1 -0
- package/dist/modules/forecasting/ForecastingClient.js +48 -0
- package/dist/modules/forecasting/ForecastingClient.js.map +1 -0
- package/dist/modules/forecasting/index.d.ts +2 -0
- package/dist/modules/forecasting/index.d.ts.map +1 -0
- package/dist/modules/forecasting/index.js +2 -0
- package/dist/modules/forecasting/index.js.map +1 -0
- package/dist/modules/monitoring/MonitoringClient.d.ts +67 -0
- package/dist/modules/monitoring/MonitoringClient.d.ts.map +1 -0
- package/dist/modules/monitoring/MonitoringClient.js +48 -0
- package/dist/modules/monitoring/MonitoringClient.js.map +1 -0
- package/dist/modules/monitoring/index.d.ts +2 -0
- package/dist/modules/monitoring/index.d.ts.map +1 -0
- package/dist/modules/monitoring/index.js +2 -0
- package/dist/modules/monitoring/index.js.map +1 -0
- package/dist/modules/notifications/NotificationsClient.d.ts +68 -0
- package/dist/modules/notifications/NotificationsClient.d.ts.map +1 -0
- package/dist/modules/notifications/NotificationsClient.js +50 -0
- package/dist/modules/notifications/NotificationsClient.js.map +1 -0
- package/dist/modules/notifications/index.d.ts +2 -0
- package/dist/modules/notifications/index.d.ts.map +1 -0
- package/dist/modules/notifications/index.js +2 -0
- package/dist/modules/notifications/index.js.map +1 -0
- package/dist/modules/oracle/OracleClient.d.ts +48 -0
- package/dist/modules/oracle/OracleClient.d.ts.map +1 -0
- package/dist/modules/oracle/OracleClient.js +34 -0
- package/dist/modules/oracle/OracleClient.js.map +1 -0
- package/dist/modules/oracle/index.d.ts +2 -0
- package/dist/modules/oracle/index.d.ts.map +1 -0
- package/dist/modules/oracle/index.js +2 -0
- package/dist/modules/oracle/index.js.map +1 -0
- package/dist/modules/storage/StorageClient.d.ts +44 -0
- package/dist/modules/storage/StorageClient.d.ts.map +1 -0
- package/dist/modules/storage/StorageClient.js +43 -0
- package/dist/modules/storage/StorageClient.js.map +1 -0
- package/dist/modules/storage/index.d.ts +2 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +2 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/templates/TemplateDeploymentClient.d.ts +208 -0
- package/dist/modules/templates/TemplateDeploymentClient.d.ts.map +1 -0
- package/dist/modules/templates/TemplateDeploymentClient.js +101 -0
- package/dist/modules/templates/TemplateDeploymentClient.js.map +1 -0
- package/dist/modules/templates/index.d.ts +8 -0
- package/dist/modules/templates/index.d.ts.map +1 -0
- package/dist/modules/templates/index.js +7 -0
- package/dist/modules/templates/index.js.map +1 -0
- package/dist/modules/webhooks/WebhooksClient.d.ts +85 -0
- package/dist/modules/webhooks/WebhooksClient.d.ts.map +1 -0
- package/dist/modules/webhooks/WebhooksClient.js +68 -0
- package/dist/modules/webhooks/WebhooksClient.js.map +1 -0
- package/dist/modules/webhooks/index.d.ts +2 -0
- package/dist/modules/webhooks/index.d.ts.map +1 -0
- package/dist/modules/webhooks/index.js +2 -0
- package/dist/modules/webhooks/index.js.map +1 -0
- package/dist/modules/zk/ZKClient.d.ts +67 -0
- package/dist/modules/zk/ZKClient.d.ts.map +1 -0
- package/dist/modules/zk/ZKClient.js +36 -0
- package/dist/modules/zk/ZKClient.js.map +1 -0
- package/dist/modules/zk/index.d.ts +2 -0
- package/dist/modules/zk/index.d.ts.map +1 -0
- package/dist/modules/zk/index.js +2 -0
- package/dist/modules/zk/index.js.map +1 -0
- package/dist/providers/ChainContext.d.ts +65 -0
- package/dist/providers/ChainContext.d.ts.map +1 -0
- package/dist/providers/ChainContext.js +92 -0
- package/dist/providers/ChainContext.js.map +1 -0
- package/dist/providers/PrivyProvider.d.ts +42 -0
- package/dist/providers/PrivyProvider.d.ts.map +1 -0
- package/dist/providers/PrivyProvider.js +131 -0
- package/dist/providers/PrivyProvider.js.map +1 -0
- package/dist/providers/PrivyStack.d.ts +165 -0
- package/dist/providers/PrivyStack.d.ts.map +1 -0
- package/dist/providers/PrivyStack.js +295 -0
- package/dist/providers/PrivyStack.js.map +1 -0
- package/dist/providers/VarityDashboardProvider.d.ts +90 -0
- package/dist/providers/VarityDashboardProvider.d.ts.map +1 -0
- package/dist/providers/VarityDashboardProvider.js +242 -0
- package/dist/providers/VarityDashboardProvider.js.map +1 -0
- package/dist/providers/VarityProvider.d.ts +32 -0
- package/dist/providers/VarityProvider.d.ts.map +1 -0
- package/dist/providers/VarityProvider.js +56 -0
- package/dist/providers/VarityProvider.js.map +1 -0
- package/dist/providers/WalletContext.d.ts +68 -0
- package/dist/providers/WalletContext.d.ts.map +1 -0
- package/dist/providers/WalletContext.js +98 -0
- package/dist/providers/WalletContext.js.map +1 -0
- package/dist/providers/WalletSyncProvider.d.ts +84 -0
- package/dist/providers/WalletSyncProvider.d.ts.map +1 -0
- package/dist/providers/WalletSyncProvider.js +132 -0
- package/dist/providers/WalletSyncProvider.js.map +1 -0
- package/dist/providers/index.d.ts +47 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +51 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/tests/mocks/httpClient.mock.d.ts +62 -0
- package/dist/tests/mocks/httpClient.mock.d.ts.map +1 -0
- package/dist/tests/mocks/httpClient.mock.js +108 -0
- package/dist/tests/mocks/httpClient.mock.js.map +1 -0
- package/dist/tests/setup.d.ts +6 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +51 -0
- package/dist/tests/setup.js.map +1 -0
- package/dist/types/api-extensions.d.ts +92 -0
- package/dist/types/api-extensions.d.ts.map +1 -0
- package/dist/types/api-extensions.js +7 -0
- package/dist/types/api-extensions.js.map +1 -0
- package/dist/utils/http.d.ts +51 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +104 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/wallets/SimpleSmartWallet.d.ts +68 -0
- package/dist/wallets/SimpleSmartWallet.d.ts.map +1 -0
- package/dist/wallets/SimpleSmartWallet.js +74 -0
- package/dist/wallets/SimpleSmartWallet.js.map +1 -0
- package/dist/wallets/SmartWalletProvider.d.ts +217 -0
- package/dist/wallets/SmartWalletProvider.d.ts.map +1 -0
- package/dist/wallets/SmartWalletProvider.js +366 -0
- package/dist/wallets/SmartWalletProvider.js.map +1 -0
- package/dist/wallets/config.d.ts +199 -0
- package/dist/wallets/config.d.ts.map +1 -0
- package/dist/wallets/config.js +183 -0
- package/dist/wallets/config.js.map +1 -0
- package/dist/wallets/index.d.ts +9 -0
- package/dist/wallets/index.d.ts.map +1 -0
- package/dist/wallets/index.js +9 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/web3/AddressDisplay/AddressDisplay.d.ts +33 -0
- package/dist/web3/AddressDisplay/AddressDisplay.d.ts.map +1 -0
- package/dist/web3/AddressDisplay/AddressDisplay.js +42 -0
- package/dist/web3/AddressDisplay/AddressDisplay.js.map +1 -0
- package/dist/web3/AddressInput/AddressInput.d.ts +36 -0
- package/dist/web3/AddressInput/AddressInput.d.ts.map +1 -0
- package/dist/web3/AddressInput/AddressInput.js +54 -0
- package/dist/web3/AddressInput/AddressInput.js.map +1 -0
- package/dist/web3/AmountInput/AmountInput.d.ts +41 -0
- package/dist/web3/AmountInput/AmountInput.d.ts.map +1 -0
- package/dist/web3/AmountInput/AmountInput.js +74 -0
- package/dist/web3/AmountInput/AmountInput.js.map +1 -0
- package/dist/web3/BalanceDisplay/BalanceDisplay.d.ts +30 -0
- package/dist/web3/BalanceDisplay/BalanceDisplay.d.ts.map +1 -0
- package/dist/web3/BalanceDisplay/BalanceDisplay.js +35 -0
- package/dist/web3/BalanceDisplay/BalanceDisplay.js.map +1 -0
- package/dist/web3/BlockExplorerLink/BlockExplorerLink.d.ts +41 -0
- package/dist/web3/BlockExplorerLink/BlockExplorerLink.d.ts.map +1 -0
- package/dist/web3/BlockExplorerLink/BlockExplorerLink.js +46 -0
- package/dist/web3/BlockExplorerLink/BlockExplorerLink.js.map +1 -0
- package/dist/web3/ConnectWallet/ConnectWallet.d.ts +35 -0
- package/dist/web3/ConnectWallet/ConnectWallet.d.ts.map +1 -0
- package/dist/web3/ConnectWallet/ConnectWallet.js +58 -0
- package/dist/web3/ConnectWallet/ConnectWallet.js.map +1 -0
- package/dist/web3/DisconnectButton/DisconnectButton.d.ts +30 -0
- package/dist/web3/DisconnectButton/DisconnectButton.d.ts.map +1 -0
- package/dist/web3/DisconnectButton/DisconnectButton.js +48 -0
- package/dist/web3/DisconnectButton/DisconnectButton.js.map +1 -0
- package/dist/web3/WalletBalance/WalletBalance.d.ts +27 -0
- package/dist/web3/WalletBalance/WalletBalance.d.ts.map +1 -0
- package/dist/web3/WalletBalance/WalletBalance.js +49 -0
- package/dist/web3/WalletBalance/WalletBalance.js.map +1 -0
- package/dist/web3/WalletDropdown/WalletDropdown.d.ts +29 -0
- package/dist/web3/WalletDropdown/WalletDropdown.d.ts.map +1 -0
- package/dist/web3/WalletDropdown/WalletDropdown.js +93 -0
- package/dist/web3/WalletDropdown/WalletDropdown.js.map +1 -0
- package/dist/web3/WalletInfo/WalletInfo.d.ts +31 -0
- package/dist/web3/WalletInfo/WalletInfo.d.ts.map +1 -0
- package/dist/web3/WalletInfo/WalletInfo.js +41 -0
- package/dist/web3/WalletInfo/WalletInfo.js.map +1 -0
- package/dist/web3/index.d.ts +11 -0
- package/dist/web3/index.d.ts.map +1 -0
- package/dist/web3/index.js +14 -0
- package/dist/web3/index.js.map +1 -0
- package/package.json +105 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useVarityAPI - Main hook for Varity API integration
|
|
3
|
+
*
|
|
4
|
+
* Provides a React hook interface to the Varity API with automatic error handling,
|
|
5
|
+
* loading states, and caching.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useContext, createContext, useState, useCallback } from 'react';
|
|
8
|
+
import { VarityClient } from '../core/VarityClient';
|
|
9
|
+
const VarityAPIContext = createContext(undefined);
|
|
10
|
+
/**
|
|
11
|
+
* VarityAPIProvider - Context provider for Varity API
|
|
12
|
+
*
|
|
13
|
+
* Wrap your app with this provider to enable useVarityAPI hook.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <VarityAPIProvider config={{ apiEndpoint: 'https://api.varity.io' }}>
|
|
18
|
+
* <App />
|
|
19
|
+
* </VarityAPIProvider>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const VarityAPIProvider = ({ config, children }) => {
|
|
23
|
+
const [client] = useState(() => new VarityClient(config));
|
|
24
|
+
const [isAuthenticated, setAuthenticated] = useState(false);
|
|
25
|
+
return (React.createElement(VarityAPIContext.Provider, { value: { client, isAuthenticated, setAuthenticated } }, children));
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* useVarityAPI Hook
|
|
29
|
+
*
|
|
30
|
+
* Access Varity client from any component.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const { client, isAuthenticated } = useVarityAPI()
|
|
35
|
+
* const data = await client.analytics.getKPIs({ period: 'current_month' })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const useVarityAPI = () => {
|
|
39
|
+
const context = useContext(VarityAPIContext);
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error('useVarityAPI must be used within a VarityAPIProvider');
|
|
42
|
+
}
|
|
43
|
+
return context;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* useVarityQuery Hook
|
|
47
|
+
*
|
|
48
|
+
* Execute API queries with automatic loading and error states.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* const { data, loading, error, refetch } = useVarityQuery(
|
|
53
|
+
* async (client) => client.analytics.getKPIs({ period: 'current_month' })
|
|
54
|
+
* )
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function useVarityQuery(queryFn, deps = []) {
|
|
58
|
+
const { client } = useVarityAPI();
|
|
59
|
+
const [data, setData] = useState(null);
|
|
60
|
+
const [loading, setLoading] = useState(false);
|
|
61
|
+
const [error, setError] = useState(null);
|
|
62
|
+
const execute = useCallback(async () => {
|
|
63
|
+
setLoading(true);
|
|
64
|
+
setError(null);
|
|
65
|
+
try {
|
|
66
|
+
const result = await queryFn(client);
|
|
67
|
+
setData(result);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
72
|
+
setError(error);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
setLoading(false);
|
|
77
|
+
}
|
|
78
|
+
}, [client, ...deps]);
|
|
79
|
+
// Auto-execute on mount
|
|
80
|
+
useState(() => {
|
|
81
|
+
execute();
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
data,
|
|
85
|
+
loading,
|
|
86
|
+
error,
|
|
87
|
+
refetch: execute
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* useVarityMutation Hook
|
|
92
|
+
*
|
|
93
|
+
* Execute API mutations with loading and error states.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* const { mutate, loading, error } = useVarityMutation(
|
|
98
|
+
* async (client, file: File) => client.storage.uploadFile(file)
|
|
99
|
+
* )
|
|
100
|
+
*
|
|
101
|
+
* // Later in code
|
|
102
|
+
* await mutate(file)
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function useVarityMutation(mutationFn) {
|
|
106
|
+
const { client } = useVarityAPI();
|
|
107
|
+
const [loading, setLoading] = useState(false);
|
|
108
|
+
const [error, setError] = useState(null);
|
|
109
|
+
const [data, setData] = useState(null);
|
|
110
|
+
const mutate = useCallback(async (...args) => {
|
|
111
|
+
setLoading(true);
|
|
112
|
+
setError(null);
|
|
113
|
+
try {
|
|
114
|
+
const result = await mutationFn(client, ...args);
|
|
115
|
+
setData(result);
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
120
|
+
setError(error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
setLoading(false);
|
|
125
|
+
}
|
|
126
|
+
}, [client]);
|
|
127
|
+
return {
|
|
128
|
+
mutate,
|
|
129
|
+
loading,
|
|
130
|
+
error,
|
|
131
|
+
data,
|
|
132
|
+
reset: () => {
|
|
133
|
+
setData(null);
|
|
134
|
+
setError(null);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=useVarityAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVarityAPI.js","sourceRoot":"","sources":["../../src/hooks/useVarityAPI.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,aAAa,EAAa,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAC1F,OAAO,EAAE,YAAY,EAAsB,MAAM,sBAAsB,CAAA;AAWvE,MAAM,gBAAgB,GAAG,aAAa,CAAoC,SAAS,CAAC,CAAA;AASpF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAqC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC1F,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;IACzD,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE3D,OAAO,CACL,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,IAC5E,QAAQ,CACiB,CAC7B,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAA0B,EAAE;IACtD,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAC5B,OAA6C,EAC7C,OAAc,EAAE;IAEhB,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAA;IACjC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAW,IAAI,CAAC,CAAA;IAChD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAA;IAEtD,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACrC,UAAU,CAAC,IAAI,CAAC,CAAA;QAChB,QAAQ,CAAC,IAAI,CAAC,CAAA;QACd,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;YACpC,OAAO,CAAC,MAAM,CAAC,CAAA;YACf,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;YACrE,QAAQ,CAAC,KAAK,CAAC,CAAA;YACf,MAAM,KAAK,CAAA;QACb,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAA;IAErB,wBAAwB;IACxB,QAAQ,CAAC,GAAG,EAAE;QACZ,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,IAAI;QACJ,OAAO;QACP,KAAK;QACL,OAAO,EAAE,OAAO;KACjB,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAsE;IAEtE,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAA;IACjC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAiB,IAAI,CAAC,CAAA;IAEtD,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,GAAG,IAAW,EAAoB,EAAE;QACpE,UAAU,CAAC,IAAI,CAAC,CAAA;QAChB,QAAQ,CAAC,IAAI,CAAC,CAAA;QACd,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;YAChD,OAAO,CAAC,MAAM,CAAC,CAAA;YACf,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;YACrE,QAAQ,CAAC,KAAK,CAAC,CAAA;YACf,MAAM,KAAK,CAAA;QACb,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAEZ,OAAO;QACL,MAAM;QACN,OAAO;QACP,KAAK;QACL,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,CAAA;YACb,QAAQ,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet session information
|
|
3
|
+
*/
|
|
4
|
+
export interface WalletSession {
|
|
5
|
+
sessionToken: string;
|
|
6
|
+
walletAddress: string;
|
|
7
|
+
expiresAt: number;
|
|
8
|
+
expiresIn: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Session information from the backend
|
|
12
|
+
*/
|
|
13
|
+
export interface SessionInfo {
|
|
14
|
+
wallet_address: string;
|
|
15
|
+
session_token: string;
|
|
16
|
+
created_at: number;
|
|
17
|
+
expires_at: number;
|
|
18
|
+
metadata: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Return type for useWalletAuth hook
|
|
22
|
+
*/
|
|
23
|
+
export interface UseWalletAuthReturn {
|
|
24
|
+
/** Whether the user is authenticated with a valid session */
|
|
25
|
+
isAuthenticated: boolean;
|
|
26
|
+
/** The current session token */
|
|
27
|
+
sessionToken: string | null;
|
|
28
|
+
/** The authenticated wallet address */
|
|
29
|
+
walletAddress: string | null;
|
|
30
|
+
/** Whether authentication is in progress */
|
|
31
|
+
isAuthenticating: boolean;
|
|
32
|
+
/** Authentication error message if any */
|
|
33
|
+
authError: string | null;
|
|
34
|
+
/** List of active sessions across devices */
|
|
35
|
+
sessions: SessionInfo[];
|
|
36
|
+
/** Initiate login with wallet signature */
|
|
37
|
+
login: () => Promise<void>;
|
|
38
|
+
/** Logout and invalidate session */
|
|
39
|
+
logout: () => Promise<void>;
|
|
40
|
+
/** Refresh session expiration */
|
|
41
|
+
refreshSession: () => Promise<void>;
|
|
42
|
+
/** Get all active sessions */
|
|
43
|
+
getSessions: () => Promise<void>;
|
|
44
|
+
/** Logout from a specific session */
|
|
45
|
+
logoutFromSession: (sessionToken: string) => Promise<void>;
|
|
46
|
+
/** Logout from all devices */
|
|
47
|
+
logoutFromAllDevices: () => Promise<void>;
|
|
48
|
+
/** Add additional wallet to session (multi-wallet support) */
|
|
49
|
+
addWallet: (newWalletAddress: string) => Promise<void>;
|
|
50
|
+
/** Get axios-like fetch with auth headers */
|
|
51
|
+
authFetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for useWalletAuth hook
|
|
55
|
+
*/
|
|
56
|
+
export interface UseWalletAuthConfig {
|
|
57
|
+
/** Base URL for the API (default: from env or localhost:8000) */
|
|
58
|
+
apiBaseUrl?: string;
|
|
59
|
+
/** Auto-login when Privy authenticates (default: true) */
|
|
60
|
+
autoLogin?: boolean;
|
|
61
|
+
/** Auto-refresh session interval in minutes (default: 30) */
|
|
62
|
+
refreshIntervalMinutes?: number;
|
|
63
|
+
/** Callback when session changes */
|
|
64
|
+
onSessionChange?: (session: WalletSession | null) => void;
|
|
65
|
+
/** Callback when auth error occurs */
|
|
66
|
+
onAuthError?: (error: string) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* useWalletAuth - Wallet-based authentication with session management
|
|
70
|
+
*
|
|
71
|
+
* This hook provides complete wallet authentication functionality:
|
|
72
|
+
* - Signs in using wallet signature (EIP-191)
|
|
73
|
+
* - Manages session tokens with auto-refresh
|
|
74
|
+
* - Handles multi-device sessions
|
|
75
|
+
* - Integrates with Privy for embedded wallets
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* import { useWalletAuth } from '@varity-labs/ui-kit';
|
|
80
|
+
*
|
|
81
|
+
* function MyComponent() {
|
|
82
|
+
* const {
|
|
83
|
+
* isAuthenticated,
|
|
84
|
+
* walletAddress,
|
|
85
|
+
* login,
|
|
86
|
+
* logout,
|
|
87
|
+
* authFetch,
|
|
88
|
+
* } = useWalletAuth({
|
|
89
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* if (!isAuthenticated) {
|
|
93
|
+
* return <button onClick={login}>Sign In</button>;
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* const fetchData = async () => {
|
|
97
|
+
* // authFetch automatically includes session token
|
|
98
|
+
* const response = await authFetch('/api/v1/data');
|
|
99
|
+
* return response.json();
|
|
100
|
+
* };
|
|
101
|
+
*
|
|
102
|
+
* return <p>Connected: {walletAddress}</p>;
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function useWalletAuth(config?: UseWalletAuthConfig): UseWalletAuthReturn;
|
|
107
|
+
export default useWalletAuth;
|
|
108
|
+
//# sourceMappingURL=useWalletAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWalletAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useWalletAuth.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAElC,6DAA6D;IAC7D,eAAe,EAAE,OAAO,CAAC;IACzB,gCAAgC;IAChC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,uCAAuC;IACvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,4CAA4C;IAC5C,gBAAgB,EAAE,OAAO,CAAC;IAC1B,0CAA0C;IAC1C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAGzB,6CAA6C;IAC7C,QAAQ,EAAE,WAAW,EAAE,CAAC;IAGxB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,oCAAoC;IACpC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,iCAAiC;IACjC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,8BAA8B;IAC9B,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,qCAAqC;IACrC,iBAAiB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,8BAA8B;IAC9B,oBAAoB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,8DAA8D;IAC9D,SAAS,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAGvD,6CAA6C;IAC7C,SAAS,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChF;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6DAA6D;IAC7D,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,oCAAoC;IACpC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1D,sCAAsC;IACtC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,mBAAwB,GAAG,mBAAmB,CA4ZnF;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Authentication Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides wallet-based authentication with session management.
|
|
5
|
+
* Integrates with Privy for seamless Web3 UX and backend session tokens.
|
|
6
|
+
*
|
|
7
|
+
* This hook handles:
|
|
8
|
+
* - Wallet signature authentication
|
|
9
|
+
* - Session token management
|
|
10
|
+
* - Auto-login when Privy authenticates
|
|
11
|
+
* - Session refresh and expiration handling
|
|
12
|
+
* - Multi-device session management
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
17
|
+
import { usePrivy, useWallets } from '@privy-io/react-auth';
|
|
18
|
+
import { useActiveAccount } from 'thirdweb/react';
|
|
19
|
+
/**
|
|
20
|
+
* useWalletAuth - Wallet-based authentication with session management
|
|
21
|
+
*
|
|
22
|
+
* This hook provides complete wallet authentication functionality:
|
|
23
|
+
* - Signs in using wallet signature (EIP-191)
|
|
24
|
+
* - Manages session tokens with auto-refresh
|
|
25
|
+
* - Handles multi-device sessions
|
|
26
|
+
* - Integrates with Privy for embedded wallets
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { useWalletAuth } from '@varity-labs/ui-kit';
|
|
31
|
+
*
|
|
32
|
+
* function MyComponent() {
|
|
33
|
+
* const {
|
|
34
|
+
* isAuthenticated,
|
|
35
|
+
* walletAddress,
|
|
36
|
+
* login,
|
|
37
|
+
* logout,
|
|
38
|
+
* authFetch,
|
|
39
|
+
* } = useWalletAuth({
|
|
40
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* if (!isAuthenticated) {
|
|
44
|
+
* return <button onClick={login}>Sign In</button>;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* const fetchData = async () => {
|
|
48
|
+
* // authFetch automatically includes session token
|
|
49
|
+
* const response = await authFetch('/api/v1/data');
|
|
50
|
+
* return response.json();
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* return <p>Connected: {walletAddress}</p>;
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function useWalletAuth(config = {}) {
|
|
58
|
+
const { apiBaseUrl = process.env.NEXT_PUBLIC_API_URL ||
|
|
59
|
+
process.env.NEXT_PUBLIC_BACKEND_URL ||
|
|
60
|
+
'http://localhost:8000', autoLogin = true, refreshIntervalMinutes = 30, onSessionChange, onAuthError, } = config;
|
|
61
|
+
const { authenticated, ready } = usePrivy();
|
|
62
|
+
const { wallets } = useWallets();
|
|
63
|
+
const activeAccount = useActiveAccount();
|
|
64
|
+
const [sessionToken, setSessionToken] = useState(null);
|
|
65
|
+
const [walletAddress, setWalletAddress] = useState(null);
|
|
66
|
+
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
|
67
|
+
const [authError, setAuthError] = useState(null);
|
|
68
|
+
const [sessions, setSessions] = useState([]);
|
|
69
|
+
// Get wallet address from Privy or thirdweb
|
|
70
|
+
const address = wallets?.[0]?.address || activeAccount?.address;
|
|
71
|
+
/**
|
|
72
|
+
* Verify session is still valid
|
|
73
|
+
*/
|
|
74
|
+
const verifySession = useCallback(async (token) => {
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/session`, {
|
|
77
|
+
headers: {
|
|
78
|
+
'X-Session-Token': token,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
return response.status === 200;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}, [apiBaseUrl]);
|
|
87
|
+
// Load session from localStorage on mount
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const storedToken = localStorage.getItem('wallet_session_token');
|
|
90
|
+
const storedAddress = localStorage.getItem('wallet_address');
|
|
91
|
+
if (storedToken && storedAddress) {
|
|
92
|
+
setSessionToken(storedToken);
|
|
93
|
+
setWalletAddress(storedAddress);
|
|
94
|
+
// Verify session is still valid
|
|
95
|
+
verifySession(storedToken).catch(() => {
|
|
96
|
+
// Session invalid, clear storage
|
|
97
|
+
localStorage.removeItem('wallet_session_token');
|
|
98
|
+
localStorage.removeItem('wallet_address');
|
|
99
|
+
setSessionToken(null);
|
|
100
|
+
setWalletAddress(null);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}, [verifySession]);
|
|
104
|
+
/**
|
|
105
|
+
* Sign message with wallet
|
|
106
|
+
*/
|
|
107
|
+
const signMessage = useCallback(async (message) => {
|
|
108
|
+
// Try Privy wallet first
|
|
109
|
+
const privyWallet = wallets?.[0];
|
|
110
|
+
if (privyWallet && 'signMessage' in privyWallet) {
|
|
111
|
+
try {
|
|
112
|
+
// Privy wallets support signMessage directly
|
|
113
|
+
const signature = await privyWallet.signMessage(message);
|
|
114
|
+
return signature;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Privy wallet signing failed', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Fall back to thirdweb active account
|
|
122
|
+
if (activeAccount && 'signMessage' in activeAccount) {
|
|
123
|
+
try {
|
|
124
|
+
const signature = await activeAccount.signMessage({ message });
|
|
125
|
+
return signature;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Thirdweb wallet signing failed', error);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw new Error('No wallet available for signing');
|
|
133
|
+
}, [wallets, activeAccount]);
|
|
134
|
+
/**
|
|
135
|
+
* Login with wallet signature
|
|
136
|
+
*/
|
|
137
|
+
const login = useCallback(async () => {
|
|
138
|
+
if (!address) {
|
|
139
|
+
const error = 'No wallet connected';
|
|
140
|
+
setAuthError(error);
|
|
141
|
+
onAuthError?.(error);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
setIsAuthenticating(true);
|
|
145
|
+
setAuthError(null);
|
|
146
|
+
try {
|
|
147
|
+
// Step 1: Get authentication message
|
|
148
|
+
const messageResponse = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/message`, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers: { 'Content-Type': 'application/json' },
|
|
151
|
+
body: JSON.stringify({ wallet_address: address }),
|
|
152
|
+
});
|
|
153
|
+
if (!messageResponse.ok) {
|
|
154
|
+
throw new Error('Failed to get authentication message');
|
|
155
|
+
}
|
|
156
|
+
const { message, nonce } = await messageResponse.json();
|
|
157
|
+
// Step 2: Sign message with wallet
|
|
158
|
+
const signature = await signMessage(message);
|
|
159
|
+
// Step 3: Login with signature
|
|
160
|
+
const loginResponse = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/login`, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers: { 'Content-Type': 'application/json' },
|
|
163
|
+
body: JSON.stringify({
|
|
164
|
+
wallet_address: address,
|
|
165
|
+
signature,
|
|
166
|
+
message,
|
|
167
|
+
nonce,
|
|
168
|
+
user_agent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown',
|
|
169
|
+
}),
|
|
170
|
+
});
|
|
171
|
+
if (!loginResponse.ok) {
|
|
172
|
+
const errorData = await loginResponse.json().catch(() => ({}));
|
|
173
|
+
throw new Error(errorData.detail?.message || errorData.detail || 'Authentication failed');
|
|
174
|
+
}
|
|
175
|
+
const session = await loginResponse.json();
|
|
176
|
+
// Store session
|
|
177
|
+
setSessionToken(session.sessionToken);
|
|
178
|
+
setWalletAddress(session.walletAddress);
|
|
179
|
+
localStorage.setItem('wallet_session_token', session.sessionToken);
|
|
180
|
+
localStorage.setItem('wallet_address', session.walletAddress);
|
|
181
|
+
onSessionChange?.(session);
|
|
182
|
+
console.log('Wallet authentication successful');
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
console.error('Wallet authentication failed', error);
|
|
186
|
+
const errorMessage = error instanceof Error ? error.message : 'Authentication failed';
|
|
187
|
+
setAuthError(errorMessage);
|
|
188
|
+
onAuthError?.(errorMessage);
|
|
189
|
+
// Clear any existing session
|
|
190
|
+
setSessionToken(null);
|
|
191
|
+
setWalletAddress(null);
|
|
192
|
+
localStorage.removeItem('wallet_session_token');
|
|
193
|
+
localStorage.removeItem('wallet_address');
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
setIsAuthenticating(false);
|
|
197
|
+
}
|
|
198
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
199
|
+
}, [address, apiBaseUrl, onSessionChange, onAuthError, signMessage]);
|
|
200
|
+
/**
|
|
201
|
+
* Logout and invalidate session
|
|
202
|
+
*/
|
|
203
|
+
const logout = useCallback(async () => {
|
|
204
|
+
if (!sessionToken)
|
|
205
|
+
return;
|
|
206
|
+
try {
|
|
207
|
+
await fetch(`${apiBaseUrl}/api/v1/wallet/auth/logout`, {
|
|
208
|
+
method: 'POST',
|
|
209
|
+
headers: {
|
|
210
|
+
'X-Session-Token': sessionToken,
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
console.log('Logged out successfully');
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
console.error('Logout failed', error);
|
|
217
|
+
}
|
|
218
|
+
finally {
|
|
219
|
+
// Clear session regardless of API success
|
|
220
|
+
setSessionToken(null);
|
|
221
|
+
setWalletAddress(null);
|
|
222
|
+
localStorage.removeItem('wallet_session_token');
|
|
223
|
+
localStorage.removeItem('wallet_address');
|
|
224
|
+
onSessionChange?.(null);
|
|
225
|
+
}
|
|
226
|
+
}, [sessionToken, apiBaseUrl, onSessionChange]);
|
|
227
|
+
/**
|
|
228
|
+
* Refresh session expiration
|
|
229
|
+
*/
|
|
230
|
+
const refreshSession = useCallback(async () => {
|
|
231
|
+
if (!sessionToken)
|
|
232
|
+
return;
|
|
233
|
+
try {
|
|
234
|
+
const response = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/refresh`, {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
headers: {
|
|
237
|
+
'X-Session-Token': sessionToken,
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
if (!response.ok) {
|
|
241
|
+
throw new Error('Session refresh failed');
|
|
242
|
+
}
|
|
243
|
+
const session = await response.json();
|
|
244
|
+
console.log('Session refreshed', { expiresAt: new Date(session.expiresAt * 1000) });
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
console.error('Session refresh failed', error);
|
|
248
|
+
// Session might be expired, logout
|
|
249
|
+
await logout();
|
|
250
|
+
}
|
|
251
|
+
}, [sessionToken, apiBaseUrl, logout]);
|
|
252
|
+
/**
|
|
253
|
+
* Get all active sessions
|
|
254
|
+
*/
|
|
255
|
+
const getSessions = useCallback(async () => {
|
|
256
|
+
if (!sessionToken)
|
|
257
|
+
return;
|
|
258
|
+
try {
|
|
259
|
+
const response = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/sessions`, {
|
|
260
|
+
headers: {
|
|
261
|
+
'X-Session-Token': sessionToken,
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
if (!response.ok) {
|
|
265
|
+
throw new Error('Failed to get sessions');
|
|
266
|
+
}
|
|
267
|
+
const sessionsData = await response.json();
|
|
268
|
+
setSessions(sessionsData);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
console.error('Failed to get sessions', error);
|
|
272
|
+
}
|
|
273
|
+
}, [sessionToken, apiBaseUrl]);
|
|
274
|
+
/**
|
|
275
|
+
* Logout from specific session
|
|
276
|
+
*/
|
|
277
|
+
const logoutFromSession = useCallback(async (targetSessionToken) => {
|
|
278
|
+
if (!sessionToken)
|
|
279
|
+
return;
|
|
280
|
+
try {
|
|
281
|
+
await fetch(`${apiBaseUrl}/api/v1/wallet/auth/sessions/${targetSessionToken}`, {
|
|
282
|
+
method: 'DELETE',
|
|
283
|
+
headers: {
|
|
284
|
+
'X-Session-Token': sessionToken,
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
console.log('Session invalidated');
|
|
288
|
+
// If we logged out our own session, clear local state
|
|
289
|
+
if (targetSessionToken === sessionToken) {
|
|
290
|
+
await logout();
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
// Refresh sessions list
|
|
294
|
+
await getSessions();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
console.error('Failed to invalidate session', error);
|
|
299
|
+
}
|
|
300
|
+
}, [sessionToken, apiBaseUrl, logout, getSessions]);
|
|
301
|
+
/**
|
|
302
|
+
* Logout from all devices
|
|
303
|
+
*/
|
|
304
|
+
const logoutFromAllDevices = useCallback(async () => {
|
|
305
|
+
if (!sessionToken)
|
|
306
|
+
return;
|
|
307
|
+
try {
|
|
308
|
+
await fetch(`${apiBaseUrl}/api/v1/wallet/auth/sessions`, {
|
|
309
|
+
method: 'DELETE',
|
|
310
|
+
headers: {
|
|
311
|
+
'X-Session-Token': sessionToken,
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
console.log('Logged out from all devices');
|
|
315
|
+
// Clear local session
|
|
316
|
+
await logout();
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
console.error('Failed to logout from all devices', error);
|
|
320
|
+
}
|
|
321
|
+
}, [sessionToken, apiBaseUrl, logout]);
|
|
322
|
+
/**
|
|
323
|
+
* Add additional wallet to session (multi-wallet support)
|
|
324
|
+
*/
|
|
325
|
+
const addWallet = useCallback(async (newWalletAddress) => {
|
|
326
|
+
if (!sessionToken)
|
|
327
|
+
return;
|
|
328
|
+
try {
|
|
329
|
+
// Get authentication message for new wallet
|
|
330
|
+
const messageResponse = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/message`, {
|
|
331
|
+
method: 'POST',
|
|
332
|
+
headers: { 'Content-Type': 'application/json' },
|
|
333
|
+
body: JSON.stringify({ wallet_address: newWalletAddress }),
|
|
334
|
+
});
|
|
335
|
+
if (!messageResponse.ok) {
|
|
336
|
+
throw new Error('Failed to get authentication message');
|
|
337
|
+
}
|
|
338
|
+
const { message, nonce } = await messageResponse.json();
|
|
339
|
+
// Sign message with new wallet
|
|
340
|
+
const signature = await signMessage(message);
|
|
341
|
+
// Add wallet to session
|
|
342
|
+
const response = await fetch(`${apiBaseUrl}/api/v1/wallet/auth/add-wallet`, {
|
|
343
|
+
method: 'POST',
|
|
344
|
+
headers: {
|
|
345
|
+
'Content-Type': 'application/json',
|
|
346
|
+
'X-Session-Token': sessionToken,
|
|
347
|
+
},
|
|
348
|
+
body: JSON.stringify({
|
|
349
|
+
new_wallet_address: newWalletAddress,
|
|
350
|
+
signature,
|
|
351
|
+
message,
|
|
352
|
+
nonce,
|
|
353
|
+
}),
|
|
354
|
+
});
|
|
355
|
+
if (!response.ok) {
|
|
356
|
+
throw new Error('Failed to add wallet');
|
|
357
|
+
}
|
|
358
|
+
console.log('Wallet added successfully');
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
console.error('Failed to add wallet', error);
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
366
|
+
[sessionToken, apiBaseUrl, signMessage]);
|
|
367
|
+
/**
|
|
368
|
+
* Fetch with auth headers
|
|
369
|
+
*/
|
|
370
|
+
const authFetch = useCallback(async (input, init) => {
|
|
371
|
+
const headers = new Headers(init?.headers);
|
|
372
|
+
if (sessionToken) {
|
|
373
|
+
headers.set('X-Session-Token', sessionToken);
|
|
374
|
+
}
|
|
375
|
+
return fetch(input, { ...init, headers });
|
|
376
|
+
}, [sessionToken]);
|
|
377
|
+
// Auto-login when Privy authenticates
|
|
378
|
+
useEffect(() => {
|
|
379
|
+
if (autoLogin && ready && authenticated && address && !sessionToken && !isAuthenticating) {
|
|
380
|
+
console.log('Auto-logging in with wallet', { address });
|
|
381
|
+
login().catch((e) => console.error('Auto-login failed', e));
|
|
382
|
+
}
|
|
383
|
+
}, [autoLogin, ready, authenticated, address, sessionToken, isAuthenticating, login]);
|
|
384
|
+
// Auto-refresh session
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
if (!sessionToken)
|
|
387
|
+
return;
|
|
388
|
+
const intervalId = setInterval(() => {
|
|
389
|
+
refreshSession().catch((e) => console.error('Auto-refresh failed', e));
|
|
390
|
+
}, refreshIntervalMinutes * 60 * 1000);
|
|
391
|
+
return () => clearInterval(intervalId);
|
|
392
|
+
}, [sessionToken, refreshSession, refreshIntervalMinutes]);
|
|
393
|
+
return {
|
|
394
|
+
// Authentication state
|
|
395
|
+
isAuthenticated: !!sessionToken && !!walletAddress,
|
|
396
|
+
sessionToken,
|
|
397
|
+
walletAddress,
|
|
398
|
+
isAuthenticating,
|
|
399
|
+
authError,
|
|
400
|
+
// Session management
|
|
401
|
+
sessions,
|
|
402
|
+
// Actions
|
|
403
|
+
login,
|
|
404
|
+
logout,
|
|
405
|
+
refreshSession,
|
|
406
|
+
getSessions,
|
|
407
|
+
logoutFromSession,
|
|
408
|
+
logoutFromAllDevices,
|
|
409
|
+
addWallet,
|
|
410
|
+
// Utility
|
|
411
|
+
authFetch,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
export default useWalletAuth;
|
|
415
|
+
//# sourceMappingURL=useWalletAuth.js.map
|