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