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