@darkhunt-security/endpoint-codex 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +11 -0
- package/README.md +76 -0
- package/commands/setup.md +72 -0
- package/commands/status.md +31 -0
- package/dist/bin/backfill.mjs +21868 -0
- package/dist/bin/enroll.mjs +1244 -0
- package/dist/bin/forwarder.mjs +21846 -0
- package/dist/bin/guard.mjs +1421 -0
- package/dist/bin/init.mjs +1135 -0
- package/dist/bin/spool.mjs +1222 -0
- package/dist/bin/status.mjs +1375 -0
- package/hooks/hooks.json +39 -0
- package/package.json +27 -0
|
@@ -0,0 +1,1421 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __dhCreateRequire } from 'node:module';
|
|
3
|
+
const require = __dhCreateRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
// adapters/codex/bin/guard.mjs
|
|
6
|
+
import { dirname, join as join8 } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
// packages/core/dist/policy/match.js
|
|
10
|
+
var PATH_FIELDS = ["file_path", "path", "notebook_path", "filePath"];
|
|
11
|
+
var URL_FIELDS = ["url", "uri"];
|
|
12
|
+
function readField(input, field) {
|
|
13
|
+
const value = field.split(".").reduce((acc, key) => {
|
|
14
|
+
if (acc && typeof acc === "object" && key in acc) {
|
|
15
|
+
return acc[key];
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
}, input);
|
|
19
|
+
if (typeof value === "string")
|
|
20
|
+
return value;
|
|
21
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
22
|
+
return String(value);
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
function globToRegExp(glob) {
|
|
26
|
+
let out = "";
|
|
27
|
+
for (let i = 0; i < glob.length; i++) {
|
|
28
|
+
const c = glob[i];
|
|
29
|
+
if (c === "*") {
|
|
30
|
+
if (glob[i + 1] === "*") {
|
|
31
|
+
out += ".*";
|
|
32
|
+
i++;
|
|
33
|
+
if (glob[i + 1] === "/")
|
|
34
|
+
i++;
|
|
35
|
+
} else {
|
|
36
|
+
out += "[^/]*";
|
|
37
|
+
}
|
|
38
|
+
} else if (c === "?") {
|
|
39
|
+
out += "[^/]";
|
|
40
|
+
} else {
|
|
41
|
+
out += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new RegExp(`^${out}$`);
|
|
45
|
+
}
|
|
46
|
+
function hostOf(value) {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(value).hostname.toLowerCase();
|
|
49
|
+
} catch {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function matches(match, event) {
|
|
54
|
+
if ("all" in match)
|
|
55
|
+
return match.all.every((m) => matches(m, event));
|
|
56
|
+
if ("any" in match)
|
|
57
|
+
return match.any.some((m) => matches(m, event));
|
|
58
|
+
if ("not" in match)
|
|
59
|
+
return !matches(match.not, event);
|
|
60
|
+
if ("tool" in match)
|
|
61
|
+
return match.tool.includes(event.toolName);
|
|
62
|
+
if ("pathGlob" in match) {
|
|
63
|
+
const fields = match.field ? [match.field] : PATH_FIELDS;
|
|
64
|
+
const globs = match.pathGlob.map(globToRegExp);
|
|
65
|
+
return fields.some((f) => {
|
|
66
|
+
const value2 = readField(event.toolInput, f);
|
|
67
|
+
return value2 !== void 0 && globs.some((re) => re.test(value2));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if ("urlHost" in match) {
|
|
71
|
+
const fields = match.field ? [match.field] : URL_FIELDS;
|
|
72
|
+
const wanted = match.urlHost.map((h) => h.toLowerCase());
|
|
73
|
+
return fields.some((f) => {
|
|
74
|
+
const value2 = readField(event.toolInput, f);
|
|
75
|
+
const host = value2 === void 0 ? void 0 : hostOf(value2);
|
|
76
|
+
return host !== void 0 && wanted.some((w) => host === w || host.endsWith(`.${w}`));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const { field, pattern, flags } = match.inputRegex;
|
|
80
|
+
const value = readField(event.toolInput, field);
|
|
81
|
+
if (value === void 0)
|
|
82
|
+
return false;
|
|
83
|
+
return new RegExp(pattern, flags).test(value);
|
|
84
|
+
}
|
|
85
|
+
function inScope(scope, event) {
|
|
86
|
+
if (!scope)
|
|
87
|
+
return true;
|
|
88
|
+
if (scope.tools && !scope.tools.includes(event.toolName))
|
|
89
|
+
return false;
|
|
90
|
+
if (scope.repos) {
|
|
91
|
+
const cwd = event.cwd ?? "";
|
|
92
|
+
if (!scope.repos.some((r) => cwd.includes(r) || globToRegExp(r).test(cwd)))
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// packages/core/dist/policy/engine.js
|
|
99
|
+
var ALLOW = { decision: "allow", ruleId: null, enforcement: "blocking" };
|
|
100
|
+
function rank(c) {
|
|
101
|
+
if (c.rule.enforcement === "advisory")
|
|
102
|
+
return 1;
|
|
103
|
+
switch (c.clause.action) {
|
|
104
|
+
case "deny":
|
|
105
|
+
return 4;
|
|
106
|
+
case "ask":
|
|
107
|
+
return 3;
|
|
108
|
+
case "redact":
|
|
109
|
+
return 2;
|
|
110
|
+
default:
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function isExcepted(rule, event, now) {
|
|
115
|
+
return (rule.exceptions ?? []).some((e) => Date.parse(e.expires) > now && matches(e.match, event));
|
|
116
|
+
}
|
|
117
|
+
function applyRedactions(input, specs) {
|
|
118
|
+
const out = { ...input };
|
|
119
|
+
for (const spec of specs) {
|
|
120
|
+
const value = readField(out, spec.field);
|
|
121
|
+
if (value === void 0)
|
|
122
|
+
continue;
|
|
123
|
+
out[spec.field] = value.replace(new RegExp(spec.pattern, spec.flags ?? "g"), spec.replacement);
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
function evaluate(event, bundle, mode, now = Date.now()) {
|
|
128
|
+
if (mode === "off")
|
|
129
|
+
return ALLOW;
|
|
130
|
+
const candidates = [];
|
|
131
|
+
for (const rule of bundle.rules) {
|
|
132
|
+
if (!inScope(rule.scope, event))
|
|
133
|
+
continue;
|
|
134
|
+
if (isExcepted(rule, event, now))
|
|
135
|
+
continue;
|
|
136
|
+
const clause = rule.clauses.find((c) => matches(c.match, event));
|
|
137
|
+
if (clause)
|
|
138
|
+
candidates.push({ rule, clause });
|
|
139
|
+
}
|
|
140
|
+
if (candidates.length === 0)
|
|
141
|
+
return ALLOW;
|
|
142
|
+
const winner = candidates.reduce((a, b) => rank(b) > rank(a) ? b : a);
|
|
143
|
+
const enforcement = winner.rule.enforcement;
|
|
144
|
+
const base = {
|
|
145
|
+
decision: winner.clause.action === "redact" ? "allow" : winner.clause.action,
|
|
146
|
+
ruleId: winner.rule.id,
|
|
147
|
+
reason: winner.clause.reason,
|
|
148
|
+
enforcement,
|
|
149
|
+
...winner.clause.remediation !== void 0 ? { remediation: winner.clause.remediation } : {}
|
|
150
|
+
};
|
|
151
|
+
if (winner.clause.action === "redact") {
|
|
152
|
+
const specs = candidates.filter((c) => c.rule.enforcement === "blocking" && c.clause.action === "redact").flatMap((c) => c.clause.redact ?? []);
|
|
153
|
+
if (specs.length > 0)
|
|
154
|
+
base.updatedInput = applyRedactions(event.toolInput, specs);
|
|
155
|
+
}
|
|
156
|
+
if (mode === "dryRun" || enforcement === "advisory") {
|
|
157
|
+
const { updatedInput: _dropped, ...reported } = base;
|
|
158
|
+
return { ...reported, decision: "allow", enforcement: "advisory" };
|
|
159
|
+
}
|
|
160
|
+
return base;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// packages/core/dist/config/local.js
|
|
164
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
165
|
+
import { join as join3 } from "node:path";
|
|
166
|
+
|
|
167
|
+
// packages/core/dist/config/paths.js
|
|
168
|
+
import { homedir } from "node:os";
|
|
169
|
+
import { join } from "node:path";
|
|
170
|
+
var CONFIG_DIR = join(homedir(), ".darkhunt");
|
|
171
|
+
|
|
172
|
+
// packages/core/dist/config/profile.js
|
|
173
|
+
import { isAbsolute, join as join2, resolve } from "node:path";
|
|
174
|
+
var DEFAULT_PROFILE = "default";
|
|
175
|
+
var CREDENTIALS_BASENAME = "endpoint-credentials";
|
|
176
|
+
var DEFAULT_CREDENTIALS_PATH = join2(CONFIG_DIR, `${CREDENTIALS_BASENAME}.json`);
|
|
177
|
+
function resolveProfile(explicit, fromConfig) {
|
|
178
|
+
return explicit ?? process.env["DARKHUNT_PROFILE"] ?? fromConfig ?? DEFAULT_PROFILE;
|
|
179
|
+
}
|
|
180
|
+
function scopeKey(vendor, profile) {
|
|
181
|
+
return profile === DEFAULT_PROFILE ? vendor : `${vendor}.${profile}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// packages/core/dist/config/local.js
|
|
185
|
+
function configPath() {
|
|
186
|
+
return join3(CONFIG_DIR, `${CONFIG_BASENAME}.json`);
|
|
187
|
+
}
|
|
188
|
+
var CONFIG_BASENAME = "endpoint-config";
|
|
189
|
+
var ConfigError = class extends Error {
|
|
190
|
+
};
|
|
191
|
+
var ConfigMissingError = class extends ConfigError {
|
|
192
|
+
};
|
|
193
|
+
function readSecure(path) {
|
|
194
|
+
const mode = statSync(path).mode & 511;
|
|
195
|
+
if (mode & 63)
|
|
196
|
+
throw new ConfigError(`${path} is mode ${mode.toString(8)}; must be 0600`);
|
|
197
|
+
return readFileSync(path, "utf8");
|
|
198
|
+
}
|
|
199
|
+
function readJson(path) {
|
|
200
|
+
try {
|
|
201
|
+
return JSON.parse(readSecure(path));
|
|
202
|
+
} catch (err) {
|
|
203
|
+
if (err instanceof ConfigError)
|
|
204
|
+
throw err;
|
|
205
|
+
return void 0;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function settingsFor(file, vendor) {
|
|
209
|
+
const override = file.endpoints?.[vendor] ?? {};
|
|
210
|
+
return {
|
|
211
|
+
...file,
|
|
212
|
+
...override,
|
|
213
|
+
// Spelled out because these are nested: a spread would let an override naming only
|
|
214
|
+
// `mode` drop `failClosed` back to its default, quietly turning fail-closed off.
|
|
215
|
+
...file.capture ?? override.capture ? { capture: { ...file.capture, ...override.capture } } : {},
|
|
216
|
+
...file.enforce ?? override.enforce ? { enforce: { ...file.enforce, ...override.enforce } } : {}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function loadRuntimeSettings(vendor, options = {}) {
|
|
220
|
+
const vendorFile = readConfigFile(vendor);
|
|
221
|
+
const profile = resolveProfile(options.profile, vendorFile.profile);
|
|
222
|
+
return {
|
|
223
|
+
profile,
|
|
224
|
+
scope: scopeKey(vendor, profile),
|
|
225
|
+
enabled: vendorFile.enabled ?? true,
|
|
226
|
+
capture: { enabled: vendorFile.capture?.enabled ?? true },
|
|
227
|
+
enforce: {
|
|
228
|
+
mode: vendorFile.enforce?.mode ?? "off",
|
|
229
|
+
failClosed: vendorFile.enforce?.failClosed ?? true
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function readConfigFile(vendor) {
|
|
234
|
+
if (!existsSync(configPath())) {
|
|
235
|
+
throw new ConfigMissingError(`${configPath()} does not exist \u2014 run init.mjs to create it`);
|
|
236
|
+
}
|
|
237
|
+
const file = readJson(configPath());
|
|
238
|
+
if (!file) {
|
|
239
|
+
throw new ConfigError(`cannot read ${configPath()} \u2014 it exists but did not parse`);
|
|
240
|
+
}
|
|
241
|
+
return settingsFor(file, vendor);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// packages/core/dist/config/bundle.js
|
|
245
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
246
|
+
import { join as join4 } from "node:path";
|
|
247
|
+
function bundleCachePath(scope) {
|
|
248
|
+
return join4(CONFIG_DIR, `${scope}.bundle.json`);
|
|
249
|
+
}
|
|
250
|
+
var BundleError = class extends Error {
|
|
251
|
+
};
|
|
252
|
+
function loadBundle(scope) {
|
|
253
|
+
const path = bundleCachePath(scope);
|
|
254
|
+
let parsed;
|
|
255
|
+
try {
|
|
256
|
+
parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
257
|
+
} catch (err) {
|
|
258
|
+
throw new BundleError(`cannot load policy bundle ${path}: ${err.message}`);
|
|
259
|
+
}
|
|
260
|
+
if (!Array.isArray(parsed.rules))
|
|
261
|
+
throw new BundleError(`${path}: no rules array`);
|
|
262
|
+
return parsed;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// packages/core/dist/spool/spool.js
|
|
266
|
+
import { join as join5 } from "node:path";
|
|
267
|
+
var SPOOL_DIR = join5(CONFIG_DIR, "spool");
|
|
268
|
+
|
|
269
|
+
// packages/core/dist/runtime/beat.js
|
|
270
|
+
import { mkdirSync, readFileSync as readFileSync3, renameSync, writeFileSync } from "node:fs";
|
|
271
|
+
import { join as join6 } from "node:path";
|
|
272
|
+
var MAX_SESSIONS = 32;
|
|
273
|
+
var BEAT_LIVE_MS = 30 * 60 * 1e3;
|
|
274
|
+
function beatPath(scope) {
|
|
275
|
+
return join6(CONFIG_DIR, `${scope}.hook-beat.json`);
|
|
276
|
+
}
|
|
277
|
+
function loadBeat(scope) {
|
|
278
|
+
try {
|
|
279
|
+
const beat = JSON.parse(readFileSync3(beatPath(scope), "utf8"));
|
|
280
|
+
return { ...beat, sessions: beat.sessions ?? {} };
|
|
281
|
+
} catch {
|
|
282
|
+
return void 0;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function saveBeat(scope, beat) {
|
|
286
|
+
try {
|
|
287
|
+
mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
288
|
+
const target = beatPath(scope);
|
|
289
|
+
const tmp = `${target}.tmp`;
|
|
290
|
+
writeFileSync(tmp, JSON.stringify(beat), { mode: 384 });
|
|
291
|
+
renameSync(tmp, target);
|
|
292
|
+
} catch {
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function applyBeat(previous, hook) {
|
|
296
|
+
const at = new Date(hook.at).toISOString();
|
|
297
|
+
const sessions = { ...previous?.sessions };
|
|
298
|
+
sessions[hook.sessionId] = {
|
|
299
|
+
...hook.transcriptPath !== void 0 ? { transcriptPath: hook.transcriptPath } : {},
|
|
300
|
+
at
|
|
301
|
+
};
|
|
302
|
+
const ordered = Object.entries(sessions).sort((a, b) => b[1].at.localeCompare(a[1].at));
|
|
303
|
+
const kept = Object.fromEntries(ordered.slice(0, MAX_SESSIONS));
|
|
304
|
+
const lastSpawnAt = hook.spawned ? at : previous?.lastSpawnAt;
|
|
305
|
+
const lastSpoolAt = hook.lane === "spool" ? at : previous?.lastSpoolAt;
|
|
306
|
+
return {
|
|
307
|
+
at,
|
|
308
|
+
lane: hook.lane,
|
|
309
|
+
sessions: kept,
|
|
310
|
+
...lastSpawnAt !== void 0 ? { lastSpawnAt } : {},
|
|
311
|
+
...lastSpoolAt !== void 0 ? { lastSpoolAt } : {}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// packages/core/dist/runtime/spawn.js
|
|
316
|
+
import { spawn } from "node:child_process";
|
|
317
|
+
function spawnForwarder(scriptPath) {
|
|
318
|
+
try {
|
|
319
|
+
const child = spawn(process.execPath, [scriptPath], {
|
|
320
|
+
detached: true,
|
|
321
|
+
stdio: "ignore"
|
|
322
|
+
});
|
|
323
|
+
child.unref();
|
|
324
|
+
} catch {
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// packages/core/dist/runtime/guard.js
|
|
329
|
+
var GUARD_SPAWN_INTERVAL_MS = 6e4;
|
|
330
|
+
function runGuard(codec, rawPayload, forwarderScript) {
|
|
331
|
+
let failClosed = true;
|
|
332
|
+
try {
|
|
333
|
+
const config = loadRuntimeSettings(codec.vendor);
|
|
334
|
+
failClosed = config.enforce.failClosed;
|
|
335
|
+
let event;
|
|
336
|
+
let decodeError;
|
|
337
|
+
try {
|
|
338
|
+
event = codec.decodeToolCall(JSON.parse(rawPayload));
|
|
339
|
+
} catch (err) {
|
|
340
|
+
decodeError = err;
|
|
341
|
+
}
|
|
342
|
+
captureFromGuard(config, event, forwarderScript);
|
|
343
|
+
if (!config.enabled || config.enforce.mode === "off") {
|
|
344
|
+
return codec.encodeDecision({ decision: "allow", ruleId: null, enforcement: "blocking" });
|
|
345
|
+
}
|
|
346
|
+
if (decodeError !== void 0)
|
|
347
|
+
throw decodeError;
|
|
348
|
+
const bundle = loadBundle(config.scope);
|
|
349
|
+
return codec.encodeDecision(evaluate(event, bundle, config.enforce.mode));
|
|
350
|
+
} catch (err) {
|
|
351
|
+
if (err instanceof ConfigMissingError) {
|
|
352
|
+
return codec.encodeDecision({ decision: "allow", ruleId: null, enforcement: "advisory" });
|
|
353
|
+
}
|
|
354
|
+
const reason = `darkhunt guard failed: ${err.message}`;
|
|
355
|
+
if (failClosed)
|
|
356
|
+
return codec.encodeFailClosed(reason);
|
|
357
|
+
return codec.encodeDecision({ decision: "allow", ruleId: null, enforcement: "advisory" });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function captureFromGuard(config, event, forwarderScript) {
|
|
361
|
+
try {
|
|
362
|
+
if (!event || !config.enabled || !config.capture.enabled)
|
|
363
|
+
return;
|
|
364
|
+
const now = Date.now();
|
|
365
|
+
const previous = loadBeat(config.scope);
|
|
366
|
+
const last = previous?.lastSpawnAt !== void 0 ? Date.parse(previous.lastSpawnAt) : NaN;
|
|
367
|
+
const due = Number.isNaN(last) || now - last >= GUARD_SPAWN_INTERVAL_MS;
|
|
368
|
+
const spawned = due && forwarderScript !== void 0;
|
|
369
|
+
saveBeat(config.scope, applyBeat(previous, {
|
|
370
|
+
lane: "guard",
|
|
371
|
+
sessionId: event.sessionId,
|
|
372
|
+
...event.transcriptPath !== void 0 ? { transcriptPath: event.transcriptPath } : {},
|
|
373
|
+
at: now,
|
|
374
|
+
spawned
|
|
375
|
+
}));
|
|
376
|
+
if (spawned)
|
|
377
|
+
spawnForwarder(forwarderScript);
|
|
378
|
+
} catch {
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async function readStdin(stream) {
|
|
382
|
+
const chunks = [];
|
|
383
|
+
for await (const chunk of stream)
|
|
384
|
+
chunks.push(chunk);
|
|
385
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// packages/core/dist/forwarder/tail.js
|
|
389
|
+
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
390
|
+
var LINE_CEILING = 64 * 1024 * 1024;
|
|
391
|
+
|
|
392
|
+
// packages/core/dist/forwarder/lock.js
|
|
393
|
+
var STALE_MS = 5 * 60 * 1e3;
|
|
394
|
+
|
|
395
|
+
// node_modules/@darkhunt-security/telemetry/package.json
|
|
396
|
+
var package_default = {
|
|
397
|
+
name: "@darkhunt-security/telemetry",
|
|
398
|
+
version: "0.5.5-build.165",
|
|
399
|
+
description: "TypeScript SDK for sending LLM traces, generations, and observations to the Darkhunt platform for persistence and security data enrichment. Built on OpenTelemetry primitives, with built-in client-side data masking.",
|
|
400
|
+
type: "module",
|
|
401
|
+
license: "Apache-2.0",
|
|
402
|
+
author: "Darkhunt Limited",
|
|
403
|
+
homepage: "https://github.com/darkhunt-security/darkhunt-telemetry-ts#readme",
|
|
404
|
+
bugs: {
|
|
405
|
+
url: "https://github.com/darkhunt-security/darkhunt-telemetry-ts/issues"
|
|
406
|
+
},
|
|
407
|
+
keywords: [
|
|
408
|
+
"opentelemetry",
|
|
409
|
+
"otel",
|
|
410
|
+
"otlp",
|
|
411
|
+
"llm",
|
|
412
|
+
"observability",
|
|
413
|
+
"tracing",
|
|
414
|
+
"data-masking",
|
|
415
|
+
"pii"
|
|
416
|
+
],
|
|
417
|
+
engines: {
|
|
418
|
+
node: "^18.19.0 || >=20.6.0"
|
|
419
|
+
},
|
|
420
|
+
main: "dist/index.js",
|
|
421
|
+
types: "dist/index.d.ts",
|
|
422
|
+
exports: {
|
|
423
|
+
".": {
|
|
424
|
+
types: "./dist/index.d.ts",
|
|
425
|
+
import: "./dist/index.js",
|
|
426
|
+
default: "./dist/index.js"
|
|
427
|
+
},
|
|
428
|
+
"./transports": {
|
|
429
|
+
types: "./dist/transports/index.d.ts",
|
|
430
|
+
import: "./dist/transports/index.js",
|
|
431
|
+
default: "./dist/transports/index.js"
|
|
432
|
+
},
|
|
433
|
+
"./temporal": {
|
|
434
|
+
types: "./dist/temporal/index.d.ts",
|
|
435
|
+
import: "./dist/temporal/index.js",
|
|
436
|
+
default: "./dist/temporal/index.js"
|
|
437
|
+
},
|
|
438
|
+
"./temporal/workflow": {
|
|
439
|
+
types: "./dist/temporal/workflow-interceptors.d.ts",
|
|
440
|
+
import: "./dist/temporal/workflow-interceptors.js",
|
|
441
|
+
default: "./dist/temporal/workflow-interceptors.js"
|
|
442
|
+
},
|
|
443
|
+
"./package.json": "./package.json"
|
|
444
|
+
},
|
|
445
|
+
files: [
|
|
446
|
+
"dist/",
|
|
447
|
+
"LICENSE",
|
|
448
|
+
"NOTICE",
|
|
449
|
+
"README.md"
|
|
450
|
+
],
|
|
451
|
+
publishConfig: {
|
|
452
|
+
registry: "https://registry.npmjs.org",
|
|
453
|
+
access: "public"
|
|
454
|
+
},
|
|
455
|
+
repository: {
|
|
456
|
+
type: "git",
|
|
457
|
+
url: "git+https://github.com/darkhunt-security/darkhunt-telemetry-ts.git"
|
|
458
|
+
},
|
|
459
|
+
scripts: {
|
|
460
|
+
dev: "tsx watch src/index.ts",
|
|
461
|
+
prepare: "tsx scripts/generate-rules-json.ts && tsc",
|
|
462
|
+
prebuild: "tsx scripts/generate-rules-json.ts",
|
|
463
|
+
build: "tsc",
|
|
464
|
+
prepublishOnly: "npm run build",
|
|
465
|
+
pretypecheck: "tsx scripts/generate-rules-json.ts",
|
|
466
|
+
typecheck: "tsc --noEmit",
|
|
467
|
+
test: "tsx scripts/generate-rules-json.ts && node --import tsx --test 'test/**/*.test.ts'",
|
|
468
|
+
"test:coverage": "tsx scripts/generate-rules-json.ts && c8 --reporter=lcov --reporter=text --include 'src/**/*.ts' --exclude 'src/**/*.d.ts' --exclude 'src/masking/rules/**' node --import tsx --test 'test/**/*.test.ts'",
|
|
469
|
+
lint: "eslint",
|
|
470
|
+
format: "prettier --write .",
|
|
471
|
+
"format:check": "prettier --check ."
|
|
472
|
+
},
|
|
473
|
+
dependencies: {
|
|
474
|
+
"@noble/hashes": "^1.8.0",
|
|
475
|
+
"@opentelemetry/api": "^1.9.1",
|
|
476
|
+
"@opentelemetry/context-async-hooks": "^2.0.0",
|
|
477
|
+
"@opentelemetry/core": "^2.0.0",
|
|
478
|
+
"@opentelemetry/otlp-transformer": "^0.218.0",
|
|
479
|
+
"@opentelemetry/resources": "^2.0.0",
|
|
480
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
481
|
+
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
482
|
+
"@opentelemetry/semantic-conventions": "^1.30.0"
|
|
483
|
+
},
|
|
484
|
+
devDependencies: {
|
|
485
|
+
"@eslint/js": "^9.0.0",
|
|
486
|
+
"@temporalio/common": "^1.20.2",
|
|
487
|
+
"@temporalio/worker": "^1.20.2",
|
|
488
|
+
"@temporalio/workflow": "^1.20.2",
|
|
489
|
+
"@types/node": "^25.0.0",
|
|
490
|
+
c8: "^11.0.0",
|
|
491
|
+
eslint: "^9.0.0",
|
|
492
|
+
"eslint-config-prettier": "^10.0.0",
|
|
493
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
494
|
+
prettier: "^3.8.0",
|
|
495
|
+
tsx: "^4.19.0",
|
|
496
|
+
typescript: "^5.9.0",
|
|
497
|
+
"typescript-eslint": "^8.0.0",
|
|
498
|
+
yaml: "^2.8.4"
|
|
499
|
+
},
|
|
500
|
+
peerDependencies: {
|
|
501
|
+
"@temporalio/common": ">=1.11.0 <2",
|
|
502
|
+
"@temporalio/worker": ">=1.11.0 <2",
|
|
503
|
+
"@temporalio/workflow": ">=1.11.0 <2"
|
|
504
|
+
},
|
|
505
|
+
peerDependenciesMeta: {
|
|
506
|
+
"@temporalio/common": {
|
|
507
|
+
optional: true
|
|
508
|
+
},
|
|
509
|
+
"@temporalio/worker": {
|
|
510
|
+
optional: true
|
|
511
|
+
},
|
|
512
|
+
"@temporalio/workflow": {
|
|
513
|
+
optional: true
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/aba.js
|
|
519
|
+
var WEIGHTS = [3, 7, 1, 3, 7, 1, 3, 7, 1];
|
|
520
|
+
function aba(input) {
|
|
521
|
+
const digits = input.replace(/\s/g, "");
|
|
522
|
+
if (digits.length !== 9)
|
|
523
|
+
return false;
|
|
524
|
+
let sum = 0;
|
|
525
|
+
for (let i = 0; i < 9; i++) {
|
|
526
|
+
const n = digits.charCodeAt(i) - 48;
|
|
527
|
+
if (n < 0 || n > 9)
|
|
528
|
+
return false;
|
|
529
|
+
sum += n * WEIGHTS[i];
|
|
530
|
+
}
|
|
531
|
+
return sum % 10 === 0;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
535
|
+
function isBytes(a) {
|
|
536
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
537
|
+
}
|
|
538
|
+
function anumber(n) {
|
|
539
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
540
|
+
throw new Error("positive integer expected, got " + n);
|
|
541
|
+
}
|
|
542
|
+
function abytes(b, ...lengths) {
|
|
543
|
+
if (!isBytes(b))
|
|
544
|
+
throw new Error("Uint8Array expected");
|
|
545
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
546
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
547
|
+
}
|
|
548
|
+
function aexists(instance, checkFinished = true) {
|
|
549
|
+
if (instance.destroyed)
|
|
550
|
+
throw new Error("Hash instance has been destroyed");
|
|
551
|
+
if (checkFinished && instance.finished)
|
|
552
|
+
throw new Error("Hash#digest() has already been called");
|
|
553
|
+
}
|
|
554
|
+
function aoutput(out, instance) {
|
|
555
|
+
abytes(out);
|
|
556
|
+
const min = instance.outputLen;
|
|
557
|
+
if (out.length < min) {
|
|
558
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function u32(arr) {
|
|
562
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
563
|
+
}
|
|
564
|
+
function clean(...arrays) {
|
|
565
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
566
|
+
arrays[i].fill(0);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function createView(arr) {
|
|
570
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
571
|
+
}
|
|
572
|
+
function rotr(word, shift) {
|
|
573
|
+
return word << 32 - shift | word >>> shift;
|
|
574
|
+
}
|
|
575
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
576
|
+
function byteSwap(word) {
|
|
577
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
578
|
+
}
|
|
579
|
+
function byteSwap32(arr) {
|
|
580
|
+
for (let i = 0; i < arr.length; i++) {
|
|
581
|
+
arr[i] = byteSwap(arr[i]);
|
|
582
|
+
}
|
|
583
|
+
return arr;
|
|
584
|
+
}
|
|
585
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
586
|
+
function utf8ToBytes(str) {
|
|
587
|
+
if (typeof str !== "string")
|
|
588
|
+
throw new Error("string expected");
|
|
589
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
590
|
+
}
|
|
591
|
+
function toBytes(data) {
|
|
592
|
+
if (typeof data === "string")
|
|
593
|
+
data = utf8ToBytes(data);
|
|
594
|
+
abytes(data);
|
|
595
|
+
return data;
|
|
596
|
+
}
|
|
597
|
+
var Hash = class {
|
|
598
|
+
};
|
|
599
|
+
function createHasher(hashCons) {
|
|
600
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
601
|
+
const tmp = hashCons();
|
|
602
|
+
hashC.outputLen = tmp.outputLen;
|
|
603
|
+
hashC.blockLen = tmp.blockLen;
|
|
604
|
+
hashC.create = () => hashCons();
|
|
605
|
+
return hashC;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
609
|
+
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
610
|
+
if (typeof view.setBigUint64 === "function")
|
|
611
|
+
return view.setBigUint64(byteOffset, value, isLE2);
|
|
612
|
+
const _32n2 = BigInt(32);
|
|
613
|
+
const _u32_max = BigInt(4294967295);
|
|
614
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
615
|
+
const wl = Number(value & _u32_max);
|
|
616
|
+
const h = isLE2 ? 4 : 0;
|
|
617
|
+
const l = isLE2 ? 0 : 4;
|
|
618
|
+
view.setUint32(byteOffset + h, wh, isLE2);
|
|
619
|
+
view.setUint32(byteOffset + l, wl, isLE2);
|
|
620
|
+
}
|
|
621
|
+
function Chi(a, b, c) {
|
|
622
|
+
return a & b ^ ~a & c;
|
|
623
|
+
}
|
|
624
|
+
function Maj(a, b, c) {
|
|
625
|
+
return a & b ^ a & c ^ b & c;
|
|
626
|
+
}
|
|
627
|
+
var HashMD = class extends Hash {
|
|
628
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
629
|
+
super();
|
|
630
|
+
this.finished = false;
|
|
631
|
+
this.length = 0;
|
|
632
|
+
this.pos = 0;
|
|
633
|
+
this.destroyed = false;
|
|
634
|
+
this.blockLen = blockLen;
|
|
635
|
+
this.outputLen = outputLen;
|
|
636
|
+
this.padOffset = padOffset;
|
|
637
|
+
this.isLE = isLE2;
|
|
638
|
+
this.buffer = new Uint8Array(blockLen);
|
|
639
|
+
this.view = createView(this.buffer);
|
|
640
|
+
}
|
|
641
|
+
update(data) {
|
|
642
|
+
aexists(this);
|
|
643
|
+
data = toBytes(data);
|
|
644
|
+
abytes(data);
|
|
645
|
+
const { view, buffer, blockLen } = this;
|
|
646
|
+
const len = data.length;
|
|
647
|
+
for (let pos = 0; pos < len; ) {
|
|
648
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
649
|
+
if (take === blockLen) {
|
|
650
|
+
const dataView = createView(data);
|
|
651
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
652
|
+
this.process(dataView, pos);
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
656
|
+
this.pos += take;
|
|
657
|
+
pos += take;
|
|
658
|
+
if (this.pos === blockLen) {
|
|
659
|
+
this.process(view, 0);
|
|
660
|
+
this.pos = 0;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
this.length += data.length;
|
|
664
|
+
this.roundClean();
|
|
665
|
+
return this;
|
|
666
|
+
}
|
|
667
|
+
digestInto(out) {
|
|
668
|
+
aexists(this);
|
|
669
|
+
aoutput(out, this);
|
|
670
|
+
this.finished = true;
|
|
671
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
672
|
+
let { pos } = this;
|
|
673
|
+
buffer[pos++] = 128;
|
|
674
|
+
clean(this.buffer.subarray(pos));
|
|
675
|
+
if (this.padOffset > blockLen - pos) {
|
|
676
|
+
this.process(view, 0);
|
|
677
|
+
pos = 0;
|
|
678
|
+
}
|
|
679
|
+
for (let i = pos; i < blockLen; i++)
|
|
680
|
+
buffer[i] = 0;
|
|
681
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
682
|
+
this.process(view, 0);
|
|
683
|
+
const oview = createView(out);
|
|
684
|
+
const len = this.outputLen;
|
|
685
|
+
if (len % 4)
|
|
686
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
687
|
+
const outLen = len / 4;
|
|
688
|
+
const state = this.get();
|
|
689
|
+
if (outLen > state.length)
|
|
690
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
691
|
+
for (let i = 0; i < outLen; i++)
|
|
692
|
+
oview.setUint32(4 * i, state[i], isLE2);
|
|
693
|
+
}
|
|
694
|
+
digest() {
|
|
695
|
+
const { buffer, outputLen } = this;
|
|
696
|
+
this.digestInto(buffer);
|
|
697
|
+
const res = buffer.slice(0, outputLen);
|
|
698
|
+
this.destroy();
|
|
699
|
+
return res;
|
|
700
|
+
}
|
|
701
|
+
_cloneInto(to) {
|
|
702
|
+
to || (to = new this.constructor());
|
|
703
|
+
to.set(...this.get());
|
|
704
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
705
|
+
to.destroyed = destroyed;
|
|
706
|
+
to.finished = finished;
|
|
707
|
+
to.length = length;
|
|
708
|
+
to.pos = pos;
|
|
709
|
+
if (length % blockLen)
|
|
710
|
+
to.buffer.set(buffer);
|
|
711
|
+
return to;
|
|
712
|
+
}
|
|
713
|
+
clone() {
|
|
714
|
+
return this._cloneInto();
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
718
|
+
1779033703,
|
|
719
|
+
3144134277,
|
|
720
|
+
1013904242,
|
|
721
|
+
2773480762,
|
|
722
|
+
1359893119,
|
|
723
|
+
2600822924,
|
|
724
|
+
528734635,
|
|
725
|
+
1541459225
|
|
726
|
+
]);
|
|
727
|
+
|
|
728
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
729
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
730
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
731
|
+
function fromBig(n, le = false) {
|
|
732
|
+
if (le)
|
|
733
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
734
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
735
|
+
}
|
|
736
|
+
function split(lst, le = false) {
|
|
737
|
+
const len = lst.length;
|
|
738
|
+
let Ah = new Uint32Array(len);
|
|
739
|
+
let Al = new Uint32Array(len);
|
|
740
|
+
for (let i = 0; i < len; i++) {
|
|
741
|
+
const { h, l } = fromBig(lst[i], le);
|
|
742
|
+
[Ah[i], Al[i]] = [h, l];
|
|
743
|
+
}
|
|
744
|
+
return [Ah, Al];
|
|
745
|
+
}
|
|
746
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
747
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
748
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
749
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
750
|
+
|
|
751
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
752
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
753
|
+
1116352408,
|
|
754
|
+
1899447441,
|
|
755
|
+
3049323471,
|
|
756
|
+
3921009573,
|
|
757
|
+
961987163,
|
|
758
|
+
1508970993,
|
|
759
|
+
2453635748,
|
|
760
|
+
2870763221,
|
|
761
|
+
3624381080,
|
|
762
|
+
310598401,
|
|
763
|
+
607225278,
|
|
764
|
+
1426881987,
|
|
765
|
+
1925078388,
|
|
766
|
+
2162078206,
|
|
767
|
+
2614888103,
|
|
768
|
+
3248222580,
|
|
769
|
+
3835390401,
|
|
770
|
+
4022224774,
|
|
771
|
+
264347078,
|
|
772
|
+
604807628,
|
|
773
|
+
770255983,
|
|
774
|
+
1249150122,
|
|
775
|
+
1555081692,
|
|
776
|
+
1996064986,
|
|
777
|
+
2554220882,
|
|
778
|
+
2821834349,
|
|
779
|
+
2952996808,
|
|
780
|
+
3210313671,
|
|
781
|
+
3336571891,
|
|
782
|
+
3584528711,
|
|
783
|
+
113926993,
|
|
784
|
+
338241895,
|
|
785
|
+
666307205,
|
|
786
|
+
773529912,
|
|
787
|
+
1294757372,
|
|
788
|
+
1396182291,
|
|
789
|
+
1695183700,
|
|
790
|
+
1986661051,
|
|
791
|
+
2177026350,
|
|
792
|
+
2456956037,
|
|
793
|
+
2730485921,
|
|
794
|
+
2820302411,
|
|
795
|
+
3259730800,
|
|
796
|
+
3345764771,
|
|
797
|
+
3516065817,
|
|
798
|
+
3600352804,
|
|
799
|
+
4094571909,
|
|
800
|
+
275423344,
|
|
801
|
+
430227734,
|
|
802
|
+
506948616,
|
|
803
|
+
659060556,
|
|
804
|
+
883997877,
|
|
805
|
+
958139571,
|
|
806
|
+
1322822218,
|
|
807
|
+
1537002063,
|
|
808
|
+
1747873779,
|
|
809
|
+
1955562222,
|
|
810
|
+
2024104815,
|
|
811
|
+
2227730452,
|
|
812
|
+
2361852424,
|
|
813
|
+
2428436474,
|
|
814
|
+
2756734187,
|
|
815
|
+
3204031479,
|
|
816
|
+
3329325298
|
|
817
|
+
]);
|
|
818
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
819
|
+
var SHA256 = class extends HashMD {
|
|
820
|
+
constructor(outputLen = 32) {
|
|
821
|
+
super(64, outputLen, 8, false);
|
|
822
|
+
this.A = SHA256_IV[0] | 0;
|
|
823
|
+
this.B = SHA256_IV[1] | 0;
|
|
824
|
+
this.C = SHA256_IV[2] | 0;
|
|
825
|
+
this.D = SHA256_IV[3] | 0;
|
|
826
|
+
this.E = SHA256_IV[4] | 0;
|
|
827
|
+
this.F = SHA256_IV[5] | 0;
|
|
828
|
+
this.G = SHA256_IV[6] | 0;
|
|
829
|
+
this.H = SHA256_IV[7] | 0;
|
|
830
|
+
}
|
|
831
|
+
get() {
|
|
832
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
833
|
+
return [A, B, C, D, E, F, G, H];
|
|
834
|
+
}
|
|
835
|
+
// prettier-ignore
|
|
836
|
+
set(A, B, C, D, E, F, G, H) {
|
|
837
|
+
this.A = A | 0;
|
|
838
|
+
this.B = B | 0;
|
|
839
|
+
this.C = C | 0;
|
|
840
|
+
this.D = D | 0;
|
|
841
|
+
this.E = E | 0;
|
|
842
|
+
this.F = F | 0;
|
|
843
|
+
this.G = G | 0;
|
|
844
|
+
this.H = H | 0;
|
|
845
|
+
}
|
|
846
|
+
process(view, offset) {
|
|
847
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
848
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
849
|
+
for (let i = 16; i < 64; i++) {
|
|
850
|
+
const W15 = SHA256_W[i - 15];
|
|
851
|
+
const W2 = SHA256_W[i - 2];
|
|
852
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
853
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
854
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
855
|
+
}
|
|
856
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
857
|
+
for (let i = 0; i < 64; i++) {
|
|
858
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
859
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
860
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
861
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
862
|
+
H = G;
|
|
863
|
+
G = F;
|
|
864
|
+
F = E;
|
|
865
|
+
E = D + T1 | 0;
|
|
866
|
+
D = C;
|
|
867
|
+
C = B;
|
|
868
|
+
B = A;
|
|
869
|
+
A = T1 + T2 | 0;
|
|
870
|
+
}
|
|
871
|
+
A = A + this.A | 0;
|
|
872
|
+
B = B + this.B | 0;
|
|
873
|
+
C = C + this.C | 0;
|
|
874
|
+
D = D + this.D | 0;
|
|
875
|
+
E = E + this.E | 0;
|
|
876
|
+
F = F + this.F | 0;
|
|
877
|
+
G = G + this.G | 0;
|
|
878
|
+
H = H + this.H | 0;
|
|
879
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
880
|
+
}
|
|
881
|
+
roundClean() {
|
|
882
|
+
clean(SHA256_W);
|
|
883
|
+
}
|
|
884
|
+
destroy() {
|
|
885
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
886
|
+
clean(this.buffer);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
890
|
+
|
|
891
|
+
// node_modules/@noble/hashes/esm/sha256.js
|
|
892
|
+
var sha2562 = sha256;
|
|
893
|
+
|
|
894
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/base58check.js
|
|
895
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
896
|
+
var BASE = 58n;
|
|
897
|
+
function base58check(input) {
|
|
898
|
+
if (input.length === 0)
|
|
899
|
+
return false;
|
|
900
|
+
let leadingOnes = 0;
|
|
901
|
+
while (leadingOnes < input.length && input.charAt(leadingOnes) === "1") {
|
|
902
|
+
leadingOnes++;
|
|
903
|
+
}
|
|
904
|
+
let num = 0n;
|
|
905
|
+
for (let i = 0; i < input.length; i++) {
|
|
906
|
+
const idx = ALPHABET.indexOf(input.charAt(i));
|
|
907
|
+
if (idx === -1)
|
|
908
|
+
return false;
|
|
909
|
+
num = num * BASE + BigInt(idx);
|
|
910
|
+
}
|
|
911
|
+
const bodyBytes = [];
|
|
912
|
+
while (num > 0n) {
|
|
913
|
+
bodyBytes.unshift(Number(num & 0xffn));
|
|
914
|
+
num >>= 8n;
|
|
915
|
+
}
|
|
916
|
+
const bytes = new Uint8Array(leadingOnes + bodyBytes.length);
|
|
917
|
+
for (let i = 0; i < bodyBytes.length; i++)
|
|
918
|
+
bytes[leadingOnes + i] = bodyBytes[i];
|
|
919
|
+
if (bytes.length < 5)
|
|
920
|
+
return false;
|
|
921
|
+
const payload = bytes.subarray(0, bytes.length - 4);
|
|
922
|
+
const checksum = bytes.subarray(bytes.length - 4);
|
|
923
|
+
const hash = sha2562(sha2562(payload));
|
|
924
|
+
for (let i = 0; i < 4; i++) {
|
|
925
|
+
if (hash[i] !== checksum[i])
|
|
926
|
+
return false;
|
|
927
|
+
}
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/bech32.js
|
|
932
|
+
var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
933
|
+
var GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
934
|
+
var BECH32_CONST = 1;
|
|
935
|
+
var BECH32M_CONST = 734539939;
|
|
936
|
+
function polymod(values) {
|
|
937
|
+
let chk = 1;
|
|
938
|
+
for (const v of values) {
|
|
939
|
+
const top = chk >>> 25;
|
|
940
|
+
chk = (chk & 33554431) << 5 ^ v;
|
|
941
|
+
for (let i = 0; i < 5; i++) {
|
|
942
|
+
if (top >> i & 1)
|
|
943
|
+
chk ^= GENERATOR[i];
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return chk;
|
|
947
|
+
}
|
|
948
|
+
function hrpExpand(hrp) {
|
|
949
|
+
const out = [];
|
|
950
|
+
for (let i = 0; i < hrp.length; i++)
|
|
951
|
+
out.push(hrp.charCodeAt(i) >> 5);
|
|
952
|
+
out.push(0);
|
|
953
|
+
for (let i = 0; i < hrp.length; i++)
|
|
954
|
+
out.push(hrp.charCodeAt(i) & 31);
|
|
955
|
+
return out;
|
|
956
|
+
}
|
|
957
|
+
function bech32(input) {
|
|
958
|
+
if (input.length > 90)
|
|
959
|
+
return false;
|
|
960
|
+
const lower = input.toLowerCase();
|
|
961
|
+
const upper = input.toUpperCase();
|
|
962
|
+
if (input !== lower && input !== upper)
|
|
963
|
+
return false;
|
|
964
|
+
const sepIdx = lower.lastIndexOf("1");
|
|
965
|
+
if (sepIdx < 1 || sepIdx + 7 > lower.length)
|
|
966
|
+
return false;
|
|
967
|
+
const hrp = lower.slice(0, sepIdx);
|
|
968
|
+
for (let i = 0; i < hrp.length; i++) {
|
|
969
|
+
const c = hrp.charCodeAt(i);
|
|
970
|
+
if (c < 33 || c > 126)
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
const data = [];
|
|
974
|
+
for (let i = sepIdx + 1; i < lower.length; i++) {
|
|
975
|
+
const idx = CHARSET.indexOf(lower.charAt(i));
|
|
976
|
+
if (idx === -1)
|
|
977
|
+
return false;
|
|
978
|
+
data.push(idx);
|
|
979
|
+
}
|
|
980
|
+
const checksum = polymod(hrpExpand(hrp).concat(data));
|
|
981
|
+
return checksum === BECH32_CONST || checksum === BECH32M_CONST;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/luhn.js
|
|
985
|
+
function luhn(input) {
|
|
986
|
+
let sum = 0;
|
|
987
|
+
let alternate = false;
|
|
988
|
+
let len = 0;
|
|
989
|
+
for (let i = input.length - 1; i >= 0; i--) {
|
|
990
|
+
const ch = input.charCodeAt(i);
|
|
991
|
+
if (ch === 32 || ch === 45)
|
|
992
|
+
continue;
|
|
993
|
+
const digit = ch - 48;
|
|
994
|
+
if (digit < 0 || digit > 9)
|
|
995
|
+
return false;
|
|
996
|
+
let n = digit;
|
|
997
|
+
if (alternate) {
|
|
998
|
+
n *= 2;
|
|
999
|
+
if (n > 9)
|
|
1000
|
+
n -= 9;
|
|
1001
|
+
}
|
|
1002
|
+
sum += n;
|
|
1003
|
+
alternate = !alternate;
|
|
1004
|
+
len++;
|
|
1005
|
+
}
|
|
1006
|
+
return len > 0 && sum % 10 === 0;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/creditCard.js
|
|
1010
|
+
function creditCard(input) {
|
|
1011
|
+
const digits = input.replace(/[\s-]/g, "");
|
|
1012
|
+
return digits.length >= 13 && digits.length <= 16 && hasValidIin(digits) && luhn(digits);
|
|
1013
|
+
}
|
|
1014
|
+
function hasValidIin(digits) {
|
|
1015
|
+
const len = digits.length;
|
|
1016
|
+
if (len < 13)
|
|
1017
|
+
return false;
|
|
1018
|
+
return isVisa(digits, len) || isMastercard(digits, len) || isAmex(digits, len) || isDiners(digits, len) || isJcb(digits, len) || isDiscover(digits, len);
|
|
1019
|
+
}
|
|
1020
|
+
function isVisa(d, len) {
|
|
1021
|
+
return d.startsWith("4") && (len === 13 || len === 16);
|
|
1022
|
+
}
|
|
1023
|
+
function isMastercard(d, len) {
|
|
1024
|
+
if (len !== 16)
|
|
1025
|
+
return false;
|
|
1026
|
+
if (d.startsWith("5")) {
|
|
1027
|
+
const d1 = d.charAt(1);
|
|
1028
|
+
return d1 >= "1" && d1 <= "5";
|
|
1029
|
+
}
|
|
1030
|
+
if (d.startsWith("2")) {
|
|
1031
|
+
const prefix = Number.parseInt(d.slice(0, 4), 10);
|
|
1032
|
+
return prefix >= 2221 && prefix <= 2720;
|
|
1033
|
+
}
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
function isAmex(d, len) {
|
|
1037
|
+
return len === 15 && (d.startsWith("34") || d.startsWith("37"));
|
|
1038
|
+
}
|
|
1039
|
+
function isDiners(d, len) {
|
|
1040
|
+
if (len !== 14)
|
|
1041
|
+
return false;
|
|
1042
|
+
if (d.startsWith("30")) {
|
|
1043
|
+
const d2 = d.charAt(2);
|
|
1044
|
+
return d2 >= "0" && d2 <= "5";
|
|
1045
|
+
}
|
|
1046
|
+
return d.startsWith("36") || d.startsWith("38");
|
|
1047
|
+
}
|
|
1048
|
+
function isJcb(d, len) {
|
|
1049
|
+
return len === 16 && d.startsWith("35");
|
|
1050
|
+
}
|
|
1051
|
+
function isDiscover(d, len) {
|
|
1052
|
+
if (len !== 16)
|
|
1053
|
+
return false;
|
|
1054
|
+
if (d.startsWith("6011"))
|
|
1055
|
+
return true;
|
|
1056
|
+
if (d.startsWith("65"))
|
|
1057
|
+
return true;
|
|
1058
|
+
if (d.startsWith("64")) {
|
|
1059
|
+
const d2 = d.charAt(2);
|
|
1060
|
+
return d2 >= "4" && d2 <= "9";
|
|
1061
|
+
}
|
|
1062
|
+
if (d.startsWith("62")) {
|
|
1063
|
+
const prefix = Number.parseInt(d.slice(0, 6), 10);
|
|
1064
|
+
return prefix >= 622126 && prefix <= 622925;
|
|
1065
|
+
}
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// node_modules/@noble/hashes/esm/sha3.js
|
|
1070
|
+
var _0n = BigInt(0);
|
|
1071
|
+
var _1n = BigInt(1);
|
|
1072
|
+
var _2n = BigInt(2);
|
|
1073
|
+
var _7n = BigInt(7);
|
|
1074
|
+
var _256n = BigInt(256);
|
|
1075
|
+
var _0x71n = BigInt(113);
|
|
1076
|
+
var SHA3_PI = [];
|
|
1077
|
+
var SHA3_ROTL = [];
|
|
1078
|
+
var _SHA3_IOTA = [];
|
|
1079
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
1080
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
1081
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
1082
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
1083
|
+
let t = _0n;
|
|
1084
|
+
for (let j = 0; j < 7; j++) {
|
|
1085
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
1086
|
+
if (R & _2n)
|
|
1087
|
+
t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
1088
|
+
}
|
|
1089
|
+
_SHA3_IOTA.push(t);
|
|
1090
|
+
}
|
|
1091
|
+
var IOTAS = split(_SHA3_IOTA, true);
|
|
1092
|
+
var SHA3_IOTA_H = IOTAS[0];
|
|
1093
|
+
var SHA3_IOTA_L = IOTAS[1];
|
|
1094
|
+
var rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
1095
|
+
var rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
1096
|
+
function keccakP(s, rounds = 24) {
|
|
1097
|
+
const B = new Uint32Array(5 * 2);
|
|
1098
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
1099
|
+
for (let x = 0; x < 10; x++)
|
|
1100
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
1101
|
+
for (let x = 0; x < 10; x += 2) {
|
|
1102
|
+
const idx1 = (x + 8) % 10;
|
|
1103
|
+
const idx0 = (x + 2) % 10;
|
|
1104
|
+
const B0 = B[idx0];
|
|
1105
|
+
const B1 = B[idx0 + 1];
|
|
1106
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
1107
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
1108
|
+
for (let y = 0; y < 50; y += 10) {
|
|
1109
|
+
s[x + y] ^= Th;
|
|
1110
|
+
s[x + y + 1] ^= Tl;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
let curH = s[2];
|
|
1114
|
+
let curL = s[3];
|
|
1115
|
+
for (let t = 0; t < 24; t++) {
|
|
1116
|
+
const shift = SHA3_ROTL[t];
|
|
1117
|
+
const Th = rotlH(curH, curL, shift);
|
|
1118
|
+
const Tl = rotlL(curH, curL, shift);
|
|
1119
|
+
const PI = SHA3_PI[t];
|
|
1120
|
+
curH = s[PI];
|
|
1121
|
+
curL = s[PI + 1];
|
|
1122
|
+
s[PI] = Th;
|
|
1123
|
+
s[PI + 1] = Tl;
|
|
1124
|
+
}
|
|
1125
|
+
for (let y = 0; y < 50; y += 10) {
|
|
1126
|
+
for (let x = 0; x < 10; x++)
|
|
1127
|
+
B[x] = s[y + x];
|
|
1128
|
+
for (let x = 0; x < 10; x++)
|
|
1129
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
1130
|
+
}
|
|
1131
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
1132
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
1133
|
+
}
|
|
1134
|
+
clean(B);
|
|
1135
|
+
}
|
|
1136
|
+
var Keccak = class _Keccak extends Hash {
|
|
1137
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1138
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
1139
|
+
super();
|
|
1140
|
+
this.pos = 0;
|
|
1141
|
+
this.posOut = 0;
|
|
1142
|
+
this.finished = false;
|
|
1143
|
+
this.destroyed = false;
|
|
1144
|
+
this.enableXOF = false;
|
|
1145
|
+
this.blockLen = blockLen;
|
|
1146
|
+
this.suffix = suffix;
|
|
1147
|
+
this.outputLen = outputLen;
|
|
1148
|
+
this.enableXOF = enableXOF;
|
|
1149
|
+
this.rounds = rounds;
|
|
1150
|
+
anumber(outputLen);
|
|
1151
|
+
if (!(0 < blockLen && blockLen < 200))
|
|
1152
|
+
throw new Error("only keccak-f1600 function is supported");
|
|
1153
|
+
this.state = new Uint8Array(200);
|
|
1154
|
+
this.state32 = u32(this.state);
|
|
1155
|
+
}
|
|
1156
|
+
clone() {
|
|
1157
|
+
return this._cloneInto();
|
|
1158
|
+
}
|
|
1159
|
+
keccak() {
|
|
1160
|
+
swap32IfBE(this.state32);
|
|
1161
|
+
keccakP(this.state32, this.rounds);
|
|
1162
|
+
swap32IfBE(this.state32);
|
|
1163
|
+
this.posOut = 0;
|
|
1164
|
+
this.pos = 0;
|
|
1165
|
+
}
|
|
1166
|
+
update(data) {
|
|
1167
|
+
aexists(this);
|
|
1168
|
+
data = toBytes(data);
|
|
1169
|
+
abytes(data);
|
|
1170
|
+
const { blockLen, state } = this;
|
|
1171
|
+
const len = data.length;
|
|
1172
|
+
for (let pos = 0; pos < len; ) {
|
|
1173
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1174
|
+
for (let i = 0; i < take; i++)
|
|
1175
|
+
state[this.pos++] ^= data[pos++];
|
|
1176
|
+
if (this.pos === blockLen)
|
|
1177
|
+
this.keccak();
|
|
1178
|
+
}
|
|
1179
|
+
return this;
|
|
1180
|
+
}
|
|
1181
|
+
finish() {
|
|
1182
|
+
if (this.finished)
|
|
1183
|
+
return;
|
|
1184
|
+
this.finished = true;
|
|
1185
|
+
const { state, suffix, pos, blockLen } = this;
|
|
1186
|
+
state[pos] ^= suffix;
|
|
1187
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
1188
|
+
this.keccak();
|
|
1189
|
+
state[blockLen - 1] ^= 128;
|
|
1190
|
+
this.keccak();
|
|
1191
|
+
}
|
|
1192
|
+
writeInto(out) {
|
|
1193
|
+
aexists(this, false);
|
|
1194
|
+
abytes(out);
|
|
1195
|
+
this.finish();
|
|
1196
|
+
const bufferOut = this.state;
|
|
1197
|
+
const { blockLen } = this;
|
|
1198
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
1199
|
+
if (this.posOut >= blockLen)
|
|
1200
|
+
this.keccak();
|
|
1201
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
1202
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
1203
|
+
this.posOut += take;
|
|
1204
|
+
pos += take;
|
|
1205
|
+
}
|
|
1206
|
+
return out;
|
|
1207
|
+
}
|
|
1208
|
+
xofInto(out) {
|
|
1209
|
+
if (!this.enableXOF)
|
|
1210
|
+
throw new Error("XOF is not possible for this instance");
|
|
1211
|
+
return this.writeInto(out);
|
|
1212
|
+
}
|
|
1213
|
+
xof(bytes) {
|
|
1214
|
+
anumber(bytes);
|
|
1215
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
1216
|
+
}
|
|
1217
|
+
digestInto(out) {
|
|
1218
|
+
aoutput(out, this);
|
|
1219
|
+
if (this.finished)
|
|
1220
|
+
throw new Error("digest() was already called");
|
|
1221
|
+
this.writeInto(out);
|
|
1222
|
+
this.destroy();
|
|
1223
|
+
return out;
|
|
1224
|
+
}
|
|
1225
|
+
digest() {
|
|
1226
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
1227
|
+
}
|
|
1228
|
+
destroy() {
|
|
1229
|
+
this.destroyed = true;
|
|
1230
|
+
clean(this.state);
|
|
1231
|
+
}
|
|
1232
|
+
_cloneInto(to) {
|
|
1233
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
1234
|
+
to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
1235
|
+
to.state32.set(this.state32);
|
|
1236
|
+
to.pos = this.pos;
|
|
1237
|
+
to.posOut = this.posOut;
|
|
1238
|
+
to.finished = this.finished;
|
|
1239
|
+
to.rounds = rounds;
|
|
1240
|
+
to.suffix = suffix;
|
|
1241
|
+
to.outputLen = outputLen;
|
|
1242
|
+
to.enableXOF = enableXOF;
|
|
1243
|
+
to.destroyed = this.destroyed;
|
|
1244
|
+
return to;
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
var gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
1248
|
+
var keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
|
|
1249
|
+
|
|
1250
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/eip55.js
|
|
1251
|
+
var ADDR_RE = /^0[xX][0-9a-fA-F]{40}$/;
|
|
1252
|
+
function eip55(input) {
|
|
1253
|
+
if (!ADDR_RE.test(input))
|
|
1254
|
+
return false;
|
|
1255
|
+
const addr = input.slice(2);
|
|
1256
|
+
const lower = addr.toLowerCase();
|
|
1257
|
+
if (addr === lower || addr === addr.toUpperCase())
|
|
1258
|
+
return true;
|
|
1259
|
+
return matchesChecksum(addr, lower);
|
|
1260
|
+
}
|
|
1261
|
+
function matchesChecksum(addr, lower) {
|
|
1262
|
+
const hashBytes = keccak_256(lower);
|
|
1263
|
+
for (let i = 0; i < 40; i++) {
|
|
1264
|
+
if (!charCaseMatchesNibble(addr.charCodeAt(i), nibbleAt(hashBytes, i))) {
|
|
1265
|
+
return false;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return true;
|
|
1269
|
+
}
|
|
1270
|
+
function nibbleAt(bytes, i) {
|
|
1271
|
+
return bytes[i >> 1] >> (i % 2 === 0 ? 4 : 0) & 15;
|
|
1272
|
+
}
|
|
1273
|
+
function charCaseMatchesNibble(ch, nibble) {
|
|
1274
|
+
if (ch >= 97 && ch <= 102)
|
|
1275
|
+
return nibble < 8;
|
|
1276
|
+
if (ch >= 65 && ch <= 70)
|
|
1277
|
+
return nibble >= 8;
|
|
1278
|
+
return true;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/ibanMod97.js
|
|
1282
|
+
function ibanMod97(input) {
|
|
1283
|
+
const iban = input.replace(/\s/g, "");
|
|
1284
|
+
const len = iban.length;
|
|
1285
|
+
if (len < 15 || len > 34)
|
|
1286
|
+
return false;
|
|
1287
|
+
let rearranged = "";
|
|
1288
|
+
for (let i = 4; i < len + 4; i++) {
|
|
1289
|
+
const c = iban.charCodeAt(i % len);
|
|
1290
|
+
if (c >= 48 && c <= 57) {
|
|
1291
|
+
rearranged += String.fromCharCode(c);
|
|
1292
|
+
} else if (c >= 65 && c <= 90) {
|
|
1293
|
+
rearranged += String(c - 65 + 10);
|
|
1294
|
+
} else if (c >= 97 && c <= 122) {
|
|
1295
|
+
rearranged += String(c - 97 + 10);
|
|
1296
|
+
} else {
|
|
1297
|
+
return false;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
try {
|
|
1301
|
+
return BigInt(rearranged) % 97n === 1n;
|
|
1302
|
+
} catch {
|
|
1303
|
+
return false;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/index.js
|
|
1308
|
+
var VALIDATORS = Object.freeze({
|
|
1309
|
+
aba,
|
|
1310
|
+
base58check,
|
|
1311
|
+
bech32,
|
|
1312
|
+
credit_card: creditCard,
|
|
1313
|
+
eip55,
|
|
1314
|
+
iban_mod97: ibanMod97,
|
|
1315
|
+
luhn
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
// node_modules/@darkhunt-security/telemetry/dist/client.js
|
|
1319
|
+
var LIB_VERSION = package_default.version;
|
|
1320
|
+
|
|
1321
|
+
// packages/core/dist/cli/status.js
|
|
1322
|
+
var SESSION_HOOK_STALE_MS = 30 * 60 * 1e3;
|
|
1323
|
+
|
|
1324
|
+
// packages/core/dist/cli/enroll.js
|
|
1325
|
+
import { homedir as homedir2 } from "node:os";
|
|
1326
|
+
import { join as join7 } from "node:path";
|
|
1327
|
+
var CLI_CREDENTIALS_PATH = join7(homedir2(), ".darkhunt", "credentials.json");
|
|
1328
|
+
|
|
1329
|
+
// adapters/codex/dist/codec.js
|
|
1330
|
+
var PHASE_BY_EVENT = {
|
|
1331
|
+
SessionStart: "start",
|
|
1332
|
+
Stop: "stop",
|
|
1333
|
+
SessionEnd: "end"
|
|
1334
|
+
};
|
|
1335
|
+
var codexCodec = {
|
|
1336
|
+
vendor: "codex",
|
|
1337
|
+
decodeToolCall(raw) {
|
|
1338
|
+
const payload = raw;
|
|
1339
|
+
if (typeof payload.session_id !== "string") {
|
|
1340
|
+
throw new Error("codex payload: missing session_id");
|
|
1341
|
+
}
|
|
1342
|
+
if (typeof payload.tool_name !== "string") {
|
|
1343
|
+
throw new Error("codex payload: missing tool_name");
|
|
1344
|
+
}
|
|
1345
|
+
return {
|
|
1346
|
+
vendor: "codex",
|
|
1347
|
+
sessionId: payload.session_id,
|
|
1348
|
+
toolName: payload.tool_name,
|
|
1349
|
+
toolInput: payload.tool_input ?? {},
|
|
1350
|
+
rawEventName: payload.hook_event_name ?? "PreToolUse",
|
|
1351
|
+
...payload.transcript_path !== void 0 ? { transcriptPath: payload.transcript_path } : {},
|
|
1352
|
+
...payload.cwd !== void 0 ? { cwd: payload.cwd } : {}
|
|
1353
|
+
};
|
|
1354
|
+
},
|
|
1355
|
+
decodeSessionEvent(raw) {
|
|
1356
|
+
const payload = raw;
|
|
1357
|
+
if (typeof payload.session_id !== "string") {
|
|
1358
|
+
throw new Error("codex payload: missing session_id");
|
|
1359
|
+
}
|
|
1360
|
+
const phase = PHASE_BY_EVENT[payload.hook_event_name ?? ""];
|
|
1361
|
+
if (!phase)
|
|
1362
|
+
throw new Error(`codex payload: unknown event ${payload.hook_event_name}`);
|
|
1363
|
+
return {
|
|
1364
|
+
vendor: "codex",
|
|
1365
|
+
sessionId: payload.session_id,
|
|
1366
|
+
phase,
|
|
1367
|
+
ts: Date.now(),
|
|
1368
|
+
...payload.transcript_path !== void 0 ? { transcriptPath: payload.transcript_path } : {},
|
|
1369
|
+
...payload.cwd !== void 0 ? { cwd: payload.cwd } : {}
|
|
1370
|
+
};
|
|
1371
|
+
},
|
|
1372
|
+
encodeDecision(decision) {
|
|
1373
|
+
const hookSpecificOutput = {
|
|
1374
|
+
hookEventName: "PreToolUse",
|
|
1375
|
+
permissionDecision: decision.decision
|
|
1376
|
+
};
|
|
1377
|
+
if (decision.reason !== void 0) {
|
|
1378
|
+
hookSpecificOutput["permissionDecisionReason"] = decision.reason;
|
|
1379
|
+
}
|
|
1380
|
+
if (decision.updatedInput !== void 0) {
|
|
1381
|
+
hookSpecificOutput["permissionDecision"] = "ask";
|
|
1382
|
+
hookSpecificOutput["permissionDecisionReason"] = `${decision.reason ?? "Sensitive value detected"} (Codex cannot rewrite tool input; confirm or edit the value yourself)`;
|
|
1383
|
+
}
|
|
1384
|
+
const body = { hookSpecificOutput };
|
|
1385
|
+
const systemMessage = [decision.reason, decision.remediation].filter(Boolean).join(" ");
|
|
1386
|
+
if (systemMessage)
|
|
1387
|
+
body["systemMessage"] = systemMessage;
|
|
1388
|
+
return {
|
|
1389
|
+
stdout: JSON.stringify(body),
|
|
1390
|
+
exitCode: hookSpecificOutput["permissionDecision"] === "deny" ? 2 : 0
|
|
1391
|
+
};
|
|
1392
|
+
},
|
|
1393
|
+
encodeFailClosed(reason) {
|
|
1394
|
+
return {
|
|
1395
|
+
stdout: JSON.stringify({
|
|
1396
|
+
hookSpecificOutput: {
|
|
1397
|
+
hookEventName: "PreToolUse",
|
|
1398
|
+
permissionDecision: "deny",
|
|
1399
|
+
permissionDecisionReason: reason
|
|
1400
|
+
},
|
|
1401
|
+
systemMessage: reason
|
|
1402
|
+
}),
|
|
1403
|
+
exitCode: 2
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
// adapters/codex/bin/guard.mjs
|
|
1409
|
+
var here = dirname(fileURLToPath(import.meta.url));
|
|
1410
|
+
var { stdout, exitCode } = runGuard(
|
|
1411
|
+
codexCodec,
|
|
1412
|
+
await readStdin(process.stdin),
|
|
1413
|
+
join8(here, "forwarder.mjs")
|
|
1414
|
+
);
|
|
1415
|
+
if (stdout) process.stdout.write(stdout);
|
|
1416
|
+
process.exit(exitCode);
|
|
1417
|
+
/*! Bundled license information:
|
|
1418
|
+
|
|
1419
|
+
@noble/hashes/esm/utils.js:
|
|
1420
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
1421
|
+
*/
|