@threadbase-sh/streamer 1.69.2 → 1.69.4
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/dist/api/handlers/sessions.handlers.d.ts +2 -0
- package/dist/api/handlers/sessions.handlers.d.ts.map +1 -1
- package/dist/cli.cjs +83 -74
- package/dist/cli.cjs.map +1 -1
- package/dist/codex-pty-runner.d.ts.map +1 -1
- package/dist/index.cjs +76 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -51
- package/dist/index.js.map +1 -1
- package/dist/pty-manager.d.ts.map +1 -1
- package/dist/pty-shared.d.ts +0 -1
- package/dist/pty-shared.d.ts.map +1 -1
- package/dist/server-wiring.d.ts +2 -0
- package/dist/server-wiring.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-pty-runner.d.ts","sourceRoot":"","sources":["../src/codex-pty-runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex-pty-runner.d.ts","sourceRoot":"","sources":["../src/codex-pty-runner.ts"],"names":[],"mappings":"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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1099,11 +1099,6 @@ var PTY_COLS = 120;
|
|
|
1099
1099
|
var PTY_ROWS = 40;
|
|
1100
1100
|
var SCREEN_SCROLLBACK = 1e3;
|
|
1101
1101
|
var REPLAY_MAX_LINES = SCREEN_SCROLLBACK + PTY_ROWS;
|
|
1102
|
-
function digestBytes(s) {
|
|
1103
|
-
const escaped = s.replace(new RegExp(String.fromCharCode(27), "g"), "\\x1b").replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\t/g, "\\t");
|
|
1104
|
-
if (escaped.length <= 200) return escaped;
|
|
1105
|
-
return `${escaped.slice(0, 100)}\u2026[${escaped.length - 200}B omitted]\u2026${escaped.slice(-100)}`;
|
|
1106
|
-
}
|
|
1107
1102
|
var pty = null;
|
|
1108
1103
|
async function loadPty() {
|
|
1109
1104
|
if (pty) return pty;
|
|
@@ -1538,17 +1533,12 @@ var CodexPtyRunner = class {
|
|
|
1538
1533
|
const lines = await this.getOutputLines(sessionId, PTY_ROWS);
|
|
1539
1534
|
if (!this.pendingReady.has(sessionId)) return;
|
|
1540
1535
|
const busy = codexScreenBlocksComposer(lines);
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
busy,
|
|
1548
|
-
hasReady: codexScreenShowsReady(lines),
|
|
1549
|
-
statusBar: bar.slice(0, 160)
|
|
1550
|
-
}
|
|
1551
|
-
);
|
|
1536
|
+
this.log.info(`[codex.ready_fallback] ${sessionId.slice(0, 8)} busy=${busy}`, {
|
|
1537
|
+
event: "codex.ready_fallback",
|
|
1538
|
+
sessionId,
|
|
1539
|
+
busy,
|
|
1540
|
+
hasReady: codexScreenShowsReady(lines)
|
|
1541
|
+
});
|
|
1552
1542
|
if (busy) {
|
|
1553
1543
|
this.armReadyFallback(sessionId);
|
|
1554
1544
|
return;
|
|
@@ -1583,10 +1573,11 @@ var CodexPtyRunner = class {
|
|
|
1583
1573
|
const gate = this.openGate.get(sessionId);
|
|
1584
1574
|
const digit = gate ? /^([0-9])\r?$/.exec(keys)?.[1] : void 0;
|
|
1585
1575
|
const out = gate && digit ? this.resolveGateAnswer(sessionId, gate, digit) : keys;
|
|
1586
|
-
this.log.info(
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1576
|
+
this.log.info(`[codex.keys.write] ${sessionId.slice(0, 8)} bytes=${out.length}`, {
|
|
1577
|
+
event: "codex.keys_write",
|
|
1578
|
+
sessionId,
|
|
1579
|
+
byteLen: out.length
|
|
1580
|
+
});
|
|
1590
1581
|
session.process.write(out);
|
|
1591
1582
|
session.lastActivityAt = /* @__PURE__ */ new Date();
|
|
1592
1583
|
}
|
|
@@ -1665,13 +1656,12 @@ var CodexPtyRunner = class {
|
|
|
1665
1656
|
writeSubmit(sessionId, session, input, path, promptCount) {
|
|
1666
1657
|
this.recordUserMessage(session, input);
|
|
1667
1658
|
this.log.info(
|
|
1668
|
-
`[codex.input.write] ${sessionId.slice(0, 8)} promptCount=${promptCount} bytes=${input.length}
|
|
1659
|
+
`[codex.input.write] ${sessionId.slice(0, 8)} promptCount=${promptCount} bytes=${input.length}`,
|
|
1669
1660
|
{
|
|
1670
1661
|
event: "codex.input_write",
|
|
1671
1662
|
sessionId,
|
|
1672
1663
|
promptCount,
|
|
1673
1664
|
byteLen: input.length,
|
|
1674
|
-
digest: digestBytes(input),
|
|
1675
1665
|
path,
|
|
1676
1666
|
phase: "input"
|
|
1677
1667
|
}
|
|
@@ -1735,8 +1725,7 @@ var CodexPtyRunner = class {
|
|
|
1735
1725
|
}
|
|
1736
1726
|
this.log.info(`[codex.submit_stale] ${sessionId.slice(0, 8)} recovering`, {
|
|
1737
1727
|
event: "codex.submit_stale",
|
|
1738
|
-
sessionId
|
|
1739
|
-
statusBar: codexStatusBarLine(lines).slice(0, 160)
|
|
1728
|
+
sessionId
|
|
1740
1729
|
});
|
|
1741
1730
|
this.markReady(sessionId, session, "quiet-fallback", "submit-stale");
|
|
1742
1731
|
} catch (err) {
|
|
@@ -2019,7 +2008,7 @@ var CodexPtyRunner = class {
|
|
|
2019
2008
|
if (this.lastScreenLog.get(sessionId) !== screenFp) {
|
|
2020
2009
|
this.lastScreenLog.set(sessionId, screenFp);
|
|
2021
2010
|
this.log.info(
|
|
2022
|
-
`[codex.screen] ${sessionId.slice(0, 8)} pending=${this.pendingReady.has(sessionId)} status=${session.status} ready=${hasReady} busy=${busy} usage=${Boolean(blocking)}
|
|
2011
|
+
`[codex.screen] ${sessionId.slice(0, 8)} pending=${this.pendingReady.has(sessionId)} status=${session.status} ready=${hasReady} busy=${busy} usage=${Boolean(blocking)}`,
|
|
2023
2012
|
{
|
|
2024
2013
|
event: "codex.screen",
|
|
2025
2014
|
sessionId,
|
|
@@ -2029,8 +2018,7 @@ var CodexPtyRunner = class {
|
|
|
2029
2018
|
hasReady,
|
|
2030
2019
|
busy,
|
|
2031
2020
|
usageHit: Boolean(blocking),
|
|
2032
|
-
usageSoft: Boolean(blocking?.soft)
|
|
2033
|
-
statusBar: bar.slice(0, 160)
|
|
2021
|
+
usageSoft: Boolean(blocking?.soft)
|
|
2034
2022
|
}
|
|
2035
2023
|
);
|
|
2036
2024
|
}
|
|
@@ -2065,8 +2053,7 @@ var CodexPtyRunner = class {
|
|
|
2065
2053
|
session.failureReason = blocking.detail ? `${blocking.prompt} ${blocking.detail}` : blocking.prompt;
|
|
2066
2054
|
this.log.info(`[codex.usage_limit] ${sessionId.slice(0, 8)}`, {
|
|
2067
2055
|
event: "codex.usage_limit",
|
|
2068
|
-
sessionId
|
|
2069
|
-
prompt: blocking.prompt
|
|
2056
|
+
sessionId
|
|
2070
2057
|
});
|
|
2071
2058
|
this.onPermissionChange?.(sessionId, blocking);
|
|
2072
2059
|
}
|
|
@@ -2112,8 +2099,7 @@ var CodexPtyRunner = class {
|
|
|
2112
2099
|
this.log.info(`[codex.gate_prompt] ${sessionId.slice(0, 8)} ${gate}`, {
|
|
2113
2100
|
event: "codex.gate_prompt",
|
|
2114
2101
|
sessionId,
|
|
2115
|
-
gate
|
|
2116
|
-
prompt: card.prompt
|
|
2102
|
+
gate
|
|
2117
2103
|
});
|
|
2118
2104
|
this.onPermissionChange?.(sessionId, card);
|
|
2119
2105
|
}
|
|
@@ -3131,10 +3117,11 @@ var PTYManager = class {
|
|
|
3131
3117
|
session.statusUpdatedAt = /* @__PURE__ */ new Date();
|
|
3132
3118
|
this.onStatusChange?.(toPublicSession2(session));
|
|
3133
3119
|
}
|
|
3134
|
-
this.log.info(
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3120
|
+
this.log.info(`[pty.keys.write] ${sessionId.slice(0, 8)} bytes=${keys.length}`, {
|
|
3121
|
+
event: "pty.keys_write",
|
|
3122
|
+
sessionId,
|
|
3123
|
+
byteLen: keys.length
|
|
3124
|
+
});
|
|
3138
3125
|
session.process.write(keys);
|
|
3139
3126
|
session.lastActivityAt = /* @__PURE__ */ new Date();
|
|
3140
3127
|
const openGate = this.permissionOpen.get(sessionId);
|
|
@@ -3196,13 +3183,12 @@ var PTYManager = class {
|
|
|
3196
3183
|
this.recordUserMessage(session, input);
|
|
3197
3184
|
const pasteBytes = buildPasteBytes(input);
|
|
3198
3185
|
this.log.info(
|
|
3199
|
-
`[pty.input.write] ${sessionId.slice(0, 8)} promptCount=${promptCount} bytes=${pasteBytes.length}
|
|
3186
|
+
`[pty.input.write] ${sessionId.slice(0, 8)} promptCount=${promptCount} bytes=${pasteBytes.length}`,
|
|
3200
3187
|
{
|
|
3201
3188
|
event: "pty.input_write",
|
|
3202
3189
|
sessionId,
|
|
3203
3190
|
promptCount,
|
|
3204
3191
|
byteLen: pasteBytes.length,
|
|
3205
|
-
digest: digestBytes(pasteBytes),
|
|
3206
3192
|
path,
|
|
3207
3193
|
phase: "paste"
|
|
3208
3194
|
}
|
|
@@ -3402,7 +3388,7 @@ var PTYManager = class {
|
|
|
3402
3388
|
this.lastChunkAt.set(sessionId, now);
|
|
3403
3389
|
const gapMs = last == null ? 0 : now - last;
|
|
3404
3390
|
this.log.info(
|
|
3405
|
-
`[pty.chunk] ${sessionId.slice(0, 8)} #${idx} +${chunk.length}B gap=${gapMs}ms status=${session.status}
|
|
3391
|
+
`[pty.chunk] ${sessionId.slice(0, 8)} #${idx} +${chunk.length}B gap=${gapMs}ms status=${session.status}`,
|
|
3406
3392
|
{
|
|
3407
3393
|
event: "pty.chunk",
|
|
3408
3394
|
sessionId,
|
|
@@ -3410,8 +3396,7 @@ var PTYManager = class {
|
|
|
3410
3396
|
chunkBytes: chunk.length,
|
|
3411
3397
|
gapMs,
|
|
3412
3398
|
status: session.status,
|
|
3413
|
-
pendingReady: this.pendingReady.has(sessionId)
|
|
3414
|
-
digest: digestBytes(data)
|
|
3399
|
+
pendingReady: this.pendingReady.has(sessionId)
|
|
3415
3400
|
}
|
|
3416
3401
|
);
|
|
3417
3402
|
session.outputBuffer = Buffer.concat([session.outputBuffer, chunk]);
|
|
@@ -3475,15 +3460,18 @@ var PTYManager = class {
|
|
|
3475
3460
|
}
|
|
3476
3461
|
const askFooterOnScreen = lines.some((l) => /Enter to select/i.test(l));
|
|
3477
3462
|
if (oscPermission || hasAskFooter || askFooterOnScreen) {
|
|
3463
|
+
const permGate = oscPermission && !askFooterOnScreen ? scrapePermissionGate(lines) : null;
|
|
3464
|
+
const askQuestion = askFooterOnScreen ? detectQuestionFromScreen(lines) : null;
|
|
3478
3465
|
this.log.debug?.(`[pty.prompt_detect] ${sessionId.slice(0, 8)} trigger`, {
|
|
3479
3466
|
event: "pty.prompt_detect",
|
|
3480
3467
|
sessionId,
|
|
3481
3468
|
oscPermission,
|
|
3482
3469
|
hasAskFooter,
|
|
3483
3470
|
askFooterOnScreen,
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3471
|
+
permGateDetected: permGate !== null,
|
|
3472
|
+
permGateOptionCount: permGate?.options.length ?? 0,
|
|
3473
|
+
askQuestionDetected: askQuestion !== null,
|
|
3474
|
+
askQuestionCount: askQuestion?.questions.length ?? 0
|
|
3487
3475
|
});
|
|
3488
3476
|
}
|
|
3489
3477
|
if (oscPermission && !askFooterOnScreen) {
|
|
@@ -4154,7 +4142,7 @@ async function readGitBranch(dir) {
|
|
|
4154
4142
|
// src/server.ts
|
|
4155
4143
|
var import_node_ws = require("@hono/node-ws");
|
|
4156
4144
|
var import_client = require("@temporalio/client");
|
|
4157
|
-
var
|
|
4145
|
+
var import_crypto14 = require("crypto");
|
|
4158
4146
|
var import_events = require("events");
|
|
4159
4147
|
var import_fs28 = require("fs");
|
|
4160
4148
|
var import_promises7 = require("fs/promises");
|
|
@@ -9263,6 +9251,7 @@ var ConversationHandlers = class {
|
|
|
9263
9251
|
};
|
|
9264
9252
|
|
|
9265
9253
|
// src/api/handlers/sessions.handlers.ts
|
|
9254
|
+
var import_crypto9 = require("crypto");
|
|
9266
9255
|
var import_fs15 = require("fs");
|
|
9267
9256
|
var import_path16 = require("path");
|
|
9268
9257
|
|
|
@@ -10558,7 +10547,9 @@ var SessionHandlers = class {
|
|
|
10558
10547
|
}
|
|
10559
10548
|
const key = permissionContentKey(gate);
|
|
10560
10549
|
if (this.pendingPermissionKey.get(sessionId) === key) return;
|
|
10561
|
-
this.pendingPermission.
|
|
10550
|
+
const prior = this.pendingPermission.get(sessionId);
|
|
10551
|
+
const gateId = prior && permissionGateKey(prior) === permissionGateKey(gate) ? prior.gateId : (0, import_crypto9.randomUUID)();
|
|
10552
|
+
this.pendingPermission.set(sessionId, { ...gate, gateId });
|
|
10562
10553
|
this.pendingPermissionKey.set(sessionId, key);
|
|
10563
10554
|
const subscriberCount = this.sessionSubscribers.get(sessionId)?.size ?? 0;
|
|
10564
10555
|
this.log.info(
|
|
@@ -10572,7 +10563,8 @@ var SessionHandlers = class {
|
|
|
10572
10563
|
...gate.detail ? { detail: gate.detail } : {},
|
|
10573
10564
|
options: gate.options,
|
|
10574
10565
|
...gate.cursor !== void 0 ? { cursor: gate.cursor } : {},
|
|
10575
|
-
contentKey: permissionGateKey(gate)
|
|
10566
|
+
contentKey: permissionGateKey(gate),
|
|
10567
|
+
gateId
|
|
10576
10568
|
});
|
|
10577
10569
|
}
|
|
10578
10570
|
/**
|
|
@@ -10600,10 +10592,15 @@ var SessionHandlers = class {
|
|
|
10600
10592
|
const body = await readBody2(req);
|
|
10601
10593
|
const contentKey = body?.contentKey;
|
|
10602
10594
|
const optionIndex = body?.optionIndex;
|
|
10595
|
+
const gateId = body?.gateId;
|
|
10603
10596
|
if (typeof contentKey !== "string" || !Number.isInteger(optionIndex) || optionIndex < 0) {
|
|
10604
10597
|
json(res, 400, { ok: false, reason: "Expected { contentKey: string, optionIndex: number }" });
|
|
10605
10598
|
return;
|
|
10606
10599
|
}
|
|
10600
|
+
if (gateId !== void 0 && typeof gateId !== "string") {
|
|
10601
|
+
json(res, 400, { ok: false, reason: "Expected gateId to be a string" });
|
|
10602
|
+
return;
|
|
10603
|
+
}
|
|
10607
10604
|
const gateClosed = () => {
|
|
10608
10605
|
this.pendingPermission.delete(sessionId);
|
|
10609
10606
|
this.pendingPermissionKey.delete(sessionId);
|
|
@@ -10615,6 +10612,16 @@ var SessionHandlers = class {
|
|
|
10615
10612
|
gateClosed();
|
|
10616
10613
|
return;
|
|
10617
10614
|
}
|
|
10615
|
+
if (gateId !== void 0 && gateId !== gate.gateId) {
|
|
10616
|
+
json(res, 409, { ok: false, reason: "gate_mismatch" });
|
|
10617
|
+
return;
|
|
10618
|
+
}
|
|
10619
|
+
if (gateId === void 0) {
|
|
10620
|
+
this.log.info(`[permission.answer_legacy_identity] ${sessionId.slice(0, 8)}`, {
|
|
10621
|
+
event: "permission.answer_legacy_identity",
|
|
10622
|
+
sessionId
|
|
10623
|
+
});
|
|
10624
|
+
}
|
|
10618
10625
|
if (permissionGateKey(gate) !== contentKey) {
|
|
10619
10626
|
json(res, 409, { ok: false, reason: "gate_mismatch" });
|
|
10620
10627
|
return;
|
|
@@ -10624,7 +10631,8 @@ var SessionHandlers = class {
|
|
|
10624
10631
|
json(res, 409, { ok: false, reason: "unknown_option" });
|
|
10625
10632
|
return;
|
|
10626
10633
|
}
|
|
10627
|
-
|
|
10634
|
+
const provider = this.sessionStore.getManaged(sessionId)?.provider;
|
|
10635
|
+
if (provider !== CODEX_CLI_PROVIDER && !await this.permissionGateStillOpen(sessionId, contentKey)) {
|
|
10628
10636
|
gateClosed();
|
|
10629
10637
|
return;
|
|
10630
10638
|
}
|
|
@@ -11332,7 +11340,7 @@ var ManagedSessionsRepository = class {
|
|
|
11332
11340
|
};
|
|
11333
11341
|
|
|
11334
11342
|
// src/db/repositories/projects.repository.ts
|
|
11335
|
-
var
|
|
11343
|
+
var import_crypto10 = require("crypto");
|
|
11336
11344
|
function rowToProject(row) {
|
|
11337
11345
|
return {
|
|
11338
11346
|
id: row.id,
|
|
@@ -11417,7 +11425,7 @@ var ProjectsRepository = class {
|
|
|
11417
11425
|
});
|
|
11418
11426
|
return rowToProject(this.getById.get(existing.id));
|
|
11419
11427
|
}
|
|
11420
|
-
const id = (0,
|
|
11428
|
+
const id = (0, import_crypto10.randomUUID)();
|
|
11421
11429
|
this.insert.run({
|
|
11422
11430
|
id,
|
|
11423
11431
|
path,
|
|
@@ -11547,7 +11555,7 @@ var RuntimeStore = class _RuntimeStore {
|
|
|
11547
11555
|
};
|
|
11548
11556
|
|
|
11549
11557
|
// src/e2ee/noise.ts
|
|
11550
|
-
var
|
|
11558
|
+
var import_crypto11 = require("crypto");
|
|
11551
11559
|
var NOISE_PROTOCOL_NAME = "Noise_IKpsk1_25519_ChaChaPoly_SHA256";
|
|
11552
11560
|
var PAIR_PROLOGUE = Buffer.from("threadbase-e2ee/1 pair", "utf-8");
|
|
11553
11561
|
var DHLEN = 32;
|
|
@@ -11563,15 +11571,15 @@ var NoiseError = class extends Error {
|
|
|
11563
11571
|
}
|
|
11564
11572
|
};
|
|
11565
11573
|
function generateKeyPair() {
|
|
11566
|
-
const { publicKey, privateKey } = (0,
|
|
11574
|
+
const { publicKey, privateKey } = (0, import_crypto11.generateKeyPairSync)("x25519");
|
|
11567
11575
|
return { publicKey, privateKey, publicKeyRaw: rawPublicKey(publicKey) };
|
|
11568
11576
|
}
|
|
11569
11577
|
function keyPairFrom(privateKey) {
|
|
11570
|
-
const publicKey = (0,
|
|
11578
|
+
const publicKey = (0, import_crypto11.createPublicKey)(privateKey);
|
|
11571
11579
|
return { publicKey, privateKey, publicKeyRaw: rawPublicKey(publicKey) };
|
|
11572
11580
|
}
|
|
11573
11581
|
function rawPublicKey(key) {
|
|
11574
|
-
const pub = key.type === "public" ? key : (0,
|
|
11582
|
+
const pub = key.type === "public" ? key : (0, import_crypto11.createPublicKey)(key);
|
|
11575
11583
|
const jwk = pub.export({ format: "jwk" });
|
|
11576
11584
|
if (jwk.crv !== "X25519" || typeof jwk.x !== "string") {
|
|
11577
11585
|
throw new NoiseError("Not an X25519 public key");
|
|
@@ -11583,7 +11591,7 @@ function publicKeyFromRaw(raw) {
|
|
|
11583
11591
|
throw new NoiseError(`X25519 public key must be ${DHLEN} bytes, got ${raw.length}`);
|
|
11584
11592
|
}
|
|
11585
11593
|
try {
|
|
11586
|
-
return (0,
|
|
11594
|
+
return (0, import_crypto11.createPublicKey)({
|
|
11587
11595
|
key: { kty: "OKP", crv: "X25519", x: raw.toString("base64url") },
|
|
11588
11596
|
format: "jwk"
|
|
11589
11597
|
});
|
|
@@ -11592,7 +11600,7 @@ function publicKeyFromRaw(raw) {
|
|
|
11592
11600
|
}
|
|
11593
11601
|
}
|
|
11594
11602
|
function pskFromPairToken(token) {
|
|
11595
|
-
return (0,
|
|
11603
|
+
return (0, import_crypto11.createHash)("sha256").update("threadbase-e2ee/1 psk", "utf-8").update(token, "utf-8").digest();
|
|
11596
11604
|
}
|
|
11597
11605
|
function chachaNonce(n) {
|
|
11598
11606
|
const nonce = Buffer.alloc(12);
|
|
@@ -11611,7 +11619,7 @@ var CipherState = class {
|
|
|
11611
11619
|
}
|
|
11612
11620
|
encryptWithAd(ad, plaintext) {
|
|
11613
11621
|
if (!this.k) return plaintext;
|
|
11614
|
-
const cipher = (0,
|
|
11622
|
+
const cipher = (0, import_crypto11.createCipheriv)("chacha20-poly1305", this.k, chachaNonce(this.n), {
|
|
11615
11623
|
authTagLength: TAGLEN
|
|
11616
11624
|
});
|
|
11617
11625
|
cipher.setAAD(ad, { plaintextLength: plaintext.length });
|
|
@@ -11624,7 +11632,7 @@ var CipherState = class {
|
|
|
11624
11632
|
if (ciphertext.length < TAGLEN) throw new NoiseError("Ciphertext shorter than its tag");
|
|
11625
11633
|
const body = ciphertext.subarray(0, ciphertext.length - TAGLEN);
|
|
11626
11634
|
const tag = ciphertext.subarray(ciphertext.length - TAGLEN);
|
|
11627
|
-
const decipher = (0,
|
|
11635
|
+
const decipher = (0, import_crypto11.createDecipheriv)("chacha20-poly1305", this.k, chachaNonce(this.n), {
|
|
11628
11636
|
authTagLength: TAGLEN
|
|
11629
11637
|
});
|
|
11630
11638
|
decipher.setAAD(ad, { plaintextLength: body.length });
|
|
@@ -11645,7 +11653,7 @@ var SymmetricState = class {
|
|
|
11645
11653
|
cipher = new CipherState();
|
|
11646
11654
|
constructor(protocolName) {
|
|
11647
11655
|
const name = Buffer.from(protocolName, "utf-8");
|
|
11648
|
-
this.h = name.length <= HASHLEN ? Buffer.concat([name, Buffer.alloc(HASHLEN - name.length)]) : (0,
|
|
11656
|
+
this.h = name.length <= HASHLEN ? Buffer.concat([name, Buffer.alloc(HASHLEN - name.length)]) : (0, import_crypto11.createHash)("sha256").update(name).digest();
|
|
11649
11657
|
this.ck = Buffer.from(this.h);
|
|
11650
11658
|
this.cipher.initializeKey(null);
|
|
11651
11659
|
}
|
|
@@ -11657,7 +11665,7 @@ var SymmetricState = class {
|
|
|
11657
11665
|
* subtly wrong.
|
|
11658
11666
|
*/
|
|
11659
11667
|
hkdf(ikm, outputs) {
|
|
11660
|
-
const raw = Buffer.from((0,
|
|
11668
|
+
const raw = Buffer.from((0, import_crypto11.hkdfSync)("sha256", ikm, this.ck, Buffer.alloc(0), HASHLEN * outputs));
|
|
11661
11669
|
const out = [];
|
|
11662
11670
|
for (let i = 0; i < outputs; i++) out.push(raw.subarray(i * HASHLEN, (i + 1) * HASHLEN));
|
|
11663
11671
|
return out;
|
|
@@ -11668,7 +11676,7 @@ var SymmetricState = class {
|
|
|
11668
11676
|
this.cipher.initializeKey(tempK);
|
|
11669
11677
|
}
|
|
11670
11678
|
mixHash(data) {
|
|
11671
|
-
this.h = (0,
|
|
11679
|
+
this.h = (0, import_crypto11.createHash)("sha256").update(this.h).update(data).digest();
|
|
11672
11680
|
}
|
|
11673
11681
|
/** Spec §5.2. Used only by the `psk` token. */
|
|
11674
11682
|
mixKeyAndHash(ikm) {
|
|
@@ -11698,7 +11706,7 @@ var SymmetricState = class {
|
|
|
11698
11706
|
}
|
|
11699
11707
|
};
|
|
11700
11708
|
function dh(privateKey, publicKey) {
|
|
11701
|
-
return (0,
|
|
11709
|
+
return (0, import_crypto11.diffieHellman)({ privateKey, publicKey });
|
|
11702
11710
|
}
|
|
11703
11711
|
function readMessage1(args) {
|
|
11704
11712
|
assertMessageSize(args.message1, NOISE_MESSAGE_1_OVERHEAD);
|
|
@@ -12010,7 +12018,7 @@ var ExternalTailManager = class {
|
|
|
12010
12018
|
};
|
|
12011
12019
|
|
|
12012
12020
|
// src/pair-store.ts
|
|
12013
|
-
var
|
|
12021
|
+
var import_crypto12 = require("crypto");
|
|
12014
12022
|
var DEFAULT_TTL_SECONDS = 180;
|
|
12015
12023
|
var SWEEP_INTERVAL_MS = 6e4;
|
|
12016
12024
|
var PairTokenStore = class {
|
|
@@ -12025,7 +12033,7 @@ var PairTokenStore = class {
|
|
|
12025
12033
|
}
|
|
12026
12034
|
}
|
|
12027
12035
|
mint() {
|
|
12028
|
-
const token = `pt_${(0,
|
|
12036
|
+
const token = `pt_${(0, import_crypto12.randomBytes)(16).toString("hex")}`;
|
|
12029
12037
|
const expiresAt = Date.now() + this.ttlMs;
|
|
12030
12038
|
this.current = { token, expiresAt, used: false };
|
|
12031
12039
|
return {
|
|
@@ -13183,7 +13191,8 @@ function createApiDeps(deps) {
|
|
|
13183
13191
|
...pendingGate.detail ? { detail: pendingGate.detail } : {},
|
|
13184
13192
|
options: pendingGate.options,
|
|
13185
13193
|
...pendingGate.cursor !== void 0 ? { cursor: pendingGate.cursor } : {},
|
|
13186
|
-
contentKey: permissionGateKey(pendingGate)
|
|
13194
|
+
contentKey: permissionGateKey(pendingGate),
|
|
13195
|
+
gateId: pendingGate.gateId
|
|
13187
13196
|
})
|
|
13188
13197
|
);
|
|
13189
13198
|
}
|
|
@@ -13250,7 +13259,7 @@ function createApiDeps(deps) {
|
|
|
13250
13259
|
}
|
|
13251
13260
|
|
|
13252
13261
|
// src/services/cache-integrity/cacheIntegrityMonitor.ts
|
|
13253
|
-
var
|
|
13262
|
+
var import_crypto13 = require("crypto");
|
|
13254
13263
|
var import_fs23 = require("fs");
|
|
13255
13264
|
|
|
13256
13265
|
// src/services/cache-integrity/alertStore.ts
|
|
@@ -13315,7 +13324,7 @@ function envInt(name, fallback) {
|
|
|
13315
13324
|
}
|
|
13316
13325
|
function fingerprintOf(ids) {
|
|
13317
13326
|
const sorted = [...ids].sort();
|
|
13318
|
-
return `sha256:${(0,
|
|
13327
|
+
return `sha256:${(0, import_crypto13.createHash)("sha256").update(sorted.join("\n")).digest("hex")}`;
|
|
13319
13328
|
}
|
|
13320
13329
|
var CacheIntegrityMonitor = class {
|
|
13321
13330
|
constructor(cache, wsHub, log10, cacheDir, rescan, runDuringReset) {
|
|
@@ -16041,7 +16050,7 @@ var StreamerServer = class {
|
|
|
16041
16050
|
runtimeStore = null;
|
|
16042
16051
|
// Identifies this streamer run. A registry row carrying a different id is a
|
|
16043
16052
|
// session that outlived the process that started it.
|
|
16044
|
-
streamerInstanceId = (0,
|
|
16053
|
+
streamerInstanceId = (0, import_crypto14.randomUUID)();
|
|
16045
16054
|
cacheMetadataRepo = null;
|
|
16046
16055
|
// Push registration + delivery state (C7). Null when the cache DB failed to
|
|
16047
16056
|
// open — registration then degrades to a no-op rather than 500ing.
|