mask-privacy 1.0.2

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.
Files changed (41) hide show
  1. package/.test_audit.db +0 -0
  2. package/README.md +250 -0
  3. package/dist/index.d.mts +257 -0
  4. package/dist/index.d.ts +257 -0
  5. package/dist/index.js +58820 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +58777 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/examples/secure_vault/email_tool.ts +13 -0
  10. package/examples/test_agent.ts +50 -0
  11. package/jest.config.js +10 -0
  12. package/package.json +37 -0
  13. package/src/client.ts +135 -0
  14. package/src/core/crypto.ts +100 -0
  15. package/src/core/exceptions.ts +23 -0
  16. package/src/core/fpe.ts +185 -0
  17. package/src/core/key_provider.ts +158 -0
  18. package/src/core/scanner.ts +308 -0
  19. package/src/core/utils.ts +76 -0
  20. package/src/core/vault.ts +540 -0
  21. package/src/index.ts +85 -0
  22. package/src/integrations/adk_hooks.ts +56 -0
  23. package/src/integrations/langchain_hooks.ts +87 -0
  24. package/src/integrations/llamaindex_hooks.ts +80 -0
  25. package/src/telemetry/audit_logger.ts +168 -0
  26. package/tests/async.test.ts +47 -0
  27. package/tests/audit_logger.test.ts +55 -0
  28. package/tests/exceptions.test.ts +75 -0
  29. package/tests/fail_strategy.test.ts +84 -0
  30. package/tests/fpe.test.ts +126 -0
  31. package/tests/hooks.test.ts +107 -0
  32. package/tests/key_provider.test.ts +68 -0
  33. package/tests/langchain.test.ts +101 -0
  34. package/tests/llamaindex.test.ts +75 -0
  35. package/tests/scanner.test.ts +107 -0
  36. package/tests/smoke.test.ts +6 -0
  37. package/tests/substring.test.ts +59 -0
  38. package/tests/vault.test.ts +101 -0
  39. package/tests/vault_backends.test.ts +124 -0
  40. package/tsconfig.json +22 -0
  41. package/tsup.config.ts +11 -0
package/.test_audit.db ADDED
Binary file
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # Mask: Just-in-Time AI Agent Security for TypeScript
2
+
3
+ Contact: millingtonsully@gmail.com
4
+
5
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+
7
+ Mask is an enterprise-grade AI Data Loss Prevention (DLP) infrastructure. It acts as the runtime enforcement layer between your Large Language Models (LLMs) and your active tool execution environment, ensuring that LLMs never see raw PII or sensitive financial records, while maintaining flawless functional execution for the end user.
8
+
9
+ ---
10
+
11
+ ## The Problem Space: LLM Data Leakage
12
+
13
+ As Large Language Model (LLM) agents gain autonomy, they become deeply integrated into enterprise systems, often requiring access to highly sensitive information such as Personally Identifiable Information (PII) and confidential financial records.
14
+
15
+ The core vulnerability in standard agentic architectures is that sensitive data retrieved by tools is injected as plain-text directly into the LLM's context window. This creates severe compliance and security risks:
16
+ - **Data Leakage:** Plain-text PII can be logged by external LLM providers, violating data residency laws or compliance frameworks (SOC2, HIPAA, PCI-DSS).
17
+ - **Inadvertent Disclosure:** If an agent is compromised via prompt injection or malicious instructions, it can be manipulated into exfiltrating the plain-text data it actively holds in its context.
18
+
19
+ ## The Solution: Privacy by Design
20
+
21
+ Mask utilizes a **Local-First Strategy** to solve the data leakage problem within your secure runtime environment.
22
+
23
+ Instead of trusting the LLM to safeguard plain-text data, the system strictly enforces cryptographic boundaries using **Just-In-Time (JIT) Encryption and Decryption Middleware**.
24
+ 1. The LLM only ever "sees" and reasons over scrambled, encrypted cyphertext.
25
+ 2. When the LLM decides to call a specific authorized tool (e.g., querying a database), a **Pre-Tool Decryption Hook** intercepts the call. It decrypts the specific parameters required by the tool, allowing the backend function to execute securely with real data.
26
+ 3. Once the tool finishes, a **Post-Tool Encryption Hook** instantly intercepts the output, detects sensitive entities, and encrypts them *before* the result is returned to the LLM's analytical context block.
27
+
28
+ This guarantees that the LLM can orchestrate workflows involving sensitive data without ever actually exposing the raw data to the model or its remote provider logs.
29
+
30
+ Additionally, we solve two critical sub-issues to make this enterprise-ready:
31
+ 1. **The Statefulness Trap**: Traditional "vaults" break down in multi-node Kubernetes environments. We support pluggable distributed vaults (Redis, DynamoDB, Memcached) so detokenization state is instantly shared across all your horizontally scaled pods.
32
+ 2. **The Schema Trap**: Strict downstream tools will crash if handed a random token. We use Format-Preserving Tokenization backed by an encrypted vault to generate tokens that retain the exact format of the original data (Emails, US Phones, SSNs, 16-digit Credit Cards, 9-digit Routing Numbers). Tokens look like real data; the real values are stored encrypted and retrieved via the vault.
33
+
34
+ ### How We Handle Data (Local-First by Default)
35
+
36
+ Mask is designed to be **Local-First**. By default, it operates entirely within your application's process using an in-memory vault. This ensures zero latency and maximum privacy out of the box.
37
+
38
+ * **Local Use (Standard):** We use a `MemoryVault`. It's fast, free, and keeps data in your RAM.
39
+ * **Distributed Use (Scalability):** For high-availability or multi-node environments, we provide backends for **Redis** and **DynamoDB**. These are intended for "Enterprise" or future "Hosted" versions where state must be shared across many servers.
40
+ * **Decryption Hooks:** Real math and business logic happen inside your local tools, after Mask has safely swapped the tokens back to real data just-in-time.
41
+
42
+ ---
43
+
44
+ ## Architectural Overview
45
+
46
+ ### The Data Plane (Mask Open Source SDK)
47
+ The Data Plane is the open-source, transparent, auditable runtime execution layer. It lives inside your secure VPC or Kubernetes clusters alongside your AI agents. It acts as the Trojan Horse of security, providing frictionless adoption for engineers while proving cryptographic soundness to security reviewers.
48
+
49
+ * **JIT Cryptography Engine:** The core pre-tool decryption and post-tool encryption hooks that intercept and mutate data in-flight.
50
+ * **Format-Preserving Tokenization Router:** Ensures downstream databases and strict schemas don't break when handed a token. Tokens look like real data; the real values are stored encrypted and retrieved via the vault.
51
+ * **Pluggable Distributed Vaults:** Support for enterprise-native caching layers (Redis, DynamoDB, Memcached) to ensure horizontally-scaled edge agents have synchronized access to detokenization mapping.
52
+ * **Local Audit Logger:** An asynchronous AuditLogger that buffers privacy events to a local SQLite database and emits structured JSON logs for SIEM ingestion.
53
+
54
+ ---
55
+
56
+ ## Advanced Architecture & Security Guarantees
57
+
58
+ While Mask can be run globally via environment variables, the underlying SDK is highly sophisticated and designed for multi-tenant, zero-trust environments.
59
+
60
+ ### 1. True Deterministic Vaultless FPE
61
+ Mask utilizes **Deterministic Format-Preserving Encryption (HMAC-SHA256)** for structured PII. If the LLM generates a prompt containing the same email address 50 times in a single session, Mask generates the *exact same Format-Preserving Token* every time. This mathematically accelerates encryption performance and crucially, prevents the LLM from hallucinating due to seeing inconsistent tokens for the same underlying entity, preserving critical reasoning context without exposing real data to the model. While token generation is deterministic and vaultless (requiring no database lookup to create), the SDK utilizes your configured vault backend for secure reversal mappings. This ensures high-fidelity audit trails and data recovery while maintaining the performance benefits of deterministic generation.
62
+
63
+
64
+ ### 2. The Explicit `MaskClient` API
65
+ For enterprise backend services handling multiple tenants at once, global singletons (environment configurations) are dangerous. Mask natively supports explicit client instantiation. Developers can isolate vaults, crypto engines, and NLP scanners on a per-request basis.
66
+
67
+ ```typescript
68
+ import { MaskClient } from 'mask-privacy';
69
+ import { MemoryVault } from 'mask-privacy/core/vault';
70
+ import { CryptoEngine } from 'mask-privacy/core/crypto';
71
+
72
+ // Fully isolated instance for strict multi-tenancy
73
+ const client = new MaskClient({
74
+ vault: new MemoryVault(),
75
+ crypto: new CryptoEngine(tenantSpecificKey),
76
+ ttl: 3600
77
+ });
78
+
79
+ const safeToken = await client.encode("user@tenant.com");
80
+ ```
81
+
82
+ ### 3. Heuristic Safety mathematically guaranteed
83
+ It is catastrophic if an SDK misidentifies a user's *real* SSN as a "token" and accidentally passes it in plaintext to an LLM. Mask's `looksLikeToken()` heuristic algorithm strictly uses universally invalid prefixes.
84
+ * SSN tokens always begin with `000` (The Social Security Administration has never issued an Area Number of 000).
85
+ * Routing tokens always begin with `0000` (The Federal Reserve valid range starts at 01).
86
+ * Credit Card tokens use the `4000-0000-0000` Visa reserved test BIN.
87
+ By generating statistically impossible tokens, Mask guarantees it will never accidentally swallow real PII.
88
+
89
+ ### 4. Enterprise Async Support
90
+ Mask is built from the ground up for high-concurrency Node.js environments. All core operations are asynchronous and promised-based. Calling `encode()`, `decode()`, or `scanAndTokenize()` allows your event loop to remain unblocked while handling PII tokenization tasks.
91
+
92
+ ### 5. Pluggable Key Providers (AWS KMS / HashiCorp Vault)
93
+ For zero-trust environments, `MASK_ENCRYPTION_KEY` no longer needs to live in a static environment variable. Developers can fetch secrets dynamically from AWS KMS, Azure Key Vault, or HashiCorp Vault at runtime and inject them into the `CryptoEngine`.
94
+
95
+ ### 6. Remote NLP Scanning
96
+ Performance-sensitive deployments can now offload the NLP models (like spaCy or Presidio) to a centralized service using the `RemotePresidioScanner`. This permits "lightweight" edge workers (e.g., AWS Lambda) to run Mask with near-zero memory footprint.
97
+
98
+ ### 7. Sub-string Detokenization
99
+ Mask includes the ability to detokenize PII embedded within larger text blocks (like email bodies or chat messages). `detokenizeText()` uses high-performance regex to find and restore all tokens within a paragraph before they hit your tools.
100
+
101
+ ## Installation and Setup
102
+
103
+ Install the core SDK via npm:
104
+ ```bash
105
+ npm install mask-privacy
106
+ ```
107
+
108
+ Add peer dependencies depending on your infrastructure:
109
+ ```bash
110
+ npm install ioredis # For Redis vaults
111
+ npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb # For DynamoDB vaults
112
+ npm install memjs # For Memcached vaults
113
+ ```
114
+
115
+ ### Framework Support
116
+ Mask supports major AI frameworks via built-in hooks:
117
+ - **LangChain**: `@langchain/core`
118
+ - **LlamaIndex**: `llamaindex`
119
+ - **Google ADK**: `@google/adk`
120
+
121
+ ### Environment Configuration
122
+
123
+ Before running your agents, Mask requires an encryption key and a vault backend selection.
124
+
125
+ #### 1. Configure Keys
126
+ By default, Mask reads from environment variables.
127
+ ```bash
128
+ # Provide your encryption keys
129
+ export MASK_ENCRYPTION_KEY="..."
130
+ export MASK_MASTER_KEY="..."
131
+ ```
132
+
133
+ #### 2. Select Scanner Type
134
+ ```bash
135
+ # Options: local (default), remote
136
+ export MASK_SCANNER_TYPE=remote
137
+ export MASK_SCANNER_URL=http://presidio-analyzer:5001/analyze
138
+ ```
139
+
140
+ #### 3. Select Vault Type
141
+ ```bash
142
+ export MASK_VAULT_TYPE=redis # Options: memory, redis, dynamodb, memcached
143
+
144
+ # Configure your chosen vault backend
145
+ # For Redis:
146
+ export MASK_REDIS_URL=redis://localhost:6379/0
147
+ # For DynamoDB:
148
+ export MASK_DYNAMODB_TABLE=mask-vault
149
+ export MASK_DYNAMODB_REGION=us-east-1
150
+ # For Memcached:
151
+ export MASK_MEMCACHED_HOST=localhost
152
+ export MASK_MEMCACHED_PORT=11211
153
+ ```
154
+
155
+ ---
156
+
157
+ ### Async Usage Example
158
+ ```typescript
159
+ import { encode, scanAndTokenize } from 'mask-privacy';
160
+
161
+ async function main() {
162
+ const token = await encode("alice@example.com");
163
+ const text = await scanAndTokenize("Contact " + token);
164
+ console.log(text);
165
+ }
166
+
167
+ main();
168
+ ```
169
+
170
+ ## Framework Integrations
171
+
172
+ Mask integrates seamlessly by injecting dynamic, recursive hooks into your agent's execution pipeline.
173
+
174
+ ### 1. LangChain
175
+ Mask integrates with LangChain via our explicit `@secureTool` decorator.
176
+
177
+ ```typescript
178
+ import { secureTool } from 'mask-privacy/integrations/langchain_hooks';
179
+
180
+ const tool = secureTool({
181
+ name: "send_email",
182
+ description: "Sends a secure email",
183
+ func: async (input: { email: string, message: string }) => {
184
+ // `email` is guaranteed to be decrypted back to the real address
185
+ return `Sent to ${input.email}`;
186
+ }
187
+ });
188
+ ```
189
+
190
+ ### 2. LlamaIndex
191
+ Use the magic hooks or explicit wrappers.
192
+
193
+ ```typescript
194
+ import { maskLlamaIndexHooks } from 'mask-privacy/integrations/llamaindex_hooks';
195
+
196
+ await maskLlamaIndexHooks(async () => {
197
+ // Tools called within this closure will be protected
198
+ const response = await queryEngine.query("Send email to bob@gmail.com");
199
+ });
200
+ ```
201
+
202
+ ### 3. Google ADK
203
+ Use `decryptBeforeTool` and `encryptAfterTool` callbacks.
204
+ ```typescript
205
+ import { decryptBeforeTool, encryptAfterTool } from 'mask-privacy/integrations/adk_hooks';
206
+
207
+ const agent = new Agent({
208
+ name: "secure_assistant",
209
+ tools: [...],
210
+ beforeToolCallback: decryptBeforeTool,
211
+ afterToolCallback: encryptAfterTool,
212
+ });
213
+ ```
214
+
215
+ ---
216
+
217
+ ## Testing and Verification
218
+
219
+ ### The Test Suite
220
+ The SDK is fully verified with a comprehensive `jest` suite. It ensures cryptographic integrity, FPE format compliance, and distributed vault TTL expiry across all layers.
221
+
222
+ ```bash
223
+ npm test
224
+ ```
225
+
226
+ ### The Interactive Demo
227
+ Observe the privacy middleware in action:
228
+ ```bash
229
+ npm run demo
230
+ ```
231
+
232
+ ---
233
+
234
+ ## Telemetry and Compliance
235
+ The SDK includes a thread-safe, asynchronous AuditLogger built-in.
236
+
237
+ As your agents encrypt and decrypt data, the logger buffers these privacy events (Action, Agent, TTL). **Raw PII is never logged.**
238
+
239
+ Audit events are stored locally in a SQLite database (`.mask_audit.db`) and flushed to stdout as structured JSON. Pipe them into your existing Datadog or Splunk agents for SOC2/HIPAA compliance reporting.
240
+
241
+ To disable the local SQLite buffer:
242
+ ```bash
243
+ export MASK_DISABLE_AUDIT_DB=true
244
+ ```
245
+
246
+ ## License
247
+
248
+ This project is licensed under the Apache License, Version 2.0.
249
+
250
+ Copyright (c) 2026 Mask AI Solutions
@@ -0,0 +1,257 @@
1
+ /** Interface every vault backend must implement. */
2
+ declare abstract class BaseVault {
3
+ /** Persist a token → plaintext mapping with a TTL. Optionally save a reverse lookup hash. */
4
+ abstract store(token: string, plaintext: string, ttlSeconds: number, ptHash?: string | null): Promise<void> | void;
5
+ /** Return the existing unexpired token for a given plaintext hash, or null. */
6
+ abstract getTokenByPlaintextHash(ptHash: string): Promise<string | null> | string | null;
7
+ /** Return the plaintext for token, or null if missing/expired. */
8
+ abstract retrieve(token: string): Promise<string | null> | string | null;
9
+ /** Delete a token and its reverse mapping. */
10
+ abstract delete(token: string): Promise<void> | void;
11
+ }
12
+ declare function getVault(): BaseVault;
13
+ /**
14
+ * Tokenise rawText, encrypt it, store in vault, return the FPE token.
15
+ */
16
+ declare function encode(rawText: string, options?: {
17
+ ttl?: number;
18
+ }): Promise<string>;
19
+ /** Async wrapper for encode (parity with Python aencode). */
20
+ declare const aencode: typeof encode;
21
+ /**
22
+ * Detokenise token via vault lookup and decrypt it.
23
+ */
24
+ declare function decode(token: string): Promise<string>;
25
+ /** Async wrapper for decode (parity with Python adecode). */
26
+ declare const adecode: typeof decode;
27
+ /**
28
+ * Find all Mask tokens within text and replace them with their original plaintext.
29
+ */
30
+ declare function detokenizeText(text: string): Promise<string>;
31
+ /** Async wrapper for detokenizeText (parity with Python adetokenize_text). */
32
+ declare const adetokenizeText: typeof detokenizeText;
33
+
34
+ /**
35
+ * Format-Preserving Encryption (FPE) token generation.
36
+ *
37
+ * Generates structurally valid, **deterministic** tokens that preserve the
38
+ * format of the original data type so downstream tools, schemas, and
39
+ * validators continue to work without modification.
40
+ *
41
+ * Determinism is achieved via HMAC-SHA256 keyed with a master key, ensuring
42
+ * the same plaintext always produces the same token. This preserves entity
43
+ * relationships for LLMs (e.g. "John" is always [TKN-abc]) without leaking
44
+ * the identity.
45
+ *
46
+ * Supported formats:
47
+ * - Email → tkn-<hex>@email.com
48
+ * - Phone → +1-555-<7 digits>
49
+ * - SSN → 000-00-<4 digits>
50
+ * - CC → 4000-0000-0000-<4 digits>
51
+ * - Routing→ 000000<3 digits>
52
+ * - Default→ [TKN-<hex>]
53
+ */
54
+ /** Clear the cached master key. Useful in tests. */
55
+ declare function resetMasterKey(): void;
56
+ /**
57
+ * Return a **deterministic**, format-preserving token for rawText.
58
+ *
59
+ * The token is structurally compatible with the original data type
60
+ * so that downstream schema validators, regex checks, and database
61
+ * constraints continue to pass.
62
+ */
63
+ declare function generateFPEToken(rawText: string): string;
64
+ /**
65
+ * Heuristic: return true if value appears to be a Mask token.
66
+ */
67
+ declare function looksLikeToken(value: string): boolean;
68
+
69
+ declare class PresidioScanner {
70
+ protected _supportedEntities: string[];
71
+ constructor();
72
+ setSupportedEntities(entities: string[]): void;
73
+ /** Validate a credit card number using the Luhn algorithm. */
74
+ protected static _luhnChecksum(ccNumber: string): boolean;
75
+ /** Validate a US ABA routing number using the checksum algorithm. */
76
+ protected static _abaChecksum(routingNumber: string): boolean;
77
+ protected _tier1Regex(text: string, encodeFn: (val: string) => Promise<string>, boostEntities: Set<string>, aggressive: boolean, confidenceThreshold: number): Promise<[string, any[]]>;
78
+ protected _tier2Nlp(text: string, encodeFn: (val: string) => Promise<string>, boostEntities: Set<string>, aggressive: boolean, confidenceThreshold: number): Promise<[string, any[]]>;
79
+ protected _resolveBoost(context?: string | null): Set<string>;
80
+ scanAndTokenize(text: string, options?: {
81
+ encodeFn?: (val: string) => Promise<string>;
82
+ pipeline?: string[];
83
+ confidenceThreshold?: number;
84
+ context?: string | null;
85
+ aggressive?: boolean;
86
+ }): Promise<string>;
87
+ scanAndReturnEntities(text: string, options?: {
88
+ encodeFn?: (val: string) => Promise<string>;
89
+ pipeline?: string[];
90
+ confidenceThreshold?: number;
91
+ context?: string | null;
92
+ aggressive?: boolean;
93
+ }): Promise<any[]>;
94
+ }
95
+ /**
96
+ * Scanner that calls a remote Presidio Analyzer endpoint.
97
+ */
98
+ declare class RemotePresidioScanner extends PresidioScanner {
99
+ private endpointUrl;
100
+ constructor(endpointUrl: string);
101
+ protected _tier2Nlp(text: string, encodeFn: (val: string) => Promise<string>, boostEntities: Set<string>, aggressive: boolean, confidenceThreshold: number): Promise<[string, any[]]>;
102
+ }
103
+ declare function getScanner(): PresidioScanner;
104
+
105
+ /**
106
+ * Custom exception hierarchy for the Mask SDK.
107
+ *
108
+ * Provides specific exceptions so callers can implement targeted
109
+ * retry/fallback logic instead of catching generic Error.
110
+ */
111
+ declare class MaskError extends Error {
112
+ constructor(message: string);
113
+ }
114
+ /** Raised when a vault backend (Redis, DynamoDB) is unreachable. */
115
+ declare class MaskVaultConnectionError extends MaskError {
116
+ }
117
+ /** Raised when CryptoEngine.decrypt() fails (bad key, corrupt data). */
118
+ declare class MaskDecryptionError extends MaskError {
119
+ }
120
+ /** Raised when spaCy / Presidio analysis exceeds the time budget. */
121
+ declare class MaskNLPTimeout extends MaskError {
122
+ }
123
+
124
+ /**
125
+ * Core cryptography engine for Mask SDK.
126
+ *
127
+ * Provides a CryptoEngine singleton that handles Envelope Encryption,
128
+ * ensuring that plaintext PII is encrypted locally before being
129
+ * transmitted and stored in distributed vaults (Redis/Memcached/DynamoDB).
130
+ *
131
+ * Requires MASK_ENCRYPTION_KEY to be set in the environment.
132
+ */
133
+ declare class CryptoEngine {
134
+ private static _instance;
135
+ private _fernet;
136
+ private constructor();
137
+ static getInstance(): CryptoEngine;
138
+ /** Clear the singleton instance to force re-initialization (useful for key rotation). */
139
+ static reset(): void;
140
+ private _init;
141
+ encrypt(plaintext: string): string;
142
+ decrypt(ciphertext: string): string;
143
+ }
144
+
145
+ /**
146
+ * Asynchronous audit logger for Mask Privacy SDK.
147
+ *
148
+ * Logs every tokenisation / detokenisation event *without* recording the
149
+ * plaintext PII. Events are batched and flushed to:
150
+ * - stdout / Console (default)
151
+ * - Customer SIEM via structured JSON log lines
152
+ *
153
+ * NOTE: This SDK is LOCAL-FIRST. Audits are stored in a local
154
+ * SQLite file (.mask_audit.db) and are NOT sent anywhere externally.
155
+ */
156
+ declare class AuditLogger {
157
+ private static _instance;
158
+ private _dbPath;
159
+ private _flushInterval;
160
+ private _running;
161
+ private _timer;
162
+ private _buffer;
163
+ private _dbDisabled;
164
+ private _db;
165
+ private constructor();
166
+ static getInstance(): AuditLogger;
167
+ log(action: string, token: string, dataType?: string, agent?: string, tool?: string, extra?: Record<string, any>): void;
168
+ start(): void;
169
+ stop(): void;
170
+ private _flush;
171
+ }
172
+
173
+ /**
174
+ * Explicit Client initialization for the Mask SDK.
175
+ *
176
+ * Provides MaskClient — a unified, explicitly-configured client that
177
+ * bundles vault, crypto, scanner, and audit logger into a single object.
178
+ */
179
+
180
+ declare class MaskClient {
181
+ vault: BaseVault;
182
+ crypto: CryptoEngine;
183
+ scanner: PresidioScanner;
184
+ auditLogger: AuditLogger;
185
+ /** backward compat alias */
186
+ logger: AuditLogger;
187
+ ttl: number;
188
+ /**
189
+ * Initialise the client with specific component instances.
190
+ *
191
+ * If an instance is not provided, the client will fall back to
192
+ * the standard environment-configured singleton for that component.
193
+ */
194
+ constructor(options?: {
195
+ vault?: BaseVault;
196
+ crypto?: CryptoEngine;
197
+ scanner?: PresidioScanner;
198
+ auditLogger?: AuditLogger;
199
+ ttl?: number;
200
+ });
201
+ /**
202
+ * Tokenise rawText, encrypt it, and store it in the vault.
203
+ *
204
+ * Includes deduplication: if the same plaintext has been encoded
205
+ * before and the token is still active, the existing token is returned.
206
+ */
207
+ encode(rawText: string): Promise<string>;
208
+ /** Retrieve token from vault and decrypt it. */
209
+ decode(token: string): Promise<string>;
210
+ /** Scan text using the Waterfall pipeline and replace PII with FPE tokens. */
211
+ scanAndTokenize(text: string): Promise<string>;
212
+ /** Async wrapper for encode (parity with Python aencode). */
213
+ aencode(rawText: string): Promise<string>;
214
+ /** Async wrapper for decode (parity with Python adecode). */
215
+ adecode(token: string): Promise<string>;
216
+ /** Async wrapper for scanAndTokenize (parity with Python ascan_and_tokenize). */
217
+ ascanAndTokenize(text: string): Promise<string>;
218
+ /** Find and replace all tokens within text with their plaintext. */
219
+ detokenizeText(text: string): Promise<string>;
220
+ /** Async wrapper for detokenizeText (parity with Python adetokenize_text). */
221
+ adetokenizeText(text: string): Promise<string>;
222
+ }
223
+
224
+ /**
225
+ * Mask Privacy SDK
226
+ * Just-In-Time Privacy Middleware for AI Agents.
227
+ *
228
+ * Provides format-preserving encryption, local/distributed vaulting,
229
+ * and framework-agnostic tool interception hooks.
230
+ */
231
+ declare const VERSION = "1.0.0";
232
+
233
+ /**
234
+ * Detect PII entities in text and return a list of objects with metadata.
235
+ */
236
+ declare function detectEntitiesWithConfidence(text: string, options?: {
237
+ pipeline?: string[];
238
+ confidenceThreshold?: number;
239
+ context?: string | null;
240
+ aggressive?: boolean;
241
+ }): Promise<any[]>;
242
+ /**
243
+ * Async variant of getScanner().scanAndTokenize().
244
+ */
245
+ declare function ascanAndTokenize(text: string, options?: {
246
+ pipeline?: string[];
247
+ confidenceThreshold?: number;
248
+ context?: string | null;
249
+ aggressive?: boolean;
250
+ }): Promise<string>;
251
+
252
+ /**
253
+ * Drop-in decorator for LangChain tools with automatic PII protection.
254
+ */
255
+ declare function secureTool(...args: any[]): any;
256
+
257
+ export { MaskClient, MaskDecryptionError, MaskError, MaskNLPTimeout, MaskVaultConnectionError, RemotePresidioScanner, VERSION, adecode, adetokenizeText, aencode, ascanAndTokenize, decode, detectEntitiesWithConfidence, detokenizeText, encode, generateFPEToken, getScanner, getVault, looksLikeToken, resetMasterKey, secureTool };