@crossdyne/security 0.5.0-beta.1 → 0.5.0-beta.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.
package/dist/index.d.cts CHANGED
@@ -31,7 +31,6 @@ declare class CryptoService {
31
31
  * Encrypts a serializable object to a Base64 string.
32
32
  * @param dataModel - Object or Uint8Array to encrypt.
33
33
  * @param key - AES-256 key (32 bytes).
34
- * @param options - AES-GCM configuration; uses default if omitted.
35
34
  * @returns Base64-encoded ciphertext with prepended nonce.
36
35
  */
37
36
  encryptData<T>(dataModel: T, key: Uint8Array, version?: CryptoVersion): Promise<string>;
@@ -39,7 +38,6 @@ declare class CryptoService {
39
38
  * Decrypts a Base64-encoded ciphertext back to the original object.
40
39
  * @param encryptedBase64 - The encrypted data.
41
40
  * @param key - AES-256 key (32 bytes).
42
- * @param options - AES-GCM configuration; uses default if omitted.
43
41
  * @returns Deserialized object, or null if input is empty.
44
42
  * @throws If authentication tag mismatch or corrupted data.
45
43
  */
@@ -57,31 +55,18 @@ declare class CryptoService {
57
55
  */
58
56
  declare class KeyDerivationService {
59
57
  /**
60
- * Derives KEK and Base64 AuthHash. Identity is hashed as-is — caller must
61
- * normalize (trim, lowercase, etc.) before calling.
62
- * @param identity - User identity (pre-normalized by caller).
63
- * @param identity - User identity (email, username).
64
- * @param password - User password.
65
- * @param salt - Random salt.
66
- * @param options - KDF configuration; uses default if omitted.
67
- * @returns Object with `kek` (Uint8Array) and `authHash` (Base64 string).
68
- */
58
+ * Derives KEK and Base64 AuthHash. Identity is used as-is in the
59
+ * combined salt string — caller must normalize (trim, lowercase, etc.) before calling.
60
+ * @param identity - User identity (email, username). Must be pre-normalized by caller.
61
+ * @param password - User password.
62
+ * @param salt - Random salt (minimum 16 bytes).
63
+ * @param version - Crypto version for profile selection.
64
+ * @returns Object with `kek` (Uint8Array) and `authHash` (Base64 string).
65
+ */
69
66
  deriveKeysFromPassword(identity: string, password: string, salt: Uint8Array, version: CryptoVersion): Promise<{
70
67
  kek: Uint8Array;
71
68
  authHash: string;
72
69
  }>;
73
- /**
74
- * Derives an SRP-compatible authentication hash (output size = hash output length).
75
- * Identity is hashed as-is — caller must normalize (trim, lowercase, etc.) before calling.
76
- * @param identity - User identity (pre-normalized by caller).
77
- * @param identity - User identity.
78
- * @param password - User password.
79
- * @param salt - Random salt.
80
- * @param srpHashAlgorithm - SRP hash algorithm (SHA-256/384/512).
81
- * @param options - KDF configuration; uses default if omitted.
82
- * @returns Raw hash bytes for use as SRP verifier input (x).
83
- */
84
- deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpHashAlgorithm: HashAlgorithm, version: CryptoVersion): Promise<Uint8Array>;
85
70
  }
86
71
 
87
72
  /**
@@ -172,45 +157,51 @@ declare class CryptoProfileRegistry {
172
157
  }
173
158
 
174
159
  /**
175
- * Immutable SRP cryptographic context: modulus, generator, multiplier k, hash algorithm, and sizes.
160
+ * SRP-6a Diffie-Hellman groups (RFC 5054).
161
+ * 1024 (~80) deprecated, 1536 (~90) legacy, 2048 (~112) baseline,
162
+ * 3072+ (≥128) preferred. g=2 for ≤2048, g=5 for 3072-6144, g=19 for 8192.
163
+ * Always use {@link SrpGroupParams} to get N and g.
176
164
  */
177
- interface SrpContext {
178
- /** Prime modulus N. */
179
- readonly N: bigint;
180
- /** Generator g. */
181
- readonly g: bigint;
182
- /** Multiplier k = H(PAD(N) || PAD(g)) (RFC 5054, 2.5.3) */
183
- readonly k: bigint;
184
- /** Modulus size in bytes (ceil(bit length / 8)). */
185
- readonly modulusSize: number;
186
- /** Hash algorithm used for SRP computations. */
187
- readonly hashAlgorithmName: HashAlgorithm;
188
- /** Hash output size in bytes (e.g., 32 for SHA-256). */
189
- readonly hashSize: number;
165
+ declare enum SrpGroup {
166
+ /** 1024-bit, g=2, ~80-bit security. Deprecated, legacy only. */
167
+ Rfc5054_1024 = 1,
168
+ /** 1536-bit, g=2, ~90-bit security. Minimum for legacy systems. */
169
+ Rfc5054_1536 = 2,
170
+ /** 2048-bit, g=2, ~112-bit security. Recommended baseline. */
171
+ Rfc5054_2048 = 3,
172
+ /** 3072-bit, g=5, ~128-bit security. Preferred for long-term. */
173
+ Rfc5054_3072 = 4,
174
+ /** 4096-bit, g=5, ~156-bit security. High-security environments. */
175
+ Rfc5054_4096 = 5,
176
+ /** 6144-bit, g=5, ~192-bit security. Specialized high-assurance. */
177
+ Rfc5054_6144 = 6,
178
+ /** 8192-bit, g=19, ~256-bit security. Experimental, extremely slow. */
179
+ Rfc5054_8192 = 7,
180
+ /** User-supplied N and g. Validate safe prime and generator. */
181
+ Custom = 99
190
182
  }
191
183
 
192
184
  /**
193
185
  * Client-side SRP-6a implementation: proof generation, verifier creation, server M2 verification.
194
186
  */
195
187
  declare class SrpClientService {
196
- private readonly keyDerivation;
197
188
  /**
198
189
  * Computes SRP verifier v = g^x mod N from the authentication hash.
199
190
  * @param authHash - Auth hash (Base64).
200
- * @param ctx - SRP context (N, g, hash algorithm, etc.).
191
+ * @param group - SRP group (determines modulus N, generator g, hash).
201
192
  * @returns Verifier as Base64 string.
202
193
  */
203
- generateSrpVerifier(authHash: string, ctx: SrpContext): Promise<string>;
194
+ generateSrpVerifier(authHash: string, group: SrpGroup): Promise<string>;
204
195
  /**
205
196
  * Generates client proof (A, M1, session key S) from server challenge.
206
197
  * @param login - User login.
207
- * @param password - Plaintext password.
198
+ * @param authHashBytes - SRP private exponent x as raw bytes (derived from auth hash).
208
199
  * @param saltBase64 - Server salt (standard Base64).
209
200
  * @param B_base64 - Server public ephemeral B (standard Base64).
210
- * @param ctx - SRP context.
201
+ * @param group - SRP group (determines modulus N, generator g, hash).
211
202
  * @returns Object with A and M1 as standard Base64; SessionKeyK as raw bytes.
212
203
  */
213
- generateSrpProof(login: string, password: string, saltBase64: string, B_base64: string, ctx: SrpContext, version: CryptoVersion): Promise<{
204
+ generateSrpProof(login: string, authHashBytes: Uint8Array<ArrayBufferLike>, saltBase64: string, B_base64: string, group: SrpGroup): Promise<{
214
205
  A: string;
215
206
  M1: string;
216
207
  SessionKeyK: Uint8Array;
@@ -219,12 +210,12 @@ declare class SrpClientService {
219
210
  * Validates the server proof M2 to authenticate the server.
220
211
  * @param A_b64 - Client public A (Base64).
221
212
  * @param M1_b64 - Client proof M1 (Base64).
222
- * @param S_b64 - Session key S (Base64).
213
+ * @param sessionKeyK - Session key K as raw bytes.
223
214
  * @param serverM2_b64 - Server proof M2 (Base64).
224
- * @param ctx - SRP context.
215
+ * @param group - SRP group (determines modulus N, generator g, hash).
225
216
  * @returns True if the server proof is valid.
226
217
  */
227
- verifyServerM2(A_b64: string, M1_b64: string, sessionKeyK: Uint8Array, serverM2_b64: string, ctx: SrpContext): Promise<boolean>;
218
+ verifyServerM2(A_b64: string, M1_b64: string, sessionKeyK: Uint8Array, serverM2_b64: string, group: SrpGroup): Promise<boolean>;
228
219
  }
229
220
 
230
221
  /**
@@ -233,13 +224,13 @@ declare class SrpClientService {
233
224
  interface SrpSessionState {
234
225
  /** User login identifier. */
235
226
  login: string;
236
- /** Server private ephemeral key (Base64). */
227
+ /** Server private ephemeral key (raw bytes). */
237
228
  privateKeyB: Uint8Array;
238
- /** Password verifier (Base64). */
229
+ /** Password verifier v (raw bytes). */
239
230
  verifier: Uint8Array;
240
- /** Server public ephemeral key B (Base64). */
231
+ /** Server public ephemeral key B (raw bytes). */
241
232
  publicKeyB: Uint8Array;
242
- /** User salt s (needed for RFC 5054 M1). */
233
+ /** User salt s (raw bytes). */
243
234
  salt: Uint8Array;
244
235
  }
245
236
  /**
@@ -250,45 +241,39 @@ declare class SrpServerService {
250
241
  * Generates server challenge B and session state from verifier.
251
242
  * @param login - User login.
252
243
  * @param verifierBytes - Stored verifier v as byte array.
253
- * @param ctx - SRP context (hash, N, g, etc.).
254
- * @returns Session state with private b, verifier, and public B.
244
+ * @param salt - User salt (raw bytes).
245
+ * @param group - SRP group (determines modulus N, generator g, hash).
246
+ * @returns Session state with private b, verifier, public B, and salt.
255
247
  */
256
- getSrpChallenge(login: string, verifierBytes: Uint8Array, salt: Uint8Array, ctx: SrpContext): Promise<SrpSessionState>;
248
+ getSrpChallenge(login: string, verifierBytes: Uint8Array, salt: Uint8Array, group: SrpGroup): Promise<SrpSessionState>;
257
249
  /**
258
250
  * Verifies client M1 proof and returns server M2 proof.
259
251
  * @param sessionState - Server session state.
260
252
  * @param a - Client public A (Base64).
261
253
  * @param m1 - Client proof M1 (Base64).
262
- * @param ctx - SRP context.
254
+ * @param group - SRP group (determines modulus N, generator g, hash).
263
255
  * @returns Server proof M2 as Base64 string.
264
256
  * @throws If verification fails or input is invalid.
265
257
  */
266
- verifySrpProof(sessionState: SrpSessionState, a: string, m1: string, ctx: SrpContext): Promise<string>;
258
+ verifySrpProof(sessionState: SrpSessionState, a: string, m1: string, group: SrpGroup): Promise<string>;
267
259
  }
268
260
 
269
261
  /**
270
- * SRP-6a Diffie-Hellman groups (RFC 5054).
271
- * 1024 (~80) deprecated, 1536 (~90) legacy, 2048 (~112) baseline,
272
- * 3072+ (≥128) preferred. g=2 for ≤2048, g=5 for 3072-6144, g=19 for 8192.
273
- * Always use {@link SrpGroupParams} to get N and g.
262
+ * Service for deriving SRP authentication hashes via PBKDF2 → HKDF.
274
263
  */
275
- declare enum SrpGroup {
276
- /** 1024-bit, g=2, ~80-bit security. Deprecated, legacy only. */
277
- Rfc5054_1024 = 1,
278
- /** 1536-bit, g=2, ~90-bit security. Minimum for legacy systems. */
279
- Rfc5054_1536 = 2,
280
- /** 2048-bit, g=2, ~112-bit security. Recommended baseline. */
281
- Rfc5054_2048 = 3,
282
- /** 3072-bit, g=5, ~128-bit security. Preferred for long-term. */
283
- Rfc5054_3072 = 4,
284
- /** 4096-bit, g=5, ~156-bit security. High-security environments. */
285
- Rfc5054_4096 = 5,
286
- /** 6144-bit, g=5, ~192-bit security. Specialized high-assurance. */
287
- Rfc5054_6144 = 6,
288
- /** 8192-bit, g=19, ~256-bit security. Experimental, extremely slow. */
289
- Rfc5054_8192 = 7,
290
- /** User-supplied N and g. Validate safe prime and generator. */
291
- Custom = 99
264
+ declare class SrpKeyDerivationService {
265
+ /**
266
+ * Derives an SRP-compatible authentication hash (output size = hash output length).
267
+ * Identity is used as-is in the combined string — caller must normalize
268
+ * (trim, lowercase, etc.) before calling.
269
+ * @param identity - User identity (email, username). Must be pre-normalized by caller.
270
+ * @param password - User password.
271
+ * @param salt - Random salt (minimum 16 bytes).
272
+ * @param srpGroup - SRP group (determines hash algorithm and modulus).
273
+ * @param version - Crypto version for KDF profile selection.
274
+ * @returns Raw hash bytes for use as SRP verifier input (x).
275
+ */
276
+ deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpGroup: SrpGroup, version: CryptoVersion): Promise<Uint8Array>;
292
277
  }
293
278
 
294
279
  /**
@@ -333,6 +318,24 @@ declare class SrpGroupParams {
333
318
  static getG(group: SrpGroup): bigint;
334
319
  }
335
320
 
321
+ /**
322
+ * Immutable SRP cryptographic context: modulus, generator, multiplier k, hash algorithm, and sizes.
323
+ */
324
+ interface SrpContext {
325
+ /** Prime modulus N. */
326
+ readonly N: bigint;
327
+ /** Generator g. */
328
+ readonly g: bigint;
329
+ /** Multiplier k = H(PAD(N) || PAD(g)) (RFC 5054, 2.5.3) */
330
+ readonly k: bigint;
331
+ /** Modulus size in bytes (ceil(bit length / 8)). */
332
+ readonly modulusSize: number;
333
+ /** Hash algorithm used for SRP computations. */
334
+ readonly hashAlgorithmName: HashAlgorithm;
335
+ /** Hash output size in bytes (e.g., 32 for SHA-256). */
336
+ readonly hashSize: number;
337
+ }
338
+
336
339
  /**
337
340
  * Factory for creating an {@link SrpContext} from an SRP group.
338
341
  * Automatically selects the hash algorithm (SHA-256 for ≤3072-bit, SHA-384 for 4096+).
@@ -360,8 +363,15 @@ declare class SecurityUtils {
360
363
  static bigIntToFixedBytes(bn: bigint, length: number): Uint8Array;
361
364
  /** Constant-time comparison of two Uint8Arrays. */
362
365
  static fixedTimeEquals(a: Uint8Array, b: Uint8Array): boolean;
363
- /** Modular exponentiation (base^exp mod mod) using binary exponentiation. */
364
- static expMod(base: bigint, exp: bigint, mod: bigint): bigint;
366
+ /**
367
+ * Async modular exponentiation with event-loop yielding.
368
+ * @param base - The base value.
369
+ * @param exp - The exponent.
370
+ * @param mod - The modulus.
371
+ * @param yieldEvery - Number of iterations before yielding (default 64).
372
+ */
373
+ static expModAsync(base: bigint, exp: bigint, mod: bigint, yieldEvery?: number): Promise<bigint>;
374
+ /** Converts bigint to minimal-length big-endian bytes (no padding). */
365
375
  static bigIntToRawBytes(bn: bigint): Uint8Array;
366
376
  }
367
377
 
@@ -381,7 +391,7 @@ declare class SrpEncoding {
381
391
  * Follows RFC 5054 / SRP-6a:
382
392
  * - H(N) and H(g) are hashed as modulus-sized values.
383
393
  * - Identity (I) is hashed as raw UTF-8 bytes.
384
- * - A and B are padded to the modulus size before hashing.
394
+ * - A and B are zero-padded to the modulus size before hashing.
385
395
  * - K is the session key (H(S) without padding).
386
396
  *
387
397
  * @param ctx - SRP context containing N, g, hash algorithm, and modulus size.
@@ -393,14 +403,17 @@ declare class SrpEncoding {
393
403
  * @returns The M1 proof as raw hash bytes.
394
404
  */
395
405
  static computeM1(ctx: SrpContext, A: bigint, B: bigint, sessionKeyK: Uint8Array, identity: string, salt: Uint8Array): Promise<Uint8Array>;
396
- /** Computes M2 = H(A || M1 || sessionKeyK). */
406
+ /**
407
+ * Computes M2 = H( PAD(A) || M1 || sessionKeyK ).
408
+ * A is zero-padded to the modulus size before hashing.
409
+ */
397
410
  static computeM2(ctx: SrpContext, A: bigint, m1Bytes: Uint8Array, sessionKeyK: Uint8Array): Promise<Uint8Array>;
398
411
  /** Computes session key K = H(S). */
399
412
  static computeSessionKey(ctx: SrpContext, S: bigint): Promise<Uint8Array>;
400
- /** Hashes bytes and returns raw Uint8Array (для M1/M2). */
413
+ /** Hashes concatenated byte arrays and returns raw Uint8Array. */
401
414
  private static computeHash;
402
415
  /** Concatenates byte arrays and returns the hash as bigint. */
403
416
  private static hash;
404
417
  }
405
418
 
406
- export { AesGcmOptions, CryptoProfile, CryptoProfileRegistry, CryptoService, CryptoVersion, type HashAlgorithm, KdfOptions, KeyDerivationService, SecurityConstants, SecurityUtils, SrpClientService, type SrpContext, SrpContextFactory, SrpEncoding, SrpGroup, SrpGroupParams, SrpOptions, SrpServerService, type SrpSessionState, SupportedHashAlgorithms };
419
+ export { AesGcmOptions, CryptoProfile, CryptoProfileRegistry, CryptoService, CryptoVersion, type HashAlgorithm, KdfOptions, KeyDerivationService, SecurityConstants, SecurityUtils, SrpClientService, type SrpContext, SrpContextFactory, SrpEncoding, SrpGroup, SrpGroupParams, SrpKeyDerivationService, SrpOptions, SrpServerService, type SrpSessionState, SupportedHashAlgorithms };
package/dist/index.d.ts CHANGED
@@ -31,7 +31,6 @@ declare class CryptoService {
31
31
  * Encrypts a serializable object to a Base64 string.
32
32
  * @param dataModel - Object or Uint8Array to encrypt.
33
33
  * @param key - AES-256 key (32 bytes).
34
- * @param options - AES-GCM configuration; uses default if omitted.
35
34
  * @returns Base64-encoded ciphertext with prepended nonce.
36
35
  */
37
36
  encryptData<T>(dataModel: T, key: Uint8Array, version?: CryptoVersion): Promise<string>;
@@ -39,7 +38,6 @@ declare class CryptoService {
39
38
  * Decrypts a Base64-encoded ciphertext back to the original object.
40
39
  * @param encryptedBase64 - The encrypted data.
41
40
  * @param key - AES-256 key (32 bytes).
42
- * @param options - AES-GCM configuration; uses default if omitted.
43
41
  * @returns Deserialized object, or null if input is empty.
44
42
  * @throws If authentication tag mismatch or corrupted data.
45
43
  */
@@ -57,31 +55,18 @@ declare class CryptoService {
57
55
  */
58
56
  declare class KeyDerivationService {
59
57
  /**
60
- * Derives KEK and Base64 AuthHash. Identity is hashed as-is — caller must
61
- * normalize (trim, lowercase, etc.) before calling.
62
- * @param identity - User identity (pre-normalized by caller).
63
- * @param identity - User identity (email, username).
64
- * @param password - User password.
65
- * @param salt - Random salt.
66
- * @param options - KDF configuration; uses default if omitted.
67
- * @returns Object with `kek` (Uint8Array) and `authHash` (Base64 string).
68
- */
58
+ * Derives KEK and Base64 AuthHash. Identity is used as-is in the
59
+ * combined salt string — caller must normalize (trim, lowercase, etc.) before calling.
60
+ * @param identity - User identity (email, username). Must be pre-normalized by caller.
61
+ * @param password - User password.
62
+ * @param salt - Random salt (minimum 16 bytes).
63
+ * @param version - Crypto version for profile selection.
64
+ * @returns Object with `kek` (Uint8Array) and `authHash` (Base64 string).
65
+ */
69
66
  deriveKeysFromPassword(identity: string, password: string, salt: Uint8Array, version: CryptoVersion): Promise<{
70
67
  kek: Uint8Array;
71
68
  authHash: string;
72
69
  }>;
73
- /**
74
- * Derives an SRP-compatible authentication hash (output size = hash output length).
75
- * Identity is hashed as-is — caller must normalize (trim, lowercase, etc.) before calling.
76
- * @param identity - User identity (pre-normalized by caller).
77
- * @param identity - User identity.
78
- * @param password - User password.
79
- * @param salt - Random salt.
80
- * @param srpHashAlgorithm - SRP hash algorithm (SHA-256/384/512).
81
- * @param options - KDF configuration; uses default if omitted.
82
- * @returns Raw hash bytes for use as SRP verifier input (x).
83
- */
84
- deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpHashAlgorithm: HashAlgorithm, version: CryptoVersion): Promise<Uint8Array>;
85
70
  }
86
71
 
87
72
  /**
@@ -172,45 +157,51 @@ declare class CryptoProfileRegistry {
172
157
  }
173
158
 
174
159
  /**
175
- * Immutable SRP cryptographic context: modulus, generator, multiplier k, hash algorithm, and sizes.
160
+ * SRP-6a Diffie-Hellman groups (RFC 5054).
161
+ * 1024 (~80) deprecated, 1536 (~90) legacy, 2048 (~112) baseline,
162
+ * 3072+ (≥128) preferred. g=2 for ≤2048, g=5 for 3072-6144, g=19 for 8192.
163
+ * Always use {@link SrpGroupParams} to get N and g.
176
164
  */
177
- interface SrpContext {
178
- /** Prime modulus N. */
179
- readonly N: bigint;
180
- /** Generator g. */
181
- readonly g: bigint;
182
- /** Multiplier k = H(PAD(N) || PAD(g)) (RFC 5054, 2.5.3) */
183
- readonly k: bigint;
184
- /** Modulus size in bytes (ceil(bit length / 8)). */
185
- readonly modulusSize: number;
186
- /** Hash algorithm used for SRP computations. */
187
- readonly hashAlgorithmName: HashAlgorithm;
188
- /** Hash output size in bytes (e.g., 32 for SHA-256). */
189
- readonly hashSize: number;
165
+ declare enum SrpGroup {
166
+ /** 1024-bit, g=2, ~80-bit security. Deprecated, legacy only. */
167
+ Rfc5054_1024 = 1,
168
+ /** 1536-bit, g=2, ~90-bit security. Minimum for legacy systems. */
169
+ Rfc5054_1536 = 2,
170
+ /** 2048-bit, g=2, ~112-bit security. Recommended baseline. */
171
+ Rfc5054_2048 = 3,
172
+ /** 3072-bit, g=5, ~128-bit security. Preferred for long-term. */
173
+ Rfc5054_3072 = 4,
174
+ /** 4096-bit, g=5, ~156-bit security. High-security environments. */
175
+ Rfc5054_4096 = 5,
176
+ /** 6144-bit, g=5, ~192-bit security. Specialized high-assurance. */
177
+ Rfc5054_6144 = 6,
178
+ /** 8192-bit, g=19, ~256-bit security. Experimental, extremely slow. */
179
+ Rfc5054_8192 = 7,
180
+ /** User-supplied N and g. Validate safe prime and generator. */
181
+ Custom = 99
190
182
  }
191
183
 
192
184
  /**
193
185
  * Client-side SRP-6a implementation: proof generation, verifier creation, server M2 verification.
194
186
  */
195
187
  declare class SrpClientService {
196
- private readonly keyDerivation;
197
188
  /**
198
189
  * Computes SRP verifier v = g^x mod N from the authentication hash.
199
190
  * @param authHash - Auth hash (Base64).
200
- * @param ctx - SRP context (N, g, hash algorithm, etc.).
191
+ * @param group - SRP group (determines modulus N, generator g, hash).
201
192
  * @returns Verifier as Base64 string.
202
193
  */
203
- generateSrpVerifier(authHash: string, ctx: SrpContext): Promise<string>;
194
+ generateSrpVerifier(authHash: string, group: SrpGroup): Promise<string>;
204
195
  /**
205
196
  * Generates client proof (A, M1, session key S) from server challenge.
206
197
  * @param login - User login.
207
- * @param password - Plaintext password.
198
+ * @param authHashBytes - SRP private exponent x as raw bytes (derived from auth hash).
208
199
  * @param saltBase64 - Server salt (standard Base64).
209
200
  * @param B_base64 - Server public ephemeral B (standard Base64).
210
- * @param ctx - SRP context.
201
+ * @param group - SRP group (determines modulus N, generator g, hash).
211
202
  * @returns Object with A and M1 as standard Base64; SessionKeyK as raw bytes.
212
203
  */
213
- generateSrpProof(login: string, password: string, saltBase64: string, B_base64: string, ctx: SrpContext, version: CryptoVersion): Promise<{
204
+ generateSrpProof(login: string, authHashBytes: Uint8Array<ArrayBufferLike>, saltBase64: string, B_base64: string, group: SrpGroup): Promise<{
214
205
  A: string;
215
206
  M1: string;
216
207
  SessionKeyK: Uint8Array;
@@ -219,12 +210,12 @@ declare class SrpClientService {
219
210
  * Validates the server proof M2 to authenticate the server.
220
211
  * @param A_b64 - Client public A (Base64).
221
212
  * @param M1_b64 - Client proof M1 (Base64).
222
- * @param S_b64 - Session key S (Base64).
213
+ * @param sessionKeyK - Session key K as raw bytes.
223
214
  * @param serverM2_b64 - Server proof M2 (Base64).
224
- * @param ctx - SRP context.
215
+ * @param group - SRP group (determines modulus N, generator g, hash).
225
216
  * @returns True if the server proof is valid.
226
217
  */
227
- verifyServerM2(A_b64: string, M1_b64: string, sessionKeyK: Uint8Array, serverM2_b64: string, ctx: SrpContext): Promise<boolean>;
218
+ verifyServerM2(A_b64: string, M1_b64: string, sessionKeyK: Uint8Array, serverM2_b64: string, group: SrpGroup): Promise<boolean>;
228
219
  }
229
220
 
230
221
  /**
@@ -233,13 +224,13 @@ declare class SrpClientService {
233
224
  interface SrpSessionState {
234
225
  /** User login identifier. */
235
226
  login: string;
236
- /** Server private ephemeral key (Base64). */
227
+ /** Server private ephemeral key (raw bytes). */
237
228
  privateKeyB: Uint8Array;
238
- /** Password verifier (Base64). */
229
+ /** Password verifier v (raw bytes). */
239
230
  verifier: Uint8Array;
240
- /** Server public ephemeral key B (Base64). */
231
+ /** Server public ephemeral key B (raw bytes). */
241
232
  publicKeyB: Uint8Array;
242
- /** User salt s (needed for RFC 5054 M1). */
233
+ /** User salt s (raw bytes). */
243
234
  salt: Uint8Array;
244
235
  }
245
236
  /**
@@ -250,45 +241,39 @@ declare class SrpServerService {
250
241
  * Generates server challenge B and session state from verifier.
251
242
  * @param login - User login.
252
243
  * @param verifierBytes - Stored verifier v as byte array.
253
- * @param ctx - SRP context (hash, N, g, etc.).
254
- * @returns Session state with private b, verifier, and public B.
244
+ * @param salt - User salt (raw bytes).
245
+ * @param group - SRP group (determines modulus N, generator g, hash).
246
+ * @returns Session state with private b, verifier, public B, and salt.
255
247
  */
256
- getSrpChallenge(login: string, verifierBytes: Uint8Array, salt: Uint8Array, ctx: SrpContext): Promise<SrpSessionState>;
248
+ getSrpChallenge(login: string, verifierBytes: Uint8Array, salt: Uint8Array, group: SrpGroup): Promise<SrpSessionState>;
257
249
  /**
258
250
  * Verifies client M1 proof and returns server M2 proof.
259
251
  * @param sessionState - Server session state.
260
252
  * @param a - Client public A (Base64).
261
253
  * @param m1 - Client proof M1 (Base64).
262
- * @param ctx - SRP context.
254
+ * @param group - SRP group (determines modulus N, generator g, hash).
263
255
  * @returns Server proof M2 as Base64 string.
264
256
  * @throws If verification fails or input is invalid.
265
257
  */
266
- verifySrpProof(sessionState: SrpSessionState, a: string, m1: string, ctx: SrpContext): Promise<string>;
258
+ verifySrpProof(sessionState: SrpSessionState, a: string, m1: string, group: SrpGroup): Promise<string>;
267
259
  }
268
260
 
269
261
  /**
270
- * SRP-6a Diffie-Hellman groups (RFC 5054).
271
- * 1024 (~80) deprecated, 1536 (~90) legacy, 2048 (~112) baseline,
272
- * 3072+ (≥128) preferred. g=2 for ≤2048, g=5 for 3072-6144, g=19 for 8192.
273
- * Always use {@link SrpGroupParams} to get N and g.
262
+ * Service for deriving SRP authentication hashes via PBKDF2 → HKDF.
274
263
  */
275
- declare enum SrpGroup {
276
- /** 1024-bit, g=2, ~80-bit security. Deprecated, legacy only. */
277
- Rfc5054_1024 = 1,
278
- /** 1536-bit, g=2, ~90-bit security. Minimum for legacy systems. */
279
- Rfc5054_1536 = 2,
280
- /** 2048-bit, g=2, ~112-bit security. Recommended baseline. */
281
- Rfc5054_2048 = 3,
282
- /** 3072-bit, g=5, ~128-bit security. Preferred for long-term. */
283
- Rfc5054_3072 = 4,
284
- /** 4096-bit, g=5, ~156-bit security. High-security environments. */
285
- Rfc5054_4096 = 5,
286
- /** 6144-bit, g=5, ~192-bit security. Specialized high-assurance. */
287
- Rfc5054_6144 = 6,
288
- /** 8192-bit, g=19, ~256-bit security. Experimental, extremely slow. */
289
- Rfc5054_8192 = 7,
290
- /** User-supplied N and g. Validate safe prime and generator. */
291
- Custom = 99
264
+ declare class SrpKeyDerivationService {
265
+ /**
266
+ * Derives an SRP-compatible authentication hash (output size = hash output length).
267
+ * Identity is used as-is in the combined string — caller must normalize
268
+ * (trim, lowercase, etc.) before calling.
269
+ * @param identity - User identity (email, username). Must be pre-normalized by caller.
270
+ * @param password - User password.
271
+ * @param salt - Random salt (minimum 16 bytes).
272
+ * @param srpGroup - SRP group (determines hash algorithm and modulus).
273
+ * @param version - Crypto version for KDF profile selection.
274
+ * @returns Raw hash bytes for use as SRP verifier input (x).
275
+ */
276
+ deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpGroup: SrpGroup, version: CryptoVersion): Promise<Uint8Array>;
292
277
  }
293
278
 
294
279
  /**
@@ -333,6 +318,24 @@ declare class SrpGroupParams {
333
318
  static getG(group: SrpGroup): bigint;
334
319
  }
335
320
 
321
+ /**
322
+ * Immutable SRP cryptographic context: modulus, generator, multiplier k, hash algorithm, and sizes.
323
+ */
324
+ interface SrpContext {
325
+ /** Prime modulus N. */
326
+ readonly N: bigint;
327
+ /** Generator g. */
328
+ readonly g: bigint;
329
+ /** Multiplier k = H(PAD(N) || PAD(g)) (RFC 5054, 2.5.3) */
330
+ readonly k: bigint;
331
+ /** Modulus size in bytes (ceil(bit length / 8)). */
332
+ readonly modulusSize: number;
333
+ /** Hash algorithm used for SRP computations. */
334
+ readonly hashAlgorithmName: HashAlgorithm;
335
+ /** Hash output size in bytes (e.g., 32 for SHA-256). */
336
+ readonly hashSize: number;
337
+ }
338
+
336
339
  /**
337
340
  * Factory for creating an {@link SrpContext} from an SRP group.
338
341
  * Automatically selects the hash algorithm (SHA-256 for ≤3072-bit, SHA-384 for 4096+).
@@ -360,8 +363,15 @@ declare class SecurityUtils {
360
363
  static bigIntToFixedBytes(bn: bigint, length: number): Uint8Array;
361
364
  /** Constant-time comparison of two Uint8Arrays. */
362
365
  static fixedTimeEquals(a: Uint8Array, b: Uint8Array): boolean;
363
- /** Modular exponentiation (base^exp mod mod) using binary exponentiation. */
364
- static expMod(base: bigint, exp: bigint, mod: bigint): bigint;
366
+ /**
367
+ * Async modular exponentiation with event-loop yielding.
368
+ * @param base - The base value.
369
+ * @param exp - The exponent.
370
+ * @param mod - The modulus.
371
+ * @param yieldEvery - Number of iterations before yielding (default 64).
372
+ */
373
+ static expModAsync(base: bigint, exp: bigint, mod: bigint, yieldEvery?: number): Promise<bigint>;
374
+ /** Converts bigint to minimal-length big-endian bytes (no padding). */
365
375
  static bigIntToRawBytes(bn: bigint): Uint8Array;
366
376
  }
367
377
 
@@ -381,7 +391,7 @@ declare class SrpEncoding {
381
391
  * Follows RFC 5054 / SRP-6a:
382
392
  * - H(N) and H(g) are hashed as modulus-sized values.
383
393
  * - Identity (I) is hashed as raw UTF-8 bytes.
384
- * - A and B are padded to the modulus size before hashing.
394
+ * - A and B are zero-padded to the modulus size before hashing.
385
395
  * - K is the session key (H(S) without padding).
386
396
  *
387
397
  * @param ctx - SRP context containing N, g, hash algorithm, and modulus size.
@@ -393,14 +403,17 @@ declare class SrpEncoding {
393
403
  * @returns The M1 proof as raw hash bytes.
394
404
  */
395
405
  static computeM1(ctx: SrpContext, A: bigint, B: bigint, sessionKeyK: Uint8Array, identity: string, salt: Uint8Array): Promise<Uint8Array>;
396
- /** Computes M2 = H(A || M1 || sessionKeyK). */
406
+ /**
407
+ * Computes M2 = H( PAD(A) || M1 || sessionKeyK ).
408
+ * A is zero-padded to the modulus size before hashing.
409
+ */
397
410
  static computeM2(ctx: SrpContext, A: bigint, m1Bytes: Uint8Array, sessionKeyK: Uint8Array): Promise<Uint8Array>;
398
411
  /** Computes session key K = H(S). */
399
412
  static computeSessionKey(ctx: SrpContext, S: bigint): Promise<Uint8Array>;
400
- /** Hashes bytes and returns raw Uint8Array (для M1/M2). */
413
+ /** Hashes concatenated byte arrays and returns raw Uint8Array. */
401
414
  private static computeHash;
402
415
  /** Concatenates byte arrays and returns the hash as bigint. */
403
416
  private static hash;
404
417
  }
405
418
 
406
- export { AesGcmOptions, CryptoProfile, CryptoProfileRegistry, CryptoService, CryptoVersion, type HashAlgorithm, KdfOptions, KeyDerivationService, SecurityConstants, SecurityUtils, SrpClientService, type SrpContext, SrpContextFactory, SrpEncoding, SrpGroup, SrpGroupParams, SrpOptions, SrpServerService, type SrpSessionState, SupportedHashAlgorithms };
419
+ export { AesGcmOptions, CryptoProfile, CryptoProfileRegistry, CryptoService, CryptoVersion, type HashAlgorithm, KdfOptions, KeyDerivationService, SecurityConstants, SecurityUtils, SrpClientService, type SrpContext, SrpContextFactory, SrpEncoding, SrpGroup, SrpGroupParams, SrpKeyDerivationService, SrpOptions, SrpServerService, type SrpSessionState, SupportedHashAlgorithms };