mask-privacy 4.0.0 → 4.1.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 +10 -12
- package/dist/index.d.ts +10 -12
- package/dist/index.js +489 -226
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +478 -214
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/config.ts +1 -0
- package/src/core/crypto.ts +50 -15
- package/src/core/exceptions.ts +25 -0
- package/src/core/ff1.ts +196 -0
- package/src/core/fpe.ts +78 -166
- package/src/core/fpe_utils.ts +11 -11
- package/src/core/vault.ts +66 -17
- package/src/telemetry/audit_logger.ts +45 -3
- package/tests/bijective_fpe.test.ts +16 -12
- package/tests/fpe.test.ts +17 -8
- package/tests/security_hardening.test.ts +26 -0
- package/tests/vault.test.ts +67 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/** Interface every vault backend must implement. */
|
|
2
2
|
declare abstract class BaseVault {
|
|
3
|
-
/** Persist a token → plaintext mapping with a TTL
|
|
4
|
-
abstract store(token: string, plaintext: string, ttlSeconds: number, ptHash?: string | null): Promise<void>;
|
|
3
|
+
/** Persist a token → encrypted plaintext mapping with a TTL and optional compliance metadata. */
|
|
4
|
+
abstract store(token: string, plaintext: string, ttlSeconds: number, ptHash?: string | null, metadata?: Record<string, string> | null): Promise<void>;
|
|
5
5
|
/** Return the existing unexpired token for a given plaintext hash, or null. */
|
|
6
6
|
abstract getTokenByPlaintextHash(ptHash: string): Promise<string | null>;
|
|
7
7
|
/** Return the plaintext for token, or null if missing/expired. */
|
|
8
8
|
abstract retrieve(token: string): Promise<string | null>;
|
|
9
|
+
/** Return the plaintext hash stored for this token (used for collision detection), or null. */
|
|
10
|
+
abstract getPtHashForToken(token: string): Promise<string | null>;
|
|
9
11
|
/** Delete a token and its reverse mapping. */
|
|
10
12
|
abstract delete(token: string): Promise<void>;
|
|
11
13
|
}
|
|
@@ -15,6 +17,7 @@ type EncodeOptions = {
|
|
|
15
17
|
searchBuckets?: ('year' | 'month' | 'day' | 'numeric')[];
|
|
16
18
|
searchBucketSize?: number;
|
|
17
19
|
entityType?: string;
|
|
20
|
+
metadata?: Record<string, string> | null;
|
|
18
21
|
};
|
|
19
22
|
/**
|
|
20
23
|
* Tokenise rawText, encrypt it, store in vault, return the FPE token.
|
|
@@ -41,18 +44,11 @@ declare const adetokenizeText: typeof detokenizeText;
|
|
|
41
44
|
declare function looksLikeToken(value: string | any): boolean;
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* Generates structurally valid, **deterministic** tokens that preserve the
|
|
47
|
-
* format of the original data type so downstream tools, schemas, and
|
|
48
|
-
* validators continue to work without modification.
|
|
47
|
+
* Deterministic Pseudonymization (DP) token generation using NIST SP 800-38G FF1.
|
|
49
48
|
*/
|
|
50
|
-
/** Clear the cached master key. Useful in tests. */
|
|
51
49
|
declare function resetMasterKey(): void;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
declare function generateFPEToken(rawText: string, entityType?: string): Promise<string>;
|
|
50
|
+
declare function generateDPToken(rawText: string, entityType?: string): Promise<string>;
|
|
51
|
+
declare const generateFPEToken: typeof generateDPToken;
|
|
56
52
|
|
|
57
53
|
/**
|
|
58
54
|
* Span Resolution Engine — Sweep-Line Overlap Resolver (TypeScript).
|
|
@@ -236,6 +232,8 @@ declare class AuditLogger {
|
|
|
236
232
|
private _strictMode;
|
|
237
233
|
private _bufferFullWarned;
|
|
238
234
|
private _shutdownRegistered;
|
|
235
|
+
private _signingKey;
|
|
236
|
+
private _prevSig;
|
|
239
237
|
private constructor();
|
|
240
238
|
static getInstance(): AuditLogger;
|
|
241
239
|
log(action: string, token: string, dataType?: string, agent?: string, tool?: string, extra?: Record<string, any>): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/** Interface every vault backend must implement. */
|
|
2
2
|
declare abstract class BaseVault {
|
|
3
|
-
/** Persist a token → plaintext mapping with a TTL
|
|
4
|
-
abstract store(token: string, plaintext: string, ttlSeconds: number, ptHash?: string | null): Promise<void>;
|
|
3
|
+
/** Persist a token → encrypted plaintext mapping with a TTL and optional compliance metadata. */
|
|
4
|
+
abstract store(token: string, plaintext: string, ttlSeconds: number, ptHash?: string | null, metadata?: Record<string, string> | null): Promise<void>;
|
|
5
5
|
/** Return the existing unexpired token for a given plaintext hash, or null. */
|
|
6
6
|
abstract getTokenByPlaintextHash(ptHash: string): Promise<string | null>;
|
|
7
7
|
/** Return the plaintext for token, or null if missing/expired. */
|
|
8
8
|
abstract retrieve(token: string): Promise<string | null>;
|
|
9
|
+
/** Return the plaintext hash stored for this token (used for collision detection), or null. */
|
|
10
|
+
abstract getPtHashForToken(token: string): Promise<string | null>;
|
|
9
11
|
/** Delete a token and its reverse mapping. */
|
|
10
12
|
abstract delete(token: string): Promise<void>;
|
|
11
13
|
}
|
|
@@ -15,6 +17,7 @@ type EncodeOptions = {
|
|
|
15
17
|
searchBuckets?: ('year' | 'month' | 'day' | 'numeric')[];
|
|
16
18
|
searchBucketSize?: number;
|
|
17
19
|
entityType?: string;
|
|
20
|
+
metadata?: Record<string, string> | null;
|
|
18
21
|
};
|
|
19
22
|
/**
|
|
20
23
|
* Tokenise rawText, encrypt it, store in vault, return the FPE token.
|
|
@@ -41,18 +44,11 @@ declare const adetokenizeText: typeof detokenizeText;
|
|
|
41
44
|
declare function looksLikeToken(value: string | any): boolean;
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* Generates structurally valid, **deterministic** tokens that preserve the
|
|
47
|
-
* format of the original data type so downstream tools, schemas, and
|
|
48
|
-
* validators continue to work without modification.
|
|
47
|
+
* Deterministic Pseudonymization (DP) token generation using NIST SP 800-38G FF1.
|
|
49
48
|
*/
|
|
50
|
-
/** Clear the cached master key. Useful in tests. */
|
|
51
49
|
declare function resetMasterKey(): void;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
declare function generateFPEToken(rawText: string, entityType?: string): Promise<string>;
|
|
50
|
+
declare function generateDPToken(rawText: string, entityType?: string): Promise<string>;
|
|
51
|
+
declare const generateFPEToken: typeof generateDPToken;
|
|
56
52
|
|
|
57
53
|
/**
|
|
58
54
|
* Span Resolution Engine — Sweep-Line Overlap Resolver (TypeScript).
|
|
@@ -236,6 +232,8 @@ declare class AuditLogger {
|
|
|
236
232
|
private _strictMode;
|
|
237
233
|
private _bufferFullWarned;
|
|
238
234
|
private _shutdownRegistered;
|
|
235
|
+
private _signingKey;
|
|
236
|
+
private _prevSig;
|
|
239
237
|
private constructor();
|
|
240
238
|
static getInstance(): AuditLogger;
|
|
241
239
|
log(action: string, token: string, dataType?: string, agent?: string, tool?: string, extra?: Record<string, any>): void;
|