@cedros/login-react 0.0.1 → 0.0.2

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.
Files changed (147) hide show
  1. package/README.md +142 -2
  2. package/dist/AuthenticationSettings-CMQhep61.js +9 -0
  3. package/dist/AuthenticationSettings-CMQhep61.js.map +1 -0
  4. package/dist/AuthenticationSettings-Cro76kIC.cjs +1 -0
  5. package/dist/AuthenticationSettings-Cro76kIC.cjs.map +1 -0
  6. package/dist/CreditSystemSettings-AM7qDk1E.js +9 -0
  7. package/dist/CreditSystemSettings-AM7qDk1E.js.map +1 -0
  8. package/dist/CreditSystemSettings-CGR-uzuh.cjs +1 -0
  9. package/dist/CreditSystemSettings-CGR-uzuh.cjs.map +1 -0
  10. package/dist/DepositsSection-BVNd63B7.js +47 -0
  11. package/dist/DepositsSection-BVNd63B7.js.map +1 -0
  12. package/dist/DepositsSection-Ct1gjgIg.cjs +1 -0
  13. package/dist/DepositsSection-Ct1gjgIg.cjs.map +1 -0
  14. package/dist/EmailRegisterForm-B-ys4E3C.cjs +1 -0
  15. package/dist/EmailRegisterForm-B-ys4E3C.cjs.map +1 -0
  16. package/dist/EmailRegisterForm-BChCiZ5B.js +961 -0
  17. package/dist/EmailRegisterForm-BChCiZ5B.js.map +1 -0
  18. package/dist/EmailSettings-DFZ13JbX.cjs +1 -0
  19. package/dist/EmailSettings-DFZ13JbX.cjs.map +1 -0
  20. package/dist/EmailSettings-Di4GSWgb.js +9 -0
  21. package/dist/EmailSettings-Di4GSWgb.js.map +1 -0
  22. package/dist/EmbeddedWalletSettings-Cmn_aVL7.js +9 -0
  23. package/dist/EmbeddedWalletSettings-Cmn_aVL7.js.map +1 -0
  24. package/dist/EmbeddedWalletSettings-DRWeIJKb.cjs +1 -0
  25. package/dist/EmbeddedWalletSettings-DRWeIJKb.cjs.map +1 -0
  26. package/dist/{ErrorMessage-Bm1j5mBT.js → ErrorMessage-C8vKB0JG.js} +9 -9
  27. package/dist/ErrorMessage-C8vKB0JG.js.map +1 -0
  28. package/dist/ErrorMessage-CntMyn93.cjs.map +1 -1
  29. package/dist/{GoogleLoginButton-CvDoOc-0.js → GoogleLoginButton-Ceo2sYvX.js} +1 -1
  30. package/dist/{GoogleLoginButton-CvDoOc-0.js.map → GoogleLoginButton-Ceo2sYvX.js.map} +1 -1
  31. package/dist/ServerSettings-D8w8EpoE.cjs +1 -0
  32. package/dist/ServerSettings-D8w8EpoE.cjs.map +1 -0
  33. package/dist/ServerSettings-Wg_odW46.js +9 -0
  34. package/dist/ServerSettings-Wg_odW46.js.map +1 -0
  35. package/dist/{SolanaLoginButton-h32xN2PQ.js → SolanaLoginButton-CqVOcPa7.js} +1 -1
  36. package/dist/{SolanaLoginButton-h32xN2PQ.js.map → SolanaLoginButton-CqVOcPa7.js.map} +1 -1
  37. package/dist/TeamSection-Bj89WSC0.js +128 -0
  38. package/dist/TeamSection-Bj89WSC0.js.map +1 -0
  39. package/dist/TeamSection-DQ4nfUHN.cjs +1 -0
  40. package/dist/TeamSection-DQ4nfUHN.cjs.map +1 -0
  41. package/dist/UsersSection-BiZceDV3.cjs +1 -0
  42. package/dist/UsersSection-BiZceDV3.cjs.map +1 -0
  43. package/dist/UsersSection-W19ddPsw.js +81 -0
  44. package/dist/UsersSection-W19ddPsw.js.map +1 -0
  45. package/dist/WebhookSettings-a1c4iMvr.js +9 -0
  46. package/dist/WebhookSettings-a1c4iMvr.js.map +1 -0
  47. package/dist/WebhookSettings-onJWLytD.cjs +1 -0
  48. package/dist/WebhookSettings-onJWLytD.cjs.map +1 -0
  49. package/dist/WithdrawalsSection-BBw9gWMR.js +20 -0
  50. package/dist/WithdrawalsSection-BBw9gWMR.js.map +1 -0
  51. package/dist/WithdrawalsSection-Cws8inf6.cjs +1 -0
  52. package/dist/WithdrawalsSection-Cws8inf6.cjs.map +1 -0
  53. package/dist/admin/AdminShell.d.ts +38 -0
  54. package/dist/admin/icons.d.ts +2 -0
  55. package/dist/admin/index.d.ts +10 -0
  56. package/dist/admin/plugin.d.ts +3 -0
  57. package/dist/admin/sections/AuthenticationSettings.d.ts +3 -0
  58. package/dist/admin/sections/CreditSystemSettings.d.ts +3 -0
  59. package/dist/admin/sections/DepositsSection.d.ts +3 -0
  60. package/dist/admin/sections/EmailSettings.d.ts +3 -0
  61. package/dist/admin/sections/EmbeddedWalletSettings.d.ts +3 -0
  62. package/dist/admin/sections/FeatureSettings.d.ts +3 -0
  63. package/dist/admin/sections/InvitesSection.d.ts +3 -0
  64. package/dist/admin/sections/MembersSection.d.ts +3 -0
  65. package/dist/admin/sections/ServerSettings.d.ts +3 -0
  66. package/dist/admin/sections/SettingsSections.d.ts +7 -0
  67. package/dist/admin/sections/TeamSection.d.ts +3 -0
  68. package/dist/admin/sections/UsersSection.d.ts +3 -0
  69. package/dist/admin/sections/WebhookSettings.d.ts +3 -0
  70. package/dist/admin/sections/WithdrawalsSection.d.ts +3 -0
  71. package/dist/admin/types.d.ts +167 -0
  72. package/dist/components/admin/AdminUserDetail.d.ts +3 -1
  73. package/dist/components/admin/AdminUserList.d.ts +3 -7
  74. package/dist/components/admin/CedrosAdminDashboard.d.ts +7 -3
  75. package/dist/components/admin/PermissionsSection.d.ts +7 -0
  76. package/dist/components/admin/ProfileDropdown.d.ts +34 -0
  77. package/dist/components/admin/SetupWizard.d.ts +30 -0
  78. package/dist/components/admin/StatsBar.d.ts +17 -0
  79. package/dist/components/admin/settings/AuthenticationSettings.d.ts +4 -0
  80. package/dist/components/admin/settings/AutosaveStatus.d.ts +6 -0
  81. package/dist/components/admin/settings/CreditSystemSettings.d.ts +6 -0
  82. package/dist/components/admin/settings/EmailSettings.d.ts +4 -0
  83. package/dist/components/admin/settings/EmbeddedWalletSettings.d.ts +4 -0
  84. package/dist/components/admin/settings/FeatureSettings.d.ts +4 -0
  85. package/dist/components/admin/settings/MessagingSettings.d.ts +4 -0
  86. package/dist/components/admin/settings/SecuritySettings.d.ts +4 -0
  87. package/dist/components/admin/settings/ServerSettings.d.ts +4 -0
  88. package/dist/components/admin/settings/SettingsPageLayout.d.ts +16 -0
  89. package/dist/components/admin/settings/SsoProvidersSettings.d.ts +4 -0
  90. package/dist/components/admin/settings/WebhookSettings.d.ts +4 -0
  91. package/dist/components/admin/settings/index.d.ts +31 -0
  92. package/dist/components/admin/settings/settingsInputs.d.ts +79 -0
  93. package/dist/components/admin/settings/settingsMetadata.d.ts +18 -0
  94. package/dist/components/deposit/admin/AdminWithdrawalStats.d.ts +10 -0
  95. package/dist/components/deposit/admin/FeatureDisabledMessage.d.ts +15 -0
  96. package/dist/components/deposit/admin/featureDisabled.d.ts +9 -0
  97. package/dist/components/deposit/admin/index.d.ts +5 -0
  98. package/dist/components/invites/InviteForm.d.ts +1 -1
  99. package/dist/components/org/OrgSelector.d.ts +2 -1
  100. package/dist/components/profile/UserProfileSettings.d.ts +35 -0
  101. package/dist/components/profile/index.d.ts +2 -0
  102. package/dist/crypto/secureWipe.d.ts +0 -19
  103. package/dist/crypto/webauthnPrf.d.ts +0 -10
  104. package/dist/email-only.cjs +1 -1
  105. package/dist/email-only.js +2 -2
  106. package/dist/google-only.js +2 -2
  107. package/dist/hooks/useDashboardPermissions.d.ts +45 -0
  108. package/dist/hooks/useProfile.d.ts +35 -0
  109. package/dist/hooks/useServerFeatures.d.ts +55 -0
  110. package/dist/hooks/useSettingsAutosave.d.ts +29 -0
  111. package/dist/hooks/useSetup.d.ts +25 -0
  112. package/dist/hooks/useSsoProviders.d.ts +52 -0
  113. package/dist/index-BHR_WTP2.js +19636 -0
  114. package/dist/index-BHR_WTP2.js.map +1 -0
  115. package/dist/index-JsIJkPin.cjs +2061 -0
  116. package/dist/index-JsIJkPin.cjs.map +1 -0
  117. package/dist/index.cjs +1 -2061
  118. package/dist/index.cjs.map +1 -1
  119. package/dist/index.d.ts +21 -3
  120. package/dist/index.js +117 -14908
  121. package/dist/index.js.map +1 -1
  122. package/dist/login-react.css +1 -1
  123. package/dist/silentWalletEnroll-CQK5i65l.js +42 -0
  124. package/dist/silentWalletEnroll-CQK5i65l.js.map +1 -0
  125. package/dist/silentWalletEnroll-DBfS2sLe.cjs +1 -0
  126. package/dist/silentWalletEnroll-DBfS2sLe.cjs.map +1 -0
  127. package/dist/solana-only.js +2 -2
  128. package/dist/solanaKeypair-BD7Kq1Mw.js +1932 -0
  129. package/dist/solanaKeypair-BD7Kq1Mw.js.map +1 -0
  130. package/dist/solanaKeypair-CBQxm2hw.cjs +1 -0
  131. package/dist/solanaKeypair-CBQxm2hw.cjs.map +1 -0
  132. package/dist/types/adminUser.d.ts +56 -0
  133. package/dist/types/deposit.d.ts +2 -0
  134. package/dist/types/index.d.ts +4 -2
  135. package/dist/types/org.d.ts +34 -2
  136. package/dist/types/profile.d.ts +56 -0
  137. package/dist/types/setup.d.ts +45 -0
  138. package/dist/types/systemSettings.d.ts +5 -1
  139. package/dist/utils/adminUserApi.d.ts +10 -1
  140. package/dist/utils/profileApi.d.ts +26 -0
  141. package/dist/utils/setupApi.d.ts +21 -0
  142. package/package.json +1 -1
  143. package/dist/EmailRegisterForm-D_uCEdX9.cjs +0 -1
  144. package/dist/EmailRegisterForm-D_uCEdX9.cjs.map +0 -1
  145. package/dist/EmailRegisterForm-m3rX3A6X.js +0 -2923
  146. package/dist/EmailRegisterForm-m3rX3A6X.js.map +0 -1
  147. package/dist/ErrorMessage-Bm1j5mBT.js.map +0 -1
@@ -14,6 +14,10 @@ export interface AdminUser {
14
14
  isSystemAdmin: boolean;
15
15
  createdAt: string;
16
16
  updatedAt: string;
17
+ /** Last login timestamp (ISO 8601) */
18
+ lastLoginAt?: string;
19
+ /** Credit balance in lamports (if credit system is enabled) */
20
+ balanceLamports?: number;
17
21
  }
18
22
  /**
19
23
  * Response for listing users (admin)
@@ -89,6 +93,56 @@ export interface AdminUserCreditsResponse {
89
93
  limit: number;
90
94
  offset: number;
91
95
  }
96
+ /**
97
+ * Admin user statistics by auth method
98
+ */
99
+ export interface AdminUserStatsResponse {
100
+ /** Total number of users */
101
+ total: number;
102
+ /** Count by auth method (e.g., { email: 50, google: 25, solana: 10 }) */
103
+ authMethodCounts: Record<string, number>;
104
+ }
105
+ /**
106
+ * Chat message role
107
+ */
108
+ export type ChatMessageRole = 'user' | 'assistant' | 'system';
109
+ /**
110
+ * Individual chat message from cedros-pay
111
+ */
112
+ export interface AdminChatMessage {
113
+ id: string;
114
+ role: ChatMessageRole;
115
+ content: string;
116
+ createdAt: string;
117
+ /** Optional metadata (e.g., tool calls, function results) */
118
+ metadata?: Record<string, unknown>;
119
+ }
120
+ /**
121
+ * Chat session/conversation from cedros-pay
122
+ */
123
+ export interface AdminChatSession {
124
+ id: string;
125
+ userId: string;
126
+ /** Session title or first message preview */
127
+ title?: string;
128
+ /** Number of messages in this session */
129
+ messageCount: number;
130
+ /** When the session was created */
131
+ createdAt: string;
132
+ /** When the session was last updated */
133
+ updatedAt: string;
134
+ /** Messages in this session (populated when fetching single session) */
135
+ messages?: AdminChatMessage[];
136
+ }
137
+ /**
138
+ * Response for listing user chat sessions
139
+ */
140
+ export interface AdminUserChatsResponse {
141
+ sessions: AdminChatSession[];
142
+ total: number;
143
+ limit: number;
144
+ offset: number;
145
+ }
92
146
  /**
93
147
  * Hook return type
94
148
  */
@@ -107,6 +161,8 @@ export interface UseAdminUsersReturn {
107
161
  getUserDeposits: (userId: string, params?: ListUsersParams) => Promise<import('./deposit').AdminDepositListResponse>;
108
162
  getUserCredits: (userId: string, params?: ListUsersParams) => Promise<AdminUserCreditsResponse>;
109
163
  getUserWithdrawalHistory: (userId: string, params?: ListUsersParams) => Promise<import('./deposit').AdminUserWithdrawalHistoryResponse>;
164
+ getUserChats: (userId: string, params?: ListUsersParams) => Promise<AdminUserChatsResponse>;
165
+ getStats: () => Promise<AdminUserStatsResponse>;
110
166
  refresh: () => Promise<void>;
111
167
  clearError: () => void;
112
168
  }
@@ -96,6 +96,8 @@ export interface DepositConfigResponse {
96
96
  companyFeeFixedLamports: number;
97
97
  /** Custom token definitions from admin settings */
98
98
  customTokens?: CustomTokenDefinition[];
99
+ /** Whether to show the explainer step for non-crypto-native users */
100
+ showExplainer: boolean;
99
101
  }
100
102
  /** Swap quote response from GET /deposit/quote */
101
103
  export interface DepositQuoteResponse {
@@ -1,11 +1,13 @@
1
1
  export type { AuthMethod, AuthUser, TokenPair, AuthError, AuthErrorCode, AuthResponse, ChallengeResponse, AuthState, PasswordValidation, DisplayError, MfaRequiredResponse, MfaLoginRequest, } from './auth';
2
2
  export type { SolanaNetwork, SessionStorage, ThemeMode, SolanaConfig, FeatureFlags, SessionConfig, AuthCallbacks, ThemeOverrides, ForgotPasswordConfig, TermsOfServiceConfig, EmailOptInConfig, FormConfig, TotpConfig, WalletConfig, CedrosLoginConfig, } from './config';
3
3
  export type { TotpStatus, TotpSetupResponse, TotpEnableRequest, TotpVerifyRequest, TotpBackupCodesResponse, TotpSetupState, TotpVerifyState, } from './totp';
4
- export type { OrgRole, Organization, Membership, OrgWithMembership, Permission, CreateOrgRequest, UpdateOrgRequest, ListOrgsResponse, AuthorizeRequest, AuthorizeResponse, PermissionsResponse, OrgState, } from './org';
4
+ export type { OrgRole, Organization, Membership, OrgWithMembership, Permission, CreateOrgRequest, UpdateOrgRequest, ListOrgsResponse, AuthorizeRequest, AuthorizeResponse, PermissionsResponse, OrgState, DashboardSection, DashboardPermissions, } from './org';
5
5
  export type { Member, MemberApiResponse, MemberUser, UpdateMemberRoleRequest, ListMembersResponse, } from './member';
6
6
  export type { Invite, InviteApiResponse, CreateInviteRequest, AcceptInviteRequest, ListInvitesResponse, CreateInviteResponse, AcceptInviteResponse, } from './invite';
7
7
  export type { Session, ListSessionsResponse, RevokeAllSessionsResponse } from './session';
8
8
  export type { WalletStatus, CryptoCapabilities, EnrollmentState, RecoveryState, KdfParams, ShareAAuthMethod, WalletMaterialResponse, WalletStatusApiResponse, WalletEnrollRequest, PendingWalletRecoveryResponse, AcknowledgeRecoveryRequest, UnlockCredential, SignTransactionRequest, SignTransactionResponse, RotateUserSecretRequest, MessageResponse, WalletUnlockRequest, WalletUnlockResponse, WalletContextValue, UseWalletEnrollmentReturn, UseWalletSigningReturn, UseWalletRecoveryReturn, UseWalletMaterialReturn, UsePrfCapabilityReturn, } from './wallet';
9
9
  export type { DepositRequest, DepositResponse, DepositStatusResponse, DepositConfigResponse, DepositTier, DepositQuoteResponse, PublicDepositRequest, MicroDepositRequest, TieredDepositResponse, DepositItemResponse, DepositListResponse, CreditBalanceResponse, BalancesResponse, CreditTransactionResponse, CreditHistoryResponse, UseDepositReturn, UseCreditsReturn, AdminDepositItem, AdminDepositListResponse, AdminDepositStatsResponse, UseAdminDepositsReturn, WithdrawalHistoryItem, AdminUserWithdrawalHistoryResponse, } from './deposit';
10
10
  export type { SystemSetting, ListSystemSettingsResponse, UpdateSettingRequest, UpdateSystemSettingsRequest, UpdateSystemSettingsResponse, SettingCategoryMeta, SettingMeta, SettingPreset, UseSystemSettingsReturn, } from './systemSettings';
11
- export type { AdminCreditTransactionItem, AdminUser, AdminUserCreditStats, AdminUserCreditsResponse, AdjustCreditsRequest, ListAdminUsersResponse, ListUsersParams, SetSystemAdminRequest, UpdateUserRequest, UseAdminUsersReturn, } from './adminUser';
11
+ export type { AdminCreditTransactionItem, AdminUser, AdminUserCreditStats, AdminUserCreditsResponse, AdminUserStatsResponse, AdminChatMessage, AdminChatSession, AdminUserChatsResponse, ChatMessageRole, AdjustCreditsRequest, ListAdminUsersResponse, ListUsersParams, SetSystemAdminRequest, UpdateUserRequest, UseAdminUsersReturn, } from './adminUser';
12
+ export type { SetupStatusResponse, CreateFirstAdminRequest, CreateFirstAdminResponse, UseSetupReturn, } from './setup';
13
+ export type { UpdateProfileRequest, ChangePasswordRequest, UpdateProfileResponse, ChangePasswordResponse, UseProfileReturn, } from './profile';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Organization role in RBAC hierarchy
3
- * owner > admin > member > viewer
3
+ * owner > admin > member
4
4
  */
5
- export type OrgRole = 'owner' | 'admin' | 'member' | 'viewer';
5
+ export type OrgRole = 'owner' | 'admin' | 'member';
6
6
  /**
7
7
  * Organization entity
8
8
  */
@@ -99,3 +99,35 @@ export interface OrgState {
99
99
  /** Loading state for org operations */
100
100
  isLoading: boolean;
101
101
  }
102
+ /**
103
+ * Admin dashboard sections that can be permission-controlled
104
+ */
105
+ export type DashboardSection = 'users' | 'team' | 'deposits' | 'withdrawals' | 'settings-wallet' | 'settings-auth' | 'settings-messaging' | 'settings-credits' | 'settings-server' | 'pay-products' | 'pay-subscriptions' | 'pay-transactions' | 'pay-coupons' | 'pay-refunds' | 'pay-storefront' | 'pay-ai' | 'pay-payment' | 'pay-messaging' | 'pay-settings';
106
+ /**
107
+ * Cedros Login dashboard sections
108
+ */
109
+ export declare const LOGIN_DASHBOARD_SECTIONS: DashboardSection[];
110
+ /**
111
+ * Cedros Pay dashboard sections
112
+ */
113
+ export declare const PAY_DASHBOARD_SECTIONS: DashboardSection[];
114
+ /**
115
+ * All available dashboard sections
116
+ */
117
+ export declare const ALL_DASHBOARD_SECTIONS: DashboardSection[];
118
+ /**
119
+ * Human-readable labels for dashboard sections
120
+ */
121
+ export declare const DASHBOARD_SECTION_LABELS: Record<DashboardSection, string>;
122
+ /**
123
+ * Dashboard permissions per role
124
+ * Only admin and member are configurable - owner always has full access
125
+ */
126
+ export interface DashboardPermissions {
127
+ admin: Record<DashboardSection, boolean>;
128
+ member: Record<DashboardSection, boolean>;
129
+ }
130
+ /**
131
+ * Default dashboard permissions for new orgs
132
+ */
133
+ export declare const DEFAULT_DASHBOARD_PERMISSIONS: DashboardPermissions;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * User profile types
3
+ *
4
+ * Types for user profile management including updates and password changes.
5
+ */
6
+ /**
7
+ * Request to update user profile
8
+ */
9
+ export interface UpdateProfileRequest {
10
+ /** User's display name */
11
+ name?: string;
12
+ /** User's profile picture URL */
13
+ picture?: string;
14
+ }
15
+ /**
16
+ * Request to change password
17
+ */
18
+ export interface ChangePasswordRequest {
19
+ /** Current password for verification */
20
+ currentPassword: string;
21
+ /** New password */
22
+ newPassword: string;
23
+ }
24
+ /**
25
+ * Response from profile update
26
+ */
27
+ export interface UpdateProfileResponse {
28
+ id: string;
29
+ email?: string;
30
+ name?: string;
31
+ picture?: string;
32
+ emailVerified: boolean;
33
+ createdAt: string;
34
+ updatedAt: string;
35
+ }
36
+ /**
37
+ * Response from password change
38
+ */
39
+ export interface ChangePasswordResponse {
40
+ message: string;
41
+ }
42
+ /**
43
+ * Return type for useProfile hook
44
+ */
45
+ export interface UseProfileReturn {
46
+ /** Whether a profile operation is in progress */
47
+ isLoading: boolean;
48
+ /** Error from last operation */
49
+ error: Error | null;
50
+ /** Update profile (name, picture) */
51
+ updateProfile: (data: UpdateProfileRequest) => Promise<UpdateProfileResponse>;
52
+ /** Change password */
53
+ changePassword: (data: ChangePasswordRequest) => Promise<void>;
54
+ /** Clear error state */
55
+ clearError: () => void;
56
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Setup types for first-run configuration
3
+ */
4
+ /** Response from setup status check */
5
+ export interface SetupStatusResponse {
6
+ /** Whether initial setup is needed (no admin exists) */
7
+ needsSetup: boolean;
8
+ /** Whether at least one admin user exists */
9
+ hasAdmin: boolean;
10
+ /** Server version for compatibility checking */
11
+ serverVersion: string;
12
+ }
13
+ /** Request to create the first admin user */
14
+ export interface CreateFirstAdminRequest {
15
+ /** Admin email address */
16
+ email: string;
17
+ /** Admin password */
18
+ password: string;
19
+ /** Optional display name */
20
+ name?: string;
21
+ }
22
+ /** Response after creating first admin */
23
+ export interface CreateFirstAdminResponse {
24
+ /** Whether admin was successfully created */
25
+ success: boolean;
26
+ /** Created user ID */
27
+ userId: string;
28
+ /** Message for the user */
29
+ message: string;
30
+ }
31
+ /** Return type for useSetup hook */
32
+ export interface UseSetupReturn {
33
+ /** Current setup status */
34
+ status: SetupStatusResponse | null;
35
+ /** Whether status is loading */
36
+ isLoading: boolean;
37
+ /** Whether admin creation is in progress */
38
+ isCreating: boolean;
39
+ /** Error if any */
40
+ error: Error | null;
41
+ /** Check setup status */
42
+ checkStatus: () => Promise<void>;
43
+ /** Create first admin */
44
+ createAdmin: (request: CreateFirstAdminRequest) => Promise<CreateFirstAdminResponse>;
45
+ }
@@ -50,7 +50,7 @@ export interface SettingMeta {
50
50
  /** Maximum allowed value */
51
51
  max?: number;
52
52
  /** Input type determines how the setting is rendered */
53
- inputType: 'number' | 'duration' | 'percentage' | 'select' | 'text' | 'tokenSymbolList' | 'tokenList';
53
+ inputType: 'number' | 'duration' | 'percentage' | 'select' | 'text' | 'boolean' | 'secret' | 'tokenSymbolList' | 'tokenList';
54
54
  /** Preset values for quick selection (used with 'select' or as suggestions) */
55
55
  presets?: SettingPreset[];
56
56
  /** Value threshold that triggers a warning */
@@ -61,6 +61,10 @@ export interface SettingMeta {
61
61
  };
62
62
  /** Step for number inputs */
63
63
  step?: number;
64
+ /** Whether secret inputs should be multiline (textarea) */
65
+ multiline?: boolean;
66
+ /** Placeholder text for text inputs */
67
+ placeholder?: string;
64
68
  }
65
69
  /** Return type for useSystemSettings hook */
66
70
  export interface UseSystemSettingsReturn {
@@ -1,4 +1,4 @@
1
- import { AdminUser, AdminUserCreditsResponse, AdjustCreditsRequest, ListAdminUsersResponse, ListUsersParams, UpdateUserRequest } from '../types';
1
+ import { AdminUser, AdminUserChatsResponse, AdminUserCreditsResponse, AdminUserStatsResponse, AdjustCreditsRequest, ListAdminUsersResponse, ListUsersParams, UpdateUserRequest } from '../types';
2
2
  import { AdminDepositListResponse, AdminUserWithdrawalHistoryResponse } from '../types/deposit';
3
3
  /**
4
4
  * API client for admin user operations
@@ -48,4 +48,13 @@ export declare class AdminUserApiClient {
48
48
  * Get a user's withdrawal history
49
49
  */
50
50
  getUserWithdrawalHistory(userId: string, params?: ListUsersParams): Promise<AdminUserWithdrawalHistoryResponse>;
51
+ /**
52
+ * Get a user's chat history (from cedros-pay)
53
+ * Only available when cedros-pay is enabled.
54
+ */
55
+ getUserChats(userId: string, params?: ListUsersParams): Promise<AdminUserChatsResponse>;
56
+ /**
57
+ * Get user statistics by auth method
58
+ */
59
+ getStats(): Promise<AdminUserStatsResponse>;
51
60
  }
@@ -0,0 +1,26 @@
1
+ import { ChangePasswordRequest, ChangePasswordResponse, UpdateProfileRequest, UpdateProfileResponse } from '../types';
2
+ /**
3
+ * API client for user profile operations
4
+ *
5
+ * Supports:
6
+ * - POST /auth/change-password - Change user password
7
+ * - PATCH /auth/me - Update profile (name, picture) [requires backend support]
8
+ */
9
+ export declare class ProfileApiClient {
10
+ private client;
11
+ constructor(baseUrl: string, timeoutMs?: number, retryAttempts?: number, getAccessToken?: () => string | null);
12
+ /**
13
+ * Change the user's password
14
+ *
15
+ * Requires the current password for verification. Also revokes all other sessions
16
+ * and re-encrypts wallet Share A if using password-based wallet protection.
17
+ */
18
+ changePassword(data: ChangePasswordRequest): Promise<ChangePasswordResponse>;
19
+ /**
20
+ * Update user profile (name, picture)
21
+ *
22
+ * NOTE: Requires PATCH /auth/me endpoint on the backend.
23
+ * If not implemented, returns a rejection.
24
+ */
25
+ updateProfile(data: UpdateProfileRequest): Promise<UpdateProfileResponse>;
26
+ }
@@ -0,0 +1,21 @@
1
+ import { SetupStatusResponse, CreateFirstAdminRequest, CreateFirstAdminResponse } from '../types/setup';
2
+ /**
3
+ * API client for setup operations (unauthenticated)
4
+ *
5
+ * These endpoints are used during first-run configuration before
6
+ * any admin user exists.
7
+ */
8
+ export declare class SetupApiClient {
9
+ private client;
10
+ constructor(baseUrl: string, timeoutMs?: number, retryAttempts?: number);
11
+ /**
12
+ * Check if initial setup is required
13
+ * Returns whether the system needs initial setup (no admin exists)
14
+ */
15
+ getStatus(): Promise<SetupStatusResponse>;
16
+ /**
17
+ * Create the first admin user
18
+ * Only works when no admin users exist
19
+ */
20
+ createFirstAdmin(request: CreateFirstAdminRequest): Promise<CreateFirstAdminResponse>;
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedros/login-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "React component library for authentication with email/password, Google OAuth, and Solana wallet sign-in",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1 +0,0 @@
1
- "use strict";const b=require("react/jsx-runtime"),N=require("react"),_=require("./ErrorMessage-CntMyn93.cjs"),pe=require("./validation-BeXIfuHB.cjs");var Ee=typeof document<"u"?document.currentScript:null;let re=null,Zt=0;const ce=new Map;function Pt(){return typeof Worker>"u"?null:(re||(re=new Worker(new URL("/assets/argon2Worker-Bi5TuQvD.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:Ee&&Ee.tagName.toUpperCase()==="SCRIPT"&&Ee.src||new URL("EmailRegisterForm-D_uCEdX9.cjs",document.baseURI).href),{type:"module"}),re.onmessage=t=>{const{id:e,key:r,error:n}=t.data,s=ce.get(e);if(s){if(ce.delete(e),n){s.reject(new Error(n));return}if(!r){s.reject(new Error("Argon2 worker returned no key"));return}s.resolve(r)}},re.onerror=t=>{const e=t instanceof ErrorEvent?t.error:new Error("Argon2 worker error");for(const r of ce.values())r.reject(e instanceof Error?e:new Error(String(e)));ce.clear(),re?.terminate(),re=null}),re)}async function lt(t,e,r=_.DEFAULT_KDF_PARAMS){const n=Pt();return n?new Promise((s,o)=>{const c=Zt++;ce.set(c,{resolve:s,reject:o});const a={id:c,password:t,salt:e,params:r};n.postMessage(a)}):_.argon2Derive(t,e,r)}function ut(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Kt(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if(typeof e=="function"){var r=function n(){var s=!1;try{s=this instanceof n}catch{}return s?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}),r}var me={exports:{}};const zt=globalThis.crypto,Wt=globalThis.crypto,Ft=globalThis.crypto.subtle,Yt=globalThis.crypto.getRandomValues.bind(globalThis.crypto),Xt=globalThis.crypto.randomUUID.bind(globalThis.crypto),Qt=Object.freeze(Object.defineProperty({__proto__:null,default:zt,getRandomValues:Yt,randomUUID:Xt,subtle:Ft,webcrypto:Wt},Symbol.toStringTag,{value:"Module"})),Jt=Kt(Qt);var er=me.exports,Ge;function tr(){return Ge||(Ge=1,(function(t,e){(function(r,n){t.exports=n(Jt)})(er,function(r){var n,s,o,c,a;function i(){n={bits:8,radix:16,minBits:3,maxBits:20,bytesPerChar:2,maxBytesPerChar:6,primitivePolynomials:[null,null,1,3,3,5,3,3,29,17,9,5,83,27,43,3,45,9,39,39,9,5,3,33,27,9,71,39,9,5,83]},s={},o=new Array(1024).join("0"),c=!0,a=["nodeCryptoRandomBytes","browserCryptoGetRandomValues","testRandom"]}function p(){return!!(s&&s.rng&&typeof s.rng=="function")}function x(l,f){var u;if(f===0||f===1)return l;if(f&&f>1024)throw new Error("Padding must be multiples of no larger than 1024 bits.");return f=f||s.bits,l&&(u=l.length%f),u?(o+l).slice(-(f-u+l.length)):l}function h(l){var f="",u,d;for(d=l.length-1;d>=0;d--){if(u=parseInt(l[d],16),isNaN(u))throw new Error("Invalid hex character.");f=x(u.toString(2),4)+f}return f}function A(l){var f="",u,d;for(l=x(l,4),d=l.length;d>=4;d-=4){if(u=parseInt(l.slice(d-4,d),2),isNaN(u))throw new Error("Invalid binary character.");f=u.toString(16)+f}return f}function I(){return!!(r&&typeof r=="object"&&(typeof r.getRandomValues=="function"||typeof r.getRandomValues=="object")&&(typeof Uint32Array=="function"||typeof Uint32Array=="object"))}function k(){return typeof r=="object"&&typeof r.randomBytes=="function"}function B(l){function f(E,S,C,L){var j=0,O,U="",M;for(S&&(O=S.length-1);j<O||U.length<E;)M=Math.abs(parseInt(S[j],C)),U=U+x(M.toString(2),L),j++;return U=U.substr(-E),(U.match(/0/g)||[]).length===U.length?null:U}function u(E){var S,C,L,j,O=null;for(L=16,j=4,C=Math.ceil(E/8);O===null;)S=r.randomBytes(C),O=f(E,S.toString("hex"),L,j);return O}function d(E){var S,C,L,j=null;for(C=10,L=32,S=Math.ceil(E/32);j===null;)j=f(E,r.getRandomValues(new Uint32Array(S)),C,L);return j}function y(E){var S,C,L,j,O,U=null;j=10,O=32,C=Math.ceil(E/32),L=123456789,S=new Uint32Array(C);for(var M=0;M<S.length;M++)S[M]=L;for(;U===null;)U=f(E,S,j,O);return U}if(l&&l==="testRandom")return s.typeCSPRNG=l,y;if(l&&l==="nodeCryptoRandomBytes")return s.typeCSPRNG=l,u;if(l&&l==="browserCryptoGetRandomValues")return s.typeCSPRNG=l,d;if(k())return s.typeCSPRNG="nodeCryptoRandomBytes",u;if(I())return s.typeCSPRNG="browserCryptoGetRandomValues",d}function R(l,f){var u=[],d;for(f&&(l=x(l,f)),d=l.length;d>s.bits;d-=s.bits)u.push(parseInt(l.slice(d-s.bits,d),2));return u.push(parseInt(l.slice(0,d),2)),u}function m(l,f){var u=s.logs[l],d=0,y;for(y=f.length-1;y>=0;y--)d!==0?d=s.exps[(u+s.logs[d])%s.maxShares]^f[y]:d=f[y];return d}function w(l,f,u){var d=0,y,E,S,C;for(S=0,y=f.length;S<y;S++)if(u[S]){for(E=s.logs[u[S]],C=0;C<y;C++)if(S!==C){if(l===f[C]){E=-1;break}E=(E+s.logs[l^f[C]]-s.logs[f[S]^f[C]]+s.maxShares)%s.maxShares}d=E===-1?d:d^s.exps[E]}return d}function g(l,f,u){var d=[],y=[l],E,S;for(E=1;E<u;E++)y[E]=parseInt(s.rng(s.bits),2);for(E=1,S=f+1;E<S;E++)d[E-1]={x:E,y:m(E,y)};return d}function v(l,f,u){var d,y,E,S,C;if(f=parseInt(f,s.radix),l=parseInt(l,10)||s.bits,d=l.toString(36).toUpperCase(),E=Math.pow(2,l)-1,S=E.toString(s.radix).length,y=x(f.toString(s.radix),S),typeof f!="number"||f%1!==0||f<1||f>E)throw new Error("Share id must be an integer between 1 and "+E+", inclusive.");return C=d+y+u,C}var T={init:function(l,f){var u=[],d=[],y=1,E,S;if(i(),l&&(typeof l!="number"||l%1!==0||l<n.minBits||l>n.maxBits))throw new Error("Number of bits must be an integer between "+n.minBits+" and "+n.maxBits+", inclusive.");if(f&&a.indexOf(f)===-1)throw new Error("Invalid RNG type argument : '"+f+"'");for(s.radix=n.radix,s.bits=l||n.bits,s.size=Math.pow(2,s.bits),s.maxShares=s.size-1,E=n.primitivePolynomials[s.bits],S=0;S<s.size;S++)d[S]=y,u[y]=S,y=y<<1,y>=s.size&&(y=y^E,y=y&s.maxShares);if(s.logs=u,s.exps=d,f&&this.setRNG(f),p()||this.setRNG(),!p()||!s.bits||!s.size||!s.maxShares||!s.logs||!s.exps||s.logs.length!==s.size||s.exps.length!==s.size)throw new Error("Initialization failed.")},combine:function(l,f){var u,d,y,E,S="",C,L,j,O=[],U=[];for(f=f||0,u=0,y=l.length;u<y;u++){if(L=this.extractShareComponents(l[u]),C===void 0)C=L.bits;else if(L.bits!==C)throw new Error("Mismatched shares: Different bit settings.");if(s.bits!==C&&this.init(C),O.indexOf(L.id)===-1)for(O.push(L.id),j=R(h(L.data)),d=0,E=j.length;d<E;d++)U[d]=U[d]||[],U[d][O.length-1]=j[d]}for(u=0,y=U.length;u<y;u++)S=x(w(f,O,U[u]).toString(2))+S;return A(f>=1?S:S.slice(S.indexOf("1")+1))},getConfig:function(){var l={};return l.radix=s.radix,l.bits=s.bits,l.maxShares=s.maxShares,l.hasCSPRNG=p(),l.typeCSPRNG=s.typeCSPRNG,l},extractShareComponents:function(l){var f,u,d,y,E={},S,C;if(f=parseInt(l.substr(0,1),36),f&&(typeof f!="number"||f%1!==0||f<n.minBits||f>n.maxBits))throw new Error("Invalid share : Number of bits must be an integer between "+n.minBits+" and "+n.maxBits+", inclusive.");if(y=Math.pow(2,f)-1,d=(Math.pow(2,f)-1).toString(s.radix).length,S="^([a-kA-K3-9]{1})([a-fA-F0-9]{"+d+"})([a-fA-F0-9]+)$",C=new RegExp(S).exec(l),C&&(u=parseInt(C[2],s.radix)),typeof u!="number"||u%1!==0||u<1||u>y)throw new Error("Invalid share : Share id must be an integer between 1 and "+s.maxShares+", inclusive.");if(C&&C[3])return E.bits=f,E.id=u,E.data=C[3],E;throw new Error("The share data provided is invalid : "+l)},setRNG:function(l){var f="Random number generator is invalid ",u=" Supply an CSPRNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's.";if(l&&typeof l=="string"&&a.indexOf(l)===-1)throw new Error("Invalid RNG type argument : '"+l+"'");if(l||(l=B()),l&&typeof l=="string"&&(l=B(l)),c){if(l&&typeof l!="function")throw new Error(f+"(Not a function)."+u);if(l&&typeof l(s.bits)!="string")throw new Error(f+"(Output is not a string)."+u);if(l&&!parseInt(l(s.bits),2))throw new Error(f+"(Binary string output not parseable to an Integer)."+u);if(l&&l(s.bits).length>s.bits)throw new Error(f+"(Output length is greater than config.bits)."+u);if(l&&l(s.bits).length<s.bits)throw new Error(f+"(Output length is less than config.bits)."+u)}return s.rng=l,!0},str2hex:function(l,f){var u,d,y="",E,S,C,L;if(typeof l!="string")throw new Error("Input must be a character string.");if(f||(f=n.bytesPerChar),typeof f!="number"||f<1||f>n.maxBytesPerChar||f%1!==0)throw new Error("Bytes per character must be an integer between 1 and "+n.maxBytesPerChar+", inclusive.");for(u=2*f,d=Math.pow(16,u)-1,C=0,L=l.length;C<L;C++){if(S=l[C].charCodeAt(),isNaN(S))throw new Error("Invalid character: "+l[C]);if(S>d)throw E=Math.ceil(Math.log(S+1)/Math.log(256)),new Error("Invalid character code ("+S+"). Maximum allowable is 256^bytes-1 ("+d+"). To convert this character, use at least "+E+" bytes.");y=x(S.toString(16),u)+y}return y},hex2str:function(l,f){var u,d="",y,E;if(typeof l!="string")throw new Error("Input must be a hexadecimal string.");if(f=f||n.bytesPerChar,typeof f!="number"||f%1!==0||f<1||f>n.maxBytesPerChar)throw new Error("Bytes per character must be an integer between 1 and "+n.maxBytesPerChar+", inclusive.");for(u=2*f,l=x(l,u),y=0,E=l.length;y<E;y+=u)d=String.fromCharCode(parseInt(l.slice(y,y+u),16))+d;return d},random:function(l){if(typeof l!="number"||l%1!==0||l<2||l>65536)throw new Error("Number of bits must be an Integer between 1 and 65536.");return A(s.rng(l))},share:function(l,f,u,d){var y,E,S=new Array(f),C=new Array(f),L,j,O;if(d=d||128,typeof l!="string")throw new Error("Secret must be a string.");if(typeof f!="number"||f%1!==0||f<2)throw new Error("Number of shares must be an integer between 2 and 2^bits-1 ("+s.maxShares+"), inclusive.");if(f>s.maxShares)throw y=Math.ceil(Math.log(f+1)/Math.LN2),new Error("Number of shares must be an integer between 2 and 2^bits-1 ("+s.maxShares+"), inclusive. To create "+f+" shares, use at least "+y+" bits.");if(typeof u!="number"||u%1!==0||u<2)throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 ("+s.maxShares+"), inclusive.");if(u>s.maxShares)throw y=Math.ceil(Math.log(u+1)/Math.LN2),new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 ("+s.maxShares+"), inclusive. To use a threshold of "+u+", use at least "+y+" bits.");if(u>f)throw new Error("Threshold number of shares was "+u+" but must be less than or equal to the "+f+" shares specified as the total to generate.");if(typeof d!="number"||d%1!==0||d<0||d>1024)throw new Error("Zero-pad length must be an integer between 0 and 1024 inclusive.");for(l="1"+h(l),l=R(l,d),L=0,O=l.length;L<O;L++)for(E=g(l[L],f,u),j=0;j<f;j++)S[j]=S[j]||E[j].x.toString(s.radix),C[j]=x(E[j].y.toString(2))+(C[j]||"");for(L=0;L<f;L++)S[L]=v(s.bits,S[L],A(C[L]));return S},newShare:function(l,f){var u,d;if(l&&typeof l=="string"&&(l=parseInt(l,s.radix)),d=l.toString(s.radix),l&&d&&f&&f[0])return u=this.extractShareComponents(f[0]),v(u.bits,d,this.combine(f,l));throw new Error("Invalid 'id' or 'shares' Array argument to newShare().")},_reset:i,_padLeft:x,_hex2bin:h,_bin2hex:A,_hasCryptoGetRandomValues:I,_hasCryptoRandomBytes:k,_getRNG:B,_isSetRNG:p,_splitNumStringToIntArray:R,_horner:m,_lagrange:w,_getShares:g,_constructPublicShareString:v};return T.init(),T})})(me)),me.exports}var rr=tr();const ft=ut(rr),nr=2,sr=3;function dt(t){if(t.length!==16)throw new Error(`Invalid seed length: expected 16, got ${t.length}`);const e=ht(t),r=ft.share(e,sr,nr);if(r.length!==3)throw new Error(`Unexpected share count: ${r.length}`);const n=ve(r[0]),s=ve(r[1]),o=ve(r[2]);return{shareA:_.toShamirShare(n),shareB:_.toShamirShare(s),shareC:_.toShamirShare(o)}}function or(t,e){const r=Ze(t),n=Ze(e);try{const s=ft.combine([r,n]),o=mt(s);if(o.length!==16)throw new Error(`Reconstructed seed has wrong length: ${o.length}`);return _.toSeed(o)}catch{throw new Error("Failed to reconstruct seed from shares")}}function ht(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function mt(t){if(!/^[0-9a-fA-F]*$/.test(t))throw new Error("Invalid hex string: contains non-hex characters");if(t.length%2!==0)throw new Error(`Invalid hex string: length ${t.length} is odd (must be even)`);const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++)e[r]=parseInt(t.substr(r*2,2),16);return e}function ve(t){const e=t.length%2===0?t:"0"+t;return mt(e)}function Ze(t){const e=ht(t);return e.startsWith("0")&&!e.startsWith("00")?e.substring(1):e}function ir(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function xe(t,...e){if(!ir(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Pe(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ar(t,e){xe(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ne(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Se(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function z(t,e){return t<<32-e|t>>>e}function cr(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function gt(t){return typeof t=="string"&&(t=cr(t)),xe(t),t}class lr{}function ur(t){const e=n=>t().update(gt(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function fr(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);const s=BigInt(32),o=BigInt(4294967295),c=Number(r>>s&o),a=Number(r&o),i=n?4:0,p=n?0:4;t.setUint32(e+i,c,n),t.setUint32(e+p,a,n)}function dr(t,e,r){return t&e^~t&r}function hr(t,e,r){return t&e^t&r^e&r}let mr=class extends lr{constructor(e,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=Se(this.buffer)}update(e){Pe(this),e=gt(e),xe(e);const{view:r,buffer:n,blockLen:s}=this,o=e.length;for(let c=0;c<o;){const a=Math.min(s-this.pos,o-c);if(a===s){const i=Se(e);for(;s<=o-c;c+=s)this.process(i,c);continue}n.set(e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pe(this),ar(e,this),this.finished=!0;const{buffer:r,view:n,blockLen:s,isLE:o}=this;let{pos:c}=this;r[c++]=128,Ne(this.buffer.subarray(c)),this.padOffset>s-c&&(this.process(n,0),c=0);for(let h=c;h<s;h++)r[h]=0;fr(n,s-8,BigInt(this.length*8),o),this.process(n,0);const a=Se(e),i=this.outputLen;if(i%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const p=i/4,x=this.get();if(p>x.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<p;h++)a.setUint32(4*h,x[h],o)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:n,length:s,finished:o,destroyed:c,pos:a}=this;return e.destroyed=c,e.finished=o,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const X=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),gr=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Q=new Uint32Array(64);class pr extends mr{constructor(e=32){super(64,e,8,!1),this.A=X[0]|0,this.B=X[1]|0,this.C=X[2]|0,this.D=X[3]|0,this.E=X[4]|0,this.F=X[5]|0,this.G=X[6]|0,this.H=X[7]|0}get(){const{A:e,B:r,C:n,D:s,E:o,F:c,G:a,H:i}=this;return[e,r,n,s,o,c,a,i]}set(e,r,n,s,o,c,a,i){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=c|0,this.G=a|0,this.H=i|0}process(e,r){for(let h=0;h<16;h++,r+=4)Q[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){const A=Q[h-15],I=Q[h-2],k=z(A,7)^z(A,18)^A>>>3,B=z(I,17)^z(I,19)^I>>>10;Q[h]=B+Q[h-7]+k+Q[h-16]|0}let{A:n,B:s,C:o,D:c,E:a,F:i,G:p,H:x}=this;for(let h=0;h<64;h++){const A=z(a,6)^z(a,11)^z(a,25),I=x+A+dr(a,i,p)+gr[h]+Q[h]|0,B=(z(n,2)^z(n,13)^z(n,22))+hr(n,s,o)|0;x=p,p=i,i=a,a=c+I|0,c=o,o=s,s=n,n=I+B|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,c=c+this.D|0,a=a+this.E|0,i=i+this.F|0,p=p+this.G|0,x=x+this.H|0,this.set(n,s,o,c,a,i,p,x)}roundClean(){Ne(Q)}destroy(){this.set(0,0,0,0,0,0,0,0),Ne(this.buffer)}}const pt=ur(()=>new pr);function bt(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Oe(t,e=""){if(!Number.isSafeInteger(t)||t<0){const r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function V(t,e,r=""){const n=bt(t),s=t?.length,o=e!==void 0;if(!n||o&&s!==e){const c=r&&`"${r}" `,a=o?` of length ${e}`:"",i=n?`length=${s}`:`type=${typeof t}`;throw new Error(c+"expected Uint8Array"+a+", got "+i)}return t}function Ke(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function br(t,e){V(t,void 0,"digestInto() output");const r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Le(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ae(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const wt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wr=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ue(t){if(V(t),wt)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=wr[t[r]];return e}const F={_0:48,_9:57,A:65,F:70,a:97,f:102};function ze(t){if(t>=F._0&&t<=F._9)return t-F._0;if(t>=F.A&&t<=F.F)return t-(F.A-10);if(t>=F.a&&t<=F.f)return t-(F.a-10)}function xt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(wt)return Uint8Array.fromHex(t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){const c=ze(t.charCodeAt(o)),a=ze(t.charCodeAt(o+1));if(c===void 0||a===void 0){const i=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+i+'" at index '+o)}n[s]=c*16+a}return n}function We(...t){let e=0;for(let n=0;n<t.length;n++){const s=t[n];V(s),e+=s.length}const r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){const o=t[n];r.set(o,s),s+=o.length}return r}function xr(t,e={}){const r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function yr(t=32){const e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}const Er=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});class vr{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=Ae(this.buffer)}update(e){Ke(this),V(e);const{view:r,buffer:n,blockLen:s}=this,o=e.length;for(let c=0;c<o;){const a=Math.min(s-this.pos,o-c);if(a===s){const i=Ae(e);for(;s<=o-c;c+=s)this.process(i,c);continue}n.set(e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ke(this),br(e,this),this.finished=!0;const{buffer:r,view:n,blockLen:s,isLE:o}=this;let{pos:c}=this;r[c++]=128,Le(this.buffer.subarray(c)),this.padOffset>s-c&&(this.process(n,0),c=0);for(let h=c;h<s;h++)r[h]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);const a=Ae(e),i=this.outputLen;if(i%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const p=i/4,x=this.get();if(p>x.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<p;h++)a.setUint32(4*h,x[h],o)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:r,buffer:n,length:s,finished:o,destroyed:c,pos:a}=this;return e.destroyed=c,e.finished=o,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const $=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),fe=BigInt(2**32-1),Fe=BigInt(32);function Sr(t,e=!1){return e?{h:Number(t&fe),l:Number(t>>Fe&fe)}:{h:Number(t>>Fe&fe)|0,l:Number(t&fe)|0}}function Ar(t,e=!1){const r=t.length;let n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){const{h:c,l:a}=Sr(t[o],e);[n[o],s[o]]=[c,a]}return[n,s]}const Ye=(t,e,r)=>t>>>r,Xe=(t,e,r)=>t<<32-r|e>>>r,oe=(t,e,r)=>t>>>r|e<<32-r,ie=(t,e,r)=>t<<32-r|e>>>r,de=(t,e,r)=>t<<64-r|e>>>r-32,he=(t,e,r)=>t>>>r-32|e<<64-r;function Y(t,e,r,n){const s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}const Br=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Rr=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,kr=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Cr=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Ir=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Nr=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0,yt=Ar(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Lr=yt[0],jr=yt[1],J=new Uint32Array(80),ee=new Uint32Array(80);class Tr extends vr{constructor(e){super(128,e,16,!1)}get(){const{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:c,Dh:a,Dl:i,Eh:p,El:x,Fh:h,Fl:A,Gh:I,Gl:k,Hh:B,Hl:R}=this;return[e,r,n,s,o,c,a,i,p,x,h,A,I,k,B,R]}set(e,r,n,s,o,c,a,i,p,x,h,A,I,k,B,R){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=c|0,this.Dh=a|0,this.Dl=i|0,this.Eh=p|0,this.El=x|0,this.Fh=h|0,this.Fl=A|0,this.Gh=I|0,this.Gl=k|0,this.Hh=B|0,this.Hl=R|0}process(e,r){for(let g=0;g<16;g++,r+=4)J[g]=e.getUint32(r),ee[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){const v=J[g-15]|0,T=ee[g-15]|0,l=oe(v,T,1)^oe(v,T,8)^Ye(v,T,7),f=ie(v,T,1)^ie(v,T,8)^Xe(v,T,7),u=J[g-2]|0,d=ee[g-2]|0,y=oe(u,d,19)^de(u,d,61)^Ye(u,d,6),E=ie(u,d,19)^he(u,d,61)^Xe(u,d,6),S=kr(f,E,ee[g-7],ee[g-16]),C=Cr(S,l,y,J[g-7],J[g-16]);J[g]=C|0,ee[g]=S|0}let{Ah:n,Al:s,Bh:o,Bl:c,Ch:a,Cl:i,Dh:p,Dl:x,Eh:h,El:A,Fh:I,Fl:k,Gh:B,Gl:R,Hh:m,Hl:w}=this;for(let g=0;g<80;g++){const v=oe(h,A,14)^oe(h,A,18)^de(h,A,41),T=ie(h,A,14)^ie(h,A,18)^he(h,A,41),l=h&I^~h&B,f=A&k^~A&R,u=Ir(w,T,f,jr[g],ee[g]),d=Nr(u,m,v,l,Lr[g],J[g]),y=u|0,E=oe(n,s,28)^de(n,s,34)^de(n,s,39),S=ie(n,s,28)^he(n,s,34)^he(n,s,39),C=n&o^n&a^o&a,L=s&c^s&i^c&i;m=B|0,w=R|0,B=I|0,R=k|0,I=h|0,k=A|0,{h,l:A}=Y(p|0,x|0,d|0,y|0),p=a|0,x=i|0,a=o|0,i=c|0,o=n|0,c=s|0;const j=Br(y,S,L);n=Rr(j,d,E,C),s=j|0}({h:n,l:s}=Y(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:c}=Y(this.Bh|0,this.Bl|0,o|0,c|0),{h:a,l:i}=Y(this.Ch|0,this.Cl|0,a|0,i|0),{h:p,l:x}=Y(this.Dh|0,this.Dl|0,p|0,x|0),{h,l:A}=Y(this.Eh|0,this.El|0,h|0,A|0),{h:I,l:k}=Y(this.Fh|0,this.Fl|0,I|0,k|0),{h:B,l:R}=Y(this.Gh|0,this.Gl|0,B|0,R|0),{h:m,l:w}=Y(this.Hh|0,this.Hl|0,m|0,w|0),this.set(n,s,o,c,a,i,p,x,h,A,I,k,B,R,m,w)}roundClean(){Le(J,ee)}destroy(){Le(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class _r extends Tr{Ah=$[0]|0;Al=$[1]|0;Bh=$[2]|0;Bl=$[3]|0;Ch=$[4]|0;Cl=$[5]|0;Dh=$[6]|0;Dl=$[7]|0;Eh=$[8]|0;El=$[9]|0;Fh=$[10]|0;Fl=$[11]|0;Gh=$[12]|0;Gl=$[13]|0;Hh=$[14]|0;Hl=$[15]|0;constructor(){super(64)}}const Or=xr(()=>new _r,Er(3));const Et=BigInt(0),Qe=BigInt(1);function je(t,e=""){if(typeof t!="boolean"){const r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Ur(t){if(typeof t=="bigint"){if(!ge(t))throw new Error("positive bigint expected, got "+t)}else Oe(t);return t}function vt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Et:BigInt("0x"+t)}function Dr(t){return vt(Ue(t))}function be(t){return vt(Ue(Te(V(t)).reverse()))}function St(t,e){Oe(e),t=Ur(t);const r=xt(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function Mr(t,e){return St(t,e).reverse()}function Te(t){return Uint8Array.from(t)}const ge=t=>typeof t=="bigint"&&Et<=t;function qr(t,e,r){return ge(t)&&ge(e)&&ge(r)&&e<=t&&t<r}function Je(t,e,r,n){if(!qr(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}const Vr=t=>(Qe<<BigInt(t))-Qe;function De(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,c,a){const i=t[o];if(a&&i===void 0)return;const p=typeof i;if(p!==c||i===null)throw new Error(`param "${o}" is invalid: expected ${c}, got ${p}`)}const s=(o,c)=>Object.entries(o).forEach(([a,i])=>n(a,i,c));s(e,!1),s(r,!0)}function et(t){const e=new WeakMap;return(r,...n)=>{const s=e.get(r);if(s!==void 0)return s;const o=t(r,...n);return e.set(r,o),o}}const G=BigInt(0),H=BigInt(1),ne=BigInt(2),At=BigInt(3),Bt=BigInt(4),Rt=BigInt(5),$r=BigInt(7),kt=BigInt(8),Hr=BigInt(9),Ct=BigInt(16);function D(t,e){const r=t%e;return r>=G?r:e+r}function W(t,e,r){let n=t;for(;e-- >G;)n*=n,n%=r;return n}function tt(t,e){if(t===G)throw new Error("invert: expected non-zero number");if(e<=G)throw new Error("invert: expected positive modulus, got "+e);let r=D(t,e),n=e,s=G,o=H;for(;r!==G;){const a=n/r,i=n%r,p=s-o*a;n=r,r=i,s=o,o=p}if(n!==H)throw new Error("invert: does not exist");return D(s,e)}function Me(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function It(t,e){const r=(t.ORDER+H)/Bt,n=t.pow(e,r);return Me(t,n,e),n}function Gr(t,e){const r=(t.ORDER-Rt)/kt,n=t.mul(e,ne),s=t.pow(n,r),o=t.mul(e,s),c=t.mul(t.mul(o,ne),s),a=t.mul(o,t.sub(c,t.ONE));return Me(t,a,e),a}function Zr(t){const e=qe(t),r=Nt(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),c=(t+$r)/Ct;return(a,i)=>{let p=a.pow(i,c),x=a.mul(p,n);const h=a.mul(p,s),A=a.mul(p,o),I=a.eql(a.sqr(x),i),k=a.eql(a.sqr(h),i);p=a.cmov(p,x,I),x=a.cmov(A,h,k);const B=a.eql(a.sqr(x),i),R=a.cmov(p,x,B);return Me(a,R,i),R}}function Nt(t){if(t<At)throw new Error("sqrt is not defined for small field");let e=t-H,r=0;for(;e%ne===G;)e/=ne,r++;let n=ne;const s=qe(t);for(;rt(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return It;let o=s.pow(n,e);const c=(e+H)/ne;return function(i,p){if(i.is0(p))return p;if(rt(i,p)!==1)throw new Error("Cannot find square root");let x=r,h=i.mul(i.ONE,o),A=i.pow(p,e),I=i.pow(p,c);for(;!i.eql(A,i.ONE);){if(i.is0(A))return i.ZERO;let k=1,B=i.sqr(A);for(;!i.eql(B,i.ONE);)if(k++,B=i.sqr(B),k===x)throw new Error("Cannot find square root");const R=H<<BigInt(x-k-1),m=i.pow(h,R);x=k,h=i.sqr(m),A=i.mul(A,h),I=i.mul(I,m)}return I}}function Pr(t){return t%Bt===At?It:t%kt===Rt?Gr:t%Ct===Hr?Zr(t):Nt(t)}const Kr=(t,e)=>(D(t,e)&H)===H,zr=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wr(t){const e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=zr.reduce((n,s)=>(n[s]="function",n),e);return De(t,r),t}function Fr(t,e,r){if(r<G)throw new Error("invalid exponent, negatives unsupported");if(r===G)return t.ONE;if(r===H)return e;let n=t.ONE,s=e;for(;r>G;)r&H&&(n=t.mul(n,s)),s=t.sqr(s),r>>=H;return n}function Lt(t,e,r=!1){const n=new Array(e.length).fill(r?t.ZERO:void 0),s=e.reduce((c,a,i)=>t.is0(a)?c:(n[i]=c,t.mul(c,a)),t.ONE),o=t.inv(s);return e.reduceRight((c,a,i)=>t.is0(a)?c:(n[i]=t.mul(c,n[i]),t.mul(c,a)),o),n}function rt(t,e){const r=(t.ORDER-H)/ne,n=t.pow(e,r),s=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),c=t.eql(n,t.neg(t.ONE));if(!s&&!o&&!c)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function Yr(t,e){e!==void 0&&Oe(e);const r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}class Xr{ORDER;BITS;BYTES;isLE;ZERO=G;ONE=H;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=G)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));const{nBitLength:s,nByteLength:o}=Yr(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return D(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return G<=e&&e<this.ORDER}is0(e){return e===G}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&H)===H}neg(e){return D(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return D(e*e,this.ORDER)}add(e,r){return D(e+r,this.ORDER)}sub(e,r){return D(e-r,this.ORDER)}mul(e,r){return D(e*r,this.ORDER)}pow(e,r){return Fr(this,e,r)}div(e,r){return D(e*tt(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return tt(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=Pr(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?Mr(e,this.BYTES):St(e,this.BYTES)}fromBytes(e,r=!1){V(e);const{_lengths:n,BYTES:s,isLE:o,ORDER:c,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);const p=new Uint8Array(s);p.set(e,o?0:p.length-e.length),e=p}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let i=o?be(e):Dr(e);if(a&&(i=D(i,c)),!r&&!this.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i}invertBatch(e){return Lt(this,e)}cmov(e,r,n){return n?r:e}}function qe(t,e={}){return new Xr(t,e)}const we=BigInt(0),_e=BigInt(1);function nt(t,e){const r=e.negate();return t?r:e}function Be(t,e){const r=Lt(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function jt(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Re(t,e){jt(t,e);const r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,o=Vr(t),c=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:c}}function st(t,e,r){const{windowSize:n,mask:s,maxNumber:o,shiftBy:c}=r;let a=Number(t&s),i=t>>c;a>n&&(a-=o,i+=_e);const p=e*n,x=p+Math.abs(a)-1,h=a===0,A=a<0,I=e%2!==0;return{nextN:i,offset:x,isZero:h,isNeg:A,isNegF:I,offsetF:p}}const ke=new WeakMap,Tt=new WeakMap;function Ce(t){return Tt.get(t)||1}function ot(t){if(t!==we)throw new Error("invalid wNAF")}class Qr{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>we;)r&_e&&(n=n.add(s)),s=s.double(),r>>=_e;return n}precomputeWindow(e,r){const{windows:n,windowSize:s}=Re(r,this.bits),o=[];let c=e,a=c;for(let i=0;i<n;i++){a=c,o.push(a);for(let p=1;p<s;p++)a=a.add(c),o.push(a);c=a.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE;const c=Re(e,this.bits);for(let a=0;a<c.windows;a++){const{nextN:i,offset:p,isZero:x,isNeg:h,isNegF:A,offsetF:I}=st(n,a,c);n=i,x?o=o.add(nt(A,r[I])):s=s.add(nt(h,r[p]))}return ot(n),{p:s,f:o}}wNAFUnsafe(e,r,n,s=this.ZERO){const o=Re(e,this.bits);for(let c=0;c<o.windows&&n!==we;c++){const{nextN:a,offset:i,isZero:p,isNeg:x}=st(n,c,o);if(n=a,!p){const h=r[i];s=s.add(x?h.negate():h)}}return ot(n),s}getPrecomputes(e,r,n){let s=ke.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),ke.set(r,s))),s}cached(e,r,n){const s=Ce(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){const o=Ce(e);return o===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,s)}createCache(e,r){jt(r,this.bits),Tt.set(e,r),ke.delete(e)}hasCache(e){return Ce(e)!==1}}function it(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wr(e),e}else return qe(t,{isLE:r})}function Jr(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const i of["p","n","h"]){const p=e[i];if(!(typeof p=="bigint"&&p>we))throw new Error(`CURVE.${i} must be positive bigint`)}const s=it(e.p,r.Fp,n),o=it(e.n,r.Fn,n),a=["Gx","Gy","a","d"];for(const i of a)if(!s.isValid(e[i]))throw new Error(`CURVE.${i} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function en(t,e){return function(n){const s=t(n);return{secretKey:s,publicKey:e(s)}}}const te=BigInt(0),q=BigInt(1),Ie=BigInt(2),tn=BigInt(8);function rn(t,e,r,n){const s=t.sqr(r),o=t.sqr(n),c=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(c,a)}function nn(t,e={}){const r=Jr("edwards",t,e,e.FpFnLE),{Fp:n,Fn:s}=r;let o=r.CURVE;const{h:c}=o;De(e,{},{uvRatio:"function"});const a=Ie<<BigInt(s.BYTES*8)-q,i=R=>n.create(R),p=e.uvRatio||((R,m)=>{try{return{isValid:!0,value:n.sqrt(n.div(R,m))}}catch{return{isValid:!1,value:te}}});if(!rn(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function x(R,m,w=!1){const g=w?q:te;return Je("coordinate "+R,m,g,a),m}function h(R){if(!(R instanceof k))throw new Error("EdwardsPoint expected")}const A=et((R,m)=>{const{X:w,Y:g,Z:v}=R,T=R.is0();m==null&&(m=T?tn:n.inv(v));const l=i(w*m),f=i(g*m),u=n.mul(v,m);if(T)return{x:te,y:q};if(u!==q)throw new Error("invZ was invalid");return{x:l,y:f}}),I=et(R=>{const{a:m,d:w}=o;if(R.is0())throw new Error("bad point: ZERO");const{X:g,Y:v,Z:T,T:l}=R,f=i(g*g),u=i(v*v),d=i(T*T),y=i(d*d),E=i(f*m),S=i(d*i(E+u)),C=i(y+i(w*i(f*u)));if(S!==C)throw new Error("bad point: equation left != right (1)");const L=i(g*v),j=i(T*l);if(L!==j)throw new Error("bad point: equation left != right (2)");return!0});class k{static BASE=new k(o.Gx,o.Gy,q,i(o.Gx*o.Gy));static ZERO=new k(te,q,q,te);static Fp=n;static Fn=s;X;Y;Z;T;constructor(m,w,g,v){this.X=x("x",m),this.Y=x("y",w),this.Z=x("z",g,!0),this.T=x("t",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){if(m instanceof k)throw new Error("extended point not allowed");const{x:w,y:g}=m||{};return x("x",w),x("y",g),new k(w,g,q,i(w*g))}static fromBytes(m,w=!1){const g=n.BYTES,{a:v,d:T}=o;m=Te(V(m,g,"point")),je(w,"zip215");const l=Te(m),f=m[g-1];l[g-1]=f&-129;const u=be(l),d=w?a:n.ORDER;Je("point.y",u,te,d);const y=i(u*u),E=i(y-q),S=i(T*y-v);let{isValid:C,value:L}=p(E,S);if(!C)throw new Error("bad point: invalid y coordinate");const j=(L&q)===q,O=(f&128)!==0;if(!w&&L===te&&O)throw new Error("bad point: x=0 and x_0=1");return O!==j&&(L=i(-L)),k.fromAffine({x:L,y:u})}static fromHex(m,w=!1){return k.fromBytes(xt(m),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return B.createCache(this,m),w||this.multiply(Ie),this}assertValidity(){I(this)}equals(m){h(m);const{X:w,Y:g,Z:v}=this,{X:T,Y:l,Z:f}=m,u=i(w*f),d=i(T*v),y=i(g*f),E=i(l*v);return u===d&&y===E}is0(){return this.equals(k.ZERO)}negate(){return new k(i(-this.X),this.Y,this.Z,i(-this.T))}double(){const{a:m}=o,{X:w,Y:g,Z:v}=this,T=i(w*w),l=i(g*g),f=i(Ie*i(v*v)),u=i(m*T),d=w+g,y=i(i(d*d)-T-l),E=u+l,S=E-f,C=u-l,L=i(y*S),j=i(E*C),O=i(y*C),U=i(S*E);return new k(L,j,U,O)}add(m){h(m);const{a:w,d:g}=o,{X:v,Y:T,Z:l,T:f}=this,{X:u,Y:d,Z:y,T:E}=m,S=i(v*u),C=i(T*d),L=i(f*g*E),j=i(l*y),O=i((v+T)*(u+d)-S-C),U=j-L,M=j+L,P=i(C-w*S),se=i(O*U),le=i(M*P),ae=i(O*P),ue=i(U*M);return new k(se,le,ue,ae)}subtract(m){return this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:w,f:g}=B.cached(this,m,v=>Be(k,v));return Be(k,[w,g])[0]}multiplyUnsafe(m,w=k.ZERO){if(!s.isValid(m))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return m===te?k.ZERO:this.is0()||m===q?this:B.unsafe(this,m,g=>Be(k,g),w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return B.unsafe(this,o.n).is0()}toAffine(m){return A(this,m)}clearCofactor(){return c===q?this:this.multiplyUnsafe(c)}toBytes(){const{x:m,y:w}=this.toAffine(),g=n.toBytes(w);return g[g.length-1]|=m&q?128:0,g}toHex(){return Ue(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const B=new Qr(k,s.BITS);return k.BASE.precompute(8),k}function sn(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');De(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:n}=r,{BASE:s,Fp:o,Fn:c}=t,a=r.randomBytes||yr,i=r.adjustScalarBytes||(u=>u),p=r.domain||((u,d,y)=>{if(je(y,"phflag"),d.length||y)throw new Error("Contexts/pre-hash are not supported");return u});function x(u){return c.create(be(u))}function h(u){const d=g.secretKey;V(u,g.secretKey,"secretKey");const y=V(e(u),2*d,"hashedSecretKey"),E=i(y.slice(0,d)),S=y.slice(d,2*d),C=x(E);return{head:E,prefix:S,scalar:C}}function A(u){const{head:d,prefix:y,scalar:E}=h(u),S=s.multiply(E),C=S.toBytes();return{head:d,prefix:y,scalar:E,point:S,pointBytes:C}}function I(u){return A(u).pointBytes}function k(u=Uint8Array.of(),...d){const y=We(...d);return x(e(p(y,V(u,void 0,"context"),!!n)))}function B(u,d,y={}){u=V(u,void 0,"message"),n&&(u=n(u));const{prefix:E,scalar:S,pointBytes:C}=A(d),L=k(y.context,E,u),j=s.multiply(L).toBytes(),O=k(y.context,j,C,u),U=c.create(L+O*S);if(!c.isValid(U))throw new Error("sign failed: invalid s");const M=We(j,c.toBytes(U));return V(M,g.signature,"result")}const R={zip215:!0};function m(u,d,y,E=R){const{context:S,zip215:C}=E,L=g.signature;u=V(u,L,"signature"),d=V(d,void 0,"message"),y=V(y,g.publicKey,"publicKey"),C!==void 0&&je(C,"zip215"),n&&(d=n(d));const j=L/2,O=u.subarray(0,j),U=be(u.subarray(j,L));let M,P,se;try{M=t.fromBytes(y,C),P=t.fromBytes(O,C),se=s.multiplyUnsafe(U)}catch{return!1}if(!C&&M.isSmallOrder())return!1;const le=k(S,P.toBytes(),M.toBytes(),d);return P.add(M.multiplyUnsafe(le)).subtract(se).clearCofactor().is0()}const w=o.BYTES,g={secretKey:w,publicKey:w,signature:2*w,seed:w};function v(u=a(g.seed)){return V(u,g.seed,"seed")}function T(u){return bt(u)&&u.length===c.BYTES}function l(u,d){try{return!!t.fromBytes(u,d)}catch{return!1}}const f={getExtendedPublicKey:A,randomSecretKey:v,isValidSecretKey:T,isValidPublicKey:l,toMontgomery(u){const{y:d}=t.fromBytes(u),y=g.publicKey,E=y===32;if(!E&&y!==57)throw new Error("only defined for 25519 and 448");const S=E?o.div(q+d,q-d):o.div(d-q,d+q);return o.toBytes(S)},toMontgomerySecret(u){const d=g.secretKey;V(u,d);const y=e(u.subarray(0,d));return i(y).subarray(0,d)}};return Object.freeze({keygen:en(v,I),getPublicKey:I,sign:B,verify:m,utils:f,Point:t,lengths:g})}const on=BigInt(1),at=BigInt(2),an=BigInt(5),cn=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ln={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cn,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function un(t){const e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=Ve,a=t*t%o*t%o,i=W(a,at,o)*a%o,p=W(i,on,o)*t%o,x=W(p,an,o)*p%o,h=W(x,e,o)*x%o,A=W(h,r,o)*h%o,I=W(A,n,o)*A%o,k=W(I,s,o)*I%o,B=W(k,s,o)*I%o,R=W(B,e,o)*x%o;return{pow_p_5_8:W(R,at,o)*t%o,b2:a}}function fn(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const ct=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function dn(t,e){const r=Ve,n=D(e*e*e,r),s=D(n*n*e,r),o=un(t*s).pow_p_5_8;let c=D(t*n*o,r);const a=D(e*c*c,r),i=c,p=D(c*ct,r),x=a===t,h=a===D(-t,r),A=a===D(-t*ct,r);return x&&(c=i),(h||A)&&(c=p),Kr(c,r)&&(c=D(-c,r)),{isValid:x||h,value:c}}const hn=nn(ln,{uvRatio:dn});function mn(t){return sn(hn,Or,Object.assign({adjustScalarBytes:fn},t))}const gn=mn({}),pn=pt,bn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function wn(t){if(t.length!==16)throw new Error(`Invalid seed length: expected 16, got ${t.length}`);const e=pn(t),r=gn.getPublicKey(e),n=new Uint8Array(64);return n.set(e,0),n.set(r,32),_.wipeBytes(e),{publicKey:r,secretKey:n}}function _t(t){const e=wn(t),r=e.publicKey;return _.wipeBytes(e.secretKey),r}function Ot(t){if(t.length!==32)throw new Error(`Invalid public key length: expected 32, got ${t.length}`);return xn(t)}function xn(t){let e=0;for(let s=0;s<t.length&&t[s]===0;s++)e++;let r=0n;for(let s=0;s<t.length;s++)r=r*256n+BigInt(t[s]);let n="";for(;r>0n;){const s=Number(r%58n);n=bn[s]+n,r=r/58n}return"1".repeat(e)+n}const yn=["https:"],Ut=["javascript:","data:","vbscript:","file:"];function En(t){if(!t||typeof t!="string")return;const e=t.trim();if(!e)return;const r=e.toLowerCase();for(const n of Ut)if(r.startsWith(n))return;try{const n=new URL(e);return yn.includes(n.protocol)?e:void 0}catch{return}}function Dt(t){if(!t||typeof t!="string")return;const e=t.trim();if(!e)return;const r=e.toLowerCase();for(const n of Ut)if(r.startsWith(n))return;try{const n=new URL(e);return n.protocol!=="https:"&&n.protocol!=="http:"?void 0:e}catch{return}}async function vn(t){const{password:e,serverUrl:r,accessToken:n,timeoutMs:s=3e4}=t,o=[];try{const c=_.generateSeed();o.push(c);const{shareA:a,shareB:i}=dt(c);o.push(a,i);const p=_.generateArgon2Salt(),x=await lt(e,p,_.DEFAULT_KDF_PARAMS);o.push(x);const h=await _.aesGcmEncryptToBase64(a,_.toEncryptionKey(x)),A=_t(c),I=Ot(A),k={solanaPubkey:I,shareAAuthMethod:"password",shareACiphertext:h.ciphertext,shareANonce:h.nonce,shareB:_.uint8ArrayToBase64(i),shareAKdfSalt:_.uint8ArrayToBase64(p),shareAKdfParams:_.DEFAULT_KDF_PARAMS,recoveryData:_.uint8ArrayToBase64(c)};return await new _.ApiClient({baseUrl:r,timeoutMs:s,getAccessToken:n?()=>n:void 0}).post("/wallet/enroll",k),{success:!0,solanaPubkey:I}}catch(c){const a=c instanceof Error?c.message:"Wallet enrollment failed";return console.warn("[silentWalletEnroll] Failed:",a),{success:!1,error:a}}finally{_.wipeAll(...o)}}function ye(t={}){const{maxAttempts:e=5,windowMs:r=6e4}=t,n=N.useRef([]),[s,o]=N.useState(!1),[,c]=N.useState(0),a=N.useCallback(()=>{c(B=>B+1)},[]),i=N.useCallback(()=>{const B=Date.now();n.current=n.current.filter(R=>B-R<r)},[r]),p=N.useCallback(()=>{i(),o(B=>n.current.length===0&&B?!1:B)},[i]),x=N.useCallback(()=>(i(),Math.max(0,e-n.current.length)),[i,e]),h=N.useCallback(()=>{if(i(),n.current.length===0)return 0;const R=n.current[0]+r;return Math.max(0,R-Date.now())},[i,r]),A=N.useCallback(()=>(i(),n.current.length<e),[i,e]),I=N.useCallback(()=>{if(p(),n.current.length>=e){const B=h(),R=Math.ceil(B/1e3);throw new Error(`Too many attempts. Please wait ${R} second${R===1?"":"s"} before trying again.`)}n.current.push(Date.now()),o(B=>B||!0),a()},[p,e,h,a]),k=N.useCallback(()=>{n.current=[],o(B=>B&&!1),a()},[a]);return N.useEffect(()=>{if(!s)return;const B=window.setInterval(()=>{p(),a()},1e3);return()=>{window.clearInterval(B)}},[s,a,p]),{checkLimit:I,isAllowed:A,getRemainingAttempts:x,getTimeUntilReset:h,reset:k}}function Sn(t){return"mfaRequired"in t&&t.mfaRequired===!0}function $e(){const{config:t,_internal:e}=_.useCedrosLogin(),[r,n]=N.useState(!1),[s,o]=N.useState(null),{checkLimit:c,getRemainingAttempts:a,getTimeUntilReset:i,reset:p}=ye({maxAttempts:5,windowMs:6e4}),x=N.useMemo(()=>new _.ApiClient({baseUrl:t.serverUrl,timeoutMs:t.requestTimeout,retryAttempts:t.retryAttempts}),[t.serverUrl,t.requestTimeout,t.retryAttempts]),h=t.callbacks,A=t.features?.walletEnrollment!==!1,I=t.serverUrl,k=N.useCallback(async(m,w)=>{if(!pe.validateEmail(m)){const g={code:"VALIDATION_ERROR",message:"Please enter a valid email address"};throw o(g),g}try{c()}catch(g){const v={code:"RATE_LIMITED",message:g instanceof Error?g.message:"Too many attempts"};throw o(v),v}n(!0),o(null);try{const g=await x.post("/login",{email:m,password:w});if(Sn(g))return{mfaRequired:!0,mfaToken:g.mfaToken,email:m,userId:g.userId};const v=g;return h?.onLoginSuccess?.(v.user,"email"),e?.handleLoginSuccess(v.user,v.tokens),p(),{mfaRequired:!1,response:v}}catch(g){const v=_.handleApiError(g,"Login failed");throw o(v),v}finally{n(!1)}},[x,h,e,c,p]),B=N.useCallback(async(m,w,g)=>{if(!pe.validateEmail(m)){const v={code:"VALIDATION_ERROR",message:"Please enter a valid email address"};throw o(v),v}try{c()}catch(v){const T={code:"RATE_LIMITED",message:v instanceof Error?v.message:"Too many attempts"};throw o(T),T}n(!0),o(null);try{const v=await x.post("/register",{email:m,password:w,name:g});if(h?.onLoginSuccess?.(v.user,"email"),e?.handleLoginSuccess(v.user,v.tokens),p(),A){const T=v.tokens?.accessToken??"";vn({password:w,serverUrl:I,accessToken:T}).then(l=>{l.success?console.log("[useEmailAuth] Wallet auto-enrolled:",l.solanaPubkey):console.warn("[useEmailAuth] Wallet auto-enrollment failed:",l.error)})}return v}catch(v){const T=_.handleApiError(v,"Registration failed");throw o(T),T}finally{n(!1)}},[x,h,e,c,p,I,A]),R=N.useCallback(()=>o(null),[]);return{login:k,register:B,isLoading:r,error:s,clearError:R,remainingAttempts:a(),timeUntilReset:i()}}function An(t){return typeof t=="object"&&t!==null&&"mfaRequired"in t&&t.mfaRequired===!0}function Mt(){const{config:t,_internal:e}=_.useCedrosLogin(),[r,n]=N.useState(!1),[s,o]=N.useState(!1),[c,a]=N.useState(null),i=N.useMemo(()=>new _.ApiClient({baseUrl:t.serverUrl,timeoutMs:t.requestTimeout,retryAttempts:t.retryAttempts}),[t.serverUrl,t.requestTimeout,t.retryAttempts]),{checkLimit:p,getRemainingAttempts:x}=ye({maxAttempts:3,windowMs:3e5}),h=N.useCallback(async B=>{if(!pe.validateEmail(B)){const R={code:"VALIDATION_ERROR",message:"Please enter a valid email address"};throw a(R),R}try{p()}catch(R){const m={code:"RATE_LIMITED",message:R instanceof Error?R.message:"Too many attempts"};throw a(m),m}n(!0),a(null),o(!1);try{await i.post("/instant-link",{email:B}),o(!0)}catch(R){const m=_.handleApiError(R,"Failed to send sign-in link");throw a(m),m}finally{n(!1)}},[i,p]),A=N.useCallback(async B=>{if(!B||B.trim().length===0){const R={code:"VALIDATION_ERROR",message:"Invalid or missing sign-in link token"};throw a(R),R}n(!0),a(null),o(!1);try{const R=await i.post("/instant-link/verify",{token:B});return An(R)||(t.callbacks?.onLoginSuccess?.(R.user,"email"),e?.handleLoginSuccess(R.user,R.tokens)),R}catch(R){const m=_.handleApiError(R,"Failed to verify sign-in link");throw a(m),m}finally{n(!1)}},[i,t.callbacks,e]),I=N.useCallback(()=>a(null),[]),k=N.useCallback(()=>{a(null),o(!1),n(!1)},[]);return{sendInstantLink:h,verifyInstantLink:A,isLoading:r,isSuccess:s,error:c,clearError:I,reset:k,remainingAttempts:x()}}function He({label:t="Password",labelAction:e,showStrengthMeter:r=!1,onValidationChange:n,error:s,className:o="",onChange:c,value:a,...i}){const[p,x]=N.useState(!1),[h,A]=N.useState(null),I=N.useId(),k=R=>{const m=R.target.value;if(r||n){const w=pe.validatePassword(m);A(w),n?.(w)}c?.(R)},B={weak:"var(--cedros-destructive, #ef4444)",fair:"var(--cedros-warning, #f59e0b)",good:"var(--cedros-success, #22c55e)",strong:"var(--cedros-success, #22c55e)"};return b.jsxs("div",{className:`cedros-password-input ${o}`,children:[b.jsxs("div",{className:"cedros-label-row",children:[b.jsx("label",{htmlFor:I,className:"cedros-label",children:t}),e]}),b.jsxs("div",{className:"cedros-password-wrapper",children:[b.jsx("input",{id:I,type:p?"text":"password",className:"cedros-input",onChange:k,value:a,"aria-invalid":s?"true":void 0,"aria-describedby":s?`${I}-error`:void 0,...i}),b.jsx("button",{type:"button",className:"cedros-password-toggle",onClick:()=>x(!p),"aria-label":p?"Hide password":"Show password","aria-pressed":p,children:p?b.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:[b.jsx("path",{d:"M2.5 10s3-6 7.5-6 7.5 6 7.5 6-3 6-7.5 6-7.5-6-7.5-6z",stroke:"currentColor",strokeWidth:"1.5"}),b.jsx("circle",{cx:"10",cy:"10",r:"2.5",stroke:"currentColor",strokeWidth:"1.5"}),b.jsx("path",{d:"M3 17L17 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):b.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:[b.jsx("path",{d:"M2.5 10s3-6 7.5-6 7.5 6 7.5 6-3 6-7.5 6-7.5-6-7.5-6z",stroke:"currentColor",strokeWidth:"1.5"}),b.jsx("circle",{cx:"10",cy:"10",r:"2.5",stroke:"currentColor",strokeWidth:"1.5"})]})})]}),s&&b.jsx("p",{id:`${I}-error`,className:"cedros-input-error",children:s}),r&&h&&a?.length>0&&b.jsxs("div",{className:"cedros-password-strength",children:[b.jsx("div",{className:"cedros-strength-bar",children:b.jsx("div",{className:"cedros-strength-fill",style:{width:`${h.strength==="weak"?25:h.strength==="fair"?50:h.strength==="good"?75:100}%`,backgroundColor:B[h.strength]}})}),b.jsx("span",{className:"cedros-strength-label",children:h.strength})]})]})}function qt(){const{config:t,_internal:e}=_.useCedrosLogin(),[r,n]=N.useState("idle"),[s,o]=N.useState(!1),[c,a]=N.useState(null),{checkLimit:i,getRemainingAttempts:p,getTimeUntilReset:x,reset:h}=ye({maxAttempts:5,windowMs:12e4}),A=N.useMemo(()=>new _.ApiClient({baseUrl:t.serverUrl,timeoutMs:t.requestTimeout,retryAttempts:t.retryAttempts}),[t.serverUrl,t.requestTimeout,t.retryAttempts]),I=N.useCallback(async(R,m)=>{const w=/^[A-Z0-9]{16}$/i.test(m)||/^[A-Z0-9]{4}(-[A-Z0-9]{4}){3}$/i.test(m);if(!(/^\d{6}$/.test(m)||w)){const v={code:"VALIDATION_ERROR",message:"Please enter a valid 6-digit code or recovery code"};throw a(v),v}try{i()}catch(v){const T={code:"RATE_LIMITED",message:v instanceof Error?v.message:"Too many attempts"};throw a(T),T}o(!0),a(null),n("verifying");try{const v=await A.post("/login/mfa",{mfaToken:R,code:m});return n("success"),h(),e&&v.user&&v.tokens&&e.handleLoginSuccess(v.user,v.tokens),v}catch(v){const T=_.handleApiError(v,"Invalid verification code");throw a(T),n("error"),T}finally{o(!1)}},[A,e,i,h]),k=N.useCallback(()=>a(null),[]),B=N.useCallback(()=>{a(null),n("idle"),o(!1)},[]);return{state:r,isLoading:s,error:c,verifyTotp:I,clearError:k,reset:B,remainingAttempts:p(),timeUntilReset:x()}}const K=6;function Vt({value:t="",onChange:e,onComplete:r,disabled:n=!1,error:s,autoFocus:o=!1,className:c=""}){const a=N.useRef([]),[i,p]=N.useState(t.padEnd(K,"")),x=N.useId();N.useEffect(()=>{p(t.padEnd(K,""))},[t]);const h=N.useCallback(m=>{m>=0&&m<K&&a.current[m]?.focus()},[]),A=N.useCallback(m=>{const w=m.replace(/\D/g,"").slice(0,K);p(w.padEnd(K,"")),e?.(w),w.length===K&&r?.(w)},[e,r]),I=N.useCallback((m,w)=>{if(!/^\d?$/.test(w))return;const g=i.split("");g[m]=w;const v=g.join("").replace(/ /g,"");A(v),w&&m<K-1&&h(m+1)},[i,A,h]),k=N.useCallback((m,w)=>{if(w.key==="Backspace"){w.preventDefault();const g=i.split("");g[m]&&g[m]!==" "?(g[m]=" ",A(g.join("").replace(/ /g,""))):m>0&&(g[m-1]=" ",A(g.join("").replace(/ /g,"")),h(m-1))}else w.key==="ArrowLeft"&&m>0?(w.preventDefault(),h(m-1)):w.key==="ArrowRight"&&m<K-1&&(w.preventDefault(),h(m+1))},[i,A,h]),B=N.useCallback(m=>{m.preventDefault();const g=m.clipboardData.getData("text").replace(/\D/g,"").slice(0,K);g&&(A(g),h(Math.min(g.length,K-1)))},[A,h]),R=N.useCallback(m=>{m.target.select()},[]);return N.useEffect(()=>{o&&!n&&a.current[0]?.focus()},[o,n]),b.jsxs("div",{className:`cedros-otp-input ${c}`,children:[b.jsx("div",{className:"cedros-otp-slots",role:"group","aria-label":"One-time password",children:Array.from({length:K}).map((m,w)=>b.jsx("input",{ref:g=>{a.current[w]=g},id:`${x}-${w}`,type:"text",inputMode:"numeric",pattern:"[0-9]*",maxLength:1,className:`cedros-otp-slot ${s?"cedros-otp-slot-error":""}`,value:i[w]===" "?"":i[w]||"",onChange:g=>I(w,g.target.value),onKeyDown:g=>k(w,g),onPaste:B,onFocus:R,disabled:n,autoComplete:"one-time-code","aria-label":`Digit ${w+1}`,"aria-invalid":s?"true":void 0},w))}),s&&b.jsx("p",{className:"cedros-otp-error",role:"alert",children:s})]})}function $t({mfaToken:t,email:e,onSuccess:r,onBack:n,className:s=""}){const{verifyTotp:o,isLoading:c,error:a,clearError:i}=qt(),[p,x]=N.useState(""),[h,A]=N.useState(!1),[I,k]=N.useState(""),B=async w=>{const g=w||(h?I:p);if(g)try{await o(t,g),r?.()}catch{h?k(""):x("")}},R=w=>{B(w)},m=()=>{A(!h),i(),x(""),k("")};return b.jsxs("div",{className:`cedros-totp-verify ${s}`,children:[b.jsxs("div",{className:"cedros-totp-verify-header",children:[b.jsxs("svg",{className:"cedros-totp-verify-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[b.jsx("rect",{x:"8",y:"20",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),b.jsx("path",{d:"M16 20V14a8 8 0 1 1 16 0v6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),b.jsx("circle",{cx:"24",cy:"32",r:"3",fill:"currentColor"})]}),b.jsx("h3",{className:"cedros-totp-title",children:"Two-factor authentication"}),b.jsx("p",{className:"cedros-totp-description",children:h?"Enter one of your recovery codes to sign in.":"Enter the 6-digit code from your authenticator app."}),e&&b.jsx("p",{className:"cedros-totp-email",children:e})]}),h?b.jsxs("div",{className:"cedros-totp-backup-input",children:[b.jsx("input",{type:"text",className:`cedros-input ${a?"cedros-input-error":""}`,placeholder:"Enter recovery code",value:I,onChange:w=>{k(w.target.value.toUpperCase()),i()},onKeyDown:w=>{w.key==="Enter"&&I&&B()},disabled:c,autoFocus:!0,autoComplete:"one-time-code"}),a&&b.jsx("p",{className:"cedros-input-error",role:"alert",children:a.message})]}):b.jsx(Vt,{value:p,onChange:w=>{x(w),i()},onComplete:R,disabled:c,error:a?.message,autoFocus:!0}),b.jsx("button",{type:"button",className:"cedros-button cedros-button-primary cedros-button-md cedros-button-full",onClick:()=>B(),disabled:c||(h?!I:p.length!==6),children:c?b.jsxs(b.Fragment,{children:[b.jsx(_.LoadingSpinner,{size:"sm"}),b.jsx("span",{children:"Verifying..."})]}):"Verify"}),b.jsxs("div",{className:"cedros-totp-verify-footer",children:[b.jsx("button",{type:"button",className:"cedros-link cedros-link-sm",onClick:m,disabled:c,children:h?"Use authenticator app":"Use a recovery code"}),n&&b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"cedros-totp-verify-divider",children:"•"}),b.jsx("button",{type:"button",className:"cedros-link cedros-link-sm",onClick:n,disabled:c,children:"Back to login"})]})]})]})}function Bn({onSuccess:t,onSwitchToRegister:e,onForgotPassword:r,className:n=""}){const{config:s}=_.useCedrosLogin(),{login:o,isLoading:c,error:a,clearError:i}=$e(),{sendInstantLink:p,isLoading:x,isSuccess:h,error:A,clearError:I,reset:k}=Mt(),[B,R]=N.useState(""),[m,w]=N.useState(""),[g,v]=N.useState(null),[T,l]=N.useState(""),f=s.forms?.forgotPassword?.mode??"reset",u=async j=>{j.preventDefault();try{const O=await o(B,m);O.mfaRequired?(v(O.mfaToken),l(O.email)):t?.()}catch{}},d=()=>{v(null),l(""),t?.()},y=()=>{v(null),l(""),w("")},E=async()=>{if(f==="instantLink")try{await p(B)}catch{}else r?.()};if(g)return b.jsx($t,{mfaToken:g,email:T,onSuccess:d,onBack:y,className:n});if(h)return b.jsxs("div",{className:`cedros-instant-link-success ${n}`,children:[b.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[b.jsx("circle",{cx:"24",cy:"24",r:"22",stroke:"currentColor",strokeWidth:"2"}),b.jsx("path",{d:"M14 24l7 7 13-13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),b.jsx("h3",{className:"cedros-success-title",children:"Check your email"}),b.jsxs("p",{className:"cedros-success-message",children:["We sent a sign-in link to ",b.jsx("strong",{children:B}),". Click the link to sign in."]}),b.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-outline",onClick:k,children:"Back to login"})]});const S=a||A,C=()=>{i(),I()},L=c||x;return b.jsxs("form",{onSubmit:u,className:`cedros-form ${n}`,children:[b.jsxs("div",{className:"cedros-form-field",children:[b.jsx("label",{htmlFor:"email",className:"cedros-label",children:"Email"}),b.jsx("input",{id:"email",type:"email",className:"cedros-input",value:B,onChange:j=>R(j.target.value),placeholder:"you@example.com",required:!0,"aria-required":"true",autoComplete:"email",disabled:L})]}),b.jsx("div",{className:"cedros-form-field",children:b.jsx(He,{value:m,onChange:j=>w(j.target.value),placeholder:"Enter your password",required:!0,autoComplete:"current-password",disabled:L,labelAction:r||f==="instantLink"?b.jsx("button",{type:"button",className:"cedros-link cedros-link-sm",onClick:E,disabled:x,children:x?"Sending...":"Forgot your password?"}):void 0})}),b.jsx(_.ErrorMessage,{error:S,onDismiss:C}),b.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary cedros-button-md cedros-button-full",disabled:L||!B||!m,"aria-busy":c,children:c?b.jsxs(b.Fragment,{children:[b.jsx(_.LoadingSpinner,{size:"sm",announce:!0,label:"Signing in"}),b.jsx("span",{children:"Signing in..."})]}):"Sign in"}),e&&b.jsxs("p",{className:"cedros-form-footer",children:["Don't have an account?"," ",b.jsx("button",{type:"button",className:"cedros-link",onClick:e,children:"Sign up"})]})]})}function Rn({onSuccess:t,onSwitchToLogin:e,className:r=""}){const{config:n}=_.useCedrosLogin(),{register:s,isLoading:o,error:c,clearError:a}=$e(),[i,p]=N.useState(""),[x,h]=N.useState(""),[A,I]=N.useState(""),[k,B]=N.useState(""),[R,m]=N.useState(null),[w,g]=N.useState(null),v=n.forms?.termsOfService,T=n.forms?.emailOptIn,l=v?.show??!1,f=v?.required??!0,u=v?.defaultChecked??!1,d=v?.label??"I agree to the Terms of Service",y=v?.url,E=Dt(y),S=T?.show??!1,C=T?.defaultChecked??!1,L=T?.label??"Send me updates and news",[j,O]=N.useState(u),[U,M]=N.useState(C),P=A===k,se=R?.isValid??!1,ae=x&&A&&k&&P&&se&&(!l||!f||j)&&!o,ue=async Z=>{if(Z.preventDefault(),g(null),l&&f&&!j){g({code:"VALIDATION_ERROR",message:"You must agree to the Terms of Service to continue"});return}if(ae)try{await s(x,A,i||void 0),t?.()}catch{}},Ht=c||w,Gt=()=>{a(),g(null)};return b.jsxs("form",{onSubmit:ue,className:`cedros-form ${r}`,children:[b.jsxs("div",{className:"cedros-form-field",children:[b.jsxs("label",{htmlFor:"name",className:"cedros-label",children:["Name ",b.jsx("span",{className:"cedros-optional",children:"(optional)"})]}),b.jsx("input",{id:"name",type:"text",className:"cedros-input",value:i,onChange:Z=>p(Z.target.value),placeholder:"Your name",autoComplete:"name",disabled:o})]}),b.jsxs("div",{className:"cedros-form-field",children:[b.jsx("label",{htmlFor:"register-email",className:"cedros-label",children:"Email"}),b.jsx("input",{id:"register-email",type:"email",className:"cedros-input",value:x,onChange:Z=>h(Z.target.value),placeholder:"you@example.com",required:!0,"aria-required":"true",autoComplete:"email",disabled:o})]}),b.jsx("div",{className:"cedros-form-field",children:b.jsx(He,{value:A,onChange:Z=>I(Z.target.value),placeholder:"Create a password",required:!0,autoComplete:"new-password",disabled:o,showStrengthMeter:!0,onValidationChange:m})}),b.jsxs("div",{className:"cedros-form-field",children:[b.jsx("label",{htmlFor:"confirm-password",className:"cedros-label",children:"Confirm Password"}),b.jsx("input",{id:"confirm-password",type:"password",className:"cedros-input",value:k,onChange:Z=>B(Z.target.value),placeholder:"Confirm your password",required:!0,"aria-required":"true",autoComplete:"new-password",disabled:o,"aria-invalid":k&&!P?"true":void 0,"aria-describedby":k&&!P?"confirm-password-error":void 0}),k&&!P&&b.jsx("p",{id:"confirm-password-error",className:"cedros-input-error",role:"alert",children:"Passwords do not match"})]}),l&&b.jsx("div",{className:"cedros-form-field cedros-checkbox-field",children:b.jsxs("label",{className:"cedros-checkbox-label",children:[b.jsx("input",{type:"checkbox",className:"cedros-checkbox",checked:j,onChange:Z=>O(Z.target.checked),disabled:o,"aria-required":f}),b.jsxs("span",{className:"cedros-checkbox-text",children:[E?b.jsxs(b.Fragment,{children:[d.replace("Terms of Service","").trim()||"I agree to the"," ",b.jsx("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:"cedros-link",children:"Terms of Service"})]}):d,f&&b.jsx("span",{className:"cedros-required",children:"*"})]})]})}),S&&b.jsx("div",{className:"cedros-form-field cedros-checkbox-field",children:b.jsxs("label",{className:"cedros-checkbox-label",children:[b.jsx("input",{type:"checkbox",className:"cedros-checkbox",checked:U,onChange:Z=>M(Z.target.checked),disabled:o}),b.jsx("span",{className:"cedros-checkbox-text",children:L})]})}),b.jsx(_.ErrorMessage,{error:Ht,onDismiss:Gt}),b.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary cedros-button-md cedros-button-full",disabled:!ae,"aria-busy":o,children:o?b.jsxs(b.Fragment,{children:[b.jsx(_.LoadingSpinner,{size:"sm",announce:!0,label:"Creating account"}),b.jsx("span",{children:"Creating account..."})]}):"Create account"}),e&&b.jsxs("p",{className:"cedros-form-footer",children:["Already have an account?"," ",b.jsx("button",{type:"button",className:"cedros-link",onClick:e,children:"Sign in"})]})]})}exports.EmailLoginForm=Bn;exports.EmailRegisterForm=Rn;exports.OtpInput=Vt;exports.PasswordInput=He;exports.TotpVerify=$t;exports.abytes=xe;exports.argon2DeriveInWorker=lt;exports.combineShares=or;exports.getDefaultExportFromCjs=ut;exports.getPublicKeyFromSeed=_t;exports.publicKeyToBase58=Ot;exports.sanitizeExternalUrl=Dt;exports.sanitizeImageUrl=En;exports.sha256=pt;exports.splitSecret=dt;exports.useEmailAuth=$e;exports.useInstantLink=Mt;exports.useRateLimiter=ye;exports.useTotpVerify=qt;