session-peer 0.5.1 → 0.6.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.
Files changed (52) hide show
  1. package/CONTRIBUTING.md +26 -0
  2. package/PARITY.md +134 -4
  3. package/README.ja.md +12 -8
  4. package/README.ko.md +12 -8
  5. package/README.md +12 -8
  6. package/README.zh-CN.md +12 -8
  7. package/RELEASING.md +142 -0
  8. package/VALIDATION.md +154 -2
  9. package/dist/app-server.d.ts +10 -2
  10. package/dist/app-server.js +115 -53
  11. package/dist/cli.js +54 -4
  12. package/dist/codex-storage.d.ts +46 -0
  13. package/dist/codex-storage.js +447 -0
  14. package/dist/diagnostics.js +23 -102
  15. package/dist/discovery.d.ts +32 -1
  16. package/dist/discovery.js +405 -89
  17. package/dist/handoff-operations.js +40 -10
  18. package/dist/help.js +18 -2
  19. package/dist/macos-acl.d.ts +10 -0
  20. package/dist/macos-acl.js +75 -0
  21. package/dist/output.js +6 -1
  22. package/dist/process.d.ts +1 -0
  23. package/dist/process.js +1 -1
  24. package/dist/protocol.d.ts +2 -2
  25. package/dist/protocol.js +1 -1
  26. package/dist/receipt-collector.d.ts +12 -0
  27. package/dist/receipt-collector.js +283 -0
  28. package/dist/receipt-command.d.ts +10 -0
  29. package/dist/receipt-command.js +246 -0
  30. package/dist/receipt-producer.d.ts +7 -0
  31. package/dist/receipt-producer.js +107 -0
  32. package/dist/receipt-protocol.d.ts +219 -0
  33. package/dist/receipt-protocol.js +374 -0
  34. package/dist/receipt-send.d.ts +26 -0
  35. package/dist/receipt-send.js +375 -0
  36. package/dist/receipt-state.d.ts +89 -0
  37. package/dist/receipt-state.js +503 -0
  38. package/dist/receipt-store.d.ts +32 -0
  39. package/dist/receipt-store.js +286 -0
  40. package/dist/replies.js +3 -1
  41. package/dist/send.d.ts +14 -3
  42. package/dist/send.js +165 -63
  43. package/dist/skill-metadata.js +5 -3
  44. package/docs/api.md +155 -7
  45. package/docs/design/remote-deployment.md +8 -0
  46. package/docs/design/typescript-skill-compatibility.md +50 -0
  47. package/docs/guide.ja.md +47 -15
  48. package/docs/guide.ko.md +50 -19
  49. package/docs/guide.md +48 -16
  50. package/docs/guide.zh-CN.md +47 -15
  51. package/docs/shorthand.md +1 -1
  52. package/package.json +5 -3
@@ -0,0 +1,246 @@
1
+ // Explicit owner commands for the local receipt-only collector. This module
2
+ // never launches programs, submits native input or discovers another endpoint.
3
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
4
+ import { lstatSync, realpathSync } from 'node:fs';
5
+ import { setTimeout as delay } from 'node:timers/promises';
6
+ import { Refusal } from './discovery.js';
7
+ import { HandoffBudget, canonicalId, parseWaitTimeout, safeId } from './handoff.js';
8
+ import { ReceiptState } from './receipt-state.js';
9
+ import { receiptExchange, startReceiptCollector } from './receipt-collector.js';
10
+ import { RECEIPT_LIMITS, parseProducerProbeRequest, publicReceiptError, validateManagedHandoff, validateManagedReceipt } from './receipt-protocol.js';
11
+ import { VERSION } from './protocol.js';
12
+ const operations = ['init', 'serve', 'respond', 'status', 'wait', 'revoke', 'probe'];
13
+ function fail(code, exit = 2) { throw new Refusal(code, exit); }
14
+ function options(args) {
15
+ if (args[0] !== 'receipt' || !operations.includes(args[1]))
16
+ fail('unsupported_receipt_command');
17
+ const operation = args[1], values = new Map();
18
+ let json = false;
19
+ const names = ['--state-dir', '--collector', '--ledger-epoch', '--correlation-id', '--wait-timeout', '--receipt'];
20
+ for (let i = 2; i < args.length; i++) {
21
+ const token = args[i], equal = token.indexOf('='), key = equal < 0 ? token : token.slice(0, equal);
22
+ if (key === '--json') {
23
+ if (json || equal >= 0)
24
+ fail('invalid_option');
25
+ json = true;
26
+ continue;
27
+ }
28
+ if (!names.includes(key))
29
+ fail('unsupported_option');
30
+ if (values.has(key))
31
+ fail('invalid_option');
32
+ const value = equal < 0 ? args[++i] : token.slice(equal + 1);
33
+ if (value === undefined || (equal < 0 && value.startsWith('--')))
34
+ fail('invalid_option');
35
+ values.set(key, value);
36
+ }
37
+ if (!json)
38
+ fail('json_output_required');
39
+ const allowed = {
40
+ init: ['--state-dir', '--collector'], serve: ['--state-dir', '--collector'],
41
+ respond: ['--collector', '--receipt'], status: ['--collector', '--ledger-epoch', '--correlation-id'],
42
+ wait: ['--collector', '--ledger-epoch', '--correlation-id', '--wait-timeout'],
43
+ revoke: ['--collector', '--ledger-epoch', '--correlation-id'], probe: []
44
+ };
45
+ if ([...values.keys()].some(key => !allowed[operation].includes(key)))
46
+ fail('inapplicable_option');
47
+ return { operation, values };
48
+ }
49
+ function absolute(value, code, maximum = 4096) {
50
+ if (!safeId(value, maximum) || !isAbsolute(value) || resolve(value) !== value)
51
+ fail(code);
52
+ return value;
53
+ }
54
+ function success(response) {
55
+ if (!response.ok)
56
+ throw new Refusal(response.error, 1);
57
+ return response.body;
58
+ }
59
+ function unknown(error, handoff, exit = 1) {
60
+ if (!(error instanceof Refusal) || error.code !== 'receipt_transport_unknown')
61
+ return undefined;
62
+ return { value: { ok: false, status: 'unknown', error: 'receipt_transport_unknown', retryAllowed: false,
63
+ ...(handoff ? { handoff } : {}) }, exitCode: exit };
64
+ }
65
+ function waitResult(handoff) {
66
+ const satisfied = handoff.wait.status === 'satisfied';
67
+ return { value: { ok: satisfied, handoff }, exitCode: satisfied ? 0 : handoff.wait.status === 'stopped' && handoff.wait.reason === 'stopped_by_operator' ? 130 : 1 };
68
+ }
69
+ async function privateInput(readInput) {
70
+ let raw;
71
+ try {
72
+ raw = await readInput(RECEIPT_LIMITS.privateFrame, true, RECEIPT_LIMITS.readMs);
73
+ }
74
+ catch {
75
+ throw new Refusal('invalid_receipt_protocol', 1);
76
+ }
77
+ if (typeof raw !== 'string')
78
+ throw new Refusal('invalid_receipt_protocol', 1);
79
+ if (Buffer.byteLength(raw, 'utf8') > RECEIPT_LIMITS.privateFrame)
80
+ throw new Refusal('receipt_frame_too_large', 1);
81
+ return raw;
82
+ }
83
+ function platform() {
84
+ if (process.platform === 'win32' || process.getuid?.() === undefined)
85
+ throw new Refusal('receipt_storage_unsupported', 1);
86
+ }
87
+ // Initialization may create only its explicitly selected leaf. Reject an alias
88
+ // before creating files that could not later pass the collector endpoint guard.
89
+ function statePath(value) {
90
+ const path = absolute(value, 'invalid_receipt_state');
91
+ try {
92
+ let present = true;
93
+ try {
94
+ lstatSync(path);
95
+ }
96
+ catch (error) {
97
+ if (error.code === 'ENOENT')
98
+ present = false;
99
+ else
100
+ throw error;
101
+ }
102
+ const existing = present ? path : dirname(path);
103
+ if (realpathSync(existing) !== existing)
104
+ throw new Error();
105
+ }
106
+ catch {
107
+ throw new Refusal('receipt_storage_untrusted', 1);
108
+ }
109
+ return path;
110
+ }
111
+ async function wait(socket, epoch, id, seconds) {
112
+ const budget = new HandoffBudget(seconds);
113
+ let interrupted = false, stopAttempted = false;
114
+ let latest, original;
115
+ let context, operationId;
116
+ const selector = { ledgerEpoch: epoch, correlationId: id };
117
+ const stop = () => { interrupted = true; };
118
+ const accept = (value) => {
119
+ const next = validateManagedHandoff(value);
120
+ if (next.ledgerEpoch !== epoch || next.correlationId !== id || next.wait.for !== 'acknowledged' || !canonicalId(next.wait.operationId))
121
+ throw new Refusal('invalid_receipt_protocol', 1);
122
+ if (original && (next.schemaVersion !== original.schemaVersion || next.targetGeneration !== original.targetGeneration ||
123
+ next.wait.operationId !== operationId || next.wait.deadlineAtUtcMs !== original.wait.deadlineAtUtcMs ||
124
+ (original.schemaVersion === 2 && (next.schemaVersion !== 2 || next.receiptContext.id !== original.receiptContext.id))))
125
+ throw new Refusal('receipt_binding_conflict', 1);
126
+ if (!original) {
127
+ original = structuredClone(next);
128
+ operationId = next.wait.operationId;
129
+ }
130
+ return next;
131
+ };
132
+ const retained = (error) => ({ value: { ok: false, status: 'unknown',
133
+ error: publicReceiptError(error), retryAllowed: false, ...(latest ? { handoff: latest } : {}) }, exitCode: latest?.wait.status === 'stopped' && latest.wait.reason === 'stopped_by_operator' ? 130 : 1 });
134
+ process.on('SIGINT', stop);
135
+ process.on('SIGTERM', stop);
136
+ try {
137
+ const hello = await receiptExchange(socket, null, 'hello', {}, budget.remainingMs());
138
+ const remainingMs = Math.floor(budget.remainingMs()), capabilities = success(hello);
139
+ context = hello.collectorContextId;
140
+ if (!('clockReferenceMs' in capabilities) || remainingMs < 1)
141
+ throw new Refusal('deadline_before_effect', 1);
142
+ const opened = success(await receiptExchange(socket, context, 'wait-open', { ...selector, goal: 'acknowledged', timeoutSeconds: seconds, clockReferenceMs: capabilities.clockReferenceMs, remainingMs }, budget.remainingMs()));
143
+ latest = accept(opened.handoff);
144
+ while (latest.wait.status === 'pending') {
145
+ if (budget.remainingMs() <= 0)
146
+ return retained(new Refusal('receipt_transport_unknown', 1));
147
+ if (interrupted && !stopAttempted) {
148
+ stopAttempted = true;
149
+ latest = accept(success(await receiptExchange(socket, context, 'wait-stop', { ...selector, operationId: operationId }, budget.remainingMs())).handoff);
150
+ return waitResult(latest);
151
+ }
152
+ await delay(Math.min(100, Math.max(1, budget.remainingMs())));
153
+ if (interrupted)
154
+ continue;
155
+ latest = accept(success(await receiptExchange(socket, context, 'wait-status', { ...selector, operationId: operationId }, budget.remainingMs())).handoff);
156
+ }
157
+ return waitResult(latest);
158
+ }
159
+ catch (error) {
160
+ // A terminal actor result may win the race against the explicit stop. Read
161
+ // that same operation once; do not retry stop, renew a wait or adopt an owner.
162
+ if (latest && stopAttempted && error instanceof Refusal && error.code === 'receipt_wait_terminal' &&
163
+ context && operationId && budget.remainingMs() > 0) {
164
+ try {
165
+ const terminal = accept(success(await receiptExchange(socket, context, 'wait-status', { ...selector, operationId }, budget.remainingMs())).handoff);
166
+ if (terminal.wait.status !== 'pending') {
167
+ latest = terminal;
168
+ return waitResult(terminal);
169
+ }
170
+ }
171
+ catch (readError) {
172
+ return retained(readError);
173
+ }
174
+ }
175
+ if (latest)
176
+ return retained(error);
177
+ const result = unknown(error, undefined, 1);
178
+ if (result)
179
+ return result;
180
+ if (interrupted)
181
+ return { value: { ok: false, error: publicReceiptError(error), retryAllowed: false }, exitCode: 1 };
182
+ throw error;
183
+ }
184
+ finally {
185
+ process.removeListener('SIGINT', stop);
186
+ process.removeListener('SIGTERM', stop);
187
+ }
188
+ }
189
+ export async function receiptCommand(args, readInput) {
190
+ const { operation, values } = options(args);
191
+ if (operation === 'probe') {
192
+ const request = parseProducerProbeRequest(await privateInput(readInput));
193
+ return { value: { ...request, implementation: 'typescript', runtimeVersion: VERSION }, exitCode: 0, raw: true };
194
+ }
195
+ platform();
196
+ if (operation === 'init' || operation === 'serve') {
197
+ const state = statePath(values.get('--state-dir'));
198
+ const socket = absolute(values.get('--collector') ?? join(state, 's'), 'receipt_endpoint_untrusted', 100);
199
+ if (dirname(socket) !== state)
200
+ throw new Refusal('receipt_endpoint_untrusted', 1);
201
+ if (operation === 'init')
202
+ return { value: { ...ReceiptState.initialize(state, socket), collector: socket }, exitCode: 0 };
203
+ const collector = await startReceiptCollector(state, socket);
204
+ return { value: { status: 'ready', collector: socket, collectorContextId: collector.contextId,
205
+ ledgerEpoch: collector.ledgerEpoch }, exitCode: 0, collector };
206
+ }
207
+ const socket = absolute(values.get('--collector'), 'receipt_endpoint_untrusted', 100);
208
+ if (operation === 'respond') {
209
+ if (values.get('--receipt') !== '-')
210
+ fail('private_receipt_stdin_required');
211
+ const raw = await privateInput(readInput), receipt = validateManagedReceipt(raw);
212
+ try {
213
+ const hello = await receiptExchange(socket, null, 'hello', {}), capabilities = success(hello);
214
+ const scope = receipt.schemaVersion === 1 ? 'original_generation' : 'delegated_context';
215
+ if (!capabilities.receiptSchemas.some((pair) => pair.receiptSchemaVersion === receipt.schemaVersion && pair.receiptScope === scope))
216
+ throw new Refusal('receipt_scope_unsupported', 1);
217
+ const result = success(await receiptExchange(socket, hello.collectorContextId, 'receipt', { receipt: raw }));
218
+ return { value: result, exitCode: 0 };
219
+ }
220
+ catch (error) {
221
+ const result = unknown(error);
222
+ if (result)
223
+ return result;
224
+ throw error;
225
+ }
226
+ }
227
+ const epoch = values.get('--ledger-epoch'), id = values.get('--correlation-id');
228
+ if (!canonicalId(epoch))
229
+ fail('invalid_ledger_epoch');
230
+ if (!canonicalId(id))
231
+ fail('invalid_correlation_id');
232
+ if (operation === 'wait')
233
+ return wait(socket, epoch, id, parseWaitTimeout(values.get('--wait-timeout') ?? '30'));
234
+ try {
235
+ const hello = await receiptExchange(socket, null, 'hello', {});
236
+ success(hello);
237
+ const result = success(await receiptExchange(socket, hello.collectorContextId, operation, { ledgerEpoch: epoch, correlationId: id }));
238
+ return { value: result, exitCode: 0 };
239
+ }
240
+ catch (error) {
241
+ const result = unknown(error);
242
+ if (result)
243
+ return result;
244
+ throw error;
245
+ }
246
+ }
@@ -0,0 +1,7 @@
1
+ import { type ProducerEvidence, type ReceiptPair } from './receipt-protocol.js';
2
+ export declare function validateReceiptProducer(pair: ReceiptPair, options?: {
3
+ timeoutMs?: number;
4
+ }): Promise<{
5
+ evidence: ProducerEvidence;
6
+ revalidate(): void;
7
+ }>;
@@ -0,0 +1,107 @@
1
+ // Local artifact continuity and a private nonce challenge; this is not code authentication.
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { closeSync, constants, fstatSync, lstatSync, openSync, opendirSync, readSync, realpathSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { Refusal } from './discovery.js';
7
+ import { inspectMacosAcls } from './macos-acl.js';
8
+ import { run } from './process.js';
9
+ import { VERSION } from './protocol.js';
10
+ import { parseProducerProbeResponse } from './receipt-protocol.js';
11
+ const fail = () => { throw new Refusal('receipt_producer_mismatch', 1); };
12
+ const identity = (s) => [s.dev, s.ino, s.uid, s.mode, s.size, s.mtimeMs, s.ctimeMs, s.birthtimeMs].join(':');
13
+ export async function validateReceiptProducer(pair, options = {}) {
14
+ const entry = fileURLToPath(new URL('./cli.js', import.meta.url)), directory = dirname(entry), node = realpathSync(process.execPath);
15
+ const pinned = new Map(), hash = createHash('sha256');
16
+ const inspect = (path, directory = false) => {
17
+ const stat = lstatSync(path);
18
+ if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile()) ||
19
+ ![0, process.getuid?.()].includes(stat.uid) || (stat.mode & 0o022) !== 0)
20
+ fail();
21
+ return stat;
22
+ };
23
+ try {
24
+ pinned.set(directory, identity(inspect(directory, true)));
25
+ pinned.set(node, identity(inspect(node)));
26
+ const names = [], listing = opendirSync(directory);
27
+ try {
28
+ let count = 0;
29
+ for (;;) {
30
+ const item = listing.readSync();
31
+ if (!item)
32
+ break;
33
+ if (++count > 128)
34
+ fail();
35
+ if (item.name.endsWith('.js'))
36
+ names.push(item.name);
37
+ }
38
+ }
39
+ finally {
40
+ listing.closeSync();
41
+ }
42
+ names.sort();
43
+ if (!names.length || !names.includes('cli.js'))
44
+ fail();
45
+ let total = 0;
46
+ for (const name of names) {
47
+ const path = join(directory, name), stat = inspect(path);
48
+ if (stat.size > 4 * 1024 * 1024 || total + stat.size > 16 * 1024 * 1024)
49
+ fail();
50
+ const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
51
+ try {
52
+ if (identity(fstatSync(fd)) !== identity(stat))
53
+ fail();
54
+ const buffer = Buffer.alloc(stat.size + 1);
55
+ let length = 0;
56
+ while (length < buffer.length) {
57
+ const got = readSync(fd, buffer, length, buffer.length - length, null);
58
+ if (!got)
59
+ break;
60
+ length += got;
61
+ }
62
+ total += length;
63
+ if (length !== stat.size || total > 16 * 1024 * 1024 || identity(fstatSync(fd)) !== identity(stat) || identity(inspect(path)) !== identity(stat))
64
+ fail();
65
+ const bytes = buffer.subarray(0, length);
66
+ hash.update(name).update('\0').update(bytes);
67
+ pinned.set(path, identity(stat));
68
+ }
69
+ finally {
70
+ closeSync(fd);
71
+ }
72
+ }
73
+ const revalidate = () => {
74
+ try {
75
+ for (const [path, value] of pinned)
76
+ if (identity(inspect(path, path === directory)) !== value)
77
+ fail();
78
+ if (process.platform === 'darwin' && inspectMacosAcls([...pinned.keys()]) !== 'clear')
79
+ fail();
80
+ for (const [path, value] of pinned)
81
+ if (identity(inspect(path, path === directory)) !== value)
82
+ fail();
83
+ }
84
+ catch {
85
+ fail();
86
+ }
87
+ };
88
+ revalidate();
89
+ const challenge = { producerProtocolVersion: 1, challengeId: randomUUID(), receiptSchemaVersion: pair.receiptSchemaVersion, receiptScope: pair.receiptScope };
90
+ const timeout = Math.min(2000, Math.floor(options.timeoutMs ?? 2000));
91
+ if (timeout < 1)
92
+ fail();
93
+ const result = await run(node, [entry, 'receipt', 'probe', '--json'], { input: JSON.stringify(challenge) + '\n', timeout, limit: 4096, rawStdout: true,
94
+ env: { PATH: '/usr/bin:/bin', LANG: 'C', LC_ALL: 'C' } });
95
+ if (result.interrupted || result.code !== 0 || !result.spawned || result.stderr.length)
96
+ fail();
97
+ const response = parseProducerProbeResponse(result.stdoutBytes ?? Buffer.from(result.stdout), challenge);
98
+ if (response.runtimeVersion !== VERSION || response.implementation !== 'typescript')
99
+ fail();
100
+ revalidate();
101
+ return { evidence: { protocolVersion: 1, artifactSha256: hash.digest('hex'), challengeId: challenge.challengeId,
102
+ receiptSchemaVersion: pair.receiptSchemaVersion, receiptScope: pair.receiptScope }, revalidate };
103
+ }
104
+ catch {
105
+ return fail();
106
+ }
107
+ }
@@ -0,0 +1,219 @@
1
+ import { type Handoff, type Receipt } from './handoff.js';
2
+ export declare const RECEIPT_LIMITS: Readonly<{
3
+ frame: 16384;
4
+ privateFrame: 4096;
5
+ depth: 16;
6
+ nodes: 1024;
7
+ connections: 16;
8
+ readMs: 2000;
9
+ writeMs: 2000;
10
+ exchangeMs: 5000;
11
+ activeWaits: 128;
12
+ }>;
13
+ export type ReceiptScope = 'original_generation' | 'delegated_context';
14
+ export type ReceiptPair = {
15
+ agent: 'codex';
16
+ receiptSchemaVersion: 1;
17
+ receiptScope: 'original_generation';
18
+ } | {
19
+ agent: 'claude';
20
+ receiptSchemaVersion: 2;
21
+ receiptScope: 'delegated_context';
22
+ };
23
+ export declare const RECEIPT_PAIRS: readonly ReceiptPair[];
24
+ export type ReceiptBinding = {
25
+ agent: 'codex';
26
+ destination: string;
27
+ target: string;
28
+ home: string;
29
+ writerIdentity: string;
30
+ generation: string;
31
+ payloadDigest: string;
32
+ } | {
33
+ agent: 'claude';
34
+ destination: string;
35
+ target: string;
36
+ registryDirectory: string;
37
+ registryRecordPath: string;
38
+ registryIdentity: string;
39
+ socketPath: string;
40
+ routeIdentity: string;
41
+ generation: null;
42
+ payloadDigest: string;
43
+ };
44
+ export type ProducerEvidence = {
45
+ protocolVersion: 1;
46
+ artifactSha256: string;
47
+ challengeId: string;
48
+ receiptSchemaVersion: 1 | 2;
49
+ receiptScope: ReceiptScope;
50
+ };
51
+ export type ReceiptV2 = {
52
+ schemaVersion: 2;
53
+ kind: 'receipt';
54
+ receiptScope: 'delegated_context';
55
+ ledgerEpoch: string;
56
+ correlationId: string;
57
+ receiptContextId: string;
58
+ receiptId: string;
59
+ capability: string;
60
+ };
61
+ export type ManagedReceipt = Receipt | ReceiptV2;
62
+ export type HandoffV2 = Omit<Handoff, 'schemaVersion' | 'targetGeneration'> & {
63
+ schemaVersion: 2;
64
+ targetGeneration: null;
65
+ receiptContext: {
66
+ kind: 'delegated_context';
67
+ id: string;
68
+ };
69
+ };
70
+ export type ManagedHandoff = Handoff | HandoffV2;
71
+ export type ReceiptHandle = {
72
+ ledgerEpoch: string;
73
+ correlationId: string;
74
+ receiptContextId: string | null;
75
+ };
76
+ export type ReceiptRequestBody = {
77
+ hello: Record<string, never>;
78
+ prepare: {
79
+ binding: ReceiptBinding;
80
+ receiptSchemaVersion: 1 | 2;
81
+ receiptScope: ReceiptScope;
82
+ producerEvidence: ProducerEvidence;
83
+ };
84
+ mint: ReceiptHandle & {
85
+ producerProtocolVersion: 1;
86
+ };
87
+ fence: ReceiptHandle & {
88
+ binding: ReceiptBinding;
89
+ };
90
+ submission: ReceiptHandle & {
91
+ status: 'submitted' | 'refused' | 'unknown';
92
+ };
93
+ status: {
94
+ ledgerEpoch: string;
95
+ correlationId: string;
96
+ };
97
+ 'wait-open': {
98
+ ledgerEpoch: string;
99
+ correlationId: string;
100
+ goal: 'acknowledged';
101
+ timeoutSeconds: number;
102
+ clockReferenceMs: number;
103
+ remainingMs: number;
104
+ };
105
+ 'wait-status': {
106
+ ledgerEpoch: string;
107
+ correlationId: string;
108
+ operationId: string;
109
+ };
110
+ 'wait-stop': {
111
+ ledgerEpoch: string;
112
+ correlationId: string;
113
+ operationId: string;
114
+ };
115
+ revoke: {
116
+ ledgerEpoch: string;
117
+ correlationId: string;
118
+ };
119
+ receipt: {
120
+ receipt: string;
121
+ };
122
+ };
123
+ export type ReceiptOperation = keyof ReceiptRequestBody;
124
+ export type ReceiptRequest = {
125
+ [K in ReceiptOperation]: {
126
+ ipcVersion: 2;
127
+ requestId: string;
128
+ collectorContextId: K extends 'hello' ? null : string;
129
+ op: K;
130
+ body: ReceiptRequestBody[K];
131
+ };
132
+ }[ReceiptOperation];
133
+ export type ReceiptResponseBody = {
134
+ hello: {
135
+ clockReferenceMs: number;
136
+ receiptSchemas: ReceiptPair[];
137
+ managedStoreVersion: 2;
138
+ endpointOwner: {
139
+ uid: number;
140
+ pid: number;
141
+ };
142
+ };
143
+ prepare: ReceiptHandle & {
144
+ handoff: ManagedHandoff;
145
+ };
146
+ mint: {
147
+ capability: string;
148
+ };
149
+ fence: {
150
+ handoff: ManagedHandoff;
151
+ };
152
+ submission: {
153
+ handoff: ManagedHandoff;
154
+ };
155
+ status: {
156
+ handoff: ManagedHandoff;
157
+ };
158
+ 'wait-open': {
159
+ handoff: ManagedHandoff;
160
+ };
161
+ 'wait-status': {
162
+ handoff: ManagedHandoff;
163
+ };
164
+ 'wait-stop': {
165
+ handoff: ManagedHandoff;
166
+ };
167
+ revoke: {
168
+ handoff: ManagedHandoff;
169
+ };
170
+ receipt: {
171
+ status: 'awaiting_submission' | 'acknowledged';
172
+ ledgerEpoch: string;
173
+ correlationId: string;
174
+ receiptId: string;
175
+ handoff: ManagedHandoff;
176
+ };
177
+ };
178
+ export type ReceiptResponse = {
179
+ ipcVersion: 2;
180
+ requestId: string;
181
+ collectorContextId: string;
182
+ } & ({
183
+ ok: true;
184
+ body: ReceiptResponseBody[ReceiptOperation];
185
+ } | {
186
+ ok: false;
187
+ error: ReceiptErrorCode;
188
+ });
189
+ export declare const RECEIPT_ERROR_CODES: readonly ["invalid_receipt_protocol", "invalid_handoff_json", "handoff_frame_too_large", "invalid_receipt", "invalid_handoff", "receipt_ipc_version_unsupported", "receipt_schema_unsupported", "receipt_scope_unsupported", "receipt_storage_unsupported", "receipt_storage_untrusted", "receipt_history_unavailable", "receipt_history_changed", "receipt_history_corrupt", "receipt_state_exists", "receipt_collector_busy", "receipt_collector_closed", "receipt_collector_error", "receipt_collector_unavailable", "receipt_ledger_full", "receipt_id_unknown", "receipt_epoch_mismatch", "receipt_binding_conflict", "receipt_scope_mismatch", "receipt_authority_unavailable", "receipt_authority_expired", "receipt_authentication_failed", "receipt_already_committed", "receipt_candidate_conflict", "receipt_already_attempted", "receipt_outcome_not_authorized", "receipt_wait_quota", "receipt_wait_unknown", "receipt_wait_terminal", "receipt_context_mismatch", "receipt_producer_mismatch", "receipt_history_quarantined", "receipt_bootstrap_unsupported", "receipt_managed_context_required", "receipt_endpoint_untrusted", "receipt_endpoint_changed", "receipt_endpoint_exists", "receipt_endpoint_busy", "receipt_transport_unknown", "receipt_frame_too_large", "receipt_transport_timeout", "insufficient_budget", "deadline_before_effect"];
190
+ export type ReceiptErrorCode = typeof RECEIPT_ERROR_CODES[number];
191
+ export declare function isReceiptErrorCode(value: unknown): value is ReceiptErrorCode;
192
+ export declare function publicReceiptError(error: unknown): ReceiptErrorCode;
193
+ export declare function validateReceiptPair(agent: unknown, version: unknown, scope: unknown): ReceiptPair;
194
+ export declare function validateBinding(value: unknown): ReceiptBinding;
195
+ export declare const validateReceiptBinding: typeof validateBinding;
196
+ export declare function validateProducerEvidence(value: unknown): ProducerEvidence;
197
+ export declare function validateReceiptV2(raw: string | Uint8Array): ReceiptV2;
198
+ export declare function validateManagedReceipt(raw: string | Uint8Array): ManagedReceipt;
199
+ export declare function validateHandoffV2(value: unknown): HandoffV2;
200
+ export declare function validateManagedHandoff(value: unknown): ManagedHandoff;
201
+ export declare function parseManagedHandoff(raw: string | Uint8Array): ManagedHandoff;
202
+ export declare function validateReceiptRequest(value: unknown): ReceiptRequest;
203
+ export declare function parseReceiptRequest(raw: string | Uint8Array): ReceiptRequest;
204
+ export declare function validateReceiptResponse(value: unknown, request: ReceiptRequest): ReceiptResponse;
205
+ export declare function parseReceiptResponse(raw: string | Uint8Array, request: ReceiptRequest): ReceiptResponse;
206
+ export type ProducerProbeRequest = {
207
+ producerProtocolVersion: 1;
208
+ challengeId: string;
209
+ receiptSchemaVersion: 1 | 2;
210
+ receiptScope: ReceiptScope;
211
+ };
212
+ export type ProducerProbeResponse = ProducerProbeRequest & {
213
+ implementation: 'typescript';
214
+ runtimeVersion: string;
215
+ };
216
+ export declare function validateProducerProbeRequest(value: unknown): ProducerProbeRequest;
217
+ export declare function validateProducerProbeResponse(value: unknown, request: ProducerProbeRequest): ProducerProbeResponse;
218
+ export declare function parseProducerProbeRequest(raw: string | Uint8Array): ProducerProbeRequest;
219
+ export declare function parseProducerProbeResponse(raw: string | Uint8Array, request: ProducerProbeRequest): ProducerProbeResponse;