@crossdyne/security 0.4.0-beta.1 → 0.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +195 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -68
- package/dist/index.d.ts +73 -68
- package/dist/index.js +195 -154
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -13,33 +13,13 @@ declare const SecurityConstants: {
|
|
|
13
13
|
declare const SupportedHashAlgorithms: ReadonlyArray<HashAlgorithm>;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Supported cryptographic profile versions.
|
|
17
|
+
* V1: baseline (PBKDF2-HMAC-SHA256, AES-256-GCM, 12-byte nonce, 16-byte tag).
|
|
18
|
+
* Append new members sequentially; never change existing values.
|
|
18
19
|
*/
|
|
19
|
-
declare
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/** Optional Additional Authenticated Data (not encrypted). */
|
|
23
|
-
associatedData?: Uint8Array;
|
|
24
|
-
/** Nonce size in bytes (must be 12). */
|
|
25
|
-
get nonceSize(): number;
|
|
26
|
-
set nonceSize(v: number);
|
|
27
|
-
/** Tag size in bytes (12–16, default 16). */
|
|
28
|
-
get tagSize(): number;
|
|
29
|
-
set tagSize(v: number);
|
|
30
|
-
/** Validates that {@link tagSize} is in the allowed range. */
|
|
31
|
-
validate(): void;
|
|
32
|
-
/** Default preset: nonce=12, tag=16, no AAD. */
|
|
33
|
-
static get default(): AesGcmOptions;
|
|
34
|
-
/** Fluent setter for {@link tagSize}. */
|
|
35
|
-
withTagSize(s: number): this;
|
|
36
|
-
/**
|
|
37
|
-
* Fluent setter for {@link associatedData}.
|
|
38
|
-
* Accepts a byte array or a UTF-8 string (encoded internally).
|
|
39
|
-
*/
|
|
40
|
-
withAssociatedData(aad: Uint8Array | string | undefined): this;
|
|
41
|
-
/** Validates and returns this instance. */
|
|
42
|
-
build(): AesGcmOptions;
|
|
20
|
+
declare enum CryptoVersion {
|
|
21
|
+
/** Version 1 — initial profile. */
|
|
22
|
+
V1 = 1
|
|
43
23
|
}
|
|
44
24
|
|
|
45
25
|
/**
|
|
@@ -54,7 +34,7 @@ declare class CryptoService {
|
|
|
54
34
|
* @param options - AES-GCM configuration; uses default if omitted.
|
|
55
35
|
* @returns Base64-encoded ciphertext with prepended nonce.
|
|
56
36
|
*/
|
|
57
|
-
encryptData<T>(dataModel: T, key: Uint8Array,
|
|
37
|
+
encryptData<T>(dataModel: T, key: Uint8Array, version?: CryptoVersion): Promise<string>;
|
|
58
38
|
/**
|
|
59
39
|
* Decrypts a Base64-encoded ciphertext back to the original object.
|
|
60
40
|
* @param encryptedBase64 - The encrypted data.
|
|
@@ -63,7 +43,7 @@ declare class CryptoService {
|
|
|
63
43
|
* @returns Deserialized object, or null if input is empty.
|
|
64
44
|
* @throws If authentication tag mismatch or corrupted data.
|
|
65
45
|
*/
|
|
66
|
-
decryptData<T>(encryptedBase64: string, key: Uint8Array,
|
|
46
|
+
decryptData<T>(encryptedBase64: string, key: Uint8Array, isBytes?: boolean): Promise<T | null>;
|
|
67
47
|
/**
|
|
68
48
|
* Generates cryptographically secure random bytes.
|
|
69
49
|
* @param length - Number of bytes (default 32).
|
|
@@ -72,49 +52,28 @@ declare class CryptoService {
|
|
|
72
52
|
generateRandomBytes: (length?: number) => Uint8Array;
|
|
73
53
|
}
|
|
74
54
|
|
|
75
|
-
/**
|
|
76
|
-
* PBKDF2 key derivation options: iterations count and hash algorithm.
|
|
77
|
-
* Mutable builder-style; call {@link build} to validate.
|
|
78
|
-
*/
|
|
79
|
-
declare class KdfOptions {
|
|
80
|
-
private _pbkdf2Iterations;
|
|
81
|
-
private _hashAlgorithm;
|
|
82
|
-
/** PBKDF2 iteration count (minimum 100_000). */
|
|
83
|
-
get pbkdf2Iterations(): number;
|
|
84
|
-
set pbkdf2Iterations(v: number);
|
|
85
|
-
/** Hash algorithm used by PBKDF2. Must be one of {@link SupportedHashAlgorithms}. */
|
|
86
|
-
get hashAlgorithm(): HashAlgorithm;
|
|
87
|
-
set hashAlgorithm(v: HashAlgorithm);
|
|
88
|
-
/** Validates iterations and hash algorithm. */
|
|
89
|
-
validate(): void;
|
|
90
|
-
/** Default preset: SHA-256, 600_000 iterations. */
|
|
91
|
-
static get default(): KdfOptions;
|
|
92
|
-
/** Fluent setter for {@link pbkdf2Iterations}. */
|
|
93
|
-
withPbkdf2Iterations(i: number): this;
|
|
94
|
-
/** Fluent setter for {@link hashAlgorithm}. */
|
|
95
|
-
withHashAlgorithm(h: HashAlgorithm): this;
|
|
96
|
-
/** Validates and returns this instance. */
|
|
97
|
-
build(): KdfOptions;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
55
|
/**
|
|
101
56
|
* Two-stage key derivation: PBKDF2 (master key) → HKDF (sub-keys).
|
|
102
57
|
*/
|
|
103
58
|
declare class KeyDerivationService {
|
|
104
59
|
/**
|
|
105
|
-
* Derives KEK and Base64 AuthHash. Identity is
|
|
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).
|
|
106
63
|
* @param identity - User identity (email, username).
|
|
107
64
|
* @param password - User password.
|
|
108
65
|
* @param salt - Random salt.
|
|
109
66
|
* @param options - KDF configuration; uses default if omitted.
|
|
110
67
|
* @returns Object with `kek` (Uint8Array) and `authHash` (Base64 string).
|
|
111
68
|
*/
|
|
112
|
-
deriveKeysFromPassword(identity: string, password: string, salt: Uint8Array,
|
|
69
|
+
deriveKeysFromPassword(identity: string, password: string, salt: Uint8Array, version: CryptoVersion): Promise<{
|
|
113
70
|
kek: Uint8Array;
|
|
114
71
|
authHash: string;
|
|
115
72
|
}>;
|
|
116
73
|
/**
|
|
117
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).
|
|
118
77
|
* @param identity - User identity.
|
|
119
78
|
* @param password - User password.
|
|
120
79
|
* @param salt - Random salt.
|
|
@@ -122,17 +81,62 @@ declare class KeyDerivationService {
|
|
|
122
81
|
* @param options - KDF configuration; uses default if omitted.
|
|
123
82
|
* @returns Raw hash bytes for use as SRP verifier input (x).
|
|
124
83
|
*/
|
|
125
|
-
deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpHashAlgorithm: HashAlgorithm,
|
|
84
|
+
deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpHashAlgorithm: HashAlgorithm, version: CryptoVersion): Promise<Uint8Array>;
|
|
126
85
|
}
|
|
127
86
|
|
|
128
87
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* Append new members sequentially; never change existing values.
|
|
88
|
+
* AES-GCM encryption options: nonce size, tag size, and optional AAD.
|
|
89
|
+
* Mutable builder-style; call {@link build} to validate.
|
|
132
90
|
*/
|
|
133
|
-
declare
|
|
134
|
-
|
|
135
|
-
|
|
91
|
+
declare class AesGcmOptions {
|
|
92
|
+
private _nonceSize;
|
|
93
|
+
private _tagSize;
|
|
94
|
+
/** Optional Additional Authenticated Data (not encrypted). */
|
|
95
|
+
associatedData?: Uint8Array;
|
|
96
|
+
/** Nonce size in bytes (must be 12). */
|
|
97
|
+
get nonceSize(): number;
|
|
98
|
+
set nonceSize(v: number);
|
|
99
|
+
/** Tag size in bytes (12–16, default 16). */
|
|
100
|
+
get tagSize(): number;
|
|
101
|
+
set tagSize(v: number);
|
|
102
|
+
/** Validates that {@link tagSize} is in the allowed range. */
|
|
103
|
+
validate(): void;
|
|
104
|
+
/** Default preset: nonce=12, tag=16, no AAD. */
|
|
105
|
+
static get default(): AesGcmOptions;
|
|
106
|
+
/** Fluent setter for {@link tagSize}. */
|
|
107
|
+
withTagSize(s: number): this;
|
|
108
|
+
/**
|
|
109
|
+
* Fluent setter for {@link associatedData}.
|
|
110
|
+
* Accepts a byte array or a UTF-8 string (encoded internally).
|
|
111
|
+
*/
|
|
112
|
+
withAssociatedData(aad: Uint8Array | string | undefined): this;
|
|
113
|
+
/** Validates and returns this instance. */
|
|
114
|
+
build(): AesGcmOptions;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* PBKDF2 key derivation options: iterations count and hash algorithm.
|
|
119
|
+
* Mutable builder-style; call {@link build} to validate.
|
|
120
|
+
*/
|
|
121
|
+
declare class KdfOptions {
|
|
122
|
+
private _pbkdf2Iterations;
|
|
123
|
+
private _hashAlgorithm;
|
|
124
|
+
/** PBKDF2 iteration count (minimum 100_000). */
|
|
125
|
+
get pbkdf2Iterations(): number;
|
|
126
|
+
set pbkdf2Iterations(v: number);
|
|
127
|
+
/** Hash algorithm used by PBKDF2. Must be one of {@link SupportedHashAlgorithms}. */
|
|
128
|
+
get hashAlgorithm(): HashAlgorithm;
|
|
129
|
+
set hashAlgorithm(v: HashAlgorithm);
|
|
130
|
+
/** Validates iterations and hash algorithm. */
|
|
131
|
+
validate(): void;
|
|
132
|
+
/** Default preset: SHA-256, 600_000 iterations. */
|
|
133
|
+
static get default(): KdfOptions;
|
|
134
|
+
/** Fluent setter for {@link pbkdf2Iterations}. */
|
|
135
|
+
withPbkdf2Iterations(i: number): this;
|
|
136
|
+
/** Fluent setter for {@link hashAlgorithm}. */
|
|
137
|
+
withHashAlgorithm(h: HashAlgorithm): this;
|
|
138
|
+
/** Validates and returns this instance. */
|
|
139
|
+
build(): KdfOptions;
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
/**
|
|
@@ -201,12 +205,12 @@ declare class SrpClientService {
|
|
|
201
205
|
* Generates client proof (A, M1, session key S) from server challenge.
|
|
202
206
|
* @param login - User login.
|
|
203
207
|
* @param password - Plaintext password.
|
|
204
|
-
* @param saltBase64 - Server salt (
|
|
205
|
-
* @param B_base64 - Server public ephemeral B (
|
|
208
|
+
* @param saltBase64 - Server salt (standard Base64).
|
|
209
|
+
* @param B_base64 - Server public ephemeral B (standard Base64).
|
|
206
210
|
* @param ctx - SRP context.
|
|
207
|
-
* @returns Object with A
|
|
211
|
+
* @returns Object with A and M1 as standard Base64; SessionKeyK as raw bytes.
|
|
208
212
|
*/
|
|
209
|
-
generateSrpProof(login: string, password: string, saltBase64: string, B_base64: string, ctx: SrpContext): Promise<{
|
|
213
|
+
generateSrpProof(login: string, password: string, saltBase64: string, B_base64: string, ctx: SrpContext, version: CryptoVersion): Promise<{
|
|
210
214
|
A: string;
|
|
211
215
|
M1: string;
|
|
212
216
|
SessionKeyK: Uint8Array;
|
|
@@ -352,12 +356,13 @@ declare class SecurityUtils {
|
|
|
352
356
|
static fromBase64(base64: string): Uint8Array;
|
|
353
357
|
/** Converts big-endian bytes to bigint. */
|
|
354
358
|
static bytesToBigInt(bytes: Uint8Array): bigint;
|
|
355
|
-
/** Converts bigint to fixed-length big-endian bytes (pads
|
|
359
|
+
/** Converts bigint to fixed-length big-endian bytes (pads only; never truncates). */
|
|
356
360
|
static bigIntToFixedBytes(bn: bigint, length: number): Uint8Array;
|
|
357
361
|
/** Constant-time comparison of two Uint8Arrays. */
|
|
358
362
|
static fixedTimeEquals(a: Uint8Array, b: Uint8Array): boolean;
|
|
359
363
|
/** Modular exponentiation (base^exp mod mod) using binary exponentiation. */
|
|
360
364
|
static expMod(base: bigint, exp: bigint, mod: bigint): bigint;
|
|
365
|
+
static bigIntToRawBytes(bn: bigint): Uint8Array;
|
|
361
366
|
}
|
|
362
367
|
|
|
363
368
|
/**
|
|
@@ -383,7 +388,7 @@ declare class SrpEncoding {
|
|
|
383
388
|
* @param A - Client ephemeral public key.
|
|
384
389
|
* @param B - Server ephemeral public key.
|
|
385
390
|
* @param sessionKeyK - Session key K as raw bytes.
|
|
386
|
-
* @param identity - User identity (login).
|
|
391
|
+
* @param identity - User identity (login). Must be pre-normalized by the caller.
|
|
387
392
|
* @param salt - User-specific salt bytes.
|
|
388
393
|
* @returns The M1 proof as raw hash bytes.
|
|
389
394
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -13,33 +13,13 @@ declare const SecurityConstants: {
|
|
|
13
13
|
declare const SupportedHashAlgorithms: ReadonlyArray<HashAlgorithm>;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Supported cryptographic profile versions.
|
|
17
|
+
* V1: baseline (PBKDF2-HMAC-SHA256, AES-256-GCM, 12-byte nonce, 16-byte tag).
|
|
18
|
+
* Append new members sequentially; never change existing values.
|
|
18
19
|
*/
|
|
19
|
-
declare
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/** Optional Additional Authenticated Data (not encrypted). */
|
|
23
|
-
associatedData?: Uint8Array;
|
|
24
|
-
/** Nonce size in bytes (must be 12). */
|
|
25
|
-
get nonceSize(): number;
|
|
26
|
-
set nonceSize(v: number);
|
|
27
|
-
/** Tag size in bytes (12–16, default 16). */
|
|
28
|
-
get tagSize(): number;
|
|
29
|
-
set tagSize(v: number);
|
|
30
|
-
/** Validates that {@link tagSize} is in the allowed range. */
|
|
31
|
-
validate(): void;
|
|
32
|
-
/** Default preset: nonce=12, tag=16, no AAD. */
|
|
33
|
-
static get default(): AesGcmOptions;
|
|
34
|
-
/** Fluent setter for {@link tagSize}. */
|
|
35
|
-
withTagSize(s: number): this;
|
|
36
|
-
/**
|
|
37
|
-
* Fluent setter for {@link associatedData}.
|
|
38
|
-
* Accepts a byte array or a UTF-8 string (encoded internally).
|
|
39
|
-
*/
|
|
40
|
-
withAssociatedData(aad: Uint8Array | string | undefined): this;
|
|
41
|
-
/** Validates and returns this instance. */
|
|
42
|
-
build(): AesGcmOptions;
|
|
20
|
+
declare enum CryptoVersion {
|
|
21
|
+
/** Version 1 — initial profile. */
|
|
22
|
+
V1 = 1
|
|
43
23
|
}
|
|
44
24
|
|
|
45
25
|
/**
|
|
@@ -54,7 +34,7 @@ declare class CryptoService {
|
|
|
54
34
|
* @param options - AES-GCM configuration; uses default if omitted.
|
|
55
35
|
* @returns Base64-encoded ciphertext with prepended nonce.
|
|
56
36
|
*/
|
|
57
|
-
encryptData<T>(dataModel: T, key: Uint8Array,
|
|
37
|
+
encryptData<T>(dataModel: T, key: Uint8Array, version?: CryptoVersion): Promise<string>;
|
|
58
38
|
/**
|
|
59
39
|
* Decrypts a Base64-encoded ciphertext back to the original object.
|
|
60
40
|
* @param encryptedBase64 - The encrypted data.
|
|
@@ -63,7 +43,7 @@ declare class CryptoService {
|
|
|
63
43
|
* @returns Deserialized object, or null if input is empty.
|
|
64
44
|
* @throws If authentication tag mismatch or corrupted data.
|
|
65
45
|
*/
|
|
66
|
-
decryptData<T>(encryptedBase64: string, key: Uint8Array,
|
|
46
|
+
decryptData<T>(encryptedBase64: string, key: Uint8Array, isBytes?: boolean): Promise<T | null>;
|
|
67
47
|
/**
|
|
68
48
|
* Generates cryptographically secure random bytes.
|
|
69
49
|
* @param length - Number of bytes (default 32).
|
|
@@ -72,49 +52,28 @@ declare class CryptoService {
|
|
|
72
52
|
generateRandomBytes: (length?: number) => Uint8Array;
|
|
73
53
|
}
|
|
74
54
|
|
|
75
|
-
/**
|
|
76
|
-
* PBKDF2 key derivation options: iterations count and hash algorithm.
|
|
77
|
-
* Mutable builder-style; call {@link build} to validate.
|
|
78
|
-
*/
|
|
79
|
-
declare class KdfOptions {
|
|
80
|
-
private _pbkdf2Iterations;
|
|
81
|
-
private _hashAlgorithm;
|
|
82
|
-
/** PBKDF2 iteration count (minimum 100_000). */
|
|
83
|
-
get pbkdf2Iterations(): number;
|
|
84
|
-
set pbkdf2Iterations(v: number);
|
|
85
|
-
/** Hash algorithm used by PBKDF2. Must be one of {@link SupportedHashAlgorithms}. */
|
|
86
|
-
get hashAlgorithm(): HashAlgorithm;
|
|
87
|
-
set hashAlgorithm(v: HashAlgorithm);
|
|
88
|
-
/** Validates iterations and hash algorithm. */
|
|
89
|
-
validate(): void;
|
|
90
|
-
/** Default preset: SHA-256, 600_000 iterations. */
|
|
91
|
-
static get default(): KdfOptions;
|
|
92
|
-
/** Fluent setter for {@link pbkdf2Iterations}. */
|
|
93
|
-
withPbkdf2Iterations(i: number): this;
|
|
94
|
-
/** Fluent setter for {@link hashAlgorithm}. */
|
|
95
|
-
withHashAlgorithm(h: HashAlgorithm): this;
|
|
96
|
-
/** Validates and returns this instance. */
|
|
97
|
-
build(): KdfOptions;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
55
|
/**
|
|
101
56
|
* Two-stage key derivation: PBKDF2 (master key) → HKDF (sub-keys).
|
|
102
57
|
*/
|
|
103
58
|
declare class KeyDerivationService {
|
|
104
59
|
/**
|
|
105
|
-
* Derives KEK and Base64 AuthHash. Identity is
|
|
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).
|
|
106
63
|
* @param identity - User identity (email, username).
|
|
107
64
|
* @param password - User password.
|
|
108
65
|
* @param salt - Random salt.
|
|
109
66
|
* @param options - KDF configuration; uses default if omitted.
|
|
110
67
|
* @returns Object with `kek` (Uint8Array) and `authHash` (Base64 string).
|
|
111
68
|
*/
|
|
112
|
-
deriveKeysFromPassword(identity: string, password: string, salt: Uint8Array,
|
|
69
|
+
deriveKeysFromPassword(identity: string, password: string, salt: Uint8Array, version: CryptoVersion): Promise<{
|
|
113
70
|
kek: Uint8Array;
|
|
114
71
|
authHash: string;
|
|
115
72
|
}>;
|
|
116
73
|
/**
|
|
117
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).
|
|
118
77
|
* @param identity - User identity.
|
|
119
78
|
* @param password - User password.
|
|
120
79
|
* @param salt - Random salt.
|
|
@@ -122,17 +81,62 @@ declare class KeyDerivationService {
|
|
|
122
81
|
* @param options - KDF configuration; uses default if omitted.
|
|
123
82
|
* @returns Raw hash bytes for use as SRP verifier input (x).
|
|
124
83
|
*/
|
|
125
|
-
deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpHashAlgorithm: HashAlgorithm,
|
|
84
|
+
deriveAuthHashForSrp(identity: string, password: string, salt: Uint8Array, srpHashAlgorithm: HashAlgorithm, version: CryptoVersion): Promise<Uint8Array>;
|
|
126
85
|
}
|
|
127
86
|
|
|
128
87
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* Append new members sequentially; never change existing values.
|
|
88
|
+
* AES-GCM encryption options: nonce size, tag size, and optional AAD.
|
|
89
|
+
* Mutable builder-style; call {@link build} to validate.
|
|
132
90
|
*/
|
|
133
|
-
declare
|
|
134
|
-
|
|
135
|
-
|
|
91
|
+
declare class AesGcmOptions {
|
|
92
|
+
private _nonceSize;
|
|
93
|
+
private _tagSize;
|
|
94
|
+
/** Optional Additional Authenticated Data (not encrypted). */
|
|
95
|
+
associatedData?: Uint8Array;
|
|
96
|
+
/** Nonce size in bytes (must be 12). */
|
|
97
|
+
get nonceSize(): number;
|
|
98
|
+
set nonceSize(v: number);
|
|
99
|
+
/** Tag size in bytes (12–16, default 16). */
|
|
100
|
+
get tagSize(): number;
|
|
101
|
+
set tagSize(v: number);
|
|
102
|
+
/** Validates that {@link tagSize} is in the allowed range. */
|
|
103
|
+
validate(): void;
|
|
104
|
+
/** Default preset: nonce=12, tag=16, no AAD. */
|
|
105
|
+
static get default(): AesGcmOptions;
|
|
106
|
+
/** Fluent setter for {@link tagSize}. */
|
|
107
|
+
withTagSize(s: number): this;
|
|
108
|
+
/**
|
|
109
|
+
* Fluent setter for {@link associatedData}.
|
|
110
|
+
* Accepts a byte array or a UTF-8 string (encoded internally).
|
|
111
|
+
*/
|
|
112
|
+
withAssociatedData(aad: Uint8Array | string | undefined): this;
|
|
113
|
+
/** Validates and returns this instance. */
|
|
114
|
+
build(): AesGcmOptions;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* PBKDF2 key derivation options: iterations count and hash algorithm.
|
|
119
|
+
* Mutable builder-style; call {@link build} to validate.
|
|
120
|
+
*/
|
|
121
|
+
declare class KdfOptions {
|
|
122
|
+
private _pbkdf2Iterations;
|
|
123
|
+
private _hashAlgorithm;
|
|
124
|
+
/** PBKDF2 iteration count (minimum 100_000). */
|
|
125
|
+
get pbkdf2Iterations(): number;
|
|
126
|
+
set pbkdf2Iterations(v: number);
|
|
127
|
+
/** Hash algorithm used by PBKDF2. Must be one of {@link SupportedHashAlgorithms}. */
|
|
128
|
+
get hashAlgorithm(): HashAlgorithm;
|
|
129
|
+
set hashAlgorithm(v: HashAlgorithm);
|
|
130
|
+
/** Validates iterations and hash algorithm. */
|
|
131
|
+
validate(): void;
|
|
132
|
+
/** Default preset: SHA-256, 600_000 iterations. */
|
|
133
|
+
static get default(): KdfOptions;
|
|
134
|
+
/** Fluent setter for {@link pbkdf2Iterations}. */
|
|
135
|
+
withPbkdf2Iterations(i: number): this;
|
|
136
|
+
/** Fluent setter for {@link hashAlgorithm}. */
|
|
137
|
+
withHashAlgorithm(h: HashAlgorithm): this;
|
|
138
|
+
/** Validates and returns this instance. */
|
|
139
|
+
build(): KdfOptions;
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
/**
|
|
@@ -201,12 +205,12 @@ declare class SrpClientService {
|
|
|
201
205
|
* Generates client proof (A, M1, session key S) from server challenge.
|
|
202
206
|
* @param login - User login.
|
|
203
207
|
* @param password - Plaintext password.
|
|
204
|
-
* @param saltBase64 - Server salt (
|
|
205
|
-
* @param B_base64 - Server public ephemeral B (
|
|
208
|
+
* @param saltBase64 - Server salt (standard Base64).
|
|
209
|
+
* @param B_base64 - Server public ephemeral B (standard Base64).
|
|
206
210
|
* @param ctx - SRP context.
|
|
207
|
-
* @returns Object with A
|
|
211
|
+
* @returns Object with A and M1 as standard Base64; SessionKeyK as raw bytes.
|
|
208
212
|
*/
|
|
209
|
-
generateSrpProof(login: string, password: string, saltBase64: string, B_base64: string, ctx: SrpContext): Promise<{
|
|
213
|
+
generateSrpProof(login: string, password: string, saltBase64: string, B_base64: string, ctx: SrpContext, version: CryptoVersion): Promise<{
|
|
210
214
|
A: string;
|
|
211
215
|
M1: string;
|
|
212
216
|
SessionKeyK: Uint8Array;
|
|
@@ -352,12 +356,13 @@ declare class SecurityUtils {
|
|
|
352
356
|
static fromBase64(base64: string): Uint8Array;
|
|
353
357
|
/** Converts big-endian bytes to bigint. */
|
|
354
358
|
static bytesToBigInt(bytes: Uint8Array): bigint;
|
|
355
|
-
/** Converts bigint to fixed-length big-endian bytes (pads
|
|
359
|
+
/** Converts bigint to fixed-length big-endian bytes (pads only; never truncates). */
|
|
356
360
|
static bigIntToFixedBytes(bn: bigint, length: number): Uint8Array;
|
|
357
361
|
/** Constant-time comparison of two Uint8Arrays. */
|
|
358
362
|
static fixedTimeEquals(a: Uint8Array, b: Uint8Array): boolean;
|
|
359
363
|
/** Modular exponentiation (base^exp mod mod) using binary exponentiation. */
|
|
360
364
|
static expMod(base: bigint, exp: bigint, mod: bigint): bigint;
|
|
365
|
+
static bigIntToRawBytes(bn: bigint): Uint8Array;
|
|
361
366
|
}
|
|
362
367
|
|
|
363
368
|
/**
|
|
@@ -383,7 +388,7 @@ declare class SrpEncoding {
|
|
|
383
388
|
* @param A - Client ephemeral public key.
|
|
384
389
|
* @param B - Server ephemeral public key.
|
|
385
390
|
* @param sessionKeyK - Session key K as raw bytes.
|
|
386
|
-
* @param identity - User identity (login).
|
|
391
|
+
* @param identity - User identity (login). Must be pre-normalized by the caller.
|
|
387
392
|
* @param salt - User-specific salt bytes.
|
|
388
393
|
* @returns The M1 proof as raw hash bytes.
|
|
389
394
|
*/
|