mask-privacy 4.1.0 → 4.3.0
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.mts +27 -19
- package/dist/index.d.ts +27 -19
- package/dist/index.js +351 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +335 -173
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +4 -0
- package/src/core/crypto.ts +152 -103
- package/src/core/fpe.ts +68 -33
- package/src/core/fpe_utils.ts +48 -2
- package/src/core/key_provider.ts +80 -0
- package/src/core/vault.ts +92 -67
- package/src/telemetry/audit_logger.ts +93 -15
- package/tests/bijective_fpe.test.ts +2 -2
- package/tests/compliance_pci.test.ts +53 -0
- package/tests/fpe.test.ts +2 -2
- package/tests/security_hardening.test.ts +91 -0
- package/tests/vault_backends.test.ts +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -180,44 +180,43 @@ declare class MaskSecurityError extends MaskError {
|
|
|
180
180
|
/**
|
|
181
181
|
* Core cryptography engine for Mask SDK.
|
|
182
182
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
183
|
+
* Supports a JSON-based Keyring for transparent key rotation:
|
|
184
|
+
* MASK_KEYRING='{"v1":"oldkey...","v2":"newkey..."}'
|
|
185
|
+
* The *last* key in the JSON object is the active encryption key.
|
|
186
|
+
* All keys in the keyring are available for decryption (zero-downtime rotation).
|
|
186
187
|
*
|
|
187
|
-
*
|
|
188
|
-
* Includes a compatibility layer to decrypt legacy Fernet-format tokens.
|
|
188
|
+
* Legacy single-key mode (MASK_ENCRYPTION_KEY) is fully mapped to key ID "default".
|
|
189
189
|
*
|
|
190
|
-
*
|
|
190
|
+
* Ciphertext envelope format: aes:v2:{keyId}:{base64(iv+authTag+ciphertext)}
|
|
191
|
+
*
|
|
192
|
+
* Uses AES-256-GCM via native Node.js crypto and Argon2id for key derivation.
|
|
191
193
|
*/
|
|
192
194
|
declare class CryptoEngine {
|
|
193
195
|
private static _instance;
|
|
194
|
-
private
|
|
196
|
+
private _keyring;
|
|
197
|
+
private _activeKeyId;
|
|
195
198
|
private _indexSecret;
|
|
196
199
|
private constructor();
|
|
197
200
|
/**
|
|
198
201
|
* Return the singleton instance, initialising it if necessary.
|
|
199
|
-
*
|
|
202
|
+
* Async because Argon2id key derivation is async.
|
|
200
203
|
*/
|
|
201
204
|
static getInstanceAsync(): Promise<CryptoEngine>;
|
|
202
205
|
/** Legacy synchronous accessor — will throw if not already initialised. */
|
|
203
206
|
static getInstance(): CryptoEngine;
|
|
204
|
-
/** Clear the singleton
|
|
207
|
+
/** Clear the singleton (useful for key rotation / tests). */
|
|
205
208
|
static reset(): void;
|
|
209
|
+
private _deriveAesKey;
|
|
206
210
|
private _init;
|
|
207
211
|
/** Return the secret used for HMAC-based blind indexing. */
|
|
208
212
|
getIndexSecret(): Promise<Buffer>;
|
|
213
|
+
/** Encrypt plaintext using the active keyring key.
|
|
214
|
+
* Envelope format: aes:v2:{keyId}:{base64(iv+authTag+ciphertext)}
|
|
215
|
+
*/
|
|
209
216
|
encrypt(plaintext: string): string;
|
|
217
|
+
/** Decrypt ciphertext. Supports all historical envelope formats. */
|
|
210
218
|
decrypt(ciphertext: string): string;
|
|
211
|
-
/** Decrypt an AES-256-GCM token (base64 encoded). */
|
|
212
219
|
private _decryptAesGcm;
|
|
213
|
-
/**
|
|
214
|
-
* Attempt to decrypt a legacy Fernet-format token.
|
|
215
|
-
*
|
|
216
|
-
* Fernet format: Version (1) || Timestamp (8) || IV (16) || Ciphertext (var) || HMAC (32)
|
|
217
|
-
* All base64url-encoded.
|
|
218
|
-
*
|
|
219
|
-
* We try to use the `fernet` npm package if available, otherwise throw.
|
|
220
|
-
*/
|
|
221
220
|
private _decryptLegacyFernet;
|
|
222
221
|
}
|
|
223
222
|
|
|
@@ -234,13 +233,22 @@ declare class AuditLogger {
|
|
|
234
233
|
private _shutdownRegistered;
|
|
235
234
|
private _signingKey;
|
|
236
235
|
private _prevSig;
|
|
236
|
+
private _instanceId;
|
|
237
237
|
private constructor();
|
|
238
238
|
static getInstance(): AuditLogger;
|
|
239
|
+
private _getOverflowPath;
|
|
240
|
+
private _writeOverflow;
|
|
241
|
+
private _consumeOverflow;
|
|
239
242
|
log(action: string, token: string, dataType?: string, agent?: string, tool?: string, extra?: Record<string, any>): void;
|
|
240
243
|
start(): void;
|
|
241
244
|
stop(): Promise<void>;
|
|
242
245
|
private _flush;
|
|
243
|
-
/** Synchronous flush for use in signal handlers where async is unreliable.
|
|
246
|
+
/** Synchronous flush for use in signal handlers where async is unreliable.
|
|
247
|
+
*
|
|
248
|
+
* Computes HMAC signatures to maintain chain integrity and writes to the
|
|
249
|
+
* secure ndjson audit file (MASK_SECURE_AUDIT_LOG_DIR) if configured,
|
|
250
|
+
* ensuring SOC 2 tamper-evidence guarantees hold through process shutdown.
|
|
251
|
+
*/
|
|
244
252
|
private _flushSync;
|
|
245
253
|
}
|
|
246
254
|
|
package/dist/index.d.ts
CHANGED
|
@@ -180,44 +180,43 @@ declare class MaskSecurityError extends MaskError {
|
|
|
180
180
|
/**
|
|
181
181
|
* Core cryptography engine for Mask SDK.
|
|
182
182
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
183
|
+
* Supports a JSON-based Keyring for transparent key rotation:
|
|
184
|
+
* MASK_KEYRING='{"v1":"oldkey...","v2":"newkey..."}'
|
|
185
|
+
* The *last* key in the JSON object is the active encryption key.
|
|
186
|
+
* All keys in the keyring are available for decryption (zero-downtime rotation).
|
|
186
187
|
*
|
|
187
|
-
*
|
|
188
|
-
* Includes a compatibility layer to decrypt legacy Fernet-format tokens.
|
|
188
|
+
* Legacy single-key mode (MASK_ENCRYPTION_KEY) is fully mapped to key ID "default".
|
|
189
189
|
*
|
|
190
|
-
*
|
|
190
|
+
* Ciphertext envelope format: aes:v2:{keyId}:{base64(iv+authTag+ciphertext)}
|
|
191
|
+
*
|
|
192
|
+
* Uses AES-256-GCM via native Node.js crypto and Argon2id for key derivation.
|
|
191
193
|
*/
|
|
192
194
|
declare class CryptoEngine {
|
|
193
195
|
private static _instance;
|
|
194
|
-
private
|
|
196
|
+
private _keyring;
|
|
197
|
+
private _activeKeyId;
|
|
195
198
|
private _indexSecret;
|
|
196
199
|
private constructor();
|
|
197
200
|
/**
|
|
198
201
|
* Return the singleton instance, initialising it if necessary.
|
|
199
|
-
*
|
|
202
|
+
* Async because Argon2id key derivation is async.
|
|
200
203
|
*/
|
|
201
204
|
static getInstanceAsync(): Promise<CryptoEngine>;
|
|
202
205
|
/** Legacy synchronous accessor — will throw if not already initialised. */
|
|
203
206
|
static getInstance(): CryptoEngine;
|
|
204
|
-
/** Clear the singleton
|
|
207
|
+
/** Clear the singleton (useful for key rotation / tests). */
|
|
205
208
|
static reset(): void;
|
|
209
|
+
private _deriveAesKey;
|
|
206
210
|
private _init;
|
|
207
211
|
/** Return the secret used for HMAC-based blind indexing. */
|
|
208
212
|
getIndexSecret(): Promise<Buffer>;
|
|
213
|
+
/** Encrypt plaintext using the active keyring key.
|
|
214
|
+
* Envelope format: aes:v2:{keyId}:{base64(iv+authTag+ciphertext)}
|
|
215
|
+
*/
|
|
209
216
|
encrypt(plaintext: string): string;
|
|
217
|
+
/** Decrypt ciphertext. Supports all historical envelope formats. */
|
|
210
218
|
decrypt(ciphertext: string): string;
|
|
211
|
-
/** Decrypt an AES-256-GCM token (base64 encoded). */
|
|
212
219
|
private _decryptAesGcm;
|
|
213
|
-
/**
|
|
214
|
-
* Attempt to decrypt a legacy Fernet-format token.
|
|
215
|
-
*
|
|
216
|
-
* Fernet format: Version (1) || Timestamp (8) || IV (16) || Ciphertext (var) || HMAC (32)
|
|
217
|
-
* All base64url-encoded.
|
|
218
|
-
*
|
|
219
|
-
* We try to use the `fernet` npm package if available, otherwise throw.
|
|
220
|
-
*/
|
|
221
220
|
private _decryptLegacyFernet;
|
|
222
221
|
}
|
|
223
222
|
|
|
@@ -234,13 +233,22 @@ declare class AuditLogger {
|
|
|
234
233
|
private _shutdownRegistered;
|
|
235
234
|
private _signingKey;
|
|
236
235
|
private _prevSig;
|
|
236
|
+
private _instanceId;
|
|
237
237
|
private constructor();
|
|
238
238
|
static getInstance(): AuditLogger;
|
|
239
|
+
private _getOverflowPath;
|
|
240
|
+
private _writeOverflow;
|
|
241
|
+
private _consumeOverflow;
|
|
239
242
|
log(action: string, token: string, dataType?: string, agent?: string, tool?: string, extra?: Record<string, any>): void;
|
|
240
243
|
start(): void;
|
|
241
244
|
stop(): Promise<void>;
|
|
242
245
|
private _flush;
|
|
243
|
-
/** Synchronous flush for use in signal handlers where async is unreliable.
|
|
246
|
+
/** Synchronous flush for use in signal handlers where async is unreliable.
|
|
247
|
+
*
|
|
248
|
+
* Computes HMAC signatures to maintain chain integrity and writes to the
|
|
249
|
+
* secure ndjson audit file (MASK_SECURE_AUDIT_LOG_DIR) if configured,
|
|
250
|
+
* ensuring SOC 2 tamper-evidence guarantees hold through process shutdown.
|
|
251
|
+
*/
|
|
244
252
|
private _flushSync;
|
|
245
253
|
}
|
|
246
254
|
|