mask-privacy 4.1.0 → 4.2.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 CHANGED
@@ -180,44 +180,43 @@ declare class MaskSecurityError extends MaskError {
180
180
  /**
181
181
  * Core cryptography engine for Mask SDK.
182
182
  *
183
- * Provides a CryptoEngine singleton that handles Envelope Encryption,
184
- * ensuring that plaintext PII is encrypted locally before being
185
- * transmitted and stored in distributed vaults (Redis/Memcached/DynamoDB).
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
- * Uses AES-256-GCM (authenticated encryption) via native Node.js crypto.
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
- * Requires MASK_ENCRYPTION_KEY to be set in the environment.
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 _aesKey;
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
- * This is asynchronous because key providers (KMS, etc.) might be async.
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 instance to force re-initialization (useful for key rotation). */
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
- * Provides a CryptoEngine singleton that handles Envelope Encryption,
184
- * ensuring that plaintext PII is encrypted locally before being
185
- * transmitted and stored in distributed vaults (Redis/Memcached/DynamoDB).
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
- * Uses AES-256-GCM (authenticated encryption) via native Node.js crypto.
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
- * Requires MASK_ENCRYPTION_KEY to be set in the environment.
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 _aesKey;
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
- * This is asynchronous because key providers (KMS, etc.) might be async.
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 instance to force re-initialization (useful for key rotation). */
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