@adhdev/session-host-core 1.0.82-rc.37 → 1.0.82-rc.38
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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { OPERATOR_RECOVERY_TARGET, recoveryTargetBytes, RecoveryOwnerAdmission, assertRecoveryLaunchIdentity, isRecoveryEndpoint } from './operator-recovery.js';
|
|
2
|
-
export type { RecoveryOwnerOperation, RecoveryOwnerGrant, RecoveryOwnerChallenge, RecoveryOwnerEnrollment, RecoveryHostBinding, RecoveryPhysicalProof } from './operator-recovery.js';
|
|
3
1
|
export type {
|
|
4
2
|
MeshWriterAssignment,
|
|
5
3
|
MeshWriterStopTarget,
|
package/src/types.ts
CHANGED
|
@@ -400,10 +400,6 @@ export interface HostUpgradeLeasePayload {
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
export type SessionHostRequest =
|
|
403
|
-
| { type: 'prepare_operator_recovery_fence_v1'; payload?: {} }
|
|
404
|
-
| { type: 'install_operator_recovery_fence_v1'; payload: { message: string; signature: string } }
|
|
405
|
-
| { type: 'attest_operator_recovery_v1'; payload: { nonce: string; fenceDigest: string } }
|
|
406
|
-
| { type: 'get_operator_recovery_coverage_v1'; payload: { nonce: string } }
|
|
407
403
|
| { type: 'get_upgrade_lease'; payload?: {} }
|
|
408
404
|
| { type: 'acquire_upgrade_lease'; payload: HostUpgradeLeasePayload }
|
|
409
405
|
| { type: 'release_upgrade_lease'; payload: HostUpgradeLeasePayload }
|
|
@@ -441,10 +437,6 @@ export type SessionHostRequest =
|
|
|
441
437
|
export type SessionHostRequestType = SessionHostRequest['type'];
|
|
442
438
|
|
|
443
439
|
export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[] = [
|
|
444
|
-
'prepare_operator_recovery_fence_v1',
|
|
445
|
-
'install_operator_recovery_fence_v1',
|
|
446
|
-
'attest_operator_recovery_v1',
|
|
447
|
-
'get_operator_recovery_coverage_v1',
|
|
448
440
|
'get_upgrade_lease',
|
|
449
441
|
'acquire_upgrade_lease',
|
|
450
442
|
'release_upgrade_lease',
|
package/src/operator-recovery.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { createPublicKey, randomBytes, verify, type KeyObject } from 'node:crypto';
|
|
2
|
-
import { isAbsolute, basename } from 'node:path';
|
|
3
|
-
import { performance } from 'node:perf_hooks';
|
|
4
|
-
|
|
5
|
-
/** This association is owner asserted, never a historical native receipt. */
|
|
6
|
-
export const OPERATOR_RECOVERY_TARGET = Object.freeze({
|
|
7
|
-
association: 'operator_asserted' as const,
|
|
8
|
-
taskId: 'a1cdf3c0-f029-4d17-a8e9-db64e0a55501',
|
|
9
|
-
meshId: 'mesh_271444af883843e9b36c67155b87b22f',
|
|
10
|
-
attemptId: 'mesh_queue:mesh_271444af883843e9b36c67155b87b22f:a1cdf3c0-f029-4d17-a8e9-db64e0a55501:0',
|
|
11
|
-
generation: 0, dispatchNonce: 1,
|
|
12
|
-
deliveryId: 'dlv-7e259b34-b049-47ee-a466-2ca9c12bcff4',
|
|
13
|
-
ownerDaemonId: 'daemon_mach_4462a75330c548be9c2e74dd9f7f6ffb',
|
|
14
|
-
nodeId: 'node_d82de0cef9b042b6948986609e32142f',
|
|
15
|
-
workerDaemonId: 'daemon_mach_6733c865d60f432dbeb119a6875ee303',
|
|
16
|
-
sessionId: 'de321185-4ebc-40aa-8c6e-b4919e87fae3',
|
|
17
|
-
providerSessionId: '60806c79-7d77-4614-9fa6-e628533478ba',
|
|
18
|
-
namespace: '6a2ef3162182',
|
|
19
|
-
});
|
|
20
|
-
export const recoveryTargetBytes = JSON.stringify(OPERATOR_RECOVERY_TARGET);
|
|
21
|
-
/** Shared final admission guard for saved IDs, new aliases and provider argv.
|
|
22
|
-
* This is a permanent exact-target denial, independent of journal availability. */
|
|
23
|
-
export function assertRecoveryLaunchIdentity(value: unknown): void {
|
|
24
|
-
if (!value || typeof value !== 'object') return;
|
|
25
|
-
const identities = new Set(['sessionId', 'runtimeId', 'runtimeSessionId', 'providerSessionId',
|
|
26
|
-
'presetSessionKey', 'resumeSessionId', 'key']);
|
|
27
|
-
const nested = new Set(['options', 'meta', 'settings', 'settingsOverride', 'restartBinding', 'sessionBinding', 'launchCommand']);
|
|
28
|
-
for (const [key, field] of Object.entries(value)) {
|
|
29
|
-
if (identities.has(key) || ['args', 'cliArgs', 'cliArgsWithBrain'].includes(key)) {
|
|
30
|
-
const bytes = JSON.stringify(field)?.toLowerCase();
|
|
31
|
-
if (bytes?.includes(OPERATOR_RECOVERY_TARGET.sessionId) || bytes?.includes(OPERATOR_RECOVERY_TARGET.providerSessionId)) {
|
|
32
|
-
throw new Error('operator_recovery_fenced');
|
|
33
|
-
}
|
|
34
|
-
} else if (nested.has(key)) assertRecoveryLaunchIdentity(field);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export type RecoveryOwnerOperation = 'anchor_recover' | 'fence_install' | 'witness_enroll';
|
|
38
|
-
export interface RecoveryOwnerGrant { readonly purpose: 'operator_recovery_v1'; readonly operation: RecoveryOwnerOperation }
|
|
39
|
-
export function isRecoveryEndpoint(endpoint: string): boolean {
|
|
40
|
-
return isAbsolute(endpoint) && basename(endpoint) === `adhdev-preview-session-host-${OPERATOR_RECOVERY_TARGET.namespace}.sock`;
|
|
41
|
-
}
|
|
42
|
-
export interface RecoveryOwnerChallenge { readonly message: string }
|
|
43
|
-
export interface RecoveryOwnerEnrollment {
|
|
44
|
-
/** Trusted boot dependency, provisioned outside delegated worker authority.
|
|
45
|
-
* Do not load this from daemon config, IPC arguments or an MCP credential. */
|
|
46
|
-
publicKey: string;
|
|
47
|
-
enrollmentId: string;
|
|
48
|
-
coordinatorBootId: string;
|
|
49
|
-
authEpoch: string;
|
|
50
|
-
verifyCurrent: () => boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Signature possession authenticates the separately enrolled owner signer.
|
|
54
|
-
* This verifier does not enroll keys or assert user presence on their behalf. */
|
|
55
|
-
export class RecoveryOwnerAdmission {
|
|
56
|
-
private readonly key: KeyObject;
|
|
57
|
-
private readonly enrollment: Readonly<RecoveryOwnerEnrollment>;
|
|
58
|
-
private readonly pending = new Map<string, { deadline: number; operation: RecoveryOwnerOperation }>();
|
|
59
|
-
private readonly grants = new WeakMap<object, { deadline: number; operation: RecoveryOwnerOperation }>();
|
|
60
|
-
private lastNow = -Infinity;
|
|
61
|
-
constructor(enrollment: RecoveryOwnerEnrollment, private readonly clock = () => performance.now()) {
|
|
62
|
-
this.enrollment = Object.freeze({ ...enrollment });
|
|
63
|
-
if (!enrollment.enrollmentId || !enrollment.coordinatorBootId || !enrollment.authEpoch ||
|
|
64
|
-
typeof enrollment.verifyCurrent !== 'function') throw new Error('recovery_owner_enrollment_required');
|
|
65
|
-
this.key = createPublicKey(enrollment.publicKey);
|
|
66
|
-
if (this.key.asymmetricKeyType !== 'ed25519') throw new Error('recovery_owner_key_type');
|
|
67
|
-
}
|
|
68
|
-
private now(): number {
|
|
69
|
-
const n = this.clock();
|
|
70
|
-
if (!Number.isFinite(n) || n < this.lastNow || this.enrollment.verifyCurrent() !== true) {
|
|
71
|
-
this.pending.clear();
|
|
72
|
-
this.lastNow = Infinity; // A revocation or clock rollback cannot be undone.
|
|
73
|
-
throw new Error('recovery_owner_revoked');
|
|
74
|
-
}
|
|
75
|
-
this.lastNow = n;
|
|
76
|
-
return n;
|
|
77
|
-
}
|
|
78
|
-
challenge(operation: RecoveryOwnerOperation = 'anchor_recover'): RecoveryOwnerChallenge {
|
|
79
|
-
if (!['anchor_recover', 'fence_install', 'witness_enroll'].includes(operation)) throw new Error('recovery_owner_operation_rejected');
|
|
80
|
-
const now = this.now();
|
|
81
|
-
for (const [message, entry] of this.pending) if (entry.deadline <= now) this.pending.delete(message);
|
|
82
|
-
if (this.pending.size >= 16) throw new Error('recovery_owner_challenge_limit');
|
|
83
|
-
const message = JSON.stringify(['operator_recovery_v1', operation, recoveryTargetBytes,
|
|
84
|
-
this.enrollment.enrollmentId, this.enrollment.coordinatorBootId, this.enrollment.authEpoch,
|
|
85
|
-
randomBytes(32).toString('hex')]);
|
|
86
|
-
this.pending.set(message, { deadline: now + 30_000, operation });
|
|
87
|
-
return Object.freeze({ message });
|
|
88
|
-
}
|
|
89
|
-
authorize(message: string, signature: string): RecoveryOwnerGrant {
|
|
90
|
-
const now = this.now();
|
|
91
|
-
const entry = this.pending.get(message);
|
|
92
|
-
this.pending.delete(message); // Every verification attempt burns the challenge.
|
|
93
|
-
if (!entry || now >= entry.deadline || !/^[a-f0-9]{128}$/.test(signature) ||
|
|
94
|
-
!verify(null, Buffer.from(message), this.key, Buffer.from(signature, 'hex'))) {
|
|
95
|
-
throw new Error('recovery_owner_signature_rejected');
|
|
96
|
-
}
|
|
97
|
-
const grant = Object.freeze({ purpose: 'operator_recovery_v1' as const, operation: entry.operation });
|
|
98
|
-
this.grants.set(grant, entry);
|
|
99
|
-
return grant;
|
|
100
|
-
}
|
|
101
|
-
assertGrant(grant: unknown): asserts grant is RecoveryOwnerGrant {
|
|
102
|
-
const now = this.now();
|
|
103
|
-
const entry = typeof grant === 'object' && grant !== null ? this.grants.get(grant) : undefined;
|
|
104
|
-
if (!entry || now >= entry.deadline) throw new Error('recovery_owner_grant_rejected');
|
|
105
|
-
}
|
|
106
|
-
/** Burn synchronously before any work or await. The private continuation
|
|
107
|
-
* rechecks the ORIGINAL deadline and revocation; it cannot mint a new grant. */
|
|
108
|
-
reserve(grant: unknown, operation: RecoveryOwnerOperation): () => void {
|
|
109
|
-
this.assertGrant(grant);
|
|
110
|
-
const entry = this.grants.get(grant as object)!;
|
|
111
|
-
this.grants.delete(grant as object);
|
|
112
|
-
if (entry.operation !== operation) throw new Error('recovery_owner_operation_rejected');
|
|
113
|
-
return () => {
|
|
114
|
-
if (this.now() >= entry.deadline) throw new Error('recovery_owner_grant_rejected');
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
consume(grant: unknown): void {
|
|
118
|
-
this.assertGrant(grant);
|
|
119
|
-
this.grants.delete(grant as object);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface RecoveryHostBinding {
|
|
124
|
-
namespace: string; endpoint: string; hostBootId: string; workerDaemonId: string;
|
|
125
|
-
}
|
|
126
|
-
export interface RecoveryPhysicalProof extends RecoveryHostBinding {
|
|
127
|
-
protocol: 1;
|
|
128
|
-
verdict: 'ABSENT' | 'LIVE' | 'UNKNOWN';
|
|
129
|
-
reason: string;
|
|
130
|
-
nonce: string;
|
|
131
|
-
fenceDigest: string;
|
|
132
|
-
sessionId: string;
|
|
133
|
-
providerSessionId: string;
|
|
134
|
-
}
|