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