flare-redact 1.9.0 → 1.10.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +122 -1225
  3. package/bench/adversarial-runtime.mjs +27 -6
  4. package/dist/ai-sdk.d.ts +62 -0
  5. package/dist/ai-sdk.d.ts.map +1 -0
  6. package/dist/ai-sdk.js +263 -0
  7. package/dist/ai-sdk.js.map +1 -0
  8. package/dist/checksums.d.ts +43 -0
  9. package/dist/checksums.d.ts.map +1 -1
  10. package/dist/checksums.js +184 -0
  11. package/dist/checksums.js.map +1 -1
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +5 -2
  14. package/dist/cli.js.map +1 -1
  15. package/dist/detectors.d.ts.map +1 -1
  16. package/dist/detectors.js +7 -4
  17. package/dist/detectors.js.map +1 -1
  18. package/dist/extra.d.ts.map +1 -1
  19. package/dist/extra.js +229 -1
  20. package/dist/extra.js.map +1 -1
  21. package/dist/file-discovery.d.ts +5 -0
  22. package/dist/file-discovery.d.ts.map +1 -1
  23. package/dist/file-discovery.js +5 -1
  24. package/dist/file-discovery.js.map +1 -1
  25. package/dist/gateway/body.d.ts.map +1 -1
  26. package/dist/gateway/body.js +2 -1
  27. package/dist/gateway/body.js.map +1 -1
  28. package/dist/gateway/config.d.ts +5 -3
  29. package/dist/gateway/config.d.ts.map +1 -1
  30. package/dist/gateway/config.js.map +1 -1
  31. package/dist/gateway/index.d.ts +1 -0
  32. package/dist/gateway/index.d.ts.map +1 -1
  33. package/dist/gateway/index.js +1 -0
  34. package/dist/gateway/index.js.map +1 -1
  35. package/dist/gateway/server.d.ts.map +1 -1
  36. package/dist/gateway/server.js +17 -1
  37. package/dist/gateway/server.js.map +1 -1
  38. package/dist/gateway/sse.d.ts +35 -0
  39. package/dist/gateway/sse.d.ts.map +1 -0
  40. package/dist/gateway/sse.js +217 -0
  41. package/dist/gateway/sse.js.map +1 -0
  42. package/dist/help.d.ts.map +1 -1
  43. package/dist/help.js +11 -5
  44. package/dist/help.js.map +1 -1
  45. package/dist/init.d.ts.map +1 -1
  46. package/dist/init.js +12 -3
  47. package/dist/init.js.map +1 -1
  48. package/dist/llm.d.ts.map +1 -1
  49. package/dist/llm.js +20 -9
  50. package/dist/llm.js.map +1 -1
  51. package/dist/locales.d.ts +3 -2
  52. package/dist/locales.d.ts.map +1 -1
  53. package/dist/locales.js +152 -3
  54. package/dist/locales.js.map +1 -1
  55. package/dist/pack.d.ts.map +1 -1
  56. package/dist/pack.js +14 -1
  57. package/dist/pack.js.map +1 -1
  58. package/dist/vault.d.ts +26 -1
  59. package/dist/vault.d.ts.map +1 -1
  60. package/dist/vault.js +61 -3
  61. package/dist/vault.js.map +1 -1
  62. package/docker/README.md +8 -5
  63. package/docs/guide.md +1416 -0
  64. package/package.json +10 -3
  65. package/spec/SPEC.md +40 -3
  66. package/spec/conformance/README.md +8 -1
  67. package/spec/conformance/cases.json +60 -1
  68. package/spec/conformance/expected.json +815 -7
  69. package/spec/detectors.json +1118 -222
  70. package/spec/detectors.schema.json +3 -1
@@ -8,15 +8,36 @@ const cases = {
8
8
  tokenLike: (n) => 'A'.repeat(n) + '=',
9
9
  separators: (n) => '1-'.repeat(Math.floor(n / 2)),
10
10
  unicode: (n) => '密'.repeat(n),
11
+ schemeRun: (n) => 'a-b.'.repeat(Math.floor(n / 4)) + '://',
12
+ // Token prefixes followed by long runs of their body characters that never
13
+ // complete a token: each pattern must give up in time linear in the run.
14
+ tokenPrefixes: (n) => {
15
+ const prefixes = ['glpat-', 'glrt-', 'pypi-AgEIcHlwaS5vcmc', 'ABSK', 'ops_eyJ', 'sntrys_eyJ', 'glc_', 'fm2_', 'pscale_tkn_', 'ATATT3', 'HRKU-', 'dckr_pat_', 'tvly-', 'pcsk_ab1cd_'];
16
+ let out = '';
17
+ for (let i = 0; out.length < n; i++) out += prefixes[i % prefixes.length] + 'A'.repeat(1_200) + '-';
18
+ return out.slice(0, n);
19
+ },
20
+ hexRuns: (n) => ('0123456789abcdef'.repeat(4) + '-us ').repeat(Math.ceil(n / 68)).slice(0, n),
21
+ atlasRuns: (n) => ('A'.repeat(14) + '.atlasv1.' + 'A'.repeat(90) + ' ').repeat(Math.ceil(n / 114)).slice(0, n),
22
+ // Shapes the opt-in national IDs look for: printed digit groups, dotted
23
+ // groups, letter-digit runs and ID prefixes that never complete.
24
+ spacedDigits: (n) => '12 '.repeat(Math.floor(n / 3)),
25
+ dottedDigits: (n) => '12.'.repeat(Math.floor(n / 3)),
26
+ letterDigitRun: (n) => 'AB1'.repeat(Math.floor(n / 3)),
27
+ idPrefixes: (n) => 'ABCD850101H S1234567 010185-123 '.repeat(Math.floor(n / 32)),
11
28
  };
29
+ // The default policy, and every opt-in identifier through the pii tag.
30
+ const policies = { default: {}, pii: { enable: ['pii'] } };
12
31
 
13
32
  const results = [];
14
- for (const [name, build] of Object.entries(cases)) {
15
- for (const length of lengths) {
16
- const input = build(length);
17
- const start = performance.now();
18
- const findings = scan(input);
19
- results.push({ name, length: input.length, durationMs: performance.now() - start, findings: findings.length });
33
+ for (const [policy, options] of Object.entries(policies)) {
34
+ for (const [name, build] of Object.entries(cases)) {
35
+ for (const length of lengths) {
36
+ const input = build(length);
37
+ const start = performance.now();
38
+ const findings = scan(input, options);
39
+ results.push({ name, policy, length: input.length, durationMs: performance.now() - start, findings: findings.length });
40
+ }
20
41
  }
21
42
  }
22
43
 
@@ -0,0 +1,62 @@
1
+ /**
2
+ * A language model middleware for the Vercel AI SDK (`ai`). One middleware
3
+ * covers every provider the SDK supports: prompts are redacted to opaque
4
+ * placeholders before the provider sees them, and the placeholders are put
5
+ * back in what the model returns, streamed or not.
6
+ *
7
+ * import { wrapLanguageModel } from 'ai';
8
+ * import { flareRedactMiddleware } from 'flare-redact/ai-sdk';
9
+ *
10
+ * const model = wrapLanguageModel({ model: baseModel, middleware: flareRedactMiddleware() });
11
+ *
12
+ * The types here are structural on purpose: the package does not depend on
13
+ * `ai`, and the same object works with the middleware contracts of AI SDK 5
14
+ * (`v2`), 6 (`v3`) and 7 (`v4`), whose prompt and stream shapes match for
15
+ * everything this touches.
16
+ */
17
+ import { type VaultOptions } from './vault.js';
18
+ import type { Session } from './session.js';
19
+ export interface FlareRedactMiddlewareOptions extends VaultOptions {
20
+ /**
21
+ * Keep one vault for a whole conversation instead of one per model call, so
22
+ * a value keeps the same placeholder in every step and turn. The session's
23
+ * own options apply; the other options here are ignored.
24
+ */
25
+ session?: Session;
26
+ }
27
+ /**
28
+ * The middleware object. It satisfies `LanguageModelMiddleware` from `ai` 5, 6
29
+ * and 7 without importing it.
30
+ */
31
+ export interface FlareRedactLanguageModelMiddleware {
32
+ readonly specificationVersion: 'v3';
33
+ readonly middlewareVersion: 'v2';
34
+ transformParams<P>(options: {
35
+ type: 'generate' | 'stream';
36
+ params: P;
37
+ }): Promise<P>;
38
+ wrapGenerate<R>(options: {
39
+ doGenerate: () => PromiseLike<R>;
40
+ params: unknown;
41
+ }): Promise<R>;
42
+ wrapStream<S extends {
43
+ stream: unknown;
44
+ }>(options: {
45
+ doStream: () => PromiseLike<S>;
46
+ params: unknown;
47
+ }): Promise<S>;
48
+ }
49
+ /**
50
+ * A Vercel AI SDK language model middleware that keeps secrets and personal
51
+ * data out of every prompt, for any provider:
52
+ *
53
+ * wrapLanguageModel({ model, middleware: flareRedactMiddleware({ preset: 'llm' }) })
54
+ *
55
+ * System, user and assistant text, reasoning, tool-call inputs and tool
56
+ * results are redacted to opaque placeholders before the call; text,
57
+ * reasoning, tool calls and structured output are restored in the result and
58
+ * in the stream, including placeholders split across chunks. Files and images
59
+ * are passed through unchanged. Takes the same options as `wrapOpenAI`.
60
+ */
61
+ export declare function flareRedactMiddleware(opts?: FlareRedactMiddlewareOptions): FlareRedactLanguageModelMiddleware;
62
+ //# sourceMappingURL=ai-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../src/ai-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAA6G,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1J,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,4BAA6B,SAAQ,YAAY;IAChE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,oBAAoB,EAAE,IAAI,CAAC;IACpC,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;IACjC,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;QAAC,MAAM,EAAE,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACpF,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5F,UAAU,CAAC,CAAC,SAAS;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,EAAE,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACrH;AAsMD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,GAAE,4BAAiC,GAAG,kCAAkC,CA0CjH"}
package/dist/ai-sdk.js ADDED
@@ -0,0 +1,263 @@
1
+ /**
2
+ * A language model middleware for the Vercel AI SDK (`ai`). One middleware
3
+ * covers every provider the SDK supports: prompts are redacted to opaque
4
+ * placeholders before the provider sees them, and the placeholders are put
5
+ * back in what the model returns, streamed or not.
6
+ *
7
+ * import { wrapLanguageModel } from 'ai';
8
+ * import { flareRedactMiddleware } from 'flare-redact/ai-sdk';
9
+ *
10
+ * const model = wrapLanguageModel({ model: baseModel, middleware: flareRedactMiddleware() });
11
+ *
12
+ * The types here are structural on purpose: the package does not depend on
13
+ * `ai`, and the same object works with the middleware contracts of AI SDK 5
14
+ * (`v2`), 6 (`v3`) and 7 (`v4`), whose prompt and stream shapes match for
15
+ * everything this touches.
16
+ */
17
+ import { buildRestore, buildStreamRestore, createVault, escapeEntriesForJson } from './vault.js';
18
+ const isObj = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ /** Keys that identify or route a part. They carry no user text and are never rewritten. */
20
+ const STRUCTURAL = new Set([
21
+ 'type', 'role', 'id', 'toolCallId', 'toolName', 'approvalId', 'approved',
22
+ 'mediaType', 'data', 'kind', 'providerOptions', 'providerExecuted',
23
+ ]);
24
+ /** Parts that pass through untouched: files and images, and provider-defined parts. */
25
+ const PASS_THROUGH = new Set(['file', 'image', 'reasoning-file', 'custom']);
26
+ const isJson = (text) => {
27
+ try {
28
+ JSON.parse(text);
29
+ return true;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ };
35
+ function redactPrompt(prompt, vault) {
36
+ if (!Array.isArray(prompt))
37
+ return prompt;
38
+ // Every string that is not structural, one level down: the values of a tool
39
+ // result (`text`, `json`, `error-*`), a denial reason, and fields of part
40
+ // types this version does not know about yet.
41
+ const redactLoose = (part) => {
42
+ const out = {};
43
+ for (const [key, value] of Object.entries(part))
44
+ out[key] = STRUCTURAL.has(key) ? value : vault.redact(value);
45
+ return out;
46
+ };
47
+ const redactToolOutput = (output) => {
48
+ if (!isObj(output))
49
+ return vault.redact(output);
50
+ if (output.type === 'content' && Array.isArray(output.value)) {
51
+ return {
52
+ ...output,
53
+ value: output.value.map((item) => isObj(item) && item.type === 'text' && typeof item.text === 'string' ? { ...item, text: vault.redact(item.text) } : item),
54
+ };
55
+ }
56
+ return redactLoose(output);
57
+ };
58
+ const redactPart = (part) => {
59
+ if (typeof part === 'string')
60
+ return vault.redact(part);
61
+ if (!isObj(part))
62
+ return part;
63
+ const type = part.type;
64
+ if (typeof type === 'string' && PASS_THROUGH.has(type))
65
+ return part;
66
+ switch (type) {
67
+ case 'text':
68
+ case 'reasoning':
69
+ return typeof part.text === 'string' ? { ...part, text: vault.redact(part.text) } : part;
70
+ case 'tool-call':
71
+ return { ...part, input: vault.redact(part.input) };
72
+ case 'tool-result':
73
+ return 'output' in part ? { ...part, output: redactToolOutput(part.output) } : redactLoose(part);
74
+ default:
75
+ return redactLoose(part);
76
+ }
77
+ };
78
+ return prompt.map((message) => {
79
+ if (!isObj(message))
80
+ return message;
81
+ const { content } = message;
82
+ if (typeof content === 'string')
83
+ return { ...message, content: vault.redact(content) };
84
+ if (Array.isArray(content))
85
+ return { ...message, content: content.map(redactPart) };
86
+ return message;
87
+ });
88
+ }
89
+ function restorers(vault, jsonOutput) {
90
+ const entries = vault.entries();
91
+ const escaped = escapeEntriesForJson(entries);
92
+ const plain = buildRestore(entries);
93
+ const json = buildRestore(escaped);
94
+ return {
95
+ text: jsonOutput ? json : plain,
96
+ // A placeholder can only sit inside a string in valid JSON, so the
97
+ // original goes in escaped; anything that is not JSON gets it verbatim.
98
+ toolInput: (input) => (entries.length && isJson(input) ? json(input) : plain(input)),
99
+ value: (value) => vault.restore(value),
100
+ stream: (kind) => buildStreamRestore(kind === 'json' || (kind === 'text' && jsonOutput) ? escaped : entries),
101
+ };
102
+ }
103
+ function restoreContent(content, restore) {
104
+ if (!Array.isArray(content))
105
+ return content;
106
+ return content.map((part) => {
107
+ if (!isObj(part))
108
+ return typeof part === 'string' ? restore.text(part) : part;
109
+ const type = part.type;
110
+ if (typeof type === 'string' && PASS_THROUGH.has(type))
111
+ return part;
112
+ if (type === 'text' && typeof part.text === 'string')
113
+ return { ...restore.value(part), text: restore.text(part.text) };
114
+ if (type === 'tool-call' && typeof part.input === 'string')
115
+ return { ...part, input: restore.toolInput(part.input) };
116
+ return restore.value(part);
117
+ });
118
+ }
119
+ /** The stream part types whose `delta` is text the model wrote, and the part that ends each. */
120
+ const DELTAS = new Map([
121
+ ['text-delta', 'text-end'],
122
+ ['reasoning-delta', 'reasoning-end'],
123
+ ['tool-input-delta', 'tool-input-end'],
124
+ ]);
125
+ const ENDS = new Map([...DELTAS].map(([delta, end]) => [end, delta]));
126
+ function restoreStream(stream, restore) {
127
+ // One restorer per streamed block, keyed by part type and id, so a
128
+ // placeholder split across deltas is rebuilt before it is passed on.
129
+ const open = new Map();
130
+ const textTools = new Set();
131
+ const key = (type, id) => `${type}\u0000${String(id)}`;
132
+ const flushOne = (type, id, controller) => {
133
+ const block = open.get(key(type, id));
134
+ if (!block)
135
+ return;
136
+ open.delete(key(type, id));
137
+ const tail = block.restorer.flush();
138
+ if (tail)
139
+ controller.enqueue({ type, id, delta: tail });
140
+ };
141
+ const flushAll = (controller) => {
142
+ for (const { type, id } of [...open.values()])
143
+ flushOne(type, id, controller);
144
+ };
145
+ return stream.pipeThrough(new TransformStream({
146
+ transform(part, controller) {
147
+ if (!isObj(part) || typeof part.type !== 'string') {
148
+ controller.enqueue(part);
149
+ return;
150
+ }
151
+ const { type } = part;
152
+ if (DELTAS.has(type) && typeof part.delta === 'string') {
153
+ const k = key(type, part.id);
154
+ let block = open.get(k);
155
+ if (!block) {
156
+ // Reasoning is prose even when the answer is JSON; tool input is JSON
157
+ // unless its tool-input-start said otherwise.
158
+ const kind = type === 'text-delta' ? 'text' : type === 'reasoning-delta' || textTools.has(part.id) ? 'plain' : 'json';
159
+ block = { type, id: part.id, restorer: restore.stream(kind) };
160
+ open.set(k, block);
161
+ }
162
+ const delta = block.restorer.push(part.delta);
163
+ if (delta || part.providerMetadata !== undefined)
164
+ controller.enqueue({ ...part, delta });
165
+ return;
166
+ }
167
+ const deltaType = ENDS.get(type);
168
+ if (deltaType) {
169
+ flushOne(deltaType, part.id, controller);
170
+ if (type === 'tool-input-end')
171
+ textTools.delete(part.id);
172
+ // A text-end can carry citations quoting what the model was sent.
173
+ controller.enqueue(restore.value(part));
174
+ return;
175
+ }
176
+ switch (type) {
177
+ case 'tool-input-start':
178
+ if (part.inputEncoding === 'text')
179
+ textTools.add(part.id);
180
+ controller.enqueue(part);
181
+ return;
182
+ case 'tool-call':
183
+ controller.enqueue(typeof part.input === 'string' ? { ...part, input: restore.toolInput(part.input) } : part);
184
+ return;
185
+ case 'tool-result':
186
+ case 'source':
187
+ controller.enqueue(restore.value(part));
188
+ return;
189
+ case 'finish':
190
+ flushAll(controller);
191
+ controller.enqueue(part);
192
+ return;
193
+ default:
194
+ // Text and reasoning blocks are restored above; files, metadata,
195
+ // errors and raw provider chunks pass through as they arrived.
196
+ controller.enqueue(part);
197
+ }
198
+ },
199
+ flush(controller) {
200
+ flushAll(controller);
201
+ },
202
+ }));
203
+ }
204
+ const wantsJson = (params) => isObj(params) && isObj(params.responseFormat) && params.responseFormat.type === 'json';
205
+ /**
206
+ * A Vercel AI SDK language model middleware that keeps secrets and personal
207
+ * data out of every prompt, for any provider:
208
+ *
209
+ * wrapLanguageModel({ model, middleware: flareRedactMiddleware({ preset: 'llm' }) })
210
+ *
211
+ * System, user and assistant text, reasoning, tool-call inputs and tool
212
+ * results are redacted to opaque placeholders before the call; text,
213
+ * reasoning, tool calls and structured output are restored in the result and
214
+ * in the stream, including placeholders split across chunks. Files and images
215
+ * are passed through unchanged. Takes the same options as `wrapOpenAI`.
216
+ */
217
+ export function flareRedactMiddleware(opts = {}) {
218
+ const { session, ...vaultOptions } = opts;
219
+ // Fail at setup, not on the first request, when a preset or detector option is wrong.
220
+ if (!session)
221
+ createVault(vaultOptions);
222
+ // The vault lives exactly as long as one call: transformParams creates it,
223
+ // the wrap step that follows restores with it. The params object is the key.
224
+ const vaults = new WeakMap();
225
+ const vaultFor = (params) => {
226
+ const found = isObj(params) ? vaults.get(params) : undefined;
227
+ if (!found) {
228
+ throw new Error('flareRedactMiddleware: the prompt was not redacted. Pass the middleware object to wrapLanguageModel whole, without replacing transformParams.');
229
+ }
230
+ return found;
231
+ };
232
+ return {
233
+ specificationVersion: 'v3',
234
+ middlewareVersion: 'v2',
235
+ async transformParams({ params }) {
236
+ if (!isObj(params))
237
+ return params;
238
+ const vault = session ? session.vault : createVault(vaultOptions);
239
+ const redacted = { ...params, prompt: redactPrompt(params.prompt, vault) };
240
+ vaults.set(redacted, { vault, json: wantsJson(params) });
241
+ return redacted;
242
+ },
243
+ async wrapGenerate({ doGenerate, params }) {
244
+ const { vault, json } = vaultFor(params);
245
+ const result = await doGenerate();
246
+ if (!isObj(result) || !vault.size)
247
+ return result;
248
+ const restore = restorers(vault, json);
249
+ const out = { ...result, content: restoreContent(result.content, restore) };
250
+ if (typeof result.structuredOutputText === 'string')
251
+ out.structuredOutputText = restore.toolInput(result.structuredOutputText);
252
+ return out;
253
+ },
254
+ async wrapStream({ doStream, params }) {
255
+ const { vault, json } = vaultFor(params);
256
+ const result = await doStream();
257
+ if (!vault.size)
258
+ return result;
259
+ return { ...result, stream: restoreStream(result.stream, restorers(vault, json)) };
260
+ },
261
+ };
262
+ }
263
+ //# sourceMappingURL=ai-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../src/ai-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAA2D,MAAM,YAAY,CAAC;AA0B1J,MAAM,KAAK,GAAG,CAAC,KAAc,EAAgB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAErH,2FAA2F;AAC3F,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU;IACxE,WAAW,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EAAE,QAAQ,EAAE,MAAM,EAAuD;YACvH,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,MAAM,GAAG,MAAM,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,CAAC,IAAI;gBAAE,OAAO,MAAM,CAAC;YAC/B,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,MAAiC,EAAE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QAChH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -47,4 +47,47 @@ export declare function cnResidentIdValid(value: string): boolean;
47
47
  export declare function jpMyNumberValid(value: string): boolean;
48
48
  /** Italy Codice Fiscale — 16 chars, odd/even table checksum. */
49
49
  export declare function codiceFiscaleValid(value: string): boolean;
50
+ /** Romania CNP: 13 digits, birth date, weighted mod-11 check digit (10 is written as 1). */
51
+ export declare function cnpValid(value: string): boolean;
52
+ /**
53
+ * Sweden personnummer: YYMMDD-NNNC (or `+` from age 100), or YYYYMMDDNNNC.
54
+ * Luhn over the ten-digit form; a samordningsnummer adds 60 to the day.
55
+ */
56
+ export declare function personnummerValid(value: string): boolean;
57
+ /** Finland henkilötunnus: DDMMYY, century sign, individual number, mod-31 check character. */
58
+ export declare function hetuValid(value: string): boolean;
59
+ /** Norway fødselsnummer (and D- and H-numbers): 11 digits, two mod-11 check digits. */
60
+ export declare function fodselsnummerValid(value: string): boolean;
61
+ /**
62
+ * Belgium national register number: YYMMDD, counter, check = 97 − (n mod 97),
63
+ * with a 2 prefixed for people born from 2000. BIS numbers add 20 or 40 to the
64
+ * month. The day is not checked: it is 00 when unknown and runs past 31 once a
65
+ * date's counter is used up.
66
+ */
67
+ export declare function beNationalNumberValid(value: string): boolean;
68
+ /** Portugal NIF of a person (first digit 1-3, or 45 for non-residents): weighted mod-11. */
69
+ export declare function ptNifValid(value: string): boolean;
70
+ /** South Africa ID number: YYMMDD, citizenship digit 0-2, Luhn over all 13 digits. */
71
+ export declare function zaIdValid(value: string): boolean;
72
+ /**
73
+ * Mexico CURP: 18 characters, birth date, sex, state, check digit. The check
74
+ * alphabet is 0-9, A-N, Ñ, O-Z, so O-Z count one higher than their place in A-Z.
75
+ */
76
+ export declare function curpValid(value: string): boolean;
77
+ /** Chile RUT / RUN: 7-8 digits and a mod-11 check character (10 is K, 11 is 0). */
78
+ export declare function rutValid(value: string): boolean;
79
+ /**
80
+ * Argentina CUIL / CUIT of a person (prefix 20, 23, 24 or 27): weighted mod-11.
81
+ * A check value of 10 is accepted as 9, the digit used for it in practice.
82
+ */
83
+ export declare function cuitValid(value: string): boolean;
84
+ /** Singapore NRIC / FIN (S, T, F, G series): weighted mod-11 check letter. */
85
+ export declare function nricValid(value: string): boolean;
86
+ /** Greece AMKA: DDMMYY birth date, serial, Luhn over all 11 digits. */
87
+ export declare function amkaValid(value: string): boolean;
88
+ /**
89
+ * UK National Insurance number. No checksum exists; HMRC's allocation rules
90
+ * (letters never used in the prefix, prefixes never issued, suffix A-D) are checked.
91
+ */
92
+ export declare function ninoValid(value: string): boolean;
50
93
  //# sourceMappingURL=checksums.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checksums.d.ts","sourceRoot":"","sources":["../src/checksums.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAehD;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAYhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAazD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,SAAU,GAAG,MAAM,CAW7E;AAED,2DAA2D;AAC3D,wBAAgB,S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CAOhD;AAGD,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOhD;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAKhD;AAGD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAIhD"}
package/dist/checksums.js CHANGED
@@ -299,4 +299,188 @@ export function codiceFiscaleValid(value) {
299
299
  }
300
300
  return String.fromCharCode(65 + (sum % 26)) === cf[15];
301
301
  }
302
+ /** Day 01-31 and month 01-12, the plausibility check shared by date-based IDs. */
303
+ function plausibleDate(day, month) {
304
+ return day >= 1 && day <= 31 && month >= 1 && month <= 12;
305
+ }
306
+ const CNP_WEIGHTS = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
307
+ /** Romania CNP: 13 digits, birth date, weighted mod-11 check digit (10 is written as 1). */
308
+ export function cnpValid(value) {
309
+ const d = onlyDigits(value);
310
+ if (d.length !== 13 || d[0] === '0')
311
+ return false;
312
+ if (!plausibleDate(Number(d.slice(5, 7)), Number(d.slice(3, 5))))
313
+ return false;
314
+ let sum = 0;
315
+ for (let i = 0; i < 12; i++)
316
+ sum += Number(d[i]) * CNP_WEIGHTS[i];
317
+ const r = sum % 11;
318
+ return (r === 10 ? 1 : r) === Number(d[12]);
319
+ }
320
+ /**
321
+ * Sweden personnummer: YYMMDD-NNNC (or `+` from age 100), or YYYYMMDDNNNC.
322
+ * Luhn over the ten-digit form; a samordningsnummer adds 60 to the day.
323
+ */
324
+ export function personnummerValid(value) {
325
+ let d = value.replace(/[-+]/g, '');
326
+ if (!/^\d+$/.test(d))
327
+ return false;
328
+ if (d.length === 12) {
329
+ if (!/^(?:18|19|20)/.test(d))
330
+ return false;
331
+ d = d.slice(2);
332
+ }
333
+ if (d.length !== 10)
334
+ return false;
335
+ const day = Number(d.slice(4, 6));
336
+ if (!plausibleDate(day > 60 ? day - 60 : day, Number(d.slice(2, 4))))
337
+ return false;
338
+ return luhnCheck(d);
339
+ }
340
+ const HETU_CHECK = '0123456789ABCDEFHJKLMNPRSTUVWXY';
341
+ /** Finland henkilötunnus: DDMMYY, century sign, individual number, mod-31 check character. */
342
+ export function hetuValid(value) {
343
+ const m = value.match(/^(\d{2})(\d{2})(\d{2})[-+A-FU-Y](\d{3})([0-9A-FHJ-NPR-Y])$/);
344
+ if (!m)
345
+ return false;
346
+ if (!plausibleDate(Number(m[1]), Number(m[2])) || Number(m[4]) < 2)
347
+ return false;
348
+ return HETU_CHECK[Number(m[1] + m[2] + m[3] + m[4]) % 31] === m[5];
349
+ }
350
+ const FNR_W1 = [3, 7, 6, 1, 8, 9, 4, 5, 2];
351
+ const FNR_W2 = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
352
+ /** Norway fødselsnummer (and D- and H-numbers): 11 digits, two mod-11 check digits. */
353
+ export function fodselsnummerValid(value) {
354
+ const d = onlyDigits(value);
355
+ if (d.length !== 11)
356
+ return false;
357
+ const day = Number(d.slice(0, 2));
358
+ const month = Number(d.slice(2, 4));
359
+ if (!plausibleDate(day > 40 ? day - 40 : day, month > 40 ? month - 40 : month))
360
+ return false;
361
+ const check = (weights) => {
362
+ let sum = 0;
363
+ for (let i = 0; i < weights.length; i++)
364
+ sum += Number(d[i]) * weights[i];
365
+ return (11 - (sum % 11)) % 11;
366
+ };
367
+ return check(FNR_W1) === Number(d[9]) && check(FNR_W2) === Number(d[10]);
368
+ }
369
+ /**
370
+ * Belgium national register number: YYMMDD, counter, check = 97 − (n mod 97),
371
+ * with a 2 prefixed for people born from 2000. BIS numbers add 20 or 40 to the
372
+ * month. The day is not checked: it is 00 when unknown and runs past 31 once a
373
+ * date's counter is used up.
374
+ */
375
+ export function beNationalNumberValid(value) {
376
+ const d = onlyDigits(value);
377
+ if (d.length !== 11)
378
+ return false;
379
+ const month = Number(d.slice(2, 4));
380
+ if (month > 52 || month % 20 > 12)
381
+ return false;
382
+ const base = Number(d.slice(0, 9));
383
+ const check = Number(d.slice(9));
384
+ return 97 - (base % 97) === check || 97 - ((2_000_000_000 + base) % 97) === check;
385
+ }
386
+ /** Portugal NIF of a person (first digit 1-3, or 45 for non-residents): weighted mod-11. */
387
+ export function ptNifValid(value) {
388
+ const d = onlyDigits(value);
389
+ if (d.length !== 9 || !(/^[123]/.test(d) || d.startsWith('45')))
390
+ return false;
391
+ let sum = 0;
392
+ for (let i = 0; i < 8; i++)
393
+ sum += Number(d[i]) * (9 - i);
394
+ return ((11 - (sum % 11)) % 11) % 10 === Number(d[8]);
395
+ }
396
+ /** South Africa ID number: YYMMDD, citizenship digit 0-2, Luhn over all 13 digits. */
397
+ export function zaIdValid(value) {
398
+ const d = onlyDigits(value);
399
+ if (d.length !== 13 || d[10] > '2')
400
+ return false;
401
+ if (!plausibleDate(Number(d.slice(4, 6)), Number(d.slice(2, 4))))
402
+ return false;
403
+ return luhnCheck(d);
404
+ }
405
+ const CURP_STATES = new Set([
406
+ 'AS', 'BC', 'BS', 'CC', 'CH', 'CL', 'CM', 'CS', 'DF', 'DG', 'GR', 'GT', 'HG', 'JC', 'MC', 'MN', 'MS',
407
+ 'NE', 'NL', 'NT', 'OC', 'PL', 'QR', 'QT', 'SL', 'SP', 'SR', 'TC', 'TL', 'TS', 'VZ', 'YN', 'ZS',
408
+ ]);
409
+ /**
410
+ * Mexico CURP: 18 characters, birth date, sex, state, check digit. The check
411
+ * alphabet is 0-9, A-N, Ñ, O-Z, so O-Z count one higher than their place in A-Z.
412
+ */
413
+ export function curpValid(value) {
414
+ const m = value.match(/^[A-Z]{4}(\d{2})(\d{2})(\d{2})[HM]([A-Z]{2})[B-DF-HJ-NP-TV-Z]{3}[0-9A-Z]\d$/);
415
+ if (!m || !plausibleDate(Number(m[3]), Number(m[2])) || !CURP_STATES.has(m[4]))
416
+ return false;
417
+ let sum = 0;
418
+ for (let i = 0; i < 17; i++) {
419
+ const c = value.charCodeAt(i);
420
+ const v = c <= 57 ? c - 48 : c <= 78 ? c - 55 : c - 54;
421
+ sum += v * (18 - i);
422
+ }
423
+ return (10 - (sum % 10)) % 10 === Number(value[17]);
424
+ }
425
+ /** Chile RUT / RUN: 7-8 digits and a mod-11 check character (10 is K, 11 is 0). */
426
+ export function rutValid(value) {
427
+ const m = value.replace(/[ \t\n\x0B\f\r.-]/g, '').toUpperCase().match(/^(\d{7,8})([0-9K])$/);
428
+ if (!m)
429
+ return false;
430
+ let sum = 0;
431
+ let weight = 2;
432
+ for (let i = m[1].length - 1; i >= 0; i--) {
433
+ sum += Number(m[1][i]) * weight;
434
+ weight = weight === 7 ? 2 : weight + 1;
435
+ }
436
+ const r = 11 - (sum % 11);
437
+ return (r === 11 ? '0' : r === 10 ? 'K' : String(r)) === m[2];
438
+ }
439
+ const CUIT_WEIGHTS = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
440
+ /**
441
+ * Argentina CUIL / CUIT of a person (prefix 20, 23, 24 or 27): weighted mod-11.
442
+ * A check value of 10 is accepted as 9, the digit used for it in practice.
443
+ */
444
+ export function cuitValid(value) {
445
+ const d = onlyDigits(value);
446
+ if (d.length !== 11 || !/^2[0347]/.test(d))
447
+ return false;
448
+ let sum = 0;
449
+ for (let i = 0; i < 10; i++)
450
+ sum += Number(d[i]) * CUIT_WEIGHTS[i];
451
+ const r = sum % 11;
452
+ return (r === 0 ? 0 : r === 1 ? 9 : 11 - r) === Number(d[10]);
453
+ }
454
+ const NRIC_WEIGHTS = [2, 7, 6, 5, 4, 3, 2];
455
+ /** Singapore NRIC / FIN (S, T, F, G series): weighted mod-11 check letter. */
456
+ export function nricValid(value) {
457
+ const m = value.match(/^([STFG])(\d{7})([A-Z])$/);
458
+ if (!m)
459
+ return false;
460
+ let sum = m[1] === 'T' || m[1] === 'G' ? 4 : 0;
461
+ for (let i = 0; i < 7; i++)
462
+ sum += Number(m[2][i]) * NRIC_WEIGHTS[i];
463
+ const letters = m[1] === 'S' || m[1] === 'T' ? 'JZIHGFEDCBA' : 'XWUTRQPNMLK';
464
+ return letters[sum % 11] === m[3];
465
+ }
466
+ /** Greece AMKA: DDMMYY birth date, serial, Luhn over all 11 digits. */
467
+ export function amkaValid(value) {
468
+ const d = onlyDigits(value);
469
+ if (d.length !== 11)
470
+ return false;
471
+ if (!plausibleDate(Number(d.slice(0, 2)), Number(d.slice(2, 4))))
472
+ return false;
473
+ return luhnCheck(d);
474
+ }
475
+ const NINO_UNUSED_PREFIXES = new Set(['BG', 'GB', 'KN', 'NK', 'NT', 'TN', 'ZZ']);
476
+ /**
477
+ * UK National Insurance number. No checksum exists; HMRC's allocation rules
478
+ * (letters never used in the prefix, prefixes never issued, suffix A-D) are checked.
479
+ */
480
+ export function ninoValid(value) {
481
+ const n = value.replace(/ /g, '');
482
+ if (!/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z]\d{6}[A-D]$/.test(n))
483
+ return false;
484
+ return !NINO_UNUSED_PREFIXES.has(n.slice(0, 2));
485
+ }
302
486
  //# sourceMappingURL=checksums.js.map