@conarium-ai/core 0.2.0 → 0.2.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.
- package/CHANGELOG.md +79 -1
- package/README.md +20 -3
- package/SECURITY.md +15 -0
- package/bin/conarium-init.mjs +11 -2
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +4 -0
- package/dist/audit.js.map +1 -1
- package/dist/governance.d.ts.map +1 -1
- package/dist/governance.js +15 -5
- package/dist/governance.js.map +1 -1
- package/dist/http.d.ts +0 -5
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +32 -9
- package/dist/http.js.map +1 -1
- package/dist/iban.d.ts +56 -0
- package/dist/iban.d.ts.map +1 -0
- package/dist/iban.js +166 -0
- package/dist/iban.js.map +1 -0
- package/dist/llm-gate.d.ts +1 -1
- package/dist/llm-gate.js +1 -1
- package/docs/RECEIPT-SPEC.md +21 -5
- package/examples/demo-bank/README.md +5 -0
- package/examples/per-user-identity/README.md +63 -0
- package/examples/per-user-identity/mint-token.mjs +92 -0
- package/examples/per-user-identity/policy.overlay.json +15 -0
- package/examples/per-user-identity/prove-identity.mjs +138 -0
- package/examples/per-user-identity/rollback.sh +8 -0
- package/package.json +6 -2
- package/test-vectors/keys/vector-key.SECRET-TEST-ONLY.pem +0 -6
package/dist/http.js
CHANGED
|
@@ -87,6 +87,20 @@ function readBody(req) {
|
|
|
87
87
|
* test edilebilir olması gerekiyor: bir devralma denemesi düzeltmeden önce
|
|
88
88
|
* kırmızı yanmadan "kapatıldı" denemez.
|
|
89
89
|
*/
|
|
90
|
+
/**
|
|
91
|
+
* Hata gövdeleri JSON-RPC olmak ZORUNDA.
|
|
92
|
+
*
|
|
93
|
+
* 2026-08-13'te canlıda yaşandı: geçit yeniden başlatıldı, istemci elindeki eski
|
|
94
|
+
* `Mcp-Session-Id` ile geldi, sunucu `400 expected initialize` + `text/plain`
|
|
95
|
+
* döndü. İstemci tarafındaki proxy bunu ayrıştıramadı ve kullanıcıya
|
|
96
|
+
* "Invalid content from server" dedi — yani gerçek sebep (oturum düştü, yeniden
|
|
97
|
+
* başlat) kullanıcıya HİÇ ulaşmadı. Düz metin hata, teşhis edilemeyen hata demek.
|
|
98
|
+
*/
|
|
99
|
+
function sendRpcError(res, status, code, message, headers = {}) {
|
|
100
|
+
res
|
|
101
|
+
.writeHead(status, { 'content-type': 'application/json', ...headers })
|
|
102
|
+
.end(JSON.stringify({ jsonrpc: '2.0', error: { code, message }, id: null }));
|
|
103
|
+
}
|
|
90
104
|
export function createHandler(deps, transports, limiter) {
|
|
91
105
|
return async (req, res) => {
|
|
92
106
|
try {
|
|
@@ -100,7 +114,7 @@ export function createHandler(deps, transports, limiter) {
|
|
|
100
114
|
const pathMatch = url.pathname.match(/^\/t\/([^/]+)\/mcp$/);
|
|
101
115
|
const isPlainMcp = url.pathname === '/mcp';
|
|
102
116
|
if (!pathMatch && !isPlainMcp) {
|
|
103
|
-
res
|
|
117
|
+
sendRpcError(res, 404, -32600, 'not found — the MCP endpoint is /mcp');
|
|
104
118
|
return;
|
|
105
119
|
}
|
|
106
120
|
const bearer = String(req.headers.authorization || '').replace(/^Bearer\s+/i, '');
|
|
@@ -110,15 +124,15 @@ export function createHandler(deps, transports, limiter) {
|
|
|
110
124
|
// kimin geçtiğini adlandırır. Eşleşmeyen token hâlâ kapıda kalır.
|
|
111
125
|
const kisi = resolveActor(supplied, TOKEN_STORE, deps.config.consumer ?? 'unknown');
|
|
112
126
|
if (!kisi.isUser && !tokenOk(supplied)) {
|
|
113
|
-
res
|
|
127
|
+
sendRpcError(res, 401, -32001, 'unauthorized');
|
|
114
128
|
return;
|
|
115
129
|
}
|
|
116
130
|
// Limit AFTER auth: an unauthorized flood must not burn a real client's budget.
|
|
117
131
|
const client = clientKey(req.headers, req.socket.remoteAddress ?? undefined);
|
|
118
132
|
if (!limiter.take(client)) {
|
|
119
|
-
res
|
|
120
|
-
|
|
121
|
-
|
|
133
|
+
sendRpcError(res, 429, -32002, 'rate limited', {
|
|
134
|
+
'retry-after': String(limiter.retryAfter(client)),
|
|
135
|
+
});
|
|
122
136
|
return;
|
|
123
137
|
}
|
|
124
138
|
const sessionId = String(req.headers['mcp-session-id'] || '') || undefined;
|
|
@@ -130,21 +144,30 @@ export function createHandler(deps, transports, limiter) {
|
|
|
130
144
|
// paylaşılan-token sahibi, o kişinin profil/maskeleme bağlamıyla çalışır
|
|
131
145
|
// ve o andan sonraki her makbuz yanlış kişiyi adlandırır.
|
|
132
146
|
if (!sessionOwnerMatches(existing.owner, supplied)) {
|
|
133
|
-
res
|
|
147
|
+
sendRpcError(res, 403, -32003, 'session owner mismatch');
|
|
134
148
|
return;
|
|
135
149
|
}
|
|
136
150
|
const body = req.method === 'POST' ? await readBody(req) : undefined;
|
|
137
151
|
await existing.transport.handleRequest(req, res, body);
|
|
138
152
|
return;
|
|
139
153
|
}
|
|
154
|
+
// Oturum kimliği GELDİ ama sunucuda yok: yeniden başlatılmış geçit, ya da
|
|
155
|
+
// süresi dolmuş oturum. Spec bunun için 404 der — istemcinin yapması gereken
|
|
156
|
+
// yeni bir initialize açmaktır. 400 "isteğin bozuk" demektir; istemci bunu
|
|
157
|
+
// toparlanma sinyali saymaz ve bağlantı kalıcı olarak ölür. Canlıda tam olarak
|
|
158
|
+
// bu yaşandı: 03:38'deki yeniden başlatmadan sonra konnektör bir daha açılmadı.
|
|
159
|
+
if (sessionId) {
|
|
160
|
+
sendRpcError(res, 404, -32004, 'session not found — send a new initialize request');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
140
163
|
// Yeni oturum: yalnız initialize POST açar
|
|
141
164
|
if (req.method !== 'POST') {
|
|
142
|
-
res
|
|
165
|
+
sendRpcError(res, 400, -32600, 'no session — open one with an initialize POST');
|
|
143
166
|
return;
|
|
144
167
|
}
|
|
145
168
|
const body = await readBody(req);
|
|
146
169
|
if (!isInitializeRequest(body)) {
|
|
147
|
-
res
|
|
170
|
+
sendRpcError(res, 400, -32600, 'expected initialize');
|
|
148
171
|
return;
|
|
149
172
|
}
|
|
150
173
|
const owner = ownerKey(supplied);
|
|
@@ -164,7 +187,7 @@ export function createHandler(deps, transports, limiter) {
|
|
|
164
187
|
console.error('[conarium-http] istek hatası:', err.message);
|
|
165
188
|
try {
|
|
166
189
|
if (!res.headersSent)
|
|
167
|
-
res
|
|
190
|
+
sendRpcError(res, 500, -32603, 'internal error');
|
|
168
191
|
}
|
|
169
192
|
catch { /* */ }
|
|
170
193
|
}
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAA6C,MAAM,WAAW,CAAA;AACvG,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,IAAI,CAAC,CAAA;AAC1D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,WAAW,CAAA;AACzD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAA;AA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CAAA;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC9B,KAAK,MAAM,CAAC,IAAI,UAAU,CAAC,MAAM,EAAE;YAAE,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC9E,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU;YAAE,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE;IACjC,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC5F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAC,EAAE,CAAA;AAEJ,IAAI,oBAAoB,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAA;QAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/iban.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IBAN content detector — deterministic, checksummed, not overridable.
|
|
3
|
+
*
|
|
4
|
+
* Column policy (`maskColumns: ['*.iban']`) only fires when the column is
|
|
5
|
+
* named. A free-text note, or a column the operator forgot to list, used to
|
|
6
|
+
* send the IBAN to the model — sometimes half-masked by the digit detector
|
|
7
|
+
* (`TR00000000000[MASKED_PII]`), which looks like protection and is worse
|
|
8
|
+
* than leaving it alone.
|
|
9
|
+
*
|
|
10
|
+
* A profile may empty `maskColumns`. It must not switch this off: identity
|
|
11
|
+
* fields are not a privilege the controller can grant the model.
|
|
12
|
+
*
|
|
13
|
+
* Checksum (ISO 7064 mod-97-10) is the false-positive brake. Shape alone
|
|
14
|
+
* would mask any 15–34 character alphanumeric run that starts with two
|
|
15
|
+
* letters; the remainder-1 test is what refuses a random 26-digit string.
|
|
16
|
+
* Tests that disable the checksum MUST go red if this brake is removed.
|
|
17
|
+
*
|
|
18
|
+
* The candidate regex is greedy and will eat the next word (`havale IBAN
|
|
19
|
+
* tamam`). After a match we shrink from the end until the remainder is a
|
|
20
|
+
* real IBAN (or an IBAN-shaped lookalike). Lookalikes that fail checksum
|
|
21
|
+
* are not masked — they are shielded so the phone/card regexes cannot
|
|
22
|
+
* nibble the tail.
|
|
23
|
+
*/
|
|
24
|
+
export declare const IBAN_MASK: "[MASKED_PII]";
|
|
25
|
+
/** Strip grouping spaces/hyphens; IBAN letters are case-insensitive. */
|
|
26
|
+
export declare function normalizeIban(raw: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* ISO 13616 electronic form: 2-letter country, 2 check digits, 11–30 BBAN.
|
|
29
|
+
* Country-specific lengths are not a dictionary we maintain — checksum is
|
|
30
|
+
* the acceptance test.
|
|
31
|
+
*/
|
|
32
|
+
export declare function looksLikeIban(normalized: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* ISO 7064 MOD-97-10 over the rearranged IBAN.
|
|
35
|
+
* Remainder must be 1. A candidate that fails this is not an IBAN.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ibanMod97Ok(normalized: string): boolean;
|
|
38
|
+
export interface MaskIbanOpts {
|
|
39
|
+
/** Production default true. Tests flip this to prove the brake exists. */
|
|
40
|
+
checksum?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface IbanPass {
|
|
43
|
+
text: string;
|
|
44
|
+
count: number;
|
|
45
|
+
restore: (s: string) => string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Mask checksum-valid IBANs; shield remaining IBAN-shaped spans so later
|
|
49
|
+
* digit detectors cannot half-mask them. Call `restore` after those detectors.
|
|
50
|
+
*/
|
|
51
|
+
export declare function prepareIbanPass(text: string, opts?: MaskIbanOpts): IbanPass;
|
|
52
|
+
export declare function maskIbansInText(text: string, opts?: MaskIbanOpts): {
|
|
53
|
+
text: string;
|
|
54
|
+
count: number;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=iban.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iban.d.ts","sourceRoot":"","sources":["../src/iban.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,SAAS,EAAG,cAAuB,CAAA;AAKhD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAQvD;AAED,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAyBD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAC/B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,QAAQ,CAsF/E;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAGtG"}
|
package/dist/iban.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IBAN content detector — deterministic, checksummed, not overridable.
|
|
3
|
+
*
|
|
4
|
+
* Column policy (`maskColumns: ['*.iban']`) only fires when the column is
|
|
5
|
+
* named. A free-text note, or a column the operator forgot to list, used to
|
|
6
|
+
* send the IBAN to the model — sometimes half-masked by the digit detector
|
|
7
|
+
* (`TR00000000000[MASKED_PII]`), which looks like protection and is worse
|
|
8
|
+
* than leaving it alone.
|
|
9
|
+
*
|
|
10
|
+
* A profile may empty `maskColumns`. It must not switch this off: identity
|
|
11
|
+
* fields are not a privilege the controller can grant the model.
|
|
12
|
+
*
|
|
13
|
+
* Checksum (ISO 7064 mod-97-10) is the false-positive brake. Shape alone
|
|
14
|
+
* would mask any 15–34 character alphanumeric run that starts with two
|
|
15
|
+
* letters; the remainder-1 test is what refuses a random 26-digit string.
|
|
16
|
+
* Tests that disable the checksum MUST go red if this brake is removed.
|
|
17
|
+
*
|
|
18
|
+
* The candidate regex is greedy and will eat the next word (`havale IBAN
|
|
19
|
+
* tamam`). After a match we shrink from the end until the remainder is a
|
|
20
|
+
* real IBAN (or an IBAN-shaped lookalike). Lookalikes that fail checksum
|
|
21
|
+
* are not masked — they are shielded so the phone/card regexes cannot
|
|
22
|
+
* nibble the tail.
|
|
23
|
+
*/
|
|
24
|
+
export const IBAN_MASK = '[MASKED_PII]';
|
|
25
|
+
const SHIELD_OPEN = '\uE000';
|
|
26
|
+
const SHIELD_CLOSE = '\uE001';
|
|
27
|
+
/** Strip grouping spaces/hyphens; IBAN letters are case-insensitive. */
|
|
28
|
+
export function normalizeIban(raw) {
|
|
29
|
+
return raw.replace(/[\s-]/g, '').toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ISO 13616 electronic form: 2-letter country, 2 check digits, 11–30 BBAN.
|
|
33
|
+
* Country-specific lengths are not a dictionary we maintain — checksum is
|
|
34
|
+
* the acceptance test.
|
|
35
|
+
*/
|
|
36
|
+
export function looksLikeIban(normalized) {
|
|
37
|
+
return /^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(normalized);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* ISO 7064 MOD-97-10 over the rearranged IBAN.
|
|
41
|
+
* Remainder must be 1. A candidate that fails this is not an IBAN.
|
|
42
|
+
*/
|
|
43
|
+
export function ibanMod97Ok(normalized) {
|
|
44
|
+
const rearranged = normalized.slice(4) + normalized.slice(0, 4);
|
|
45
|
+
let rem = 0;
|
|
46
|
+
for (const ch of rearranged) {
|
|
47
|
+
const piece = ch >= 'A' && ch <= 'Z' ? String(ch.charCodeAt(0) - 55) : ch;
|
|
48
|
+
for (const d of piece)
|
|
49
|
+
rem = (rem * 10 + (d.charCodeAt(0) - 48)) % 97;
|
|
50
|
+
}
|
|
51
|
+
return rem === 1;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Country letters + check digits, then 11–30 grouped alphanumerics.
|
|
55
|
+
* Spaces/hyphens inside the body are the common written form.
|
|
56
|
+
* No trailing `\b`: we shrink the greedy match ourselves.
|
|
57
|
+
*/
|
|
58
|
+
const IBAN_CANDIDATE = /\b[A-Za-z]{2}[\s-]*\d{2}(?:[\s-]*[A-Za-z0-9]){11,30}/g;
|
|
59
|
+
function trimTrailingIbanChar(s) {
|
|
60
|
+
return s.replace(/[\s-]*[A-Za-z0-9]$/i, '');
|
|
61
|
+
}
|
|
62
|
+
function longestWhere(raw, pred) {
|
|
63
|
+
let candidate = raw;
|
|
64
|
+
while (candidate.length >= 15) {
|
|
65
|
+
if (pred(normalizeIban(candidate)))
|
|
66
|
+
return candidate;
|
|
67
|
+
const next = trimTrailingIbanChar(candidate);
|
|
68
|
+
if (next === candidate)
|
|
69
|
+
break;
|
|
70
|
+
candidate = next;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Mask checksum-valid IBANs; shield remaining IBAN-shaped spans so later
|
|
76
|
+
* digit detectors cannot half-mask them. Call `restore` after those detectors.
|
|
77
|
+
*/
|
|
78
|
+
export function prepareIbanPass(text, opts = {}) {
|
|
79
|
+
const checksum = opts.checksum !== false;
|
|
80
|
+
const holes = [];
|
|
81
|
+
let count = 0;
|
|
82
|
+
// ⛔ String.replace ile TEK aday regex'i yetmiyor, olculdu (08-13):
|
|
83
|
+
// "IBAN1 ve IBAN2" tek eslesme oluyor (gruplama bosluklarina izin veren
|
|
84
|
+
// [\s-]* araya giren "ve"yi de alnum sayiyor), sonra {11,30} siniri
|
|
85
|
+
// eslesmeyi IKINCI IBAN'IN ORTASINDA kesiyor ("...841326 ve TR33 00").
|
|
86
|
+
// replace eslesmenin SONUNDAN devam ettigi icin ikinci IBAN'in kalani bir
|
|
87
|
+
// daha hicbir desene uymuyordu: iki IBAN'li her metinde count=1 ve ikinci
|
|
88
|
+
// IBAN TAMAMEN aciktaydi. Odeme metninde "X hesabindan Y hesabina" siradan
|
|
89
|
+
// bir cumle, yani bu kenar durum degil.
|
|
90
|
+
//
|
|
91
|
+
// Cozum: capa bul → oradan IBAN bicimli en uzun akisi topla (en fazla 34
|
|
92
|
+
// alnum) → checksum tutana kadar sondan kis → ve taramaya TUKETILEN parcanin
|
|
93
|
+
// hemen ardindan devam et. Boylece asiri acgozlu akis ikinci IBAN'i yutsa
|
|
94
|
+
// bile, imlec onun basina geri doner.
|
|
95
|
+
const ANCHOR = /\b[A-Za-z]{2}[\s-]*\d{2}/g;
|
|
96
|
+
const isAlnum = (c) => /[A-Za-z0-9]/.test(c);
|
|
97
|
+
const isSep = (c) => /[\s-]/.test(c);
|
|
98
|
+
const runFrom = (s, start) => {
|
|
99
|
+
let i = start;
|
|
100
|
+
let alnum = 0;
|
|
101
|
+
let end = start;
|
|
102
|
+
while (i < s.length && alnum < 34) {
|
|
103
|
+
if (isAlnum(s[i])) {
|
|
104
|
+
alnum++;
|
|
105
|
+
i++;
|
|
106
|
+
end = i;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (isSep(s[i])) {
|
|
110
|
+
let j = i;
|
|
111
|
+
while (j < s.length && isSep(s[j]))
|
|
112
|
+
j++;
|
|
113
|
+
if (j < s.length && isAlnum(s[j]) && alnum < 34) {
|
|
114
|
+
i = j;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
return s.slice(start, end);
|
|
121
|
+
};
|
|
122
|
+
let out = '';
|
|
123
|
+
let cursor = 0;
|
|
124
|
+
ANCHOR.lastIndex = 0;
|
|
125
|
+
let anchor;
|
|
126
|
+
while ((anchor = ANCHOR.exec(text)) !== null) {
|
|
127
|
+
if (anchor.index < cursor) {
|
|
128
|
+
ANCHOR.lastIndex = cursor;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const run = runFrom(text, anchor.index);
|
|
132
|
+
if (run.length < 15) {
|
|
133
|
+
ANCHOR.lastIndex = anchor.index + 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const valid = longestWhere(run, (n) => looksLikeIban(n) && (!checksum || ibanMod97Ok(n)));
|
|
137
|
+
const shape = valid ?? longestWhere(run, looksLikeIban);
|
|
138
|
+
if (!shape) {
|
|
139
|
+
ANCHOR.lastIndex = anchor.index + 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
out += text.slice(cursor, anchor.index);
|
|
143
|
+
if (valid) {
|
|
144
|
+
count++;
|
|
145
|
+
out += IBAN_MASK;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const id = holes.length;
|
|
149
|
+
holes.push(shape);
|
|
150
|
+
out += `${SHIELD_OPEN}${id}${SHIELD_CLOSE}`;
|
|
151
|
+
}
|
|
152
|
+
cursor = anchor.index + shape.length;
|
|
153
|
+
ANCHOR.lastIndex = cursor;
|
|
154
|
+
}
|
|
155
|
+
const next = out + text.slice(cursor);
|
|
156
|
+
return {
|
|
157
|
+
text: next,
|
|
158
|
+
count,
|
|
159
|
+
restore: (s) => s.replace(new RegExp(`${SHIELD_OPEN}(\\d+)${SHIELD_CLOSE}`, 'g'), (_, id) => holes[Number(id)] ?? _),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export function maskIbansInText(text, opts = {}) {
|
|
163
|
+
const pass = prepareIbanPass(text, opts);
|
|
164
|
+
return { text: pass.restore(pass.text), count: pass.count };
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=iban.js.map
|
package/dist/iban.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iban.js","sourceRoot":"","sources":["../src/iban.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,cAAuB,CAAA;AAEhD,MAAM,WAAW,GAAG,QAAQ,CAAA;AAC5B,MAAM,YAAY,GAAG,QAAQ,CAAA;AAE7B,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,OAAO,gCAAgC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,UAAkB;IAC5C,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/D,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,KAAK,M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,CAAC;YACN,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAA;YACvB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACjB,GAAG,IAAI,GAAG,WAAW,GAAG,EAAE,GAAG,YAAY,EAAE,CAAA;QAC7C,CAAC;QACD,MAAM,GAAG,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAA;QACpC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAA;IAC3B,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACrC,OAAO;QACL,IAAI,EAAE,IAAI;QACV,KAAK;QACL,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CACvB,IAAI,MAAM,CAAC,GAAG,WAAW,SAAS,YAAY,EAAE,EAAE,GAAG,CAAC,EACtD,CAAC,CAAC,EAAE,EAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAC1C;KACF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,OAAqB,EAAE;IACnE,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IACxC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAA;AAC7D,CAAC"}
|
package/dist/llm-gate.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface GateAudit {
|
|
|
10
10
|
* Kullanım (jarvis-web/lib/konnektor/llm.ts):
|
|
11
11
|
* export const claudeLlm = governLlm(rawClaudeLlm, policy, a => appendAudit(a));
|
|
12
12
|
*
|
|
13
|
-
* NOT (dürüst): maskPII regex'i email/TCKN/telefon/kart yakalar. AD/UNVAN gibi
|
|
13
|
+
* NOT (dürüst): maskPII regex'i email/TCKN/telefon/kart/IBAN (mod-97) yakalar. AD/UNVAN gibi
|
|
14
14
|
* yapısal PII regex'e uymaz → onlar ctx üretim kaynağında pseudonymize edilmeli (Faz 2).
|
|
15
15
|
*/
|
|
16
16
|
export declare function governLlm(llm: LlmFn, policy?: GovernancePolicy, onAudit?: (a: GateAudit) => void): LlmFn;
|
package/dist/llm-gate.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Governance } from './governance.js';
|
|
|
4
4
|
* Kullanım (jarvis-web/lib/konnektor/llm.ts):
|
|
5
5
|
* export const claudeLlm = governLlm(rawClaudeLlm, policy, a => appendAudit(a));
|
|
6
6
|
*
|
|
7
|
-
* NOT (dürüst): maskPII regex'i email/TCKN/telefon/kart yakalar. AD/UNVAN gibi
|
|
7
|
+
* NOT (dürüst): maskPII regex'i email/TCKN/telefon/kart/IBAN (mod-97) yakalar. AD/UNVAN gibi
|
|
8
8
|
* yapısal PII regex'e uymaz → onlar ctx üretim kaynağında pseudonymize edilmeli (Faz 2).
|
|
9
9
|
*/
|
|
10
10
|
export function governLlm(llm, policy = {}, onAudit) {
|
package/docs/RECEIPT-SPEC.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
# Conarium Receipt Spec
|
|
1
|
+
# Conarium Receipt Spec
|
|
2
2
|
|
|
3
|
-
Public specification for **verifiable access receipts**.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Public specification for **verifiable access receipts**. Schema version
|
|
4
|
+
**`conarium-receipt/0.3`** is canonical. The verifier also accepts `0.1` and
|
|
5
|
+
`0.2` forever — published receipts keep their original `v` string; this document
|
|
6
|
+
does not change it.
|
|
7
|
+
|
|
8
|
+
Implements the portable side of EU AI Act Articles 12 (logging) and 19 (content
|
|
9
|
+
of logs) for Conarium's governed MCP gateway.
|
|
6
10
|
|
|
7
11
|
Design source: `docs/superpowers/specs/2026-07-29-conarium-receipt-design.md`.
|
|
8
12
|
|
|
@@ -16,6 +20,18 @@ Design source: `docs/superpowers/specs/2026-07-29-conarium-receipt-design.md`.
|
|
|
16
20
|
silinmediğini, yeniden sıralanmadığını ve geriye dönük tarihlenmediğini**
|
|
17
21
|
kanıtlar. **Oluşturma anında doğru olduğunu kanıtlamaz.**
|
|
18
22
|
|
|
23
|
+
## Media type
|
|
24
|
+
|
|
25
|
+
| | |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Media type | `application/vnd.conarium.receipt+json` |
|
|
28
|
+
| Single receipt | `.json` — one JSON object, schema `conarium-receipt/0.3` |
|
|
29
|
+
| Chain (append-only) | `.jsonl` — one receipt object per line, same schema, `chain.seq` contiguous |
|
|
30
|
+
|
|
31
|
+
The vendor tree is the stable identifier for tools that switch on type rather
|
|
32
|
+
than filename. A `.jsonl` file is still `application/vnd.conarium.receipt+json`
|
|
33
|
+
with an outer sequence; there is no separate chain media type.
|
|
34
|
+
|
|
19
35
|
## Schema
|
|
20
36
|
|
|
21
37
|
Version string: `conarium-receipt/0.3` (verifier also accepts `0.1` and `0.2` — forever)
|
|
@@ -30,7 +46,7 @@ Version string: `conarium-receipt/0.3` (verifier also accepts `0.1` and `0.2`
|
|
|
30
46
|
| `flags` | triggered policy flags | strings |
|
|
31
47
|
| `masking` | counts by class | never raw values |
|
|
32
48
|
| `request.argsHash` | request fingerprint | `sha256:…` of args — not the query text |
|
|
33
|
-
| `consentRef` | reserved | always `null` in
|
|
49
|
+
| `consentRef` | reserved | always `null` in `conarium-receipt/0.3` (and in 0.1/0.2). The field exists so a later schema can fill it without renaming. |
|
|
34
50
|
| `chain.seq` | coverage backbone | contiguous integer; required even before v0.2 coverage proofs |
|
|
35
51
|
| `chain.prevHash` / `chain.hash` | integrity | JCS (RFC 8785 subset) → SHA-256 |
|
|
36
52
|
| `sig` | Ed25519 over `chain.hash` | `{ alg, keyId, value }` |
|
|
@@ -25,6 +25,11 @@ npx conarium-doctor
|
|
|
25
25
|
|
|
26
26
|
Expected: doctor EXIT 0, including Reachability to `127.0.0.1:54329`.
|
|
27
27
|
|
|
28
|
+
`conarium-init` prints a `--config .../_keys/conarium.config.json` hint. Ignore it
|
|
29
|
+
here: that is the scaffold it just wrote, with a placeholder DSN. The config this
|
|
30
|
+
demo runs on is the one in this directory, which `conarium-doctor` picks up from
|
|
31
|
+
the working directory. `--out ./_keys` exists precisely so init does not overwrite it.
|
|
32
|
+
|
|
28
33
|
Then prove the product, in this order:
|
|
29
34
|
|
|
30
35
|
```bash
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Per-user identity — local pack (Hetzner stays untouched)
|
|
2
|
+
|
|
3
|
+
Today a shared token writes `assurance: shared-token` and names nobody.
|
|
4
|
+
The code for `policy.profiles` / `policy.actorProfiles` is already in
|
|
5
|
+
`src/governance.ts`. This directory is the operator kit to turn it on
|
|
6
|
+
**locally**, prove it, and roll it back. Copying to `/opt/conarium-mcp`
|
|
7
|
+
is a separate patron decision.
|
|
8
|
+
|
|
9
|
+
## 1. Mint tokens (hash only on disk)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
node examples/per-user-identity/mint-token.mjs --id emekcan --file ./conarium.tokens.json
|
|
13
|
+
node examples/per-user-identity/mint-token.mjs --id copilot --file ./conarium.tokens.json
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Stdout prints the raw token **once**. The file stores `{ sha256, id }` only.
|
|
17
|
+
POSIX mode `0600`. Point the gateway at it:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export CONARIUM_TOKENS_FILE=$PWD/conarium.tokens.json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Do not commit `conarium.tokens.json` or the raw tokens.
|
|
24
|
+
|
|
25
|
+
## 2. Config overlay (c2)
|
|
26
|
+
|
|
27
|
+
Merge `policy.overlay.json` under `policy` of the live c2
|
|
28
|
+
config. Do **not** replace `allowTables` / connectors.
|
|
29
|
+
|
|
30
|
+
- Base (AI / unlisted actor): names stay masked.
|
|
31
|
+
- `emekcan` → profile `patron`: name columns visible; email / TCKN / IBAN
|
|
32
|
+
scanners still run (a profile cannot switch those off).
|
|
33
|
+
|
|
34
|
+
Backup first:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cp conarium.config.c2.json conarium.config.c2.json.bak
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 3. Local proof (this machine, not Hetzner)
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm run build
|
|
44
|
+
node examples/per-user-identity/prove-identity.mjs
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Same row, two tokens: patron sees the name, the other sees `[MASKED_PII]`.
|
|
48
|
+
Both receipts carry `assurance: per-user-token`. The patron receipt's
|
|
49
|
+
`policy.id` is `conarium.policy/patron`; the other stays `conarium.policy`.
|
|
50
|
+
`conarium-verify` must exit 0.
|
|
51
|
+
|
|
52
|
+
## 4. Rollback (one command)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# POSIX
|
|
56
|
+
cp conarium.config.c2.json.bak conarium.config.c2.json && unset CONARIUM_TOKENS_FILE
|
|
57
|
+
|
|
58
|
+
# Windows PowerShell
|
|
59
|
+
Copy-Item conarium.config.c2.json.bak conarium.config.c2.json -Force; Remove-Item Env:CONARIUM_TOKENS_FILE -ErrorAction SilentlyContinue
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Leave the tokens file in place or delete it; without `CONARIUM_TOKENS_FILE`
|
|
63
|
+
every caller is `shared-token` again. No Hetzner restart is part of this pack.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Mint a per-user token into conarium.tokens.json.
|
|
4
|
+
*
|
|
5
|
+
* The file stores SHA-256 only. The raw token is printed once, to stdout,
|
|
6
|
+
* and is never written. 0600 on POSIX.
|
|
7
|
+
*
|
|
8
|
+
* node mint-token.mjs --id emekcan [--file ./conarium.tokens.json]
|
|
9
|
+
*
|
|
10
|
+
* Exit: 0 wrote · 1 refused · 2 could not run
|
|
11
|
+
*/
|
|
12
|
+
import { createHash, randomBytes } from 'node:crypto'
|
|
13
|
+
import { existsSync, readFileSync, writeFileSync, chmodSync, mkdirSync } from 'node:fs'
|
|
14
|
+
import { dirname, resolve } from 'node:path'
|
|
15
|
+
import { platform } from 'node:os'
|
|
16
|
+
|
|
17
|
+
const ARGS = process.argv.slice(2)
|
|
18
|
+
const has = (f) => ARGS.includes(f)
|
|
19
|
+
const valueOf = (f, fallback) => {
|
|
20
|
+
const i = ARGS.indexOf(f)
|
|
21
|
+
return i >= 0 && ARGS[i + 1] ? ARGS[i + 1] : fallback
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (has('--help') || has('-h')) {
|
|
25
|
+
console.log(`conarium mint-token — append a hashed per-user token
|
|
26
|
+
|
|
27
|
+
--id <actor> person id written on the receipt (required)
|
|
28
|
+
--file <path> tokens file (default: ./conarium.tokens.json)
|
|
29
|
+
--bytes <n> raw token length (default: 32)
|
|
30
|
+
|
|
31
|
+
The raw token is printed once. It is not stored.`)
|
|
32
|
+
process.exit(0)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const id = valueOf('--id', '')
|
|
36
|
+
if (!id || id.startsWith('--')) {
|
|
37
|
+
console.error('refusing: --id <actor> is required')
|
|
38
|
+
process.exit(1)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const file = resolve(process.cwd(), valueOf('--file', './conarium.tokens.json'))
|
|
42
|
+
const bytes = Number(valueOf('--bytes', '32'))
|
|
43
|
+
if (!Number.isInteger(bytes) || bytes < 24 || bytes > 64) {
|
|
44
|
+
console.error('refusing: --bytes must be an integer 24–64')
|
|
45
|
+
process.exit(1)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const raw = randomBytes(bytes).toString('base64url')
|
|
49
|
+
const sha256 = createHash('sha256').update(raw).digest('hex')
|
|
50
|
+
|
|
51
|
+
let doc = { tokens: [] }
|
|
52
|
+
if (existsSync(file)) {
|
|
53
|
+
try {
|
|
54
|
+
doc = JSON.parse(readFileSync(file, 'utf8'))
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error(`cannot read ${file}: ${e.message}`)
|
|
57
|
+
process.exit(2)
|
|
58
|
+
}
|
|
59
|
+
if (!Array.isArray(doc.tokens)) doc.tokens = []
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (doc.tokens.some((t) => t && t.sha256 === sha256)) {
|
|
63
|
+
console.error('refusing: hash collision (rerun)')
|
|
64
|
+
process.exit(1)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
doc.tokens.push({ sha256, id })
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
71
|
+
writeFileSync(file, JSON.stringify(doc, null, 2) + '\n', { encoding: 'utf8' })
|
|
72
|
+
if (platform() !== 'win32') {
|
|
73
|
+
try { chmodSync(file, 0o600) } catch { /* doctor still accepts */ }
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error(`cannot write ${file}: ${e.message}`)
|
|
77
|
+
process.exit(2)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const stored = readFileSync(file, 'utf8')
|
|
81
|
+
if (stored.includes(raw)) {
|
|
82
|
+
console.error('refusing: raw token leaked into the file — not printing it')
|
|
83
|
+
process.exit(2)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(`id ${id}`)
|
|
87
|
+
console.log(`sha256 ${sha256}`)
|
|
88
|
+
console.log(`file ${file}`)
|
|
89
|
+
console.log(`token ${raw}`)
|
|
90
|
+
console.log('')
|
|
91
|
+
console.log('The token line is the only copy. Put it in the client env, not in git.')
|
|
92
|
+
process.exit(0)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Overlay for a live conarium.config.c2.json. Merge under policy. Do not replace allowTables/denyTables/connectors. Base policy (AI) keeps names masked; the patron profile unmasks name columns only. Email/TCKN/IBAN scanners still run.",
|
|
3
|
+
"policy": {
|
|
4
|
+
"maskColumns": ["*.customer_name", "*.email", "*.phone", "*.tckn", "*.iban"],
|
|
5
|
+
"profiles": {
|
|
6
|
+
"patron": {
|
|
7
|
+
"maskColumns": ["*.email", "*.phone", "*.tckn", "*.iban"],
|
|
8
|
+
"maskLabelledNames": false
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"actorProfiles": {
|
|
12
|
+
"emekcan": "patron"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|