@elanlanguages/bridge-anonymization 0.1.2 → 0.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/README.md +304 -71
- package/dist/crypto/pii-map-crypto.d.ts +50 -36
- package/dist/crypto/pii-map-crypto.d.ts.map +1 -1
- package/dist/crypto/pii-map-crypto.js +137 -72
- package/dist/crypto/pii-map-crypto.js.map +1 -1
- package/dist/index.d.ts +27 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -55
- package/dist/index.js.map +1 -1
- package/dist/ner/model-manager.d.ts +20 -11
- package/dist/ner/model-manager.d.ts.map +1 -1
- package/dist/ner/model-manager.js +154 -81
- package/dist/ner/model-manager.js.map +1 -1
- package/dist/ner/ner-model.d.ts +1 -1
- package/dist/ner/ner-model.d.ts.map +1 -1
- package/dist/ner/ner-model.js +49 -36
- package/dist/ner/ner-model.js.map +1 -1
- package/dist/ner/onnx-runtime.d.ts +8 -7
- package/dist/ner/onnx-runtime.d.ts.map +1 -1
- package/dist/ner/onnx-runtime.js +56 -25
- package/dist/ner/onnx-runtime.js.map +1 -1
- package/dist/ner/tokenizer.d.ts +5 -0
- package/dist/ner/tokenizer.d.ts.map +1 -1
- package/dist/ner/tokenizer.js +18 -5
- package/dist/ner/tokenizer.js.map +1 -1
- package/dist/pipeline/index.d.ts +7 -4
- package/dist/pipeline/index.d.ts.map +1 -1
- package/dist/pipeline/index.js +7 -4
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/resolver.d.ts.map +1 -1
- package/dist/pipeline/resolver.js +3 -2
- package/dist/pipeline/resolver.js.map +1 -1
- package/dist/pipeline/semantic-data-loader.d.ts +165 -0
- package/dist/pipeline/semantic-data-loader.d.ts.map +1 -0
- package/dist/pipeline/semantic-data-loader.js +655 -0
- package/dist/pipeline/semantic-data-loader.js.map +1 -0
- package/dist/pipeline/semantic-enricher.d.ts +112 -0
- package/dist/pipeline/semantic-enricher.d.ts.map +1 -0
- package/dist/pipeline/semantic-enricher.js +318 -0
- package/dist/pipeline/semantic-enricher.js.map +1 -0
- package/dist/pipeline/tagger.d.ts +52 -12
- package/dist/pipeline/tagger.d.ts.map +1 -1
- package/dist/pipeline/tagger.js +226 -21
- package/dist/pipeline/tagger.js.map +1 -1
- package/dist/pipeline/title-extractor.d.ts +79 -0
- package/dist/pipeline/title-extractor.d.ts.map +1 -0
- package/dist/pipeline/title-extractor.js +801 -0
- package/dist/pipeline/title-extractor.js.map +1 -0
- package/dist/types/index.d.ts +66 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +14 -3
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +5 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/path.d.ts +34 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +96 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/storage-browser.d.ts +51 -0
- package/dist/utils/storage-browser.d.ts.map +1 -0
- package/dist/utils/storage-browser.js +381 -0
- package/dist/utils/storage-browser.js.map +1 -0
- package/dist/utils/storage-node.d.ts +43 -0
- package/dist/utils/storage-node.d.ts.map +1 -0
- package/dist/utils/storage-node.js +93 -0
- package/dist/utils/storage-node.js.map +1 -0
- package/dist/utils/storage.d.ts +70 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/dist/utils/storage.js +69 -0
- package/dist/utils/storage.js.map +1 -0
- package/package.json +8 -5
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PII Map Encryption
|
|
3
3
|
* AES-256-GCM encryption for the PII mapping
|
|
4
|
+
* Uses Web Crypto API for browser compatibility
|
|
4
5
|
*/
|
|
5
|
-
import { EncryptedPIIMap } from
|
|
6
|
-
import type { RawPIIMap } from
|
|
6
|
+
import { EncryptedPIIMap } from "../types/index.js";
|
|
7
|
+
import type { RawPIIMap } from "../pipeline/tagger.js";
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Uint8Array to a Base64 string
|
|
10
|
+
*/
|
|
11
|
+
export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a Base64 string to a Uint8Array
|
|
14
|
+
*/
|
|
15
|
+
export declare function base64ToUint8Array(base64: string): Uint8Array;
|
|
7
16
|
/**
|
|
8
17
|
* Encryption configuration
|
|
9
18
|
*/
|
|
10
19
|
export interface EncryptionConfig {
|
|
11
|
-
/** Algorithm (default: aes-256-gcm) */
|
|
12
|
-
algorithm: string;
|
|
13
20
|
/** IV length in bytes (default: 12 for GCM) */
|
|
14
21
|
ivLength: number;
|
|
15
|
-
/** Auth tag length in
|
|
22
|
+
/** Auth tag length in bits (default: 128) */
|
|
16
23
|
authTagLength: number;
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
@@ -28,47 +35,47 @@ export interface KeyGenOptions {
|
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
37
|
* Generates a random encryption key
|
|
31
|
-
* @returns
|
|
38
|
+
* @returns Promise resolving to Uint8Array containing the key
|
|
32
39
|
*/
|
|
33
|
-
export declare function generateKey(options?: Partial<KeyGenOptions>):
|
|
40
|
+
export declare function generateKey(options?: Partial<KeyGenOptions>): Uint8Array;
|
|
41
|
+
/**
|
|
42
|
+
* Generates a random salt for key derivation
|
|
43
|
+
* @param length - Salt length in bytes (default: 16)
|
|
44
|
+
* @returns Uint8Array containing the salt
|
|
45
|
+
*/
|
|
46
|
+
export declare function generateSalt(length?: number): Uint8Array;
|
|
34
47
|
/**
|
|
35
48
|
* Derives a key from a password using PBKDF2
|
|
36
49
|
* @param password - Password string
|
|
37
|
-
* @param salt - Salt
|
|
50
|
+
* @param salt - Salt Uint8Array (should be randomly generated and stored)
|
|
38
51
|
* @param iterations - Number of iterations (default: 100000)
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
export declare function deriveKey(password: string, salt: Buffer, iterations?: number): Buffer;
|
|
42
|
-
/**
|
|
43
|
-
* Generates a random salt for key derivation
|
|
44
|
-
* @param length - Salt length in bytes (default: 16)
|
|
45
|
-
* @returns Buffer containing the salt
|
|
52
|
+
* @returns Promise resolving to Uint8Array containing the derived key
|
|
46
53
|
*/
|
|
47
|
-
export declare function
|
|
54
|
+
export declare function deriveKey(password: string, salt: Uint8Array, iterations?: number): Promise<Uint8Array>;
|
|
48
55
|
/**
|
|
49
56
|
* Encrypts a PII map using AES-256-GCM
|
|
50
57
|
* @param piiMap - Raw PII map to encrypt
|
|
51
|
-
* @param key - 32-byte encryption key
|
|
58
|
+
* @param key - 32-byte encryption key as Uint8Array
|
|
52
59
|
* @param config - Encryption configuration
|
|
53
|
-
* @returns
|
|
60
|
+
* @returns Promise resolving to encrypted PII map
|
|
54
61
|
*/
|
|
55
|
-
export declare function encryptPIIMap(piiMap: RawPIIMap, key:
|
|
62
|
+
export declare function encryptPIIMap(piiMap: RawPIIMap, key: Uint8Array, config?: Partial<EncryptionConfig>): Promise<EncryptedPIIMap>;
|
|
56
63
|
/**
|
|
57
64
|
* Decrypts an encrypted PII map
|
|
58
65
|
* @param encrypted - Encrypted PII map
|
|
59
|
-
* @param key - 32-byte encryption key
|
|
66
|
+
* @param key - 32-byte encryption key as Uint8Array
|
|
60
67
|
* @param config - Encryption configuration
|
|
61
|
-
* @returns
|
|
68
|
+
* @returns Promise resolving to decrypted PII map
|
|
62
69
|
*/
|
|
63
|
-
export declare function decryptPIIMap(encrypted: EncryptedPIIMap, key:
|
|
70
|
+
export declare function decryptPIIMap(encrypted: EncryptedPIIMap, key: Uint8Array, config?: Partial<EncryptionConfig>): Promise<RawPIIMap>;
|
|
64
71
|
/**
|
|
65
72
|
* Key provider interface for external key management
|
|
66
73
|
*/
|
|
67
74
|
export interface KeyProvider {
|
|
68
75
|
/** Gets the current encryption key */
|
|
69
|
-
getKey(): Promise<
|
|
76
|
+
getKey(): Promise<Uint8Array>;
|
|
70
77
|
/** Rotates to a new key (optional) */
|
|
71
|
-
rotateKey?(): Promise<
|
|
78
|
+
rotateKey?(): Promise<Uint8Array>;
|
|
72
79
|
}
|
|
73
80
|
/**
|
|
74
81
|
* Simple in-memory key provider (for testing/development)
|
|
@@ -76,25 +83,32 @@ export interface KeyProvider {
|
|
|
76
83
|
*/
|
|
77
84
|
export declare class InMemoryKeyProvider implements KeyProvider {
|
|
78
85
|
private key;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
private initialKey?;
|
|
87
|
+
constructor(key?: Uint8Array);
|
|
88
|
+
getKey(): Promise<Uint8Array>;
|
|
89
|
+
rotateKey(): Promise<Uint8Array>;
|
|
82
90
|
}
|
|
83
91
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
92
|
+
* Configuration-based key provider
|
|
93
|
+
* Accepts the key at construction time (platform-agnostic)
|
|
94
|
+
* Consumer is responsible for reading the key from environment variables or config
|
|
86
95
|
*/
|
|
87
|
-
export declare class
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
export declare class ConfigKeyProvider implements KeyProvider {
|
|
97
|
+
private key;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new ConfigKeyProvider
|
|
100
|
+
* @param keyBase64 - Base64-encoded 32-byte encryption key
|
|
101
|
+
*/
|
|
102
|
+
constructor(keyBase64: string);
|
|
103
|
+
getKey(): Promise<Uint8Array>;
|
|
91
104
|
}
|
|
92
105
|
/**
|
|
93
106
|
* Validates that a key is suitable for AES-256
|
|
94
107
|
*/
|
|
95
|
-
export declare function validateKey(key:
|
|
108
|
+
export declare function validateKey(key: Uint8Array): boolean;
|
|
96
109
|
/**
|
|
97
|
-
* Securely compares two
|
|
110
|
+
* Securely compares two Uint8Arrays (constant-time)
|
|
111
|
+
* Prevents timing attacks by always comparing all bytes
|
|
98
112
|
*/
|
|
99
|
-
export declare function secureCompare(a:
|
|
113
|
+
export declare function secureCompare(a: Uint8Array, b: Uint8Array): boolean;
|
|
100
114
|
//# sourceMappingURL=pii-map-crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pii-map-crypto.d.ts","sourceRoot":"","sources":["../../src/crypto/pii-map-crypto.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pii-map-crypto.d.ts","sourceRoot":"","sources":["../../src/crypto/pii-map-crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAMvD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAG5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAG7D;AAMD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,gBAGvC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AAMD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,UAAU,CAK5E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,MAAW,GAAG,UAAU,CAI5D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,EAChB,UAAU,GAAE,MAAe,GAC1B,OAAO,CAAC,UAAU,CAAC,CA0BrB;AAMD;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,SAAS,EACjB,GAAG,EAAE,UAAU,EACf,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACrC,OAAO,CAAC,eAAe,CAAC,CAwD1B;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,eAAe,EAC1B,GAAG,EAAE,UAAU,EACf,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACrC,OAAO,CAAC,SAAS,CAAC,CAiDpB;AAMD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sCAAsC;IACtC,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9B,sCAAsC;IACtC,SAAS,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,UAAU,CAAC,CAAa;gBAEpB,GAAG,CAAC,EAAE,UAAU;IAI5B,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;IAO7B,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC;CAIjC;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,GAAG,CAAa;IAExB;;;OAGG;gBACS,SAAS,EAAE,MAAM;IAa7B,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;CAG9B;AAMD;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAEpD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CASnE"}
|
|
@@ -1,50 +1,88 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PII Map Encryption
|
|
3
3
|
* AES-256-GCM encryption for the PII mapping
|
|
4
|
+
* Uses Web Crypto API for browser compatibility
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Base64 Utility Functions
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Converts a Uint8Array to a Base64 string
|
|
11
|
+
*/
|
|
12
|
+
export function uint8ArrayToBase64(bytes) {
|
|
13
|
+
const binString = Array.from(bytes, (b) => String.fromCodePoint(b)).join("");
|
|
14
|
+
return btoa(binString);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts a Base64 string to a Uint8Array
|
|
18
|
+
*/
|
|
19
|
+
export function base64ToUint8Array(base64) {
|
|
20
|
+
const binString = atob(base64);
|
|
21
|
+
return Uint8Array.from(binString, (c) => c.codePointAt(0));
|
|
22
|
+
}
|
|
6
23
|
/**
|
|
7
24
|
* Default encryption configuration
|
|
8
25
|
*/
|
|
9
26
|
export const DEFAULT_ENCRYPTION_CONFIG = {
|
|
10
|
-
algorithm: 'aes-256-gcm',
|
|
11
27
|
ivLength: 12,
|
|
12
|
-
authTagLength:
|
|
28
|
+
authTagLength: 128, // Web Crypto uses bits, not bytes
|
|
13
29
|
};
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Core Crypto Functions
|
|
32
|
+
// ============================================================================
|
|
14
33
|
/**
|
|
15
34
|
* Generates a random encryption key
|
|
16
|
-
* @returns
|
|
35
|
+
* @returns Promise resolving to Uint8Array containing the key
|
|
17
36
|
*/
|
|
18
37
|
export function generateKey(options = {}) {
|
|
19
38
|
const length = options.length ?? 32;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Derives a key from a password using PBKDF2
|
|
24
|
-
* @param password - Password string
|
|
25
|
-
* @param salt - Salt buffer (should be randomly generated and stored)
|
|
26
|
-
* @param iterations - Number of iterations (default: 100000)
|
|
27
|
-
* @returns Buffer containing the derived key
|
|
28
|
-
*/
|
|
29
|
-
export function deriveKey(password, salt, iterations = 100000) {
|
|
30
|
-
return crypto.pbkdf2Sync(password, salt, iterations, 32, 'sha256');
|
|
39
|
+
const key = new Uint8Array(length);
|
|
40
|
+
globalThis.crypto.getRandomValues(key);
|
|
41
|
+
return key;
|
|
31
42
|
}
|
|
32
43
|
/**
|
|
33
44
|
* Generates a random salt for key derivation
|
|
34
45
|
* @param length - Salt length in bytes (default: 16)
|
|
35
|
-
* @returns
|
|
46
|
+
* @returns Uint8Array containing the salt
|
|
36
47
|
*/
|
|
37
48
|
export function generateSalt(length = 16) {
|
|
38
|
-
|
|
49
|
+
const salt = new Uint8Array(length);
|
|
50
|
+
globalThis.crypto.getRandomValues(salt);
|
|
51
|
+
return salt;
|
|
39
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Derives a key from a password using PBKDF2
|
|
55
|
+
* @param password - Password string
|
|
56
|
+
* @param salt - Salt Uint8Array (should be randomly generated and stored)
|
|
57
|
+
* @param iterations - Number of iterations (default: 100000)
|
|
58
|
+
* @returns Promise resolving to Uint8Array containing the derived key
|
|
59
|
+
*/
|
|
60
|
+
export async function deriveKey(password, salt, iterations = 100000) {
|
|
61
|
+
const encoder = new TextEncoder();
|
|
62
|
+
const passwordBuffer = encoder.encode(password);
|
|
63
|
+
// Import password as a key
|
|
64
|
+
const baseKey = await globalThis.crypto.subtle.importKey("raw", passwordBuffer, "PBKDF2", false, ["deriveBits"]);
|
|
65
|
+
// Derive bits using PBKDF2
|
|
66
|
+
const derivedBits = await globalThis.crypto.subtle.deriveBits({
|
|
67
|
+
name: "PBKDF2",
|
|
68
|
+
salt: salt,
|
|
69
|
+
iterations: iterations,
|
|
70
|
+
hash: "SHA-256",
|
|
71
|
+
}, baseKey, 256 // 32 bytes * 8 bits
|
|
72
|
+
);
|
|
73
|
+
return new Uint8Array(derivedBits);
|
|
74
|
+
}
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Encrypt / Decrypt Functions
|
|
77
|
+
// ============================================================================
|
|
40
78
|
/**
|
|
41
79
|
* Encrypts a PII map using AES-256-GCM
|
|
42
80
|
* @param piiMap - Raw PII map to encrypt
|
|
43
|
-
* @param key - 32-byte encryption key
|
|
81
|
+
* @param key - 32-byte encryption key as Uint8Array
|
|
44
82
|
* @param config - Encryption configuration
|
|
45
|
-
* @returns
|
|
83
|
+
* @returns Promise resolving to encrypted PII map
|
|
46
84
|
*/
|
|
47
|
-
export function encryptPIIMap(piiMap, key, config = {}) {
|
|
85
|
+
export async function encryptPIIMap(piiMap, key, config = {}) {
|
|
48
86
|
const encConfig = { ...DEFAULT_ENCRYPTION_CONFIG, ...config };
|
|
49
87
|
// Validate key length
|
|
50
88
|
if (key.length !== 32) {
|
|
@@ -57,50 +95,62 @@ export function encryptPIIMap(piiMap, key, config = {}) {
|
|
|
57
95
|
}
|
|
58
96
|
const plaintext = JSON.stringify(mapObject);
|
|
59
97
|
// Generate random IV
|
|
60
|
-
const iv =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
const iv = new Uint8Array(encConfig.ivLength);
|
|
99
|
+
globalThis.crypto.getRandomValues(iv);
|
|
100
|
+
// Import key for AES-GCM
|
|
101
|
+
const cryptoKey = await globalThis.crypto.subtle.importKey("raw", key, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
102
|
+
// Encrypt using AES-GCM
|
|
103
|
+
const encoder = new TextEncoder();
|
|
104
|
+
const plaintextBuffer = encoder.encode(plaintext);
|
|
105
|
+
const encryptedBuffer = await globalThis.crypto.subtle.encrypt({
|
|
106
|
+
name: "AES-GCM",
|
|
107
|
+
iv: iv,
|
|
108
|
+
tagLength: encConfig.authTagLength,
|
|
109
|
+
}, cryptoKey, plaintextBuffer);
|
|
110
|
+
// Web Crypto returns ciphertext + authTag concatenated
|
|
111
|
+
const encryptedArray = new Uint8Array(encryptedBuffer);
|
|
112
|
+
const authTagBytes = encConfig.authTagLength / 8;
|
|
113
|
+
const ciphertext = encryptedArray.slice(0, encryptedArray.length - authTagBytes);
|
|
114
|
+
const authTag = encryptedArray.slice(encryptedArray.length - authTagBytes);
|
|
70
115
|
return {
|
|
71
|
-
ciphertext:
|
|
72
|
-
iv: iv
|
|
73
|
-
authTag: authTag
|
|
116
|
+
ciphertext: uint8ArrayToBase64(ciphertext),
|
|
117
|
+
iv: uint8ArrayToBase64(iv),
|
|
118
|
+
authTag: uint8ArrayToBase64(authTag),
|
|
74
119
|
};
|
|
75
120
|
}
|
|
76
121
|
/**
|
|
77
122
|
* Decrypts an encrypted PII map
|
|
78
123
|
* @param encrypted - Encrypted PII map
|
|
79
|
-
* @param key - 32-byte encryption key
|
|
124
|
+
* @param key - 32-byte encryption key as Uint8Array
|
|
80
125
|
* @param config - Encryption configuration
|
|
81
|
-
* @returns
|
|
126
|
+
* @returns Promise resolving to decrypted PII map
|
|
82
127
|
*/
|
|
83
|
-
export function decryptPIIMap(encrypted, key, config = {}) {
|
|
128
|
+
export async function decryptPIIMap(encrypted, key, config = {}) {
|
|
84
129
|
const encConfig = { ...DEFAULT_ENCRYPTION_CONFIG, ...config };
|
|
85
130
|
// Validate key length
|
|
86
131
|
if (key.length !== 32) {
|
|
87
132
|
throw new Error(`Invalid key length: expected 32 bytes, got ${key.length}`);
|
|
88
133
|
}
|
|
89
134
|
// Decode base64
|
|
90
|
-
const ciphertext =
|
|
91
|
-
const iv =
|
|
92
|
-
const authTag =
|
|
93
|
-
//
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
135
|
+
const ciphertext = base64ToUint8Array(encrypted.ciphertext);
|
|
136
|
+
const iv = base64ToUint8Array(encrypted.iv);
|
|
137
|
+
const authTag = base64ToUint8Array(encrypted.authTag);
|
|
138
|
+
// Web Crypto expects ciphertext + authTag concatenated
|
|
139
|
+
const encryptedData = new Uint8Array(ciphertext.length + authTag.length);
|
|
140
|
+
encryptedData.set(ciphertext, 0);
|
|
141
|
+
encryptedData.set(authTag, ciphertext.length);
|
|
142
|
+
// Import key for AES-GCM
|
|
143
|
+
const cryptoKey = await globalThis.crypto.subtle.importKey("raw", key, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
144
|
+
// Decrypt using AES-GCM
|
|
145
|
+
const decryptedBuffer = await globalThis.crypto.subtle.decrypt({
|
|
146
|
+
name: "AES-GCM",
|
|
147
|
+
iv: iv,
|
|
148
|
+
tagLength: encConfig.authTagLength,
|
|
149
|
+
}, cryptoKey, encryptedData);
|
|
102
150
|
// Parse JSON back to map
|
|
103
|
-
const
|
|
151
|
+
const decoder = new TextDecoder();
|
|
152
|
+
const decryptedText = decoder.decode(decryptedBuffer);
|
|
153
|
+
const mapObject = JSON.parse(decryptedText);
|
|
104
154
|
const piiMap = new Map();
|
|
105
155
|
for (const [k, v] of Object.entries(mapObject)) {
|
|
106
156
|
piiMap.set(k, v);
|
|
@@ -112,39 +162,49 @@ export function decryptPIIMap(encrypted, key, config = {}) {
|
|
|
112
162
|
* WARNING: Not secure for production use
|
|
113
163
|
*/
|
|
114
164
|
export class InMemoryKeyProvider {
|
|
115
|
-
key;
|
|
165
|
+
key = null;
|
|
166
|
+
initialKey;
|
|
116
167
|
constructor(key) {
|
|
117
|
-
this.
|
|
168
|
+
this.initialKey = key;
|
|
118
169
|
}
|
|
119
|
-
|
|
120
|
-
|
|
170
|
+
getKey() {
|
|
171
|
+
if (this.key === null) {
|
|
172
|
+
this.key = this.initialKey ?? generateKey();
|
|
173
|
+
}
|
|
174
|
+
return Promise.resolve(this.key);
|
|
121
175
|
}
|
|
122
|
-
|
|
176
|
+
rotateKey() {
|
|
123
177
|
this.key = generateKey();
|
|
124
|
-
return this.key;
|
|
178
|
+
return Promise.resolve(this.key);
|
|
125
179
|
}
|
|
126
180
|
}
|
|
127
181
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
182
|
+
* Configuration-based key provider
|
|
183
|
+
* Accepts the key at construction time (platform-agnostic)
|
|
184
|
+
* Consumer is responsible for reading the key from environment variables or config
|
|
130
185
|
*/
|
|
131
|
-
export class
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (keyBase64
|
|
139
|
-
throw new Error(
|
|
186
|
+
export class ConfigKeyProvider {
|
|
187
|
+
key;
|
|
188
|
+
/**
|
|
189
|
+
* Creates a new ConfigKeyProvider
|
|
190
|
+
* @param keyBase64 - Base64-encoded 32-byte encryption key
|
|
191
|
+
*/
|
|
192
|
+
constructor(keyBase64) {
|
|
193
|
+
if (!keyBase64 || keyBase64.length === 0) {
|
|
194
|
+
throw new Error("Encryption key must be provided");
|
|
140
195
|
}
|
|
141
|
-
|
|
142
|
-
if (key.length !== 32) {
|
|
143
|
-
throw new Error(`Invalid key length
|
|
196
|
+
this.key = base64ToUint8Array(keyBase64);
|
|
197
|
+
if (this.key.length !== 32) {
|
|
198
|
+
throw new Error(`Invalid key length: expected 32 bytes, got ${this.key.length}`);
|
|
144
199
|
}
|
|
145
|
-
|
|
200
|
+
}
|
|
201
|
+
getKey() {
|
|
202
|
+
return Promise.resolve(this.key);
|
|
146
203
|
}
|
|
147
204
|
}
|
|
205
|
+
// ============================================================================
|
|
206
|
+
// Utility Functions
|
|
207
|
+
// ============================================================================
|
|
148
208
|
/**
|
|
149
209
|
* Validates that a key is suitable for AES-256
|
|
150
210
|
*/
|
|
@@ -152,12 +212,17 @@ export function validateKey(key) {
|
|
|
152
212
|
return key.length === 32;
|
|
153
213
|
}
|
|
154
214
|
/**
|
|
155
|
-
* Securely compares two
|
|
215
|
+
* Securely compares two Uint8Arrays (constant-time)
|
|
216
|
+
* Prevents timing attacks by always comparing all bytes
|
|
156
217
|
*/
|
|
157
218
|
export function secureCompare(a, b) {
|
|
158
219
|
if (a.length !== b.length) {
|
|
159
220
|
return false;
|
|
160
221
|
}
|
|
161
|
-
|
|
222
|
+
let result = 0;
|
|
223
|
+
for (let i = 0; i < a.length; i++) {
|
|
224
|
+
result |= a[i] ^ b[i];
|
|
225
|
+
}
|
|
226
|
+
return result === 0;
|
|
162
227
|
}
|
|
163
228
|
//# sourceMappingURL=pii-map-crypto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pii-map-crypto.js","sourceRoot":"","sources":["../../src/crypto/pii-map-crypto.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pii-map-crypto.js","sourceRoot":"","sources":["../../src/crypto/pii-map-crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB;IAClD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,CAAC;AAC9D,CAAC;AAgBD;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAqB;IACzD,QAAQ,EAAE,EAAE;IACZ,aAAa,EAAE,GAAG,EAAE,kCAAkC;CACvD,CAAC;AAUF,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,UAAkC,EAAE;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,GA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bridge Anonymization Module
|
|
3
3
|
* Main entry point for on-device PII anonymization
|
|
4
4
|
*/
|
|
5
|
-
export * from
|
|
6
|
-
export { Recognizer, RegexRecognizer, RecognizerRegistry, createDefaultRegistry, createRegistry, getGlobalRegistry, emailRecognizer, phoneRecognizer, ibanRecognizer, bicSwiftRecognizer, creditCardRecognizer, ipAddressRecognizer, urlRecognizer, createCustomIdRecognizer, createCaseIdRecognizer, createCustomerIdRecognizer, } from
|
|
7
|
-
export { NERModel, NERModelStub, createNERModel, createNERModelStub, WordPieceTokenizer, loadVocabFromFile, parseVocab, loadRuntime, detectRuntime, getRuntimeType, type INERModel, type NERModelConfig, type NERPrediction, type NERModelMode, type DownloadProgressCallback, MODEL_REGISTRY, getModelCacheDir, isModelDownloaded, downloadModel, ensureModel, clearModelCache, listDownloadedModels, } from
|
|
8
|
-
export { prenormalize, resolveEntities, tagEntities, validateOutput, generateTag, parseTag, rehydrate, } from
|
|
9
|
-
export { encryptPIIMap, decryptPIIMap, generateKey, deriveKey, generateSalt, KeyProvider, InMemoryKeyProvider,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { type
|
|
5
|
+
export * from "./types/index.js";
|
|
6
|
+
export { Recognizer, RegexRecognizer, RecognizerRegistry, createDefaultRegistry, createRegistry, getGlobalRegistry, emailRecognizer, phoneRecognizer, ibanRecognizer, bicSwiftRecognizer, creditCardRecognizer, ipAddressRecognizer, urlRecognizer, createCustomIdRecognizer, createCaseIdRecognizer, createCustomerIdRecognizer, } from "./recognizers/index.js";
|
|
7
|
+
export { NERModel, NERModelStub, createNERModel, createNERModelStub, WordPieceTokenizer, loadVocabFromFile, parseVocab, loadRuntime, detectRuntime, getRuntimeType, type INERModel, type NERModelConfig, type NERPrediction, type NERModelMode, type DownloadProgressCallback, MODEL_REGISTRY, getModelCacheDir, isModelDownloaded, downloadModel, ensureModel, clearModelCache, listDownloadedModels, } from "./ner/index.js";
|
|
8
|
+
export { prenormalize, resolveEntities, tagEntities, validateOutput, generateTag, parseTag, rehydrate, enrichSemantics, inferGender, classifyLocation, getDatabaseStats, hasName, hasLocation, isSemanticDataAvailable, isSemanticDataDownloaded, getSemanticDataCacheDir, getDataDirectory, downloadSemanticData, ensureSemanticData, initializeSemanticData, loadSemanticData, clearSemanticData, clearSemanticDataCache, getSemanticDataInfo, SEMANTIC_DATA_FILES, extractTitle, extractTitlesFromSpans, mergeAdjacentTitleSpans, getTitlesForLanguage, getAllTitles, startsWithTitle, isOnlyTitle, type SemanticDataFileInfo, type EnricherConfig, type GenderResult, type LocationResult, type TitleExtractionResult, } from "./pipeline/index.js";
|
|
9
|
+
export { encryptPIIMap, decryptPIIMap, generateKey, deriveKey, generateSalt, KeyProvider, InMemoryKeyProvider, ConfigKeyProvider, validateKey, secureCompare, uint8ArrayToBase64, base64ToUint8Array, } from "./crypto/index.js";
|
|
10
|
+
export { getStorageProvider, isNode, isBrowser, resetStorageProvider, setStorageProvider, type StorageProvider, } from "./utils/storage.js";
|
|
11
|
+
export { join as pathJoin, dirname as pathDirname, basename as pathBasename, normalize as pathNormalize, extname as pathExtname, isAbsolute as pathIsAbsolute, } from "./utils/path.js";
|
|
12
|
+
import { AnonymizationResult, AnonymizationPolicy, SemanticConfig, PIIType } from "./types/index.js";
|
|
13
|
+
import { RecognizerRegistry } from "./recognizers/index.js";
|
|
14
|
+
import { type INERModel } from "./ner/index.js";
|
|
15
|
+
import { type NERModelMode, type DownloadProgressCallback } from "./ner/model-manager.js";
|
|
16
|
+
import { type KeyProvider } from "./crypto/index.js";
|
|
15
17
|
/**
|
|
16
18
|
* NER configuration options
|
|
17
19
|
*/
|
|
@@ -45,6 +47,12 @@ export interface NERConfig {
|
|
|
45
47
|
* Callback for status messages
|
|
46
48
|
*/
|
|
47
49
|
onStatus?: (status: string) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Confidence thresholds per PII type (0.0 - 1.0)
|
|
52
|
+
* Overrides default thresholds for specified types
|
|
53
|
+
* @example { PERSON: 0.8, ORG: 0.7 }
|
|
54
|
+
*/
|
|
55
|
+
thresholds?: Partial<Record<PIIType, number>>;
|
|
48
56
|
}
|
|
49
57
|
/**
|
|
50
58
|
* Anonymizer configuration
|
|
@@ -58,9 +66,11 @@ export interface AnonymizerConfig {
|
|
|
58
66
|
*/
|
|
59
67
|
ner?: NERConfig;
|
|
60
68
|
/**
|
|
61
|
-
*
|
|
69
|
+
* Semantic enrichment configuration
|
|
70
|
+
* Enables MT-friendly PII tags with gender/scope attributes
|
|
71
|
+
* @default { enabled: false }
|
|
62
72
|
*/
|
|
63
|
-
|
|
73
|
+
semantic?: SemanticConfig;
|
|
64
74
|
/** Key provider for encryption (generates random key if not provided) */
|
|
65
75
|
keyProvider?: KeyProvider;
|
|
66
76
|
/** Default policy (uses default if not provided) */
|
|
@@ -78,15 +88,17 @@ export declare class Anonymizer {
|
|
|
78
88
|
private registry;
|
|
79
89
|
private nerModel;
|
|
80
90
|
private nerConfig;
|
|
91
|
+
private semanticConfig;
|
|
81
92
|
private keyProvider;
|
|
82
93
|
private defaultPolicy;
|
|
83
94
|
private modelVersion;
|
|
84
95
|
private policyVersion;
|
|
85
96
|
private initialized;
|
|
97
|
+
private semanticDataReady;
|
|
86
98
|
constructor(config?: AnonymizerConfig);
|
|
87
99
|
/**
|
|
88
100
|
* Initializes the anonymizer
|
|
89
|
-
* Downloads NER model if needed and loads
|
|
101
|
+
* Downloads NER model and semantic data if needed and loads them
|
|
90
102
|
*/
|
|
91
103
|
initialize(): Promise<void>;
|
|
92
104
|
/**
|
|
@@ -138,11 +150,6 @@ export declare class Anonymizer {
|
|
|
138
150
|
* ```
|
|
139
151
|
*/
|
|
140
152
|
export declare function createAnonymizer(config?: AnonymizerConfig): Anonymizer;
|
|
141
|
-
/**
|
|
142
|
-
* Creates an anonymizer with a custom NER model
|
|
143
|
-
* @deprecated Use createAnonymizer with ner: { mode: 'custom', modelPath, vocabPath } instead
|
|
144
|
-
*/
|
|
145
|
-
export declare function createAnonymizerWithNER(modelPath: string, vocabPath: string, config?: Omit<AnonymizerConfig, 'nerModel' | 'ner'>): Promise<Anonymizer>;
|
|
146
153
|
/**
|
|
147
154
|
* Convenience function for one-off anonymization
|
|
148
155
|
* Creates a temporary anonymizer with default settings (regex-only)
|
|
@@ -167,7 +174,7 @@ export declare function anonymizeRegexOnly(text: string, policy?: Partial<Anonym
|
|
|
167
174
|
* );
|
|
168
175
|
* ```
|
|
169
176
|
*/
|
|
170
|
-
export declare function anonymizeWithNER(text: string, nerConfig: Omit<NERConfig,
|
|
171
|
-
mode?:
|
|
177
|
+
export declare function anonymizeWithNER(text: string, nerConfig: Omit<NERConfig, "mode"> & {
|
|
178
|
+
mode?: "standard" | "quantized";
|
|
172
179
|
}, policy?: Partial<AnonymizationPolicy>): Promise<AnonymizationResult>;
|
|
173
180
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,eAAe,EACf,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACd,WAAW,EACX,QAAQ,EACR,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,eAAe,EACf,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACd,WAAW,EACX,QAAQ,EACR,SAAS,EACT,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,EACP,WAAW,EAEX,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EAEnB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB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