@adhdev/session-host-core 1.0.82-rc.37 → 1.0.82-rc.39
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/index.d.mts +1 -94
- package/dist/index.d.ts +1 -94
- package/dist/index.js +0 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +0 -126
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/types.ts +0 -8
- package/src/operator-recovery.ts +0 -134
package/dist/index.mjs
CHANGED
|
@@ -5,129 +5,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
// src/operator-recovery.ts
|
|
9
|
-
import { createPublicKey, randomBytes, verify } from "crypto";
|
|
10
|
-
import { isAbsolute, basename } from "path";
|
|
11
|
-
import { performance as performance2 } from "perf_hooks";
|
|
12
|
-
var OPERATOR_RECOVERY_TARGET = Object.freeze({
|
|
13
|
-
association: "operator_asserted",
|
|
14
|
-
taskId: "a1cdf3c0-f029-4d17-a8e9-db64e0a55501",
|
|
15
|
-
meshId: "mesh_271444af883843e9b36c67155b87b22f",
|
|
16
|
-
attemptId: "mesh_queue:mesh_271444af883843e9b36c67155b87b22f:a1cdf3c0-f029-4d17-a8e9-db64e0a55501:0",
|
|
17
|
-
generation: 0,
|
|
18
|
-
dispatchNonce: 1,
|
|
19
|
-
deliveryId: "dlv-7e259b34-b049-47ee-a466-2ca9c12bcff4",
|
|
20
|
-
ownerDaemonId: "daemon_mach_4462a75330c548be9c2e74dd9f7f6ffb",
|
|
21
|
-
nodeId: "node_d82de0cef9b042b6948986609e32142f",
|
|
22
|
-
workerDaemonId: "daemon_mach_6733c865d60f432dbeb119a6875ee303",
|
|
23
|
-
sessionId: "de321185-4ebc-40aa-8c6e-b4919e87fae3",
|
|
24
|
-
providerSessionId: "60806c79-7d77-4614-9fa6-e628533478ba",
|
|
25
|
-
namespace: "6a2ef3162182"
|
|
26
|
-
});
|
|
27
|
-
var recoveryTargetBytes = JSON.stringify(OPERATOR_RECOVERY_TARGET);
|
|
28
|
-
function assertRecoveryLaunchIdentity(value) {
|
|
29
|
-
if (!value || typeof value !== "object") return;
|
|
30
|
-
const identities = /* @__PURE__ */ new Set([
|
|
31
|
-
"sessionId",
|
|
32
|
-
"runtimeId",
|
|
33
|
-
"runtimeSessionId",
|
|
34
|
-
"providerSessionId",
|
|
35
|
-
"presetSessionKey",
|
|
36
|
-
"resumeSessionId",
|
|
37
|
-
"key"
|
|
38
|
-
]);
|
|
39
|
-
const nested = /* @__PURE__ */ new Set(["options", "meta", "settings", "settingsOverride", "restartBinding", "sessionBinding", "launchCommand"]);
|
|
40
|
-
for (const [key, field] of Object.entries(value)) {
|
|
41
|
-
if (identities.has(key) || ["args", "cliArgs", "cliArgsWithBrain"].includes(key)) {
|
|
42
|
-
const bytes = JSON.stringify(field)?.toLowerCase();
|
|
43
|
-
if (bytes?.includes(OPERATOR_RECOVERY_TARGET.sessionId) || bytes?.includes(OPERATOR_RECOVERY_TARGET.providerSessionId)) {
|
|
44
|
-
throw new Error("operator_recovery_fenced");
|
|
45
|
-
}
|
|
46
|
-
} else if (nested.has(key)) assertRecoveryLaunchIdentity(field);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function isRecoveryEndpoint(endpoint) {
|
|
50
|
-
return isAbsolute(endpoint) && basename(endpoint) === `adhdev-preview-session-host-${OPERATOR_RECOVERY_TARGET.namespace}.sock`;
|
|
51
|
-
}
|
|
52
|
-
var RecoveryOwnerAdmission = class {
|
|
53
|
-
constructor(enrollment, clock = () => performance2.now()) {
|
|
54
|
-
this.clock = clock;
|
|
55
|
-
this.enrollment = Object.freeze({ ...enrollment });
|
|
56
|
-
if (!enrollment.enrollmentId || !enrollment.coordinatorBootId || !enrollment.authEpoch || typeof enrollment.verifyCurrent !== "function") throw new Error("recovery_owner_enrollment_required");
|
|
57
|
-
this.key = createPublicKey(enrollment.publicKey);
|
|
58
|
-
if (this.key.asymmetricKeyType !== "ed25519") throw new Error("recovery_owner_key_type");
|
|
59
|
-
}
|
|
60
|
-
key;
|
|
61
|
-
enrollment;
|
|
62
|
-
pending = /* @__PURE__ */ new Map();
|
|
63
|
-
grants = /* @__PURE__ */ new WeakMap();
|
|
64
|
-
lastNow = -Infinity;
|
|
65
|
-
now() {
|
|
66
|
-
const n = this.clock();
|
|
67
|
-
if (!Number.isFinite(n) || n < this.lastNow || this.enrollment.verifyCurrent() !== true) {
|
|
68
|
-
this.pending.clear();
|
|
69
|
-
this.lastNow = Infinity;
|
|
70
|
-
throw new Error("recovery_owner_revoked");
|
|
71
|
-
}
|
|
72
|
-
this.lastNow = n;
|
|
73
|
-
return n;
|
|
74
|
-
}
|
|
75
|
-
challenge(operation = "anchor_recover") {
|
|
76
|
-
if (!["anchor_recover", "fence_install", "witness_enroll"].includes(operation)) throw new Error("recovery_owner_operation_rejected");
|
|
77
|
-
const now = this.now();
|
|
78
|
-
for (const [message2, entry] of this.pending) if (entry.deadline <= now) this.pending.delete(message2);
|
|
79
|
-
if (this.pending.size >= 16) throw new Error("recovery_owner_challenge_limit");
|
|
80
|
-
const message = JSON.stringify([
|
|
81
|
-
"operator_recovery_v1",
|
|
82
|
-
operation,
|
|
83
|
-
recoveryTargetBytes,
|
|
84
|
-
this.enrollment.enrollmentId,
|
|
85
|
-
this.enrollment.coordinatorBootId,
|
|
86
|
-
this.enrollment.authEpoch,
|
|
87
|
-
randomBytes(32).toString("hex")
|
|
88
|
-
]);
|
|
89
|
-
this.pending.set(message, { deadline: now + 3e4, operation });
|
|
90
|
-
return Object.freeze({ message });
|
|
91
|
-
}
|
|
92
|
-
authorize(message, signature) {
|
|
93
|
-
const now = this.now();
|
|
94
|
-
const entry = this.pending.get(message);
|
|
95
|
-
this.pending.delete(message);
|
|
96
|
-
if (!entry || now >= entry.deadline || !/^[a-f0-9]{128}$/.test(signature) || !verify(null, Buffer.from(message), this.key, Buffer.from(signature, "hex"))) {
|
|
97
|
-
throw new Error("recovery_owner_signature_rejected");
|
|
98
|
-
}
|
|
99
|
-
const grant = Object.freeze({ purpose: "operator_recovery_v1", operation: entry.operation });
|
|
100
|
-
this.grants.set(grant, entry);
|
|
101
|
-
return grant;
|
|
102
|
-
}
|
|
103
|
-
assertGrant(grant) {
|
|
104
|
-
const now = this.now();
|
|
105
|
-
const entry = typeof grant === "object" && grant !== null ? this.grants.get(grant) : void 0;
|
|
106
|
-
if (!entry || now >= entry.deadline) throw new Error("recovery_owner_grant_rejected");
|
|
107
|
-
}
|
|
108
|
-
/** Burn synchronously before any work or await. The private continuation
|
|
109
|
-
* rechecks the ORIGINAL deadline and revocation; it cannot mint a new grant. */
|
|
110
|
-
reserve(grant, operation) {
|
|
111
|
-
this.assertGrant(grant);
|
|
112
|
-
const entry = this.grants.get(grant);
|
|
113
|
-
this.grants.delete(grant);
|
|
114
|
-
if (entry.operation !== operation) throw new Error("recovery_owner_operation_rejected");
|
|
115
|
-
return () => {
|
|
116
|
-
if (this.now() >= entry.deadline) throw new Error("recovery_owner_grant_rejected");
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
consume(grant) {
|
|
120
|
-
this.assertGrant(grant);
|
|
121
|
-
this.grants.delete(grant);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
8
|
// src/types.ts
|
|
126
9
|
var SESSION_HOST_SUPPORTED_REQUEST_TYPES = [
|
|
127
|
-
"prepare_operator_recovery_fence_v1",
|
|
128
|
-
"install_operator_recovery_fence_v1",
|
|
129
|
-
"attest_operator_recovery_v1",
|
|
130
|
-
"get_operator_recovery_coverage_v1",
|
|
131
10
|
"get_upgrade_lease",
|
|
132
11
|
"acquire_upgrade_lease",
|
|
133
12
|
"release_upgrade_lease",
|
|
@@ -1630,14 +1509,11 @@ export {
|
|
|
1630
1509
|
DEFAULT_SESSION_HOST_COLS,
|
|
1631
1510
|
DEFAULT_SESSION_HOST_ROWS,
|
|
1632
1511
|
DEFAULT_SESSION_RING_BUFFER_MAX_BYTES,
|
|
1633
|
-
OPERATOR_RECOVERY_TARGET,
|
|
1634
|
-
RecoveryOwnerAdmission,
|
|
1635
1512
|
SESSION_HOST_SUPPORTED_REQUEST_TYPES,
|
|
1636
1513
|
SessionHostClient,
|
|
1637
1514
|
SessionHostRegistry,
|
|
1638
1515
|
SessionRingBuffer,
|
|
1639
1516
|
applyTerminalColorEnv,
|
|
1640
|
-
assertRecoveryLaunchIdentity,
|
|
1641
1517
|
assertTestStorageIsolated,
|
|
1642
1518
|
buildRuntimeDisplayName,
|
|
1643
1519
|
buildRuntimeKey,
|
|
@@ -1658,14 +1534,12 @@ export {
|
|
|
1658
1534
|
hiddenSpawn as hiddenSpawnProcess,
|
|
1659
1535
|
hostBootIdFromStartedAt,
|
|
1660
1536
|
isDefaultInstanceConfigDir,
|
|
1661
|
-
isRecoveryEndpoint,
|
|
1662
1537
|
isSessionHostLiveRuntime,
|
|
1663
1538
|
isSessionHostRecoverySnapshot,
|
|
1664
1539
|
isTerminalRecord,
|
|
1665
1540
|
niceLaunch,
|
|
1666
1541
|
partitionSessionHostDiagnosticsSessions,
|
|
1667
1542
|
partitionSessionHostRecords,
|
|
1668
|
-
recoveryTargetBytes,
|
|
1669
1543
|
refuseCleanupExpectedDelete,
|
|
1670
1544
|
refuseCleanupExpectedStop,
|
|
1671
1545
|
replayLaunchEnv,
|