@vunexa/lixa 0.1.6-alpha.12 → 0.1.6-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@
7
7
  * Key features:
8
8
  * - OAuth 2.0 authorization code flow with PKCE (RFC 6749, RFC 7636)
9
9
  * - OpenID Connect support
10
- * - Built-in providers available in \@vunexa/lixa-providers
10
+ * - Built-in providers available in \@vunexa/lixa-extensions/providers
11
11
  * - Custom provider support via IProvider interface
12
12
  * - Extensible session management via SessionDao.CreateSession
13
13
  * - Pluggable state and session storage via StateDao and SessionDao
@@ -132,6 +132,24 @@ export declare class AccountUnlinkError extends LixaError {
132
132
  constructor(message: string, details?: Record<string, unknown>);
133
133
  }
134
134
 
135
+ /**
136
+ * Parameters for changing a user password.
137
+ *
138
+ * @public
139
+ */
140
+ export declare interface ChangePasswordParams {
141
+ /** Username (optional if identifier or userId is provided) */
142
+ username?: string | undefined;
143
+ /** Primary identifier (optional if username or userId is provided) */
144
+ identifier?: string | undefined;
145
+ /** Unique user ID (optional if identifier or username is provided) */
146
+ userId?: string | undefined;
147
+ /** Current plaintext password */
148
+ oldPassword: string;
149
+ /** New plaintext password */
150
+ newPassword: string;
151
+ }
152
+
135
153
  /**
136
154
  * Generates an expired session cookie payload to clear the session on logout.
137
155
  *
@@ -271,6 +289,223 @@ export declare function createSessionCookie(sessionId: string, options?: CookieO
271
289
  */
272
290
  export declare function createStateCookie(state: string, options?: CookieOptions): CookiePayload;
273
291
 
292
+ export declare namespace credentials {
293
+ export {
294
+ UserCredentials,
295
+ CredentialsStorage,
296
+ IPasswordHasher,
297
+ PasswordPolicyConfig,
298
+ PasswordPolicyResult,
299
+ CredentialsConfig,
300
+ SignUpParams,
301
+ SignUpResult,
302
+ SignInParams,
303
+ SignInResult,
304
+ VerifyCredentialsParams,
305
+ ChangePasswordParams,
306
+ ScryptHasherOptions,
307
+ ScryptPasswordHasher,
308
+ Pbkdf2HasherOptions,
309
+ Pbkdf2PasswordHasher,
310
+ validatePasswordPolicy,
311
+ LocalCredentialsStorage,
312
+ CredentialsManager
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Configuration options for Credentials authentication in Lixa.
318
+ *
319
+ * @public
320
+ */
321
+ export declare interface CredentialsConfig {
322
+ /**
323
+ * Explicitly enable or disable credentials authentication.
324
+ *
325
+ * @default true
326
+ */
327
+ enabled?: boolean | undefined;
328
+ /**
329
+ * Custom storage implementation for persisting user credentials.
330
+ * Defaults to LocalCredentialsStorage (in-memory, suitable for dev & testing).
331
+ */
332
+ storage?: CredentialsStorage | undefined;
333
+ /**
334
+ * Custom password hashing strategy.
335
+ * Defaults to ScryptPasswordHasher (Node.js crypto.scrypt).
336
+ */
337
+ hasher?: IPasswordHasher | undefined;
338
+ /**
339
+ * Password strength policy configuration.
340
+ */
341
+ policy?: PasswordPolicyConfig | undefined;
342
+ /**
343
+ * Supported identifier types for registration and sign-in:
344
+ * - 'email': Identifier must be a valid email format
345
+ * - 'username': Identifier can be any username string
346
+ * - 'both': Automatically detect email or username
347
+ *
348
+ * @default 'both'
349
+ */
350
+ identifierType?: ("email" | "username" | "both") | undefined;
351
+ /**
352
+ * Whether a username is strictly required during registration (signUp).
353
+ *
354
+ * @default false
355
+ */
356
+ requireUsername?: boolean | undefined;
357
+ /**
358
+ * Whether a valid email address is strictly required during registration (signUp).
359
+ *
360
+ * @default false
361
+ */
362
+ requireEmail?: boolean | undefined;
363
+ /**
364
+ * Whether to perform dummy hash verification on unknown users to mitigate timing attacks.
365
+ *
366
+ * @default true
367
+ */
368
+ timingAttackProtection?: boolean | undefined;
369
+ /**
370
+ * Whether to automatically generate and save a session upon successful registration (signUp).
371
+ *
372
+ * @default true
373
+ */
374
+ autoCreateSessionOnSignUp?: boolean | undefined;
375
+ /**
376
+ * Session expiration time in seconds for credentials-generated sessions.
377
+ *
378
+ * @default 86400 (24 hours)
379
+ */
380
+ sessionTtlSeconds?: number | undefined;
381
+ }
382
+
383
+ /**
384
+ * Coordinates user registration, authentication, password verification, policy enforcement,
385
+ * and timing attack protection.
386
+ *
387
+ * @public
388
+ */
389
+ export declare class CredentialsManager {
390
+ private readonly storage;
391
+ private readonly hasher;
392
+ private readonly policy;
393
+ private readonly identifierType;
394
+ private readonly requireUsername;
395
+ private readonly requireEmail;
396
+ private readonly timingAttackProtection;
397
+ private dummyHash;
398
+ constructor(config?: CredentialsConfig);
399
+ private initDummyHash;
400
+ /**
401
+ * Normalizes an identifier string.
402
+ */
403
+ private normalizeIdentifier;
404
+ /**
405
+ * Validates identifier format based on configured identifierType.
406
+ */
407
+ private validateIdentifierFormat;
408
+ /**
409
+ * Registers a new user with password hashing and policy enforcement.
410
+ *
411
+ * @param params - Registration parameters
412
+ * @returns Created user credentials without password hash
413
+ */
414
+ signUp(params: SignUpParams): Promise<Omit<UserCredentials, "passwordHash">>;
415
+ /**
416
+ * Verifies credentials against storage with timing attack protection.
417
+ *
418
+ * @param params - Verification parameters
419
+ * @returns User credentials without password hash, or null if verification fails
420
+ */
421
+ verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
422
+ /**
423
+ * Changes a user's password with old password verification and new password policy enforcement.
424
+ *
425
+ * @param params - Change password parameters
426
+ * @returns True if password was successfully updated
427
+ */
428
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
429
+ /**
430
+ * Finds a user by ID and returns safe user data.
431
+ */
432
+ getUserById(id: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
433
+ /**
434
+ * Finds a user by identifier and returns safe user data.
435
+ */
436
+ getUserByIdentifier(identifier: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
437
+ /**
438
+ * Gets the underlying storage instance.
439
+ */
440
+ getStorage(): CredentialsStorage;
441
+ /**
442
+ * Gets the underlying hasher instance.
443
+ */
444
+ getHasher(): IPasswordHasher;
445
+ }
446
+
447
+ /**
448
+ * Thrown when credentials operations (signUp, signIn, etc.) are invoked on a Lixa instance
449
+ * where credentials authentication is not enabled.
450
+ *
451
+ * @public
452
+ */
453
+ export declare class CredentialsNotConfiguredError extends LixaError {
454
+ constructor(message?: string, details?: Record<string, unknown>);
455
+ }
456
+
457
+ /**
458
+ * Storage interface for managing user credentials.
459
+ *
460
+ * @remarks
461
+ * Implement this interface to persist credentials in custom databases
462
+ * (e.g. PostgreSQL, MySQL, SQLite, MongoDB, DynamoDB) or use provided adapters
463
+ * (PrismaCredentialsStorage, DrizzleCredentialsStorage).
464
+ *
465
+ * @public
466
+ */
467
+ export declare interface CredentialsStorage {
468
+ /**
469
+ * Persists a new user credential record.
470
+ *
471
+ * @param user - User credentials entity to save
472
+ */
473
+ saveUser(user: UserCredentials): Promise<void>;
474
+ /**
475
+ * Retrieves user credentials by normalized identifier (username or email).
476
+ *
477
+ * @param identifier - Normalized identifier string
478
+ * @returns UserCredentials record or null if not found
479
+ */
480
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
481
+ /**
482
+ * Retrieves user credentials by unique user ID.
483
+ *
484
+ * @param id - Unique user ID
485
+ * @returns UserCredentials record or null if not found
486
+ */
487
+ findUserById(id: string): Promise<UserCredentials | null>;
488
+ /**
489
+ * Updates the password hash for a user by user ID.
490
+ *
491
+ * @param id - Unique user ID
492
+ * @param newPasswordHash - Newly computed password hash
493
+ */
494
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
495
+ /**
496
+ * Optional helper to delete a user by user ID.
497
+ *
498
+ * @param id - Unique user ID
499
+ */
500
+ deleteUser?(id: string): Promise<void>;
501
+ /**
502
+ * Optional helper to find user directly by username.
503
+ *
504
+ * @param username - Username string
505
+ */
506
+ findUserByUsername?(username: string): Promise<UserCredentials | null>;
507
+ }
508
+
274
509
  /**
275
510
  * Decode JWT ID token to extract user information
276
511
  *
@@ -372,6 +607,15 @@ export declare function extractUserInfo(tokenData: OAuthTokenResponse, providerM
372
607
  */
373
608
  export declare function fetchUserInfo(accessToken: string, userInfoEndpoint: string): Promise<UserInfo>;
374
609
 
610
+ /**
611
+ * Thrown when user credentials (username/email and password) are invalid during authentication.
612
+ *
613
+ * @public
614
+ */
615
+ export declare class InvalidCredentialsError extends LixaError {
616
+ constructor(message?: string, details?: Record<string, unknown>);
617
+ }
618
+
375
619
  /**
376
620
  * Thrown when OAuth callback parameters (e.g. authorization code or state) are missing or malformed.
377
621
  *
@@ -399,6 +643,34 @@ export declare class InvalidStateError extends LixaError {
399
643
  constructor(message?: string, details?: Record<string, unknown>);
400
644
  }
401
645
 
646
+ /**
647
+ * Interface for password hashing and verification algorithms.
648
+ *
649
+ * @remarks
650
+ * Lixa defaults to ScryptPasswordHasher (Node.js crypto.scrypt, 0 dependencies).
651
+ * Implement this interface to use custom algorithms (e.g. bcrypt, argon2, pbkdf2).
652
+ *
653
+ * @public
654
+ */
655
+ export declare interface IPasswordHasher {
656
+ /**
657
+ * Computes a secure cryptographic hash for a plaintext password.
658
+ *
659
+ * @param password - Plaintext password
660
+ * @returns Formatted hash string containing salt and algorithm parameters
661
+ */
662
+ hash(password: string): Promise<string>;
663
+ /**
664
+ * Verifies a plaintext password against a stored hash string.
665
+ * Must use constant-time comparison to prevent timing attacks.
666
+ *
667
+ * @param password - Plaintext password to verify
668
+ * @param hash - Stored hash string
669
+ * @returns True if password matches hash, false otherwise
670
+ */
671
+ verify(password: string, hash: string): Promise<boolean>;
672
+ }
673
+
402
674
  /**
403
675
  * Interface for OAuth 2.0 and OpenID Connect provider implementations.
404
676
  *
@@ -625,6 +897,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
625
897
  private localResourceHandler;
626
898
  private userResourceStore;
627
899
  private refreshMutexes;
900
+ private credentialsManager?;
628
901
  private config;
629
902
  private stateHandler;
630
903
  private sessionHandler;
@@ -664,7 +937,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
664
937
  * Structured logging with standardized format and custom logger support.
665
938
  *
666
939
  * @param level - Log level (INFO, WARN, ERROR, DEBUG)
667
- * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource)
940
+ * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource, Credentials)
668
941
  * @param message - Log message
669
942
  * @param data - Optional data to log
670
943
  */
@@ -758,7 +1031,9 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
758
1031
  */
759
1032
  static createConfig<T extends Record<string, ProviderConfig>>(config: LixaConfig<T> & {
760
1033
  providers: T;
761
- }): LixaConfig<T>;
1034
+ }): LixaConfig<T> & {
1035
+ providers: T;
1036
+ };
762
1037
  /**
763
1038
  * Generates a cryptographically secure random state parameter for OAuth flows.
764
1039
  *
@@ -996,6 +1271,58 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
996
1271
  */
997
1272
  deleteSession(sessionId: string): Promise<void>;
998
1273
  private exchangeCodeForToken;
1274
+ /**
1275
+ * Checks if credentials (username and password) authentication is configured and enabled.
1276
+ *
1277
+ * @returns True if credentials authentication is available
1278
+ */
1279
+ isCredentialsEnabled(): boolean;
1280
+ /**
1281
+ * Returns the underlying CredentialsManager instance if configured.
1282
+ */
1283
+ getCredentialsManager(): CredentialsManager | undefined;
1284
+ /**
1285
+ * Registers a new user with username/email and password.
1286
+ * Automatically enforces password policy, hashes password with Scrypt/configured hasher,
1287
+ * stores credentials, and creates a session (unless autoCreateSessionOnSignUp is false).
1288
+ *
1289
+ * @param params - Registration parameters (identifier, password, email, username, metadata)
1290
+ * @returns Created user (without password hash) and optional active session
1291
+ * @throws WeakPasswordError if password does not meet policy requirements
1292
+ * @throws UserAlreadyExistsError if identifier is already registered
1293
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1294
+ */
1295
+ signUp(params: SignUpParams): Promise<SignUpResult>;
1296
+ /**
1297
+ * Authenticates a user with username/email and password.
1298
+ * Performs constant-time verification with timing attack mitigation, and creates an active session.
1299
+ * If account linking is configured with AUTO_LINK_BY_VERIFIED_EMAIL, merges with existing session.
1300
+ *
1301
+ * @param params - Sign-in parameters (identifier, password)
1302
+ * @returns Authenticated user, session ID, and session object
1303
+ * @throws InvalidCredentialsError if authentication fails
1304
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1305
+ */
1306
+ signIn(params: SignInParams): Promise<SignInResult>;
1307
+ /**
1308
+ * Verifies username/email and password credentials without generating a session.
1309
+ *
1310
+ * @param params - Verification parameters (identifier, password)
1311
+ * @returns User credentials (without password hash) or null if invalid
1312
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1313
+ */
1314
+ verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1315
+ /**
1316
+ * Updates a user's password after verifying the current password and enforcing policy on the new password.
1317
+ *
1318
+ * @param params - Change password parameters (userId/identifier, oldPassword, newPassword)
1319
+ * @returns True if password was updated successfully
1320
+ * @throws UserNotFoundError if user is not found
1321
+ * @throws InvalidCredentialsError if current password is incorrect
1322
+ * @throws WeakPasswordError if new password does not meet policy requirements
1323
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1324
+ */
1325
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
999
1326
  private findProviderByType;
1000
1327
  }
1001
1328
 
@@ -1010,7 +1337,11 @@ export declare interface LixaConfig<TProviders extends Record<string, ProviderCo
1010
1337
  * Map of provider names to their configurations.
1011
1338
  * Provider names will be available for autocomplete in getAuthUrl() and handleCallback().
1012
1339
  */
1013
- providers: TProviders;
1340
+ providers?: TProviders;
1341
+ /**
1342
+ * Credentials (username and password) authentication configuration.
1343
+ */
1344
+ credentials?: CredentialsConfig;
1014
1345
  /**
1015
1346
  * Account linking configuration for multi-SSO user linking.
1016
1347
  */
@@ -1085,11 +1416,30 @@ export declare interface LixaLogger {
1085
1416
  log(level: LogLevel, context: LogContext, message: string, data?: Record<string, unknown>): void;
1086
1417
  }
1087
1418
 
1419
+ /**
1420
+ * In-memory credentials storage for development, testing, and isolated environments.
1421
+ *
1422
+ * @remarks
1423
+ * Uses instance-isolated Maps to prevent state leakage across tests or Lixa instances.
1424
+ *
1425
+ * @public
1426
+ */
1427
+ export declare class LocalCredentialsStorage implements CredentialsStorage {
1428
+ private usersById;
1429
+ private identifierToId;
1430
+ saveUser(user: UserCredentials): Promise<void>;
1431
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
1432
+ findUserById(id: string): Promise<UserCredentials | null>;
1433
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
1434
+ deleteUser(id: string): Promise<void>;
1435
+ clear(): void;
1436
+ }
1437
+
1088
1438
  /**
1089
1439
  * Log context for Lixa structured logging.
1090
1440
  * @public
1091
1441
  */
1092
- export declare type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource";
1442
+ export declare type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials";
1093
1443
 
1094
1444
  /**
1095
1445
  * Log level for Lixa structured logging.
@@ -1146,6 +1496,102 @@ export declare interface OAuthTokenResponse {
1146
1496
  [key: string]: string | number | boolean | undefined;
1147
1497
  }
1148
1498
 
1499
+ /**
1500
+ * Configuration options for password validation rules.
1501
+ *
1502
+ * @public
1503
+ */
1504
+ export declare interface PasswordPolicyConfig {
1505
+ /**
1506
+ * Minimum password length in characters.
1507
+ *
1508
+ * @default 8
1509
+ */
1510
+ minLength?: number | undefined;
1511
+ /**
1512
+ * Maximum password length in characters to prevent hashing DoS attacks.
1513
+ *
1514
+ * @default 128
1515
+ */
1516
+ maxLength?: number | undefined;
1517
+ /**
1518
+ * Require at least one uppercase letter [A-Z].
1519
+ *
1520
+ * @default false
1521
+ */
1522
+ requireUppercase?: boolean | undefined;
1523
+ /**
1524
+ * Require at least one lowercase letter [a-z].
1525
+ *
1526
+ * @default false
1527
+ */
1528
+ requireLowercase?: boolean | undefined;
1529
+ /**
1530
+ * Require at least one numeric digit [0-9].
1531
+ *
1532
+ * @default false
1533
+ */
1534
+ requireNumbers?: boolean | undefined;
1535
+ /**
1536
+ * Require at least one special symbol character.
1537
+ *
1538
+ * @default false
1539
+ */
1540
+ requireSpecialChars?: boolean | undefined;
1541
+ /**
1542
+ * Optional custom validator function for enterprise or custom rules.
1543
+ * Return `true` if valid, or `false` / custom error message string if invalid.
1544
+ */
1545
+ customValidator?: ((password: string) => boolean | string | Promise<boolean | string>) | undefined;
1546
+ }
1547
+
1548
+ /**
1549
+ * Result of password policy validation.
1550
+ *
1551
+ * @public
1552
+ */
1553
+ export declare interface PasswordPolicyResult {
1554
+ /** Whether the password satisfied all configured rules */
1555
+ valid: boolean;
1556
+ /** List of human-readable error descriptions if validation failed */
1557
+ errors: string[];
1558
+ }
1559
+
1560
+ /**
1561
+ * Options for PBKDF2 password hashing.
1562
+ *
1563
+ * @public
1564
+ */
1565
+ export declare interface Pbkdf2HasherOptions {
1566
+ /** Iteration count. Default: 100000 */
1567
+ iterations?: number;
1568
+ /** HMAC digest algorithm. Default: 'sha512' */
1569
+ digest?: string;
1570
+ /** Salt length in bytes. Default: 16 */
1571
+ saltLength?: number;
1572
+ /** Derived key length in bytes. Default: 64 */
1573
+ keyLength?: number;
1574
+ }
1575
+
1576
+ /**
1577
+ * Alternative password hasher using Node.js native `crypto.pbkdf2`.
1578
+ *
1579
+ * @remarks
1580
+ * Produces PHC-formatted strings: `$pbkdf2$i=100000,d=sha512$<saltHex>$<keyHex>`.
1581
+ *
1582
+ * @public
1583
+ */
1584
+ export declare class Pbkdf2PasswordHasher implements IPasswordHasher {
1585
+ private readonly iterations;
1586
+ private readonly digest;
1587
+ private readonly saltLength;
1588
+ private readonly keyLength;
1589
+ constructor(options?: Pbkdf2HasherOptions);
1590
+ hash(password: string): Promise<string>;
1591
+ verify(password: string, hash: string): Promise<boolean>;
1592
+ private deriveKey;
1593
+ }
1594
+
1149
1595
  /**
1150
1596
  * Configuration for an OAuth provider instance.
1151
1597
  *
@@ -1305,6 +1751,61 @@ export declare type SafeLixaConfig<TProviders extends Record<string, ProviderCon
1305
1751
  providers: TProviders;
1306
1752
  };
1307
1753
 
1754
+ /**
1755
+ * Options for Scrypt password hashing.
1756
+ *
1757
+ * @public
1758
+ */
1759
+ export declare interface ScryptHasherOptions {
1760
+ /** CPU/memory cost parameter (must be power of 2). Default: 16384 (2^14) */
1761
+ cost?: number;
1762
+ /** Block size parameter. Default: 8 */
1763
+ blockSize?: number;
1764
+ /** Parallelization parameter. Default: 1 */
1765
+ parallelization?: number;
1766
+ /** Salt length in bytes. Default: 16 */
1767
+ saltLength?: number;
1768
+ /** Derived key length in bytes. Default: 64 */
1769
+ keyLength?: number;
1770
+ /** Max memory allocated in bytes. Default: 32MB */
1771
+ maxmem?: number;
1772
+ }
1773
+
1774
+ /**
1775
+ * Default secure password hasher utilizing Node.js native `crypto.scrypt`.
1776
+ *
1777
+ * @remarks
1778
+ * Produces PHC-formatted strings: `$scrypt$N=16384,r=8,p=1$<saltHex>$<keyHex>`.
1779
+ * Verification uses constant-time `crypto.timingSafeEqual` to prevent timing attacks.
1780
+ *
1781
+ * @public
1782
+ */
1783
+ export declare class ScryptPasswordHasher implements IPasswordHasher {
1784
+ private readonly cost;
1785
+ private readonly blockSize;
1786
+ private readonly parallelization;
1787
+ private readonly saltLength;
1788
+ private readonly keyLength;
1789
+ private readonly maxmem;
1790
+ constructor(options?: ScryptHasherOptions);
1791
+ /**
1792
+ * Hashes a plaintext password using Scrypt.
1793
+ *
1794
+ * @param password - Plaintext password
1795
+ * @returns Formatted Scrypt hash string
1796
+ */
1797
+ hash(password: string): Promise<string>;
1798
+ /**
1799
+ * Verifies a password against a stored Scrypt hash.
1800
+ *
1801
+ * @param password - Plaintext password
1802
+ * @param hash - Formatted Scrypt hash string
1803
+ * @returns True if password matches hash
1804
+ */
1805
+ verify(password: string, hash: string): Promise<boolean>;
1806
+ private deriveKey;
1807
+ }
1808
+
1308
1809
  /**
1309
1810
  * Serializes a cookie name, value, and options into a standard `Set-Cookie` header string.
1310
1811
  *
@@ -1333,31 +1834,31 @@ export declare interface Session<TRaw = OAuthTokenResponse> {
1333
1834
  /**
1334
1835
  * Unique session ID generated by Lixa upon authentication.
1335
1836
  */
1336
- id?: string;
1837
+ id?: string | undefined;
1337
1838
  /**
1338
1839
  * Linked identity provider accounts (AuthN) keyed by provider name.
1339
1840
  * Single source of truth for all authenticated user SSO identities.
1340
1841
  */
1341
- accounts?: Record<string, LinkedAccount>;
1842
+ accounts?: Record<string, LinkedAccount> | undefined;
1342
1843
  /**
1343
1844
  * Connected third-party resource provider tokens (AuthZ) keyed by provider name.
1344
1845
  * Single source of truth for all post-login third-party API permissions.
1345
1846
  */
1346
- resources?: Record<string, ConnectedResource>;
1847
+ resources?: Record<string, ConnectedResource> | undefined;
1347
1848
  /** Unique unified user ID across linked accounts */
1348
- userId?: string;
1849
+ userId?: string | undefined;
1349
1850
  /** Primary user email */
1350
- email?: string;
1851
+ email?: string | undefined;
1351
1852
  /**
1352
1853
  * Optional primary access token or custom session token identifier.
1353
1854
  */
1354
- token?: string;
1855
+ token?: string | undefined;
1355
1856
  /** Optional current active auth provider for this session turn */
1356
- provider?: string;
1857
+ provider?: string | undefined;
1357
1858
  /**
1358
1859
  * Optional raw session token response data from provider.
1359
1860
  */
1360
- raw?: TRaw;
1861
+ raw?: TRaw | undefined;
1361
1862
  }
1362
1863
 
1363
1864
  /**
@@ -1504,6 +2005,66 @@ export declare interface SessionStorage {
1504
2005
  } | null>;
1505
2006
  }
1506
2007
 
2008
+ /**
2009
+ * Parameters for user authentication (signIn).
2010
+ *
2011
+ * @public
2012
+ */
2013
+ export declare interface SignInParams {
2014
+ /** Username or email of the account */
2015
+ username?: string | undefined;
2016
+ /** Primary identifier (username or email) */
2017
+ identifier?: string | undefined;
2018
+ /** Plaintext password */
2019
+ password: string;
2020
+ }
2021
+
2022
+ /**
2023
+ * Result of user authentication (signIn).
2024
+ *
2025
+ * @public
2026
+ */
2027
+ export declare interface SignInResult<TSession = Session> {
2028
+ /** Authenticated user credentials (with passwordHash omitted for safety) */
2029
+ user: Omit<UserCredentials, "passwordHash">;
2030
+ /** Active session ID */
2031
+ sessionId: string;
2032
+ /** Active session object */
2033
+ session: TSession;
2034
+ }
2035
+
2036
+ /**
2037
+ * Parameters for user registration (signUp).
2038
+ *
2039
+ * @public
2040
+ */
2041
+ export declare interface SignUpParams {
2042
+ /** Username for the user (can be used directly instead of identifier) */
2043
+ username?: string | undefined;
2044
+ /** Primary identifier (username or email) */
2045
+ identifier?: string | undefined;
2046
+ /** Plaintext password */
2047
+ password: string;
2048
+ /** Optional explicit email address */
2049
+ email?: string | undefined;
2050
+ /** Optional custom user metadata */
2051
+ metadata?: Record<string, unknown> | undefined;
2052
+ }
2053
+
2054
+ /**
2055
+ * Result of user registration (signUp).
2056
+ *
2057
+ * @public
2058
+ */
2059
+ export declare interface SignUpResult<TSession = Session> {
2060
+ /** Created user credentials (with passwordHash omitted for safety) */
2061
+ user: Omit<UserCredentials, "passwordHash">;
2062
+ /** Created session ID if autoCreateSessionOnSignUp is enabled */
2063
+ sessionId?: string | undefined;
2064
+ /** Created session object if autoCreateSessionOnSignUp is enabled */
2065
+ session?: TSession | undefined;
2066
+ }
2067
+
1507
2068
  /**
1508
2069
  * OAuth state data structure.
1509
2070
  *
@@ -1707,6 +2268,39 @@ export declare class TokenExchangeError extends LixaError {
1707
2268
  constructor(message: string, status?: number, details?: Record<string, unknown>);
1708
2269
  }
1709
2270
 
2271
+ /**
2272
+ * Thrown when attempting to register a user with an identifier that already exists.
2273
+ *
2274
+ * @public
2275
+ */
2276
+ export declare class UserAlreadyExistsError extends LixaError {
2277
+ constructor(identifier: string, details?: Record<string, unknown>);
2278
+ }
2279
+
2280
+ /**
2281
+ * User credentials entity representing stored account login information.
2282
+ *
2283
+ * @public
2284
+ */
2285
+ export declare interface UserCredentials {
2286
+ /** Unique user identifier (UUID or Nanoid) */
2287
+ id: string;
2288
+ /** Primary unique lookup identifier (normalized lowercase username or email) */
2289
+ identifier: string;
2290
+ /** Username of the account */
2291
+ username?: string | undefined;
2292
+ /** Associated email address */
2293
+ email?: string | undefined;
2294
+ /** Securely hashed password string (e.g. Scrypt, Argon2, PBKDF2, Bcrypt) */
2295
+ passwordHash: string;
2296
+ /** Unix timestamp in milliseconds when user credentials were created */
2297
+ createdAt: number;
2298
+ /** Unix timestamp in milliseconds when user credentials were last updated */
2299
+ updatedAt: number;
2300
+ /** Optional custom user metadata or profile attributes */
2301
+ metadata?: Record<string, unknown> | undefined;
2302
+ }
2303
+
1710
2304
  /**
1711
2305
  * User information extracted from OAuth provider
1712
2306
  *
@@ -1724,4 +2318,48 @@ export declare interface UserInfo {
1724
2318
  iss?: string | undefined;
1725
2319
  }
1726
2320
 
2321
+ /**
2322
+ * Thrown when a user account cannot be found for credential verification or password change.
2323
+ *
2324
+ * @public
2325
+ */
2326
+ export declare class UserNotFoundError extends LixaError {
2327
+ constructor(identifierOrId?: string, details?: Record<string, unknown>);
2328
+ }
2329
+
2330
+ /**
2331
+ * Validates a plaintext password against configured password policy rules.
2332
+ *
2333
+ * @param password - Plaintext password to evaluate
2334
+ * @param policy - Optional custom policy configuration
2335
+ * @returns PasswordPolicyResult containing boolean valid flag and error messages
2336
+ *
2337
+ * @public
2338
+ */
2339
+ export declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): Promise<PasswordPolicyResult>;
2340
+
2341
+ /**
2342
+ * Parameters for raw credential verification without session creation.
2343
+ *
2344
+ * @public
2345
+ */
2346
+ export declare interface VerifyCredentialsParams {
2347
+ /** Username or email of the account */
2348
+ username?: string | undefined;
2349
+ /** Primary identifier (username or email) */
2350
+ identifier?: string | undefined;
2351
+ /** Plaintext password */
2352
+ password: string;
2353
+ }
2354
+
2355
+ /**
2356
+ * Thrown when a password does not satisfy configured password policy rules.
2357
+ *
2358
+ * @public
2359
+ */
2360
+ export declare class WeakPasswordError extends LixaError {
2361
+ readonly validationErrors: string[];
2362
+ constructor(validationErrors?: string[], details?: Record<string, unknown>);
2363
+ }
2364
+
1727
2365
  export { }