@openplanr/protocol 0.6.0 → 0.6.2
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/lib/dashboard/closed-json-contract.mjs +99 -109
- package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
- package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
- package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
- package/lib/dashboard/operate-experience-display-contract.mjs +768 -831
- package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
- package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
- package/lib/dashboard/operate-review-contract.d.mts +7 -14
- package/lib/dashboard/operate-review-contract.mjs +46 -42
- package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
- package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
- package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
- package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
- package/lib/protocol/index.d.ts +2647 -543
- package/package.json +1 -1
- package/registries/commands.json +7 -7
- package/registries/skills.json +6 -6
- package/src/browser-contracts.d.mts +4 -1
- package/src/browser-contracts.mjs +16 -5
- package/src/canonical-json.d.mts +3 -1
- package/src/canonical-json.mjs +57 -20
- package/src/compat/live-evidence-v2.mjs +1604 -485
- package/src/compat/operate-experience-live-patch.mjs +67 -15
- package/src/compat/operating-planning-contracts.mjs +183 -51
- package/src/contracts.d.mts +54 -13
- package/src/contracts.mjs +655 -345
- package/src/design-contracts.mjs +58 -21
- package/src/design-handoff-contracts.d.mts +67 -11
- package/src/design-handoff-contracts.mjs +243 -98
- package/src/design-publication-contracts.mjs +98 -33
- package/src/diagram-authoring-contracts.d.mts +422 -78
- package/src/diagram-authoring-contracts.mjs +1697 -326
- package/src/diagram-contracts.d.mts +4 -1
- package/src/diagram-contracts.mjs +16 -4
- package/src/enterprise-contracts.d.mts +211 -46
- package/src/enterprise-contracts.mjs +727 -175
- package/src/errors.mjs +4 -0
- package/src/generated/canonical-registries.mjs +13 -13
- package/src/index.d.mts +8 -8
- package/src/index.mjs +36 -20
- package/src/json-schema.d.mts +21 -6
- package/src/json-schema.mjs +66 -18
- package/src/planning-contracts.d.mts +8 -2
- package/src/planning-contracts.mjs +33 -7
- package/src/registries.d.mts +11 -3
- package/src/registries.mjs +369 -87
- package/src/review-experience-contracts.d.mts +7 -2
- package/src/review-experience-contracts.mjs +198 -49
- package/src/semver.mjs +5 -1
- package/src/skill-source-contracts.d.mts +36 -16
- package/src/skill-source-contracts.mjs +25 -6
- package/src/task-contracts.d.mts +13 -3
- package/src/task-contracts.mjs +181 -40
- package/src/workspace-contracts.d.mts +38 -10
- package/src/workspace-contracts.mjs +147 -33
|
@@ -1,54 +1,134 @@
|
|
|
1
|
-
import { assertProtocolArtifact } from '../contracts.mjs';
|
|
2
1
|
import { sha256Jcs } from '../canonical-json.mjs';
|
|
2
|
+
import { assertProtocolArtifact } from '../contracts.mjs';
|
|
3
3
|
|
|
4
4
|
const HASH = /^sha256:[a-f0-9]{64}$/u;
|
|
5
5
|
const CHECKPOINT_TRANSITIONS = Object.freeze({
|
|
6
6
|
prepared: Object.freeze({ request: 'requesting', absent: 'absent' }),
|
|
7
|
-
requesting: Object.freeze({
|
|
7
|
+
requesting: Object.freeze({
|
|
8
|
+
materialize: 'materialized',
|
|
9
|
+
absent: 'absent',
|
|
10
|
+
uncertain: 'uncertain',
|
|
11
|
+
}),
|
|
8
12
|
materialized: Object.freeze({ commit: 'committed', uncertain: 'uncertain' }),
|
|
9
|
-
committed: Object.freeze({}),
|
|
13
|
+
committed: Object.freeze({}),
|
|
14
|
+
absent: Object.freeze({}),
|
|
15
|
+
uncertain: Object.freeze({}),
|
|
10
16
|
});
|
|
11
17
|
const SCHEDULE_TRANSITIONS = Object.freeze({
|
|
12
18
|
disabled: Object.freeze({ enable: 'enabled', revoke: 'revoked', expire: 'expired' }),
|
|
13
|
-
enabled: Object.freeze({
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
enabled: Object.freeze({
|
|
20
|
+
disable: 'disabled',
|
|
21
|
+
pause: 'paused',
|
|
22
|
+
revoke: 'revoked',
|
|
23
|
+
expire: 'expired',
|
|
24
|
+
complete: 'completed',
|
|
25
|
+
'run-issued': 'enabled',
|
|
26
|
+
}),
|
|
27
|
+
paused: Object.freeze({
|
|
28
|
+
disable: 'disabled',
|
|
29
|
+
resume: 'enabled',
|
|
30
|
+
revoke: 'revoked',
|
|
31
|
+
expire: 'expired',
|
|
32
|
+
}),
|
|
33
|
+
revoked: Object.freeze({}),
|
|
34
|
+
expired: Object.freeze({}),
|
|
35
|
+
completed: Object.freeze({}),
|
|
16
36
|
});
|
|
17
37
|
const IMMUTABLE_CHECKPOINT_FIELDS = Object.freeze([
|
|
18
|
-
'checkpointId',
|
|
19
|
-
'
|
|
20
|
-
'
|
|
38
|
+
'checkpointId',
|
|
39
|
+
'requestId',
|
|
40
|
+
'requestHash',
|
|
41
|
+
'effect',
|
|
42
|
+
'provider',
|
|
43
|
+
'providerRegistrationHash',
|
|
44
|
+
'adapterVersion',
|
|
45
|
+
'sourceIdentityHash',
|
|
46
|
+
'credentialRefHash',
|
|
47
|
+
'boundsHash',
|
|
48
|
+
'queryHash',
|
|
49
|
+
'windowHash',
|
|
50
|
+
'redactionVersion',
|
|
51
|
+
'createdAt',
|
|
21
52
|
]);
|
|
22
53
|
const CONNECTOR_EVENT_FIELDS = Object.freeze([
|
|
23
|
-
'eventId',
|
|
54
|
+
'eventId',
|
|
55
|
+
'eventHash',
|
|
56
|
+
'type',
|
|
57
|
+
'expectedGeneration',
|
|
58
|
+
'expectedCheckpointHash',
|
|
59
|
+
'at',
|
|
60
|
+
'patch',
|
|
24
61
|
]);
|
|
25
62
|
const CONNECTOR_PATCH_FIELDS = Object.freeze({
|
|
26
|
-
request: Object.freeze([
|
|
63
|
+
request: Object.freeze([
|
|
64
|
+
'consentRecordId',
|
|
65
|
+
'consentRecordHash',
|
|
66
|
+
'consentExpiresAt',
|
|
67
|
+
'runtimeCapabilityHash',
|
|
68
|
+
'health',
|
|
69
|
+
]),
|
|
27
70
|
materialize: Object.freeze(['artifactId', 'artifactHash', 'watermarkDigest', 'health']),
|
|
28
71
|
commit: Object.freeze(['watermarkDigest']),
|
|
29
72
|
absent: Object.freeze(['absenceDigest', 'health']),
|
|
30
73
|
uncertain: Object.freeze(['absenceDigest', 'health']),
|
|
31
74
|
});
|
|
32
75
|
const SCHEDULE_TRANSITION_FIELDS = Object.freeze([
|
|
33
|
-
'receiptId',
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
76
|
+
'receiptId',
|
|
77
|
+
'type',
|
|
78
|
+
'expectedGeneration',
|
|
79
|
+
'expectedScheduleHash',
|
|
80
|
+
'expectedState',
|
|
81
|
+
'expectedRunCount',
|
|
82
|
+
'expectedNextEventIdentity',
|
|
83
|
+
'expectedNextDueAt',
|
|
84
|
+
'planHash',
|
|
85
|
+
'consentRecordHashes',
|
|
86
|
+
'ceilingsHash',
|
|
87
|
+
'clockHash',
|
|
88
|
+
'eventId',
|
|
89
|
+
'nextEventIdentity',
|
|
90
|
+
'nextDueAt',
|
|
91
|
+
'at',
|
|
37
92
|
]);
|
|
38
93
|
const SOURCE_CONTRACTS = Object.freeze([
|
|
39
|
-
'capacity-throughput',
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
94
|
+
'capacity-throughput',
|
|
95
|
+
'channel-economics',
|
|
96
|
+
'ci-test-evidence',
|
|
97
|
+
'competitor-positioning',
|
|
98
|
+
'context-manifest',
|
|
99
|
+
'demand-market',
|
|
100
|
+
'finance-metrics',
|
|
101
|
+
'incident-history',
|
|
102
|
+
'objective-metrics',
|
|
103
|
+
'operations-customer-health',
|
|
104
|
+
'planning-acceptance',
|
|
105
|
+
'prior-decisions',
|
|
106
|
+
'product-activation',
|
|
107
|
+
'repository-architecture',
|
|
108
|
+
'retention-discovery',
|
|
109
|
+
'support-incidents',
|
|
43
110
|
]);
|
|
44
111
|
|
|
45
112
|
export const LIVE_EVIDENCE_ABSENCE_KINDS_V2 = Object.freeze([
|
|
46
|
-
'insufficient-evidence',
|
|
47
|
-
'
|
|
113
|
+
'insufficient-evidence',
|
|
114
|
+
'missing-consent',
|
|
115
|
+
'missing-credential',
|
|
116
|
+
'provider-unavailable',
|
|
117
|
+
'rate-limited',
|
|
118
|
+
'stale',
|
|
119
|
+
'unhealthy',
|
|
120
|
+
'unsupported',
|
|
48
121
|
]);
|
|
49
122
|
export const LIVE_EVIDENCE_EFFECT_CLASS_V2 = 'provider-call';
|
|
50
123
|
export const LIVE_EVIDENCE_PORTABLE_AUTHORITY_V2 = 'none';
|
|
51
|
-
export const OPERATING_OUTCOME_EVALUATION_OPERATORS_V2 = Object.freeze([
|
|
124
|
+
export const OPERATING_OUTCOME_EVALUATION_OPERATORS_V2 = Object.freeze([
|
|
125
|
+
'gt',
|
|
126
|
+
'gte',
|
|
127
|
+
'lt',
|
|
128
|
+
'lte',
|
|
129
|
+
'eq',
|
|
130
|
+
'between',
|
|
131
|
+
]);
|
|
52
132
|
|
|
53
133
|
export class OperatingLiveEvidenceErrorV2 extends Error {
|
|
54
134
|
constructor(code, message, details = {}) {
|
|
@@ -88,14 +168,24 @@ function safePortable(value, path = '$') {
|
|
|
88
168
|
return;
|
|
89
169
|
}
|
|
90
170
|
if (typeof value !== 'string') return;
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
171
|
+
if (
|
|
172
|
+
value.includes('\u0000') ||
|
|
173
|
+
value.startsWith('/') ||
|
|
174
|
+
value.startsWith('~') ||
|
|
175
|
+
/(?:^|[\s"'`(])\/(?:Users|home|private|var|etc|tmp)\//u.test(value) ||
|
|
176
|
+
/(?:^|[\s"'`(])[A-Za-z]:[\\/][^\s]+/u.test(value) ||
|
|
177
|
+
value.split(/[\\/]/u).includes('..') ||
|
|
178
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----/u.test(value) ||
|
|
179
|
+
/\b(?:Bearer|Basic)\s+[A-Za-z0-9+/=._-]+/u.test(value) ||
|
|
180
|
+
/\b(?:api[-_ ]?key|access[-_ ]?token|client[-_ ]?secret|password|passwd|secret|token)\s*[:=]\s*[^\s]+/iu.test(
|
|
181
|
+
value,
|
|
182
|
+
)
|
|
183
|
+
) {
|
|
184
|
+
fail(
|
|
185
|
+
'LIVE_EVIDENCE_UNSAFE',
|
|
186
|
+
'Live-evidence artifacts contain private path or credential material.',
|
|
187
|
+
{ path },
|
|
188
|
+
);
|
|
99
189
|
}
|
|
100
190
|
}
|
|
101
191
|
|
|
@@ -103,7 +193,9 @@ function protocol(kind, value, protocolVersion = '2.0.0') {
|
|
|
103
193
|
try {
|
|
104
194
|
assertProtocolArtifact(kind, value, { protocolVersion });
|
|
105
195
|
} catch (cause) {
|
|
106
|
-
fail('LIVE_EVIDENCE_CONTRACT_INVALID', `Invalid ${kind} contract.`, {
|
|
196
|
+
fail('LIVE_EVIDENCE_CONTRACT_INVALID', `Invalid ${kind} contract.`, {
|
|
197
|
+
cause: cause.code ?? cause.message,
|
|
198
|
+
});
|
|
107
199
|
}
|
|
108
200
|
}
|
|
109
201
|
|
|
@@ -111,18 +203,27 @@ function selfHash(record, field) {
|
|
|
111
203
|
const { [field]: claimed, ...body } = record;
|
|
112
204
|
const expected = sha256Jcs(body);
|
|
113
205
|
if (!HASH.test(claimed ?? '') || claimed !== expected) {
|
|
114
|
-
fail('LIVE_EVIDENCE_DIGEST_MISMATCH', `${field} does not bind the exact canonical record.`, {
|
|
206
|
+
fail('LIVE_EVIDENCE_DIGEST_MISMATCH', `${field} does not bind the exact canonical record.`, {
|
|
207
|
+
field,
|
|
208
|
+
expected,
|
|
209
|
+
actual: claimed ?? null,
|
|
210
|
+
});
|
|
115
211
|
}
|
|
116
212
|
return expected;
|
|
117
213
|
}
|
|
118
214
|
|
|
119
215
|
function exactDigest(record, expected, label) {
|
|
120
216
|
const actual = sha256Jcs(record);
|
|
121
|
-
if (actual !== expected)
|
|
217
|
+
if (actual !== expected)
|
|
218
|
+
fail('LIVE_EVIDENCE_BASE_RECORD_MISMATCH', `${label} bytes do not match their bound digest.`, {
|
|
219
|
+
expected,
|
|
220
|
+
actual,
|
|
221
|
+
});
|
|
122
222
|
}
|
|
123
223
|
|
|
124
224
|
function same(left, right, label) {
|
|
125
|
-
if (sha256Jcs(left) !== sha256Jcs(right))
|
|
225
|
+
if (sha256Jcs(left) !== sha256Jcs(right))
|
|
226
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', `${label} binding changed.`, { left, right });
|
|
126
227
|
}
|
|
127
228
|
|
|
128
229
|
function assertExactKeys(value, expected, label) {
|
|
@@ -132,13 +233,19 @@ function assertExactKeys(value, expected, label) {
|
|
|
132
233
|
const actual = Object.keys(value).sort();
|
|
133
234
|
const wanted = [...expected].sort();
|
|
134
235
|
if (!sameValue(actual, wanted)) {
|
|
135
|
-
fail('LIVE_EVIDENCE_CONTRACT_INVALID', `${label} contains missing or unsupported fields.`, {
|
|
236
|
+
fail('LIVE_EVIDENCE_CONTRACT_INVALID', `${label} contains missing or unsupported fields.`, {
|
|
237
|
+
actual,
|
|
238
|
+
expected: wanted,
|
|
239
|
+
});
|
|
136
240
|
}
|
|
137
241
|
}
|
|
138
242
|
|
|
139
243
|
function currentAt(timestamp, expiresAt, label) {
|
|
140
244
|
if (!(Date.parse(timestamp) < Date.parse(expiresAt))) {
|
|
141
|
-
fail('LIVE_EVIDENCE_STALE', `${label} is not current at the bound time.`, {
|
|
245
|
+
fail('LIVE_EVIDENCE_STALE', `${label} is not current at the bound time.`, {
|
|
246
|
+
timestamp,
|
|
247
|
+
expiresAt,
|
|
248
|
+
});
|
|
142
249
|
}
|
|
143
250
|
}
|
|
144
251
|
|
|
@@ -147,28 +254,53 @@ function exactBaseRecord(options, singularKey, pluralKey, reference, identityFie
|
|
|
147
254
|
options?.[singularKey],
|
|
148
255
|
...(Array.isArray(options?.[pluralKey]) ? options[pluralKey] : []),
|
|
149
256
|
].filter((entry) => entry !== undefined);
|
|
150
|
-
const matching = supplied.filter((entry) =>
|
|
257
|
+
const matching = supplied.filter((entry) =>
|
|
258
|
+
identityFields.every((field) => entry?.[field] === reference[field]),
|
|
259
|
+
);
|
|
151
260
|
const unique = [...new Map(matching.map((entry) => [sha256Jcs(entry), entry])).values()];
|
|
152
261
|
if (unique.length !== 1) {
|
|
153
|
-
fail(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
262
|
+
fail(
|
|
263
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
264
|
+
`${label} requires exactly one matching frozen base record.`,
|
|
265
|
+
{
|
|
266
|
+
identity: Object.fromEntries(identityFields.map((field) => [field, reference[field]])),
|
|
267
|
+
matches: unique.length,
|
|
268
|
+
},
|
|
269
|
+
);
|
|
157
270
|
}
|
|
158
271
|
return unique[0];
|
|
159
272
|
}
|
|
160
273
|
|
|
161
274
|
function assertProviderBaseRecords(record, options = {}) {
|
|
162
|
-
const baseEvidenceProvider = exactBaseRecord(
|
|
163
|
-
|
|
275
|
+
const baseEvidenceProvider = exactBaseRecord(
|
|
276
|
+
options,
|
|
277
|
+
'baseEvidenceProvider',
|
|
278
|
+
'baseEvidenceProviders',
|
|
279
|
+
record.baseEvidenceProvider,
|
|
280
|
+
['providerId', 'providerVersion'],
|
|
281
|
+
'Live provider registration',
|
|
282
|
+
);
|
|
164
283
|
protocol('operate-evidence-provider-registration', baseEvidenceProvider);
|
|
165
|
-
exactDigest(
|
|
166
|
-
|
|
167
|
-
record.
|
|
284
|
+
exactDigest(
|
|
285
|
+
baseEvidenceProvider,
|
|
286
|
+
record.baseEvidenceProvider.recordDigest,
|
|
287
|
+
'Evidence-provider registration',
|
|
288
|
+
);
|
|
289
|
+
const baseResolver = exactBaseRecord(
|
|
290
|
+
options,
|
|
291
|
+
'baseResolver',
|
|
292
|
+
'baseResolvers',
|
|
293
|
+
record.baseResolver,
|
|
294
|
+
['resolverId', 'resolverVersion'],
|
|
295
|
+
'Live provider registration',
|
|
296
|
+
);
|
|
168
297
|
protocol('operate-evidence-resolver-registration', baseResolver);
|
|
169
298
|
exactDigest(baseResolver, record.baseResolver.recordDigest, 'Evidence-resolver registration');
|
|
170
299
|
if (!baseResolver.supportedEvidenceKinds.includes('operate-artifact')) {
|
|
171
|
-
fail(
|
|
300
|
+
fail(
|
|
301
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
302
|
+
'The base resolver must use the canonical operate-artifact boundary.',
|
|
303
|
+
);
|
|
172
304
|
}
|
|
173
305
|
}
|
|
174
306
|
|
|
@@ -176,11 +308,19 @@ function assertLiveEvidenceProviderRegistrationStructureV2(record) {
|
|
|
176
308
|
protocol('operate-live-evidence-provider-registration', record);
|
|
177
309
|
safePortable(record);
|
|
178
310
|
selfHash(record, 'registrationHash');
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
311
|
+
if (
|
|
312
|
+
record.effects.length !== 1 ||
|
|
313
|
+
record.effects[0] !== 'provider-call' ||
|
|
314
|
+
record.consent.required !== true ||
|
|
315
|
+
record.consent.mode !== 'named-owner-current' ||
|
|
316
|
+
record.consent.runtimeCapability !== 'opaque-local-preissued' ||
|
|
317
|
+
record.consent.noDefaultChoice !== true ||
|
|
318
|
+
record.consent.previewEffect !== 'none'
|
|
319
|
+
) {
|
|
320
|
+
fail(
|
|
321
|
+
'LIVE_EVIDENCE_AUTHORITY_INVALID',
|
|
322
|
+
'Registration must require current consent and a pre-issued opaque capability for provider-call.',
|
|
323
|
+
);
|
|
184
324
|
}
|
|
185
325
|
return freeze(clone(record));
|
|
186
326
|
}
|
|
@@ -201,7 +341,11 @@ export function assertLiveEvidenceProviderRegistryV2(registry, options = {}) {
|
|
|
201
341
|
assertLiveEvidenceProviderRegistrationV2(provider, options);
|
|
202
342
|
const identity = `${provider.providerId}@${provider.providerVersion}`;
|
|
203
343
|
if (identities.has(identity) || (previous !== null && identity.localeCompare(previous) <= 0)) {
|
|
204
|
-
fail(
|
|
344
|
+
fail(
|
|
345
|
+
'LIVE_EVIDENCE_REGISTRY_CONFLICT',
|
|
346
|
+
'Provider registry membership must be unique and canonically ordered.',
|
|
347
|
+
{ identity },
|
|
348
|
+
);
|
|
205
349
|
}
|
|
206
350
|
identities.add(identity);
|
|
207
351
|
previous = identity;
|
|
@@ -212,17 +356,30 @@ export function assertLiveEvidenceProviderRegistryV2(registry, options = {}) {
|
|
|
212
356
|
export function registerLiveEvidenceProviderV2(registry, registration, options = {}) {
|
|
213
357
|
const current = assertLiveEvidenceProviderRegistryV2(registry, options);
|
|
214
358
|
const provider = assertLiveEvidenceProviderRegistrationV2(registration, options);
|
|
215
|
-
const index = current.providers.findIndex(
|
|
359
|
+
const index = current.providers.findIndex(
|
|
360
|
+
(entry) =>
|
|
361
|
+
entry.providerId === provider.providerId &&
|
|
362
|
+
entry.providerVersion === provider.providerVersion,
|
|
363
|
+
);
|
|
216
364
|
if (index >= 0) {
|
|
217
365
|
if (current.providers[index].registrationHash !== provider.registrationHash) {
|
|
218
|
-
fail(
|
|
366
|
+
fail(
|
|
367
|
+
'LIVE_EVIDENCE_REGISTRY_CONFLICT',
|
|
368
|
+
'Divergent provider bytes cannot reuse one provider identity.',
|
|
369
|
+
);
|
|
219
370
|
}
|
|
220
371
|
return current;
|
|
221
372
|
}
|
|
222
373
|
const next = clone(current);
|
|
223
374
|
next.providers.push(clone(provider));
|
|
224
|
-
next.providers.sort((left, right) =>
|
|
225
|
-
|
|
375
|
+
next.providers.sort((left, right) =>
|
|
376
|
+
`${left.providerId}@${left.providerVersion}`.localeCompare(
|
|
377
|
+
`${right.providerId}@${right.providerVersion}`,
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
next.registryHash = sha256Jcs(
|
|
381
|
+
Object.fromEntries(Object.entries(next).filter(([key]) => key !== 'registryHash')),
|
|
382
|
+
);
|
|
226
383
|
return assertLiveEvidenceProviderRegistryV2(next, options);
|
|
227
384
|
}
|
|
228
385
|
|
|
@@ -230,129 +387,276 @@ export function assertOperatingLiveEvidenceConsentRecordV2(record) {
|
|
|
230
387
|
protocol('operating-live-evidence-consent-record', record);
|
|
231
388
|
safePortable(record);
|
|
232
389
|
selfHash(record, 'consentHash');
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
390
|
+
if (
|
|
391
|
+
record.authority !== 'none' ||
|
|
392
|
+
record.docket.defaultChoice !== null ||
|
|
393
|
+
record.docket.cancelEffect !== 'none'
|
|
394
|
+
) {
|
|
395
|
+
fail(
|
|
396
|
+
'LIVE_EVIDENCE_AUTHORITY_INVALID',
|
|
397
|
+
'Consent proof and docket cannot grant access authority or preselect an owner choice.',
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
if (sha256Jcs(record.docket) !== record.docketHash)
|
|
401
|
+
fail('LIVE_EVIDENCE_DIGEST_MISMATCH', 'Consent docket bytes changed.');
|
|
237
402
|
same(record.docket.provider, record.provider, 'Consent provider');
|
|
238
|
-
for (const field of [
|
|
403
|
+
for (const field of [
|
|
404
|
+
'adapterVersion',
|
|
405
|
+
'accountIdentityHash',
|
|
406
|
+
'selectors',
|
|
407
|
+
'scopes',
|
|
408
|
+
'queryHash',
|
|
409
|
+
'window',
|
|
410
|
+
'ceilings',
|
|
411
|
+
'classification',
|
|
412
|
+
'purpose',
|
|
413
|
+
'expiresAt',
|
|
414
|
+
]) {
|
|
239
415
|
same(record.docket[field], record[field], `Consent ${field}`);
|
|
240
416
|
}
|
|
241
417
|
currentAt(record.issuedAt, record.expiresAt, 'Consent');
|
|
242
418
|
return freeze(clone(record));
|
|
243
419
|
}
|
|
244
420
|
|
|
245
|
-
export function assertOperatingLiveEvidenceIngestionV2(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
421
|
+
export function assertOperatingLiveEvidenceIngestionV2(
|
|
422
|
+
record,
|
|
423
|
+
{
|
|
424
|
+
liveProviderRegistration,
|
|
425
|
+
baseEvidenceProvider,
|
|
426
|
+
baseResolver,
|
|
427
|
+
assignment,
|
|
428
|
+
consentRecord,
|
|
429
|
+
connectorCheckpoint,
|
|
430
|
+
} = {},
|
|
431
|
+
) {
|
|
249
432
|
protocol('operating-live-evidence-ingestion', record);
|
|
250
433
|
safePortable(record);
|
|
251
434
|
selfHash(record, 'ingestionHash');
|
|
252
|
-
if (!SOURCE_CONTRACTS.includes(record.sourceContract.id))
|
|
435
|
+
if (!SOURCE_CONTRACTS.includes(record.sourceContract.id))
|
|
436
|
+
fail(
|
|
437
|
+
'LIVE_EVIDENCE_SOURCE_CONTRACT_INVALID',
|
|
438
|
+
'Ingestion source contract is not accepted by the frozen operate-artifact resolver.',
|
|
439
|
+
);
|
|
253
440
|
if (record.status === 'materialized') {
|
|
254
|
-
if (
|
|
255
|
-
|
|
441
|
+
if (
|
|
442
|
+
record.health.status !== 'available' ||
|
|
443
|
+
record.absences.length !== 0 ||
|
|
444
|
+
record.records.length === 0
|
|
445
|
+
) {
|
|
446
|
+
fail(
|
|
447
|
+
'LIVE_EVIDENCE_FALSE_PASS',
|
|
448
|
+
'Materialized evidence requires available health, records, and no absence.',
|
|
449
|
+
);
|
|
256
450
|
}
|
|
257
|
-
if (
|
|
258
|
-
|
|
451
|
+
if (
|
|
452
|
+
record.materialization.contentDigest !== deriveOperatingLiveEvidenceContentDigestV2(record)
|
|
453
|
+
) {
|
|
454
|
+
fail(
|
|
455
|
+
'LIVE_EVIDENCE_DIGEST_MISMATCH',
|
|
456
|
+
'Materialization contentDigest does not bind the exact redacted record manifest.',
|
|
457
|
+
);
|
|
259
458
|
}
|
|
260
459
|
currentAt(record.sourceTiming.capturedAt, record.health.freshUntil, 'Provider health');
|
|
261
460
|
currentAt(record.sourceTiming.capturedAt, record.sourceTiming.freshUntil, 'Source evidence');
|
|
262
461
|
}
|
|
263
|
-
if (
|
|
264
|
-
|
|
462
|
+
if (
|
|
463
|
+
record.assignment.requestHash !== record.requestHash ||
|
|
464
|
+
record.submission.operation !== 'operate.assignment.submit'
|
|
465
|
+
) {
|
|
466
|
+
fail(
|
|
467
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
468
|
+
'Ingestion must bind its issued Assignment request and normal submission operation.',
|
|
469
|
+
);
|
|
265
470
|
}
|
|
266
471
|
if (record.assignment.assignmentRevision !== 1) {
|
|
267
|
-
fail(
|
|
472
|
+
fail(
|
|
473
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
474
|
+
'The immutable Protocol 2.0 Assignment revision must be one.',
|
|
475
|
+
);
|
|
268
476
|
}
|
|
269
477
|
if (record.materialization !== null) {
|
|
270
|
-
for (const field of ['artifactId', 'artifactCreatedEventId', 'evidenceRefId'])
|
|
478
|
+
for (const field of ['artifactId', 'artifactCreatedEventId', 'evidenceRefId'])
|
|
479
|
+
same(record.materialization[field], record.submission[field], `Materialization ${field}`);
|
|
271
480
|
}
|
|
272
481
|
for (const candidate of record.evidenceCandidates) {
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
482
|
+
if (
|
|
483
|
+
candidate.evidenceKind !== 'operate-artifact' ||
|
|
484
|
+
candidate.sourceArtifactId !== record.submission.artifactId ||
|
|
485
|
+
candidate.locator?.artifactId !== record.submission.artifactId ||
|
|
486
|
+
candidate.locator?.expectedArtifactType !== 'live-evidence-ingestion' ||
|
|
487
|
+
candidate.locator?.expectedSchemaId !== 'operating-live-evidence-ingestion' ||
|
|
488
|
+
candidate.locator?.expectedSchemaVersion !== '2.0.0' ||
|
|
489
|
+
candidate.provider.id !== record.providerRegistration.providerId ||
|
|
490
|
+
candidate.provider.version !== record.providerRegistration.providerVersion ||
|
|
491
|
+
candidate.resolver.id !== record.resolverRegistration.resolverId ||
|
|
492
|
+
candidate.resolver.version !== record.resolverRegistration.resolverVersion
|
|
493
|
+
) {
|
|
494
|
+
fail(
|
|
495
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
496
|
+
'Evidence candidates must reference the pre-issued accepted ingestion Artifact.',
|
|
497
|
+
);
|
|
283
498
|
}
|
|
284
499
|
}
|
|
285
500
|
for (const link of record.evidenceClaimLinks) {
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
501
|
+
if (
|
|
502
|
+
link.sourceArtifactId !== record.submission.artifactId ||
|
|
503
|
+
!record.evidenceCandidates.some((candidate) => candidate.candidateId === link.candidateId)
|
|
504
|
+
) {
|
|
505
|
+
fail(
|
|
506
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
507
|
+
'Evidence claim links must bind a declared candidate and accepted source Artifact.',
|
|
508
|
+
);
|
|
289
509
|
}
|
|
290
510
|
}
|
|
291
511
|
if (liveProviderRegistration !== undefined) {
|
|
292
|
-
const registration = assertLiveEvidenceProviderRegistrationV2(liveProviderRegistration, {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
512
|
+
const registration = assertLiveEvidenceProviderRegistrationV2(liveProviderRegistration, {
|
|
513
|
+
baseEvidenceProvider,
|
|
514
|
+
baseResolver,
|
|
515
|
+
});
|
|
516
|
+
if (registration.registrationHash !== record.providerRegistrationHash)
|
|
517
|
+
fail('LIVE_EVIDENCE_BASE_RECORD_MISMATCH', 'Live provider registration changed.');
|
|
518
|
+
same(
|
|
519
|
+
[registration.providerId, registration.providerVersion, registration.adapterVersion],
|
|
520
|
+
[record.provider.id, record.provider.version, record.adapterVersion],
|
|
521
|
+
'Live provider',
|
|
522
|
+
);
|
|
523
|
+
same(
|
|
524
|
+
registration.baseEvidenceProvider,
|
|
525
|
+
record.providerRegistration,
|
|
526
|
+
'Base evidence-provider reference',
|
|
527
|
+
);
|
|
528
|
+
same(
|
|
529
|
+
registration.baseResolver,
|
|
530
|
+
record.resolverRegistration,
|
|
531
|
+
'Base evidence-resolver reference',
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
if (record.resolverRegistrationHash !== record.resolverRegistration.recordDigest)
|
|
535
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Resolver registration digest fields disagree.');
|
|
299
536
|
if (baseEvidenceProvider !== undefined) {
|
|
300
537
|
protocol('operate-evidence-provider-registration', baseEvidenceProvider);
|
|
301
|
-
exactDigest(
|
|
538
|
+
exactDigest(
|
|
539
|
+
baseEvidenceProvider,
|
|
540
|
+
record.providerRegistration.recordDigest,
|
|
541
|
+
'Base evidence-provider registration',
|
|
542
|
+
);
|
|
302
543
|
}
|
|
303
544
|
if (baseResolver !== undefined) {
|
|
304
545
|
protocol('operate-evidence-resolver-registration', baseResolver);
|
|
305
|
-
exactDigest(
|
|
306
|
-
|
|
307
|
-
|
|
546
|
+
exactDigest(
|
|
547
|
+
baseResolver,
|
|
548
|
+
record.resolverRegistration.recordDigest,
|
|
549
|
+
'Base evidence-resolver registration',
|
|
550
|
+
);
|
|
551
|
+
if (
|
|
552
|
+
!baseResolver.supportedSourceContracts.some((entry) =>
|
|
553
|
+
sameValue(entry, record.sourceContract),
|
|
554
|
+
)
|
|
555
|
+
) {
|
|
556
|
+
fail(
|
|
557
|
+
'LIVE_EVIDENCE_SOURCE_CONTRACT_INVALID',
|
|
558
|
+
'The selected resolver does not support the ingestion source contract.',
|
|
559
|
+
);
|
|
308
560
|
}
|
|
309
561
|
}
|
|
310
562
|
if (assignment !== undefined) {
|
|
311
563
|
protocol('operating-assignment', assignment);
|
|
312
564
|
exactDigest(assignment, record.assignment.assignmentHash, 'Issued Assignment');
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
565
|
+
if (
|
|
566
|
+
assignment.assignmentId !== record.assignment.assignmentId ||
|
|
567
|
+
assignment.assignmentKind !== 'verification' ||
|
|
568
|
+
assignment.outputContract.schemaId !== 'operating-live-evidence-ingestion' ||
|
|
569
|
+
assignment.outputContract.schemaVersion !== '2.0.0'
|
|
570
|
+
) {
|
|
571
|
+
fail(
|
|
572
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
573
|
+
'The canonical Assignment does not authorize this ingestion output.',
|
|
574
|
+
);
|
|
317
575
|
}
|
|
318
576
|
}
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
577
|
+
if (
|
|
578
|
+
record.status === 'materialized' &&
|
|
579
|
+
(assignment === undefined ||
|
|
580
|
+
consentRecord === undefined ||
|
|
581
|
+
connectorCheckpoint === undefined ||
|
|
582
|
+
liveProviderRegistration === undefined ||
|
|
583
|
+
baseEvidenceProvider === undefined ||
|
|
584
|
+
baseResolver === undefined)
|
|
585
|
+
) {
|
|
586
|
+
fail(
|
|
587
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
588
|
+
'Materialized ingestion requires exact Assignment, consent, checkpoint, and provider registrations.',
|
|
589
|
+
);
|
|
323
590
|
}
|
|
324
591
|
if (consentRecord !== undefined) {
|
|
325
592
|
const consent = assertOperatingLiveEvidenceConsentRecordV2(consentRecord);
|
|
326
|
-
if (consent.consentHash !== record.consentRecordHash)
|
|
327
|
-
|
|
328
|
-
|
|
593
|
+
if (consent.consentHash !== record.consentRecordHash)
|
|
594
|
+
fail('LIVE_EVIDENCE_BASE_RECORD_MISMATCH', 'Consent record changed.');
|
|
595
|
+
same(
|
|
596
|
+
[consent.provider, consent.adapterVersion, consent.classification],
|
|
597
|
+
[record.provider, record.adapterVersion, record.classification],
|
|
598
|
+
'Consent provider',
|
|
599
|
+
);
|
|
600
|
+
if (sha256Jcs(consent.ceilings) !== record.boundsHash)
|
|
601
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Consent ceilings changed.');
|
|
329
602
|
currentAt(record.sourceTiming.capturedAt, consent.expiresAt, 'Consent');
|
|
330
603
|
}
|
|
331
604
|
if (connectorCheckpoint !== undefined) {
|
|
332
605
|
const checkpoint = assertOperatingConnectorCheckpointV2(connectorCheckpoint);
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
606
|
+
if (
|
|
607
|
+
checkpoint.state !== 'requesting' ||
|
|
608
|
+
checkpoint.checkpointId !== record.checkpoint.checkpointId ||
|
|
609
|
+
checkpoint.checkpointHash !== record.checkpoint.checkpointHash ||
|
|
610
|
+
checkpoint.predecessorDigest !== record.checkpoint.predecessorDigest ||
|
|
611
|
+
checkpoint.requestId !== record.requestId ||
|
|
612
|
+
checkpoint.providerRegistrationHash !== record.providerRegistrationHash ||
|
|
613
|
+
checkpoint.consentRecordHash !== record.consentRecordHash ||
|
|
614
|
+
checkpoint.runtimeCapabilityHash !== record.runtimeCapabilityHash ||
|
|
615
|
+
checkpoint.boundsHash !== record.boundsHash ||
|
|
616
|
+
!sameValue(checkpoint.provider, record.provider) ||
|
|
617
|
+
checkpoint.adapterVersion !== record.adapterVersion ||
|
|
618
|
+
!sameValue(checkpoint.health, record.health)
|
|
619
|
+
) {
|
|
620
|
+
fail(
|
|
621
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
622
|
+
'Ingestion changed its exact requesting connector checkpoint.',
|
|
623
|
+
);
|
|
342
624
|
}
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
625
|
+
if (
|
|
626
|
+
consentRecord !== undefined &&
|
|
627
|
+
(checkpoint.queryHash !== consentRecord.queryHash ||
|
|
628
|
+
checkpoint.windowHash !== sha256Jcs(consentRecord.window) ||
|
|
629
|
+
checkpoint.boundsHash !== sha256Jcs(consentRecord.ceilings))
|
|
630
|
+
) {
|
|
631
|
+
fail(
|
|
632
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
633
|
+
'Checkpoint query, window, or bounds changed from owner consent.',
|
|
634
|
+
);
|
|
347
635
|
}
|
|
348
636
|
}
|
|
349
|
-
if (
|
|
637
|
+
if (
|
|
638
|
+
assignment !== undefined &&
|
|
639
|
+
consentRecord !== undefined &&
|
|
640
|
+
connectorCheckpoint !== undefined
|
|
641
|
+
) {
|
|
350
642
|
const expectedRequestHash = deriveOperatingLiveEvidenceRequestHashV2({
|
|
351
|
-
assignment,
|
|
352
|
-
|
|
643
|
+
assignment,
|
|
644
|
+
consentRecord,
|
|
645
|
+
connectorCheckpoint,
|
|
646
|
+
liveProviderRegistration,
|
|
647
|
+
sourceContract: record.sourceContract,
|
|
648
|
+
baseEvidenceProvider,
|
|
649
|
+
baseResolver,
|
|
650
|
+
classification: record.classification,
|
|
353
651
|
});
|
|
354
|
-
if (
|
|
355
|
-
|
|
652
|
+
if (
|
|
653
|
+
record.requestHash !== expectedRequestHash ||
|
|
654
|
+
connectorCheckpoint.requestHash !== expectedRequestHash
|
|
655
|
+
) {
|
|
656
|
+
fail(
|
|
657
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
658
|
+
'Ingestion request is not the engine-derived Assignment/provider request.',
|
|
659
|
+
);
|
|
356
660
|
}
|
|
357
661
|
}
|
|
358
662
|
return freeze(clone(record));
|
|
@@ -363,14 +667,21 @@ function sameValue(left, right) {
|
|
|
363
667
|
}
|
|
364
668
|
|
|
365
669
|
export function deriveOperatingLiveEvidenceRequestHashV2({
|
|
366
|
-
assignment,
|
|
367
|
-
|
|
670
|
+
assignment,
|
|
671
|
+
consentRecord,
|
|
672
|
+
connectorCheckpoint,
|
|
673
|
+
liveProviderRegistration,
|
|
674
|
+
baseEvidenceProvider,
|
|
675
|
+
baseResolver,
|
|
676
|
+
sourceContract,
|
|
677
|
+
classification,
|
|
368
678
|
}) {
|
|
369
679
|
protocol('operating-assignment', assignment);
|
|
370
680
|
const consent = assertOperatingLiveEvidenceConsentRecordV2(consentRecord);
|
|
371
681
|
const checkpoint = assertOperatingConnectorCheckpointV2(connectorCheckpoint);
|
|
372
682
|
const registration = assertLiveEvidenceProviderRegistrationV2(liveProviderRegistration, {
|
|
373
|
-
baseEvidenceProvider,
|
|
683
|
+
baseEvidenceProvider,
|
|
684
|
+
baseResolver,
|
|
374
685
|
});
|
|
375
686
|
return sha256Jcs({
|
|
376
687
|
domain: 'openplanr-operating-live-evidence-request-v2',
|
|
@@ -392,10 +703,19 @@ export function deriveOperatingLiveEvidenceRequestHashV2({
|
|
|
392
703
|
}
|
|
393
704
|
|
|
394
705
|
export function deriveOperatingLiveEvidenceContentDigestV2(record) {
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
706
|
+
if (
|
|
707
|
+
record?.materialization === null ||
|
|
708
|
+
record?.materialization === undefined ||
|
|
709
|
+
!Array.isArray(record?.records)
|
|
710
|
+
) {
|
|
711
|
+
fail(
|
|
712
|
+
'LIVE_EVIDENCE_CONTRACT_INVALID',
|
|
713
|
+
'Materialized live evidence requires a redacted record manifest.',
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
const records = clone(record.records).sort((left, right) =>
|
|
717
|
+
left.recordIdentityHash.localeCompare(right.recordIdentityHash),
|
|
718
|
+
);
|
|
399
719
|
return sha256Jcs({
|
|
400
720
|
domain: 'openplanr-operating-live-evidence-redacted-content-v2',
|
|
401
721
|
redactionVersion: record.materialization.redactionVersion,
|
|
@@ -403,125 +723,226 @@ export function deriveOperatingLiveEvidenceContentDigestV2(record) {
|
|
|
403
723
|
});
|
|
404
724
|
}
|
|
405
725
|
|
|
406
|
-
export function assertAcceptedLiveEvidenceSourceV2(
|
|
407
|
-
|
|
408
|
-
...options
|
|
409
|
-
|
|
726
|
+
export function assertAcceptedLiveEvidenceSourceV2(
|
|
727
|
+
record,
|
|
728
|
+
{ assignment, artifact, submittedEvent, artifactCreatedEvent, validatedEvent, ...options },
|
|
729
|
+
) {
|
|
410
730
|
const ingestion = assertOperatingLiveEvidenceIngestionV2(record, { assignment, ...options });
|
|
411
731
|
protocol('operating-artifact', artifact);
|
|
412
732
|
protocol('operating-event', submittedEvent);
|
|
413
733
|
protocol('operating-event', artifactCreatedEvent);
|
|
414
734
|
protocol('operating-event', validatedEvent);
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
735
|
+
if (
|
|
736
|
+
artifact.artifactId !== ingestion.submission.artifactId ||
|
|
737
|
+
artifact.assignmentId !== ingestion.assignment.assignmentId ||
|
|
738
|
+
artifact.artifactType !== 'live-evidence-ingestion' ||
|
|
739
|
+
artifact.schemaId !== 'operating-live-evidence-ingestion' ||
|
|
740
|
+
artifact.artifactSchemaVersion !== '2.0.0' ||
|
|
741
|
+
artifact.canonicalHash !== sha256Jcs(ingestion)
|
|
742
|
+
) {
|
|
743
|
+
fail(
|
|
744
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
745
|
+
'Accepted Artifact does not bind the exact ingestion bytes and Assignment.',
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
const eventBindings = [
|
|
749
|
+
[submittedEvent, 'assignment.submitted', ingestion.submission.submittedEventId],
|
|
750
|
+
[artifactCreatedEvent, 'artifact.created', ingestion.submission.artifactCreatedEventId],
|
|
751
|
+
[validatedEvent, 'assignment.validated', ingestion.submission.validatedEventId],
|
|
752
|
+
];
|
|
422
753
|
for (const [event, type, eventId] of eventBindings) {
|
|
423
754
|
selfHash(event, 'eventHash');
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
|
|
755
|
+
if (
|
|
756
|
+
event.eventId !== eventId ||
|
|
757
|
+
event.type !== type ||
|
|
758
|
+
event.cycleId !== artifact.cycleId ||
|
|
759
|
+
event.timestamp !== artifact.createdAt ||
|
|
760
|
+
event.actor.kind !== 'runtime' ||
|
|
761
|
+
event.actor.id !== 'openplanr'
|
|
762
|
+
) {
|
|
763
|
+
fail(
|
|
764
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
765
|
+
'Accepted Event lineage does not match the pre-issued ingestion identities.',
|
|
766
|
+
{ type },
|
|
767
|
+
);
|
|
427
768
|
}
|
|
428
769
|
}
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
770
|
+
if (
|
|
771
|
+
submittedEvent.entityId !== assignment.assignmentId ||
|
|
772
|
+
artifactCreatedEvent.entityId !== artifact.artifactId ||
|
|
773
|
+
validatedEvent.entityId !== assignment.assignmentId ||
|
|
774
|
+
artifactCreatedEvent.causationId !== submittedEvent.eventId ||
|
|
775
|
+
validatedEvent.causationId !== artifactCreatedEvent.eventId ||
|
|
776
|
+
submittedEvent.correlationId !== artifactCreatedEvent.correlationId ||
|
|
777
|
+
submittedEvent.correlationId !== validatedEvent.correlationId ||
|
|
778
|
+
artifactCreatedEvent.previousEventHash !== submittedEvent.eventHash ||
|
|
779
|
+
validatedEvent.previousEventHash !== artifactCreatedEvent.eventHash ||
|
|
780
|
+
artifactCreatedEvent.sequence !== submittedEvent.sequence + 1 ||
|
|
781
|
+
validatedEvent.sequence !== artifactCreatedEvent.sequence + 1 ||
|
|
782
|
+
!sameValue(submittedEvent.payload, {
|
|
783
|
+
assignmentId: assignment.assignmentId,
|
|
784
|
+
submissionId: ingestion.submission.submissionId,
|
|
785
|
+
rawHash: artifact.rawHash,
|
|
786
|
+
canonicalHash: artifact.canonicalHash,
|
|
787
|
+
sizeBytes: artifact.sizeBytes,
|
|
788
|
+
mediaType: artifact.mediaType,
|
|
789
|
+
encoding: artifact.encoding,
|
|
790
|
+
}) ||
|
|
791
|
+
!sameValue(artifactCreatedEvent.payload, artifact) ||
|
|
792
|
+
validatedEvent.payload.assignmentId !== assignment.assignmentId ||
|
|
793
|
+
validatedEvent.payload.submissionId !== ingestion.submission.submissionId ||
|
|
794
|
+
validatedEvent.payload.artifactId !== artifact.artifactId ||
|
|
795
|
+
typeof validatedEvent.payload.validatorVersion !== 'string'
|
|
796
|
+
) {
|
|
797
|
+
fail(
|
|
798
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
799
|
+
'Runtime-created Assignment/Event payload or chain changed.',
|
|
800
|
+
);
|
|
445
801
|
}
|
|
446
802
|
return ingestion;
|
|
447
803
|
}
|
|
448
804
|
|
|
449
|
-
export function assertAcceptedLiveEvidenceBridgeV2(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
805
|
+
export function assertAcceptedLiveEvidenceBridgeV2(
|
|
806
|
+
record,
|
|
807
|
+
{
|
|
808
|
+
assignment,
|
|
809
|
+
artifact,
|
|
810
|
+
submittedEvent,
|
|
811
|
+
artifactCreatedEvent,
|
|
812
|
+
validatedEvent,
|
|
813
|
+
evidenceRef,
|
|
814
|
+
evidenceArtifact,
|
|
815
|
+
evidenceResolution,
|
|
816
|
+
resultCheckpoint,
|
|
817
|
+
checkpointHistory = [],
|
|
818
|
+
...options
|
|
819
|
+
},
|
|
820
|
+
) {
|
|
454
821
|
const ingestion = assertAcceptedLiveEvidenceSourceV2(record, {
|
|
455
|
-
assignment,
|
|
822
|
+
assignment,
|
|
823
|
+
artifact,
|
|
824
|
+
submittedEvent,
|
|
825
|
+
artifactCreatedEvent,
|
|
826
|
+
validatedEvent,
|
|
827
|
+
...options,
|
|
456
828
|
});
|
|
457
829
|
protocol('operating-evidence-ref', evidenceRef);
|
|
458
830
|
protocol('operating-artifact', evidenceArtifact);
|
|
459
831
|
protocol('operating-evidence-resolution', evidenceResolution);
|
|
460
|
-
const candidate = ingestion.evidenceCandidates.find(
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
832
|
+
const candidate = ingestion.evidenceCandidates.find(
|
|
833
|
+
(entry) => entry.candidateId === evidenceRef.candidateId,
|
|
834
|
+
);
|
|
835
|
+
const expectedLocator =
|
|
836
|
+
candidate === undefined
|
|
837
|
+
? null
|
|
838
|
+
: {
|
|
839
|
+
artifactId: candidate.locator.artifactId,
|
|
840
|
+
expectedArtifactType: candidate.locator.expectedArtifactType,
|
|
841
|
+
expectedSchemaId: candidate.locator.expectedSchemaId,
|
|
842
|
+
expectedSchemaVersion: candidate.locator.expectedSchemaVersion,
|
|
843
|
+
expectedRawHash: artifact.rawHash,
|
|
844
|
+
expectedCanonicalHash: artifact.canonicalHash,
|
|
845
|
+
};
|
|
846
|
+
if (
|
|
847
|
+
evidenceRef.evidenceRefId !== ingestion.submission.evidenceRefId ||
|
|
848
|
+
evidenceRef.sourceArtifactId !== artifact.artifactId ||
|
|
849
|
+
candidate === undefined ||
|
|
850
|
+
evidenceRef.evidenceKind !== 'operate-artifact' ||
|
|
851
|
+
!sameValue(evidenceRef.sourceContract, ingestion.sourceContract) ||
|
|
852
|
+
(candidate.locator.expectedRawHash !== undefined &&
|
|
853
|
+
candidate.locator.expectedRawHash !== artifact.rawHash) ||
|
|
854
|
+
(candidate.locator.expectedCanonicalHash !== undefined &&
|
|
855
|
+
candidate.locator.expectedCanonicalHash !== artifact.canonicalHash) ||
|
|
856
|
+
!sameValue(evidenceRef.locator, expectedLocator) ||
|
|
857
|
+
!sameValue(evidenceRef.provider, candidate.provider) ||
|
|
858
|
+
!sameValue(evidenceRef.resolver, candidate.resolver) ||
|
|
859
|
+
evidenceRef.classification !== ingestion.classification ||
|
|
860
|
+
evidenceRef.evidenceArtifactId !== evidenceArtifact.artifactId ||
|
|
861
|
+
evidenceRef.evidenceArtifactRawHash !== evidenceArtifact.rawHash ||
|
|
862
|
+
evidenceRef.evidenceArtifactCanonicalHash !== evidenceArtifact.canonicalHash ||
|
|
863
|
+
evidenceArtifact.artifactId === artifact.artifactId ||
|
|
864
|
+
evidenceArtifact.artifactType !== 'evidence-snapshot' ||
|
|
865
|
+
evidenceArtifact.assignmentId !== artifact.assignmentId ||
|
|
866
|
+
evidenceArtifact.cycleId !== artifact.cycleId ||
|
|
867
|
+
evidenceArtifact.scopeId !== artifact.scopeId ||
|
|
868
|
+
evidenceArtifact.domainId !== artifact.domainId ||
|
|
869
|
+
evidenceArtifact.domainVersion !== artifact.domainVersion ||
|
|
870
|
+
evidenceArtifact.schemaId !== 'operating-evidence-snapshot' ||
|
|
871
|
+
evidenceArtifact.artifactSchemaVersion !== '1.0.0' ||
|
|
872
|
+
evidenceArtifact.mediaType !== 'application/octet-stream' ||
|
|
873
|
+
evidenceArtifact.encoding !== 'binary' ||
|
|
874
|
+
evidenceArtifact.rawHash !== artifact.rawHash ||
|
|
875
|
+
evidenceArtifact.canonicalHash !== artifact.canonicalHash ||
|
|
876
|
+
evidenceArtifact.sizeBytes !== artifact.sizeBytes ||
|
|
877
|
+
evidenceArtifact.sensitivity !== artifact.sensitivity ||
|
|
878
|
+
evidenceArtifact.retentionClass !== artifact.retentionClass ||
|
|
879
|
+
!sameValue(evidenceArtifact.inputArtifactIds, [artifact.artifactId]) ||
|
|
880
|
+
evidenceArtifact.createdAt !== evidenceRef.resolvedAt ||
|
|
881
|
+
!sameValue(evidenceArtifact.producer, {
|
|
882
|
+
actorId: 'openplanr',
|
|
883
|
+
roleId: 'evidence-resolver',
|
|
884
|
+
runtime: 'openplanr',
|
|
885
|
+
})
|
|
886
|
+
) {
|
|
887
|
+
fail(
|
|
888
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
889
|
+
'Accepted EvidenceRef does not bind the ingestion Artifact.',
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
if (
|
|
893
|
+
evidenceResolution.outcome !== 'resolved' ||
|
|
894
|
+
evidenceResolution.error !== null ||
|
|
895
|
+
evidenceResolution.candidateId !== candidate.candidateId ||
|
|
896
|
+
evidenceResolution.sourceArtifactId !== artifact.artifactId ||
|
|
897
|
+
evidenceResolution.evidenceKind !== 'operate-artifact' ||
|
|
898
|
+
!sameValue(evidenceResolution.sourceContract, ingestion.sourceContract) ||
|
|
899
|
+
!sameValue(evidenceResolution.provider, candidate.provider) ||
|
|
900
|
+
!sameValue(evidenceResolution.resolver, candidate.resolver) ||
|
|
901
|
+
evidenceResolution.evidenceRefId !== evidenceRef.evidenceRefId ||
|
|
902
|
+
evidenceResolution.evidenceArtifactId !== evidenceArtifact.artifactId ||
|
|
903
|
+
evidenceResolution.resolvedAt !== evidenceRef.resolvedAt ||
|
|
904
|
+
evidenceArtifact.createdAt !== evidenceResolution.resolvedAt ||
|
|
905
|
+
evidenceResolution.scopeId !== artifact.scopeId ||
|
|
906
|
+
evidenceResolution.domainId !== artifact.domainId ||
|
|
907
|
+
evidenceResolution.domainVersion !== artifact.domainVersion
|
|
908
|
+
) {
|
|
909
|
+
fail(
|
|
910
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
911
|
+
'Evidence resolution changed the runtime-built snapshot or EvidenceRef custody.',
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
if (resultCheckpoint === undefined)
|
|
915
|
+
fail(
|
|
916
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
917
|
+
'Accepted ingestion requires the exact post-acceptance connector checkpoint.',
|
|
918
|
+
);
|
|
511
919
|
const requestCheckpoint = assertOperatingConnectorCheckpointV2(options.connectorCheckpoint);
|
|
512
|
-
const chain = [
|
|
920
|
+
const chain = [
|
|
921
|
+
requestCheckpoint,
|
|
922
|
+
...checkpointHistory.map(assertOperatingConnectorCheckpointV2),
|
|
923
|
+
assertOperatingConnectorCheckpointV2(resultCheckpoint),
|
|
924
|
+
];
|
|
513
925
|
for (let index = 1; index < chain.length; index += 1) {
|
|
514
|
-
if (
|
|
515
|
-
|
|
926
|
+
if (
|
|
927
|
+
chain[index].predecessorDigest !== chain[index - 1].checkpointHash ||
|
|
928
|
+
chain[index].generation !== chain[index - 1].generation + 1
|
|
929
|
+
)
|
|
930
|
+
fail('LIVE_EVIDENCE_BRIDGE_INVALID', 'Connector checkpoint lineage is not contiguous.');
|
|
516
931
|
}
|
|
517
932
|
const terminalCheckpoint = chain.at(-1);
|
|
518
|
-
if (
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
933
|
+
if (
|
|
934
|
+
!['materialized', 'committed'].includes(terminalCheckpoint.state) ||
|
|
935
|
+
terminalCheckpoint.artifactId !== artifact.artifactId ||
|
|
936
|
+
terminalCheckpoint.artifactHash !== artifact.canonicalHash ||
|
|
937
|
+
terminalCheckpoint.requestHash !== ingestion.requestHash ||
|
|
938
|
+
terminalCheckpoint.consentRecordHash !== ingestion.consentRecordHash ||
|
|
939
|
+
terminalCheckpoint.runtimeCapabilityHash !== ingestion.runtimeCapabilityHash ||
|
|
940
|
+
!sameValue(terminalCheckpoint.health, ingestion.health)
|
|
941
|
+
) {
|
|
942
|
+
fail(
|
|
943
|
+
'LIVE_EVIDENCE_BRIDGE_INVALID',
|
|
944
|
+
'Post-acceptance checkpoint changed Artifact or request custody.',
|
|
945
|
+
);
|
|
525
946
|
}
|
|
526
947
|
return ingestion;
|
|
527
948
|
}
|
|
@@ -530,29 +951,70 @@ export function assertOperatingConnectorCheckpointV2(checkpoint) {
|
|
|
530
951
|
protocol('operating-connector-checkpoint', checkpoint);
|
|
531
952
|
safePortable(checkpoint);
|
|
532
953
|
selfHash(checkpoint, 'checkpointHash');
|
|
533
|
-
if (
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
954
|
+
if (
|
|
955
|
+
checkpoint.generation === 0 &&
|
|
956
|
+
(checkpoint.state !== 'prepared' ||
|
|
957
|
+
checkpoint.predecessorDigest !== null ||
|
|
958
|
+
checkpoint.lastEventId !== null ||
|
|
959
|
+
checkpoint.lastEventHash !== null)
|
|
960
|
+
) {
|
|
961
|
+
fail(
|
|
962
|
+
'LIVE_EVIDENCE_CHECKPOINT_INVALID',
|
|
963
|
+
'Generation-zero connector checkpoint must be an unadvanced prepared record.',
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
if (
|
|
967
|
+
checkpoint.state === 'prepared' &&
|
|
968
|
+
(checkpoint.consentRecordId !== null ||
|
|
969
|
+
checkpoint.consentRecordHash !== null ||
|
|
970
|
+
checkpoint.consentExpiresAt !== null ||
|
|
971
|
+
checkpoint.runtimeCapabilityHash !== null ||
|
|
972
|
+
checkpoint.artifactId !== null ||
|
|
973
|
+
checkpoint.artifactHash !== null ||
|
|
974
|
+
checkpoint.absenceDigest !== null)
|
|
975
|
+
) {
|
|
976
|
+
fail(
|
|
977
|
+
'LIVE_EVIDENCE_CHECKPOINT_INVALID',
|
|
978
|
+
'Prepared checkpoint cannot claim consent, capability, Artifact, or absence custody.',
|
|
979
|
+
);
|
|
540
980
|
}
|
|
541
981
|
if (['requesting', 'materialized', 'committed'].includes(checkpoint.state)) {
|
|
542
|
-
if (
|
|
543
|
-
|
|
544
|
-
|
|
982
|
+
if (
|
|
983
|
+
checkpoint.consentRecordId === null ||
|
|
984
|
+
checkpoint.consentRecordHash === null ||
|
|
985
|
+
checkpoint.consentExpiresAt === null ||
|
|
986
|
+
checkpoint.runtimeCapabilityHash === null
|
|
987
|
+
) {
|
|
988
|
+
fail(
|
|
989
|
+
'LIVE_EVIDENCE_CHECKPOINT_INVALID',
|
|
990
|
+
'Requested checkpoint requires exact consent and runtime capability custody.',
|
|
991
|
+
);
|
|
545
992
|
}
|
|
546
993
|
currentAt(checkpoint.updatedAt, checkpoint.consentExpiresAt, 'Connector consent');
|
|
547
994
|
}
|
|
548
995
|
if (['materialized', 'committed'].includes(checkpoint.state)) {
|
|
549
|
-
if (
|
|
550
|
-
|
|
996
|
+
if (
|
|
997
|
+
checkpoint.health.status !== 'available' ||
|
|
998
|
+
checkpoint.artifactId === null ||
|
|
999
|
+
checkpoint.artifactHash === null ||
|
|
1000
|
+
checkpoint.absenceDigest !== null
|
|
1001
|
+
)
|
|
1002
|
+
fail(
|
|
1003
|
+
'LIVE_EVIDENCE_FALSE_PASS',
|
|
1004
|
+
'Materialized connector checkpoint requires available health and exact Artifact custody.',
|
|
1005
|
+
);
|
|
551
1006
|
currentAt(checkpoint.updatedAt, checkpoint.health.freshUntil, 'Provider health');
|
|
552
1007
|
}
|
|
553
|
-
if (
|
|
554
|
-
|
|
555
|
-
|
|
1008
|
+
if (
|
|
1009
|
+
['absent', 'uncertain'].includes(checkpoint.state) &&
|
|
1010
|
+
(checkpoint.absenceDigest === null ||
|
|
1011
|
+
checkpoint.artifactId !== null ||
|
|
1012
|
+
checkpoint.artifactHash !== null)
|
|
1013
|
+
) {
|
|
1014
|
+
fail(
|
|
1015
|
+
'LIVE_EVIDENCE_CHECKPOINT_INVALID',
|
|
1016
|
+
'Absent or uncertain checkpoint requires one typed absence and no Artifact custody.',
|
|
1017
|
+
);
|
|
556
1018
|
}
|
|
557
1019
|
return freeze(clone(checkpoint));
|
|
558
1020
|
}
|
|
@@ -561,44 +1023,95 @@ export function reduceOperatingConnectorCheckpointV2(currentValue, eventValue) {
|
|
|
561
1023
|
const current = assertOperatingConnectorCheckpointV2(currentValue);
|
|
562
1024
|
const event = clone(eventValue);
|
|
563
1025
|
assertExactKeys(event, CONNECTOR_EVENT_FIELDS, 'Connector transition Event');
|
|
564
|
-
if (!CONNECTOR_PATCH_FIELDS[event.type])
|
|
1026
|
+
if (!CONNECTOR_PATCH_FIELDS[event.type])
|
|
1027
|
+
fail('LIVE_EVIDENCE_TRANSITION_INVALID', 'Unknown connector transition type.', {
|
|
1028
|
+
type: event.type,
|
|
1029
|
+
});
|
|
565
1030
|
assertExactKeys(event.patch, CONNECTOR_PATCH_FIELDS[event.type], `${event.type} connector patch`);
|
|
566
1031
|
const claimed = event.eventHash;
|
|
567
1032
|
delete event.eventHash;
|
|
568
1033
|
const eventHash = sha256Jcs(event);
|
|
569
|
-
if (claimed !== eventHash)
|
|
1034
|
+
if (claimed !== eventHash)
|
|
1035
|
+
fail('LIVE_EVIDENCE_DIGEST_MISMATCH', 'Connector event hash does not bind the exact event.');
|
|
570
1036
|
if (current.lastEventId === event.eventId) {
|
|
571
|
-
if (current.lastEventHash !== eventHash)
|
|
1037
|
+
if (current.lastEventHash !== eventHash)
|
|
1038
|
+
fail('LIVE_EVIDENCE_REPLAY_CONFLICT', 'Divergent connector event reused one identity.');
|
|
572
1039
|
return current;
|
|
573
1040
|
}
|
|
574
|
-
if (
|
|
575
|
-
|
|
1041
|
+
if (
|
|
1042
|
+
event.expectedGeneration !== current.generation ||
|
|
1043
|
+
event.expectedCheckpointHash !== current.checkpointHash
|
|
1044
|
+
) {
|
|
1045
|
+
fail(
|
|
1046
|
+
'LIVE_EVIDENCE_CONCURRENT_MODIFICATION',
|
|
1047
|
+
'Connector checkpoint generation or digest changed.',
|
|
1048
|
+
);
|
|
576
1049
|
}
|
|
577
1050
|
const target = CHECKPOINT_TRANSITIONS[current.state]?.[event.type];
|
|
578
|
-
if (target === undefined)
|
|
1051
|
+
if (target === undefined)
|
|
1052
|
+
fail('LIVE_EVIDENCE_TRANSITION_INVALID', 'Illegal connector checkpoint transition.', {
|
|
1053
|
+
from: current.state,
|
|
1054
|
+
type: event.type,
|
|
1055
|
+
});
|
|
579
1056
|
const patch = event.patch ?? {};
|
|
580
1057
|
for (const field of IMMUTABLE_CHECKPOINT_FIELDS) {
|
|
581
|
-
if (Object.hasOwn(patch, field) && !sameValue(patch[field], current[field]))
|
|
1058
|
+
if (Object.hasOwn(patch, field) && !sameValue(patch[field], current[field]))
|
|
1059
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', `Connector ${field} cannot change.`);
|
|
582
1060
|
}
|
|
583
1061
|
if (current.state !== 'prepared') {
|
|
584
|
-
for (const field of [
|
|
1062
|
+
for (const field of [
|
|
1063
|
+
'consentRecordId',
|
|
1064
|
+
'consentRecordHash',
|
|
1065
|
+
'consentExpiresAt',
|
|
1066
|
+
'runtimeCapabilityHash',
|
|
1067
|
+
]) {
|
|
585
1068
|
if (Object.hasOwn(patch, field) && !sameValue(patch[field], current[field])) {
|
|
586
|
-
fail(
|
|
1069
|
+
fail(
|
|
1070
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1071
|
+
`Connector ${field} is frozen after request issuance.`,
|
|
1072
|
+
);
|
|
587
1073
|
}
|
|
588
1074
|
}
|
|
589
1075
|
}
|
|
590
|
-
if (
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1076
|
+
if (
|
|
1077
|
+
event.type === 'request' &&
|
|
1078
|
+
(patch.consentRecordId === null ||
|
|
1079
|
+
patch.consentRecordHash === null ||
|
|
1080
|
+
patch.consentExpiresAt === null ||
|
|
1081
|
+
patch.runtimeCapabilityHash === null)
|
|
1082
|
+
) {
|
|
1083
|
+
fail(
|
|
1084
|
+
'LIVE_EVIDENCE_AUTHORITY_INVALID',
|
|
1085
|
+
'Requesting a provider call requires current consent and one opaque runtime capability.',
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
if (
|
|
1089
|
+
event.type === 'materialize' &&
|
|
1090
|
+
(patch.artifactId === null ||
|
|
1091
|
+
patch.artifactHash === null ||
|
|
1092
|
+
patch.health?.status !== 'available')
|
|
1093
|
+
) {
|
|
1094
|
+
fail(
|
|
1095
|
+
'LIVE_EVIDENCE_FALSE_PASS',
|
|
1096
|
+
'Materialize transition requires exact Artifact and current available-health proof.',
|
|
1097
|
+
);
|
|
597
1098
|
}
|
|
598
1099
|
if (['absent', 'uncertain'].includes(event.type) && patch.absenceDigest === null) {
|
|
599
|
-
fail(
|
|
600
|
-
|
|
601
|
-
|
|
1100
|
+
fail(
|
|
1101
|
+
'LIVE_EVIDENCE_CHECKPOINT_INVALID',
|
|
1102
|
+
'Absent or uncertain transition requires a typed absence digest.',
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
const next = {
|
|
1106
|
+
...clone(current),
|
|
1107
|
+
...patch,
|
|
1108
|
+
state: target,
|
|
1109
|
+
generation: current.generation + 1,
|
|
1110
|
+
lastEventId: event.eventId,
|
|
1111
|
+
lastEventHash: eventHash,
|
|
1112
|
+
predecessorDigest: current.checkpointHash,
|
|
1113
|
+
updatedAt: event.at,
|
|
1114
|
+
};
|
|
602
1115
|
delete next.checkpointHash;
|
|
603
1116
|
next.checkpointHash = sha256Jcs(next);
|
|
604
1117
|
return assertOperatingConnectorCheckpointV2(next);
|
|
@@ -609,39 +1122,94 @@ export function assertOperatingMeasurementPlanV2(plan, { verificationPlan } = {}
|
|
|
609
1122
|
safePortable(plan);
|
|
610
1123
|
selfHash(plan, 'planHash');
|
|
611
1124
|
const terminal = [...plan.terminalResults].sort();
|
|
612
|
-
if (!sameValue(terminal, ['failed', 'insufficient-evidence', 'passed']))
|
|
613
|
-
|
|
614
|
-
if (
|
|
615
|
-
|
|
616
|
-
|
|
1125
|
+
if (!sameValue(terminal, ['failed', 'insufficient-evidence', 'passed']))
|
|
1126
|
+
fail('LIVE_EVIDENCE_PLAN_INVALID', 'Measurement plan must declare every terminal result.');
|
|
1127
|
+
if (plan.target.unit !== plan.metric.unit || plan.baseline.unit !== plan.metric.unit)
|
|
1128
|
+
fail('LIVE_EVIDENCE_UNIT_MISMATCH', 'Baseline and target units must match the metric.');
|
|
1129
|
+
if (
|
|
1130
|
+
![
|
|
1131
|
+
plan.baseline.value,
|
|
1132
|
+
...(Array.isArray(plan.target.value) ? plan.target.value : [plan.target.value]),
|
|
1133
|
+
].every(Number.isFinite) ||
|
|
1134
|
+
Date.parse(plan.window.from) > Date.parse(plan.window.to) ||
|
|
1135
|
+
Date.parse(plan.dueAt) < Date.parse(plan.window.to)
|
|
1136
|
+
) {
|
|
1137
|
+
fail(
|
|
1138
|
+
'LIVE_EVIDENCE_PLAN_INVALID',
|
|
1139
|
+
'Measurement values must be finite and the inclusive window/due chronology must be ordered.',
|
|
1140
|
+
);
|
|
617
1141
|
}
|
|
618
1142
|
const algebra = {
|
|
619
|
-
increase: ['gt', 'gte'],
|
|
1143
|
+
increase: ['gt', 'gte'],
|
|
1144
|
+
decrease: ['lt', 'lte'],
|
|
1145
|
+
maintain: ['eq'],
|
|
1146
|
+
range: ['between'],
|
|
620
1147
|
};
|
|
621
1148
|
if (!algebra[plan.target.direction]?.includes(plan.target.operator)) {
|
|
622
1149
|
fail('LIVE_EVIDENCE_PLAN_INVALID', 'Measurement direction and operator are incompatible.');
|
|
623
1150
|
}
|
|
624
1151
|
if (plan.target.operator === 'between') {
|
|
625
|
-
if (
|
|
1152
|
+
if (
|
|
1153
|
+
!Array.isArray(plan.target.value) ||
|
|
1154
|
+
plan.target.value.length !== 2 ||
|
|
1155
|
+
plan.target.value[0] > plan.target.value[1]
|
|
1156
|
+
) {
|
|
626
1157
|
fail('LIVE_EVIDENCE_PLAN_INVALID', 'Between target must be one ordered finite range.');
|
|
627
1158
|
}
|
|
628
1159
|
} else if (Array.isArray(plan.target.value)) {
|
|
629
1160
|
fail('LIVE_EVIDENCE_PLAN_INVALID', 'Scalar measurement operators cannot use a range target.');
|
|
630
1161
|
}
|
|
631
|
-
if (
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
1162
|
+
if (
|
|
1163
|
+
(plan.target.direction === 'increase' && plan.target.value <= plan.baseline.value) ||
|
|
1164
|
+
(plan.target.direction === 'decrease' && plan.target.value >= plan.baseline.value) ||
|
|
1165
|
+
(plan.target.direction === 'maintain' && plan.target.value !== plan.baseline.value)
|
|
1166
|
+
) {
|
|
1167
|
+
fail(
|
|
1168
|
+
'LIVE_EVIDENCE_PLAN_INVALID',
|
|
1169
|
+
'Measurement target does not match the declared baseline direction.',
|
|
1170
|
+
);
|
|
635
1171
|
}
|
|
636
1172
|
if (verificationPlan !== undefined) {
|
|
637
1173
|
protocol('operating-action-verification-plan', verificationPlan);
|
|
638
1174
|
exactDigest(verificationPlan, plan.verificationPlan.recordDigest, 'Action verification plan');
|
|
639
|
-
same(
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
1175
|
+
same(
|
|
1176
|
+
[
|
|
1177
|
+
verificationPlan.verificationPlanId,
|
|
1178
|
+
verificationPlan.actionId,
|
|
1179
|
+
verificationPlan.metricId,
|
|
1180
|
+
verificationPlan.baseline,
|
|
1181
|
+
verificationPlan.target,
|
|
1182
|
+
],
|
|
1183
|
+
[
|
|
1184
|
+
plan.verificationPlan.verificationPlanId,
|
|
1185
|
+
plan.action.actionId,
|
|
1186
|
+
plan.metric.metricId,
|
|
1187
|
+
plan.baseline.value,
|
|
1188
|
+
plan.verificationPlan.canonicalTarget,
|
|
1189
|
+
],
|
|
1190
|
+
'Measurement-plan specialization',
|
|
1191
|
+
);
|
|
1192
|
+
same(
|
|
1193
|
+
sha256Jcs(verificationPlan.window),
|
|
1194
|
+
plan.verificationPlan.windowDigest,
|
|
1195
|
+
'Verification window digest',
|
|
1196
|
+
);
|
|
1197
|
+
same(
|
|
1198
|
+
sha256Jcs(verificationPlan.method),
|
|
1199
|
+
plan.verificationPlan.methodDigest,
|
|
1200
|
+
'Verification method digest',
|
|
1201
|
+
);
|
|
1202
|
+
same(
|
|
1203
|
+
sha256Jcs(verificationPlan.evaluationRules),
|
|
1204
|
+
plan.verificationPlan.evaluationRulesDigest,
|
|
1205
|
+
'Verification rule digest',
|
|
1206
|
+
);
|
|
643
1207
|
const targetValues = Array.isArray(plan.target.value) ? plan.target.value : [plan.target.value];
|
|
644
|
-
if (!targetValues.includes(verificationPlan.target))
|
|
1208
|
+
if (!targetValues.includes(verificationPlan.target))
|
|
1209
|
+
fail(
|
|
1210
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1211
|
+
'Measurement target is not derivable from the canonical verification target.',
|
|
1212
|
+
);
|
|
645
1213
|
}
|
|
646
1214
|
return freeze(clone(plan));
|
|
647
1215
|
}
|
|
@@ -650,24 +1218,48 @@ export function assertOperatingMeasurementScheduleV2(schedule) {
|
|
|
650
1218
|
protocol('operating-measurement-schedule', schedule);
|
|
651
1219
|
safePortable(schedule);
|
|
652
1220
|
selfHash(schedule, 'scheduleHash');
|
|
653
|
-
if (
|
|
654
|
-
|
|
655
|
-
|
|
1221
|
+
if (
|
|
1222
|
+
schedule.generation === 0 &&
|
|
1223
|
+
(schedule.state !== 'disabled' ||
|
|
1224
|
+
schedule.runCount !== 0 ||
|
|
1225
|
+
schedule.nextEventIdentity !== null ||
|
|
1226
|
+
schedule.nextDueAt !== null ||
|
|
1227
|
+
schedule.lastReceiptId !== null ||
|
|
1228
|
+
schedule.lastTransitionHash !== null)
|
|
1229
|
+
) {
|
|
656
1230
|
fail('LIVE_EVIDENCE_SCHEDULE_INVALID', 'New schedules must be disabled and unadvanced.');
|
|
657
1231
|
}
|
|
658
|
-
if (schedule.recurrence.kind === 'once' && schedule.recurrence.intervalSeconds !== null)
|
|
659
|
-
|
|
660
|
-
if (
|
|
661
|
-
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
fail('LIVE_EVIDENCE_SCHEDULE_INVALID', '
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
1232
|
+
if (schedule.recurrence.kind === 'once' && schedule.recurrence.intervalSeconds !== null)
|
|
1233
|
+
fail('LIVE_EVIDENCE_SCHEDULE_INVALID', 'One-time schedules cannot carry an interval.');
|
|
1234
|
+
if (schedule.recurrence.kind === 'interval' && schedule.recurrence.intervalSeconds === null)
|
|
1235
|
+
fail('LIVE_EVIDENCE_SCHEDULE_INVALID', 'Interval schedules require a bounded interval.');
|
|
1236
|
+
if (
|
|
1237
|
+
Date.parse(schedule.startsAt) > Date.parse(schedule.endsAt ?? schedule.startsAt) ||
|
|
1238
|
+
schedule.runCount > schedule.maxRuns
|
|
1239
|
+
)
|
|
1240
|
+
fail('LIVE_EVIDENCE_SCHEDULE_INVALID', 'Schedule time bounds or run count are invalid.');
|
|
1241
|
+
if (
|
|
1242
|
+
schedule.state === 'enabled' &&
|
|
1243
|
+
(schedule.consentRecordHashes.length === 0 ||
|
|
1244
|
+
schedule.nextEventIdentity === null ||
|
|
1245
|
+
schedule.nextDueAt === null ||
|
|
1246
|
+
schedule.runCount >= schedule.maxRuns ||
|
|
1247
|
+
Date.parse(schedule.nextDueAt) < Date.parse(schedule.startsAt) ||
|
|
1248
|
+
(schedule.endsAt !== null && Date.parse(schedule.nextDueAt) > Date.parse(schedule.endsAt)))
|
|
1249
|
+
) {
|
|
1250
|
+
fail(
|
|
1251
|
+
'LIVE_EVIDENCE_SCHEDULE_INVALID',
|
|
1252
|
+
'Enabled schedule requires current consent, one due identity, and remaining bounded runs.',
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
if (
|
|
1256
|
+
['disabled', 'revoked', 'expired', 'completed'].includes(schedule.state) &&
|
|
1257
|
+
(schedule.nextEventIdentity !== null || schedule.nextDueAt !== null)
|
|
1258
|
+
) {
|
|
1259
|
+
fail(
|
|
1260
|
+
'LIVE_EVIDENCE_SCHEDULE_INVALID',
|
|
1261
|
+
'Inactive schedule cannot retain an executable due identity.',
|
|
1262
|
+
);
|
|
671
1263
|
}
|
|
672
1264
|
return freeze(clone(schedule));
|
|
673
1265
|
}
|
|
@@ -676,32 +1268,52 @@ function assertOperatingMeasurementScheduleReceiptStructureV2(receipt) {
|
|
|
676
1268
|
protocol('operating-measurement-schedule-receipt', receipt);
|
|
677
1269
|
safePortable(receipt);
|
|
678
1270
|
selfHash(receipt, 'receiptHash');
|
|
679
|
-
if (receipt.authority !== 'none' || receipt.scheduleHash !== receipt.resultingScheduleHash)
|
|
1271
|
+
if (receipt.authority !== 'none' || receipt.scheduleHash !== receipt.resultingScheduleHash)
|
|
1272
|
+
fail(
|
|
1273
|
+
'LIVE_EVIDENCE_SCHEDULE_INVALID',
|
|
1274
|
+
'Schedule receipt is non-authoritative and must bind its exact result schedule.',
|
|
1275
|
+
);
|
|
680
1276
|
return freeze(clone(receipt));
|
|
681
1277
|
}
|
|
682
1278
|
|
|
683
1279
|
function assertScheduleReceiptPredecessor(receipt, previousSchedule) {
|
|
684
1280
|
const previous = assertOperatingMeasurementScheduleV2(previousSchedule);
|
|
685
|
-
if (
|
|
686
|
-
|
|
687
|
-
|
|
1281
|
+
if (
|
|
1282
|
+
previous.scheduleHash !== receipt.previousScheduleHash ||
|
|
1283
|
+
previous.scheduleId !== receipt.scheduleId ||
|
|
1284
|
+
previous.state !== receipt.fromState ||
|
|
1285
|
+
previous.runCount !== receipt.previousRunCount ||
|
|
1286
|
+
previous.nextEventIdentity !== receipt.previousNextEventIdentity ||
|
|
1287
|
+
previous.nextDueAt !== receipt.previousNextDueAt
|
|
1288
|
+
) {
|
|
688
1289
|
fail('LIVE_EVIDENCE_BASE_RECORD_MISMATCH', 'Schedule receipt changed its exact predecessor.');
|
|
689
1290
|
}
|
|
690
1291
|
}
|
|
691
1292
|
|
|
692
1293
|
function assertScheduleReceiptResult(receipt, resultingSchedule) {
|
|
693
1294
|
const result = assertOperatingMeasurementScheduleV2(resultingSchedule);
|
|
694
|
-
if (
|
|
695
|
-
|
|
696
|
-
|
|
1295
|
+
if (
|
|
1296
|
+
result.scheduleHash !== receipt.resultingScheduleHash ||
|
|
1297
|
+
result.scheduleId !== receipt.scheduleId ||
|
|
1298
|
+
result.state !== receipt.toState ||
|
|
1299
|
+
result.runCount !== receipt.resultingRunCount ||
|
|
1300
|
+
result.nextEventIdentity !== receipt.resultingNextEventIdentity ||
|
|
1301
|
+
result.nextDueAt !== receipt.resultingNextDueAt
|
|
1302
|
+
) {
|
|
697
1303
|
fail('LIVE_EVIDENCE_BASE_RECORD_MISMATCH', 'Schedule receipt changed its exact result.');
|
|
698
1304
|
}
|
|
699
1305
|
}
|
|
700
1306
|
|
|
701
|
-
export function assertOperatingMeasurementScheduleReceiptV2(
|
|
1307
|
+
export function assertOperatingMeasurementScheduleReceiptV2(
|
|
1308
|
+
receipt,
|
|
1309
|
+
{ previousSchedule, resultingSchedule } = {},
|
|
1310
|
+
) {
|
|
702
1311
|
const normalized = assertOperatingMeasurementScheduleReceiptStructureV2(receipt);
|
|
703
1312
|
if (previousSchedule === undefined || resultingSchedule === undefined) {
|
|
704
|
-
fail(
|
|
1313
|
+
fail(
|
|
1314
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1315
|
+
'A certifying schedule receipt requires its exact predecessor and resulting schedules.',
|
|
1316
|
+
);
|
|
705
1317
|
}
|
|
706
1318
|
assertScheduleReceiptPredecessor(normalized, previousSchedule);
|
|
707
1319
|
assertScheduleReceiptResult(normalized, resultingSchedule);
|
|
@@ -710,155 +1322,372 @@ export function assertOperatingMeasurementScheduleReceiptV2(receipt, { previousS
|
|
|
710
1322
|
|
|
711
1323
|
function scheduleReceipt(schedule, transition, next) {
|
|
712
1324
|
const receipt = {
|
|
713
|
-
kind: 'operating-measurement-schedule-receipt',
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
1325
|
+
kind: 'operating-measurement-schedule-receipt',
|
|
1326
|
+
schemaVersion: '1.0.0',
|
|
1327
|
+
protocolVersion: '2.0.0',
|
|
1328
|
+
receiptId: transition.receiptId,
|
|
1329
|
+
authority: 'none',
|
|
1330
|
+
scheduleId: schedule.scheduleId,
|
|
1331
|
+
scheduleHash: next.scheduleHash,
|
|
1332
|
+
previousScheduleHash: transition.expectedScheduleHash,
|
|
1333
|
+
resultingScheduleHash: next.scheduleHash,
|
|
1334
|
+
measurementPlanId: schedule.measurementPlanId,
|
|
1335
|
+
planHash: schedule.planHash,
|
|
1336
|
+
consentRecordHashes: clone(schedule.consentRecordHashes),
|
|
1337
|
+
ceilingsHash: schedule.ceilingsHash,
|
|
1338
|
+
clockHash: transition.clockHash,
|
|
1339
|
+
recurrenceHash: sha256Jcs(schedule.recurrence),
|
|
1340
|
+
startsAt: schedule.startsAt,
|
|
1341
|
+
endsAt: schedule.endsAt,
|
|
1342
|
+
maxRuns: schedule.maxRuns,
|
|
1343
|
+
misfirePolicy: schedule.misfirePolicy,
|
|
1344
|
+
dstPolicy: schedule.dstPolicy,
|
|
1345
|
+
transition: transition.type,
|
|
1346
|
+
fromState: transition.expectedState,
|
|
1347
|
+
toState: next.state,
|
|
1348
|
+
previousRunCount: transition.expectedRunCount,
|
|
1349
|
+
resultingRunCount: next.runCount,
|
|
1350
|
+
previousNextEventIdentity: transition.expectedNextEventIdentity,
|
|
1351
|
+
resultingNextEventIdentity: next.nextEventIdentity,
|
|
1352
|
+
previousNextDueAt: transition.expectedNextDueAt,
|
|
1353
|
+
resultingNextDueAt: next.nextDueAt,
|
|
1354
|
+
ownerActorId: schedule.ownerActorId,
|
|
1355
|
+
eventId: transition.eventId,
|
|
1356
|
+
nextEventIdentity: next.nextEventIdentity,
|
|
725
1357
|
at: transition.at,
|
|
726
1358
|
};
|
|
727
1359
|
receipt.receiptHash = sha256Jcs(receipt);
|
|
728
1360
|
return receipt;
|
|
729
1361
|
}
|
|
730
1362
|
|
|
731
|
-
export function reduceOperatingMeasurementScheduleV2(
|
|
1363
|
+
export function reduceOperatingMeasurementScheduleV2(
|
|
1364
|
+
scheduleValue,
|
|
1365
|
+
transitionValue,
|
|
1366
|
+
{ priorReceipt } = {},
|
|
1367
|
+
) {
|
|
732
1368
|
const schedule = assertOperatingMeasurementScheduleV2(scheduleValue);
|
|
733
1369
|
const transition = clone(transitionValue);
|
|
734
1370
|
assertExactKeys(transition, SCHEDULE_TRANSITION_FIELDS, 'Measurement schedule transition');
|
|
735
1371
|
const transitionHash = sha256Jcs(transition);
|
|
736
1372
|
if (schedule.lastReceiptId === transition.receiptId) {
|
|
737
|
-
if (schedule.lastTransitionHash !== transitionHash)
|
|
738
|
-
|
|
1373
|
+
if (schedule.lastTransitionHash !== transitionHash)
|
|
1374
|
+
fail(
|
|
1375
|
+
'LIVE_EVIDENCE_REPLAY_CONFLICT',
|
|
1376
|
+
'Divergent schedule transition reused one receipt identity.',
|
|
1377
|
+
);
|
|
1378
|
+
if (priorReceipt === undefined)
|
|
1379
|
+
fail(
|
|
1380
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1381
|
+
'Exact schedule replay requires the stored immutable prior receipt.',
|
|
1382
|
+
);
|
|
739
1383
|
const receipt = assertOperatingMeasurementScheduleReceiptStructureV2(priorReceipt);
|
|
740
1384
|
const expected = scheduleReceipt(schedule, transition, schedule);
|
|
741
|
-
if (!sameValue(receipt, expected))
|
|
1385
|
+
if (!sameValue(receipt, expected))
|
|
1386
|
+
fail(
|
|
1387
|
+
'LIVE_EVIDENCE_REPLAY_CONFLICT',
|
|
1388
|
+
'Stored schedule receipt does not match the exact replay request and resulting schedule.',
|
|
1389
|
+
);
|
|
742
1390
|
assertScheduleReceiptResult(receipt, schedule);
|
|
743
1391
|
return freeze({ replay: true, schedule, receipt });
|
|
744
1392
|
}
|
|
745
|
-
if (
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
1393
|
+
if (
|
|
1394
|
+
transition.expectedGeneration !== schedule.generation ||
|
|
1395
|
+
transition.expectedScheduleHash !== schedule.scheduleHash
|
|
1396
|
+
)
|
|
1397
|
+
fail('LIVE_EVIDENCE_CONCURRENT_MODIFICATION', 'Schedule generation or digest changed.');
|
|
1398
|
+
if (
|
|
1399
|
+
transition.expectedState !== schedule.state ||
|
|
1400
|
+
transition.expectedRunCount !== schedule.runCount ||
|
|
1401
|
+
transition.expectedNextEventIdentity !== schedule.nextEventIdentity ||
|
|
1402
|
+
transition.expectedNextDueAt !== schedule.nextDueAt
|
|
1403
|
+
) {
|
|
1404
|
+
fail(
|
|
1405
|
+
'LIVE_EVIDENCE_CONCURRENT_MODIFICATION',
|
|
1406
|
+
'Schedule state, run count, or due identity changed.',
|
|
1407
|
+
);
|
|
749
1408
|
}
|
|
750
1409
|
let toState = SCHEDULE_TRANSITIONS[schedule.state]?.[transition.type];
|
|
751
|
-
if (toState === undefined)
|
|
752
|
-
|
|
753
|
-
|
|
1410
|
+
if (toState === undefined)
|
|
1411
|
+
fail('LIVE_EVIDENCE_TRANSITION_INVALID', 'Illegal measurement schedule transition.', {
|
|
1412
|
+
from: schedule.state,
|
|
1413
|
+
type: transition.type,
|
|
1414
|
+
});
|
|
1415
|
+
if (
|
|
1416
|
+
transition.planHash !== schedule.planHash ||
|
|
1417
|
+
!sameValue(transition.consentRecordHashes, schedule.consentRecordHashes) ||
|
|
1418
|
+
transition.ceilingsHash !== schedule.ceilingsHash
|
|
1419
|
+
)
|
|
1420
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Schedule transition changed plan or consent custody.');
|
|
754
1421
|
let runCount = schedule.runCount;
|
|
755
1422
|
if (transition.type === 'enable') {
|
|
756
|
-
if (
|
|
757
|
-
|
|
758
|
-
|
|
1423
|
+
if (
|
|
1424
|
+
schedule.consentRecordHashes.length === 0 ||
|
|
1425
|
+
transition.nextEventIdentity === null ||
|
|
1426
|
+
transition.nextDueAt === null ||
|
|
1427
|
+
Date.parse(transition.nextDueAt) < Date.parse(schedule.startsAt)
|
|
1428
|
+
) {
|
|
1429
|
+
fail(
|
|
1430
|
+
'LIVE_EVIDENCE_AUTHORITY_INVALID',
|
|
1431
|
+
'Enabling measurement requires consent custody and a bounded runtime-issued due identity.',
|
|
1432
|
+
);
|
|
759
1433
|
}
|
|
760
1434
|
} else if (transition.type === 'run-issued') {
|
|
761
|
-
if (
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
1435
|
+
if (
|
|
1436
|
+
schedule.nextEventIdentity !== transition.eventId ||
|
|
1437
|
+
schedule.nextDueAt === null ||
|
|
1438
|
+
Date.parse(transition.at) < Date.parse(schedule.nextDueAt) ||
|
|
1439
|
+
(schedule.endsAt !== null && Date.parse(transition.at) > Date.parse(schedule.endsAt))
|
|
1440
|
+
) {
|
|
1441
|
+
fail(
|
|
1442
|
+
'LIVE_EVIDENCE_TRANSITION_INVALID',
|
|
1443
|
+
'Measurement run is not the exact due runtime identity within its schedule window.',
|
|
1444
|
+
);
|
|
765
1445
|
}
|
|
766
1446
|
runCount += 1;
|
|
767
1447
|
const terminalRun = runCount >= schedule.maxRuns || schedule.recurrence.kind === 'once';
|
|
768
1448
|
toState = terminalRun ? 'completed' : 'enabled';
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1449
|
+
if (
|
|
1450
|
+
terminalRun
|
|
1451
|
+
? transition.nextEventIdentity !== null || transition.nextDueAt !== null
|
|
1452
|
+
: transition.nextEventIdentity === null ||
|
|
1453
|
+
transition.nextDueAt === null ||
|
|
1454
|
+
transition.nextEventIdentity === transition.eventId ||
|
|
1455
|
+
Date.parse(transition.nextDueAt) <= Date.parse(schedule.nextDueAt)
|
|
1456
|
+
) {
|
|
1457
|
+
fail(
|
|
1458
|
+
'LIVE_EVIDENCE_TRANSITION_INVALID',
|
|
1459
|
+
'Measurement run successor identity or completion state is invalid.',
|
|
1460
|
+
);
|
|
774
1461
|
}
|
|
775
1462
|
} else if (['disable', 'revoke', 'expire', 'complete'].includes(transition.type)) {
|
|
776
|
-
if (transition.nextEventIdentity !== null || transition.nextDueAt !== null)
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1463
|
+
if (transition.nextEventIdentity !== null || transition.nextDueAt !== null)
|
|
1464
|
+
fail(
|
|
1465
|
+
'LIVE_EVIDENCE_TRANSITION_INVALID',
|
|
1466
|
+
'Inactive transition cannot retain an executable due identity.',
|
|
1467
|
+
);
|
|
1468
|
+
} else if (
|
|
1469
|
+
transition.nextEventIdentity !== schedule.nextEventIdentity ||
|
|
1470
|
+
transition.nextDueAt !== schedule.nextDueAt
|
|
1471
|
+
) {
|
|
1472
|
+
fail(
|
|
1473
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1474
|
+
'Pause or resume cannot substitute the scheduled due identity.',
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
const next = {
|
|
1478
|
+
...clone(schedule),
|
|
1479
|
+
generation: schedule.generation + 1,
|
|
1480
|
+
state: toState,
|
|
1481
|
+
runCount,
|
|
1482
|
+
nextEventIdentity: transition.nextEventIdentity,
|
|
1483
|
+
nextDueAt: transition.nextDueAt,
|
|
1484
|
+
lastReceiptId: transition.receiptId,
|
|
1485
|
+
lastTransitionHash: transitionHash,
|
|
1486
|
+
};
|
|
783
1487
|
delete next.scheduleHash;
|
|
784
1488
|
next.scheduleHash = sha256Jcs(next);
|
|
785
1489
|
const normalizedNext = assertOperatingMeasurementScheduleV2(next);
|
|
786
1490
|
const receipt = scheduleReceipt(schedule, transition, normalizedNext);
|
|
787
|
-
return freeze({
|
|
788
|
-
|
|
1491
|
+
return freeze({
|
|
1492
|
+
replay: false,
|
|
1493
|
+
schedule: normalizedNext,
|
|
1494
|
+
receipt: assertOperatingMeasurementScheduleReceiptV2(receipt, {
|
|
1495
|
+
previousSchedule: schedule,
|
|
1496
|
+
resultingSchedule: normalizedNext,
|
|
1497
|
+
}),
|
|
1498
|
+
});
|
|
789
1499
|
}
|
|
790
1500
|
|
|
791
|
-
export function assertOperatingEvidenceObservationV2(
|
|
792
|
-
|
|
793
|
-
|
|
1501
|
+
export function assertOperatingEvidenceObservationV2(
|
|
1502
|
+
observation,
|
|
1503
|
+
{
|
|
1504
|
+
measurementPlan,
|
|
1505
|
+
metricObservation,
|
|
1506
|
+
ingestion,
|
|
1507
|
+
connectorCheckpoint,
|
|
1508
|
+
artifact,
|
|
1509
|
+
evidenceRefs,
|
|
1510
|
+
acceptedBridge,
|
|
1511
|
+
} = {},
|
|
1512
|
+
) {
|
|
794
1513
|
protocol('operating-evidence-observation', observation);
|
|
795
1514
|
safePortable(observation);
|
|
796
1515
|
selfHash(observation, 'observationHash');
|
|
797
|
-
if (measurementPlan === undefined)
|
|
1516
|
+
if (measurementPlan === undefined)
|
|
1517
|
+
fail(
|
|
1518
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1519
|
+
'Evidence observation requires the exact measurement plan.',
|
|
1520
|
+
);
|
|
798
1521
|
const plan = assertOperatingMeasurementPlanV2(measurementPlan);
|
|
799
|
-
if (
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1522
|
+
if (
|
|
1523
|
+
plan.measurementPlanId !== observation.measurementPlan.recordId ||
|
|
1524
|
+
plan.planHash !== observation.measurementPlan.recordDigest ||
|
|
1525
|
+
plan.metric.metricId !== observation.metricId ||
|
|
1526
|
+
plan.metric.unit !== observation.unit ||
|
|
1527
|
+
plan.metric.dimension !== observation.dimension
|
|
1528
|
+
) {
|
|
1529
|
+
fail(
|
|
1530
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1531
|
+
'Evidence observation changed measurement-plan metric custody.',
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
if (
|
|
1535
|
+
ingestion === undefined ||
|
|
1536
|
+
connectorCheckpoint === undefined ||
|
|
1537
|
+
artifact === undefined ||
|
|
1538
|
+
!Array.isArray(evidenceRefs) ||
|
|
1539
|
+
acceptedBridge === undefined
|
|
1540
|
+
) {
|
|
1541
|
+
fail(
|
|
1542
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1543
|
+
'Evidence observation requires the exact accepted ingestion bridge, checkpoint, Artifact, and EvidenceRef custody.',
|
|
1544
|
+
);
|
|
806
1545
|
}
|
|
807
1546
|
const accepted = assertAcceptedLiveEvidenceBridgeV2(ingestion, acceptedBridge);
|
|
808
|
-
if (
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1547
|
+
if (
|
|
1548
|
+
accepted.ingestionHash !== ingestion.ingestionHash ||
|
|
1549
|
+
acceptedBridge.artifact?.artifactId !== artifact.artifactId ||
|
|
1550
|
+
acceptedBridge.resultCheckpoint?.checkpointId !== connectorCheckpoint.checkpointId ||
|
|
1551
|
+
evidenceRefs.length !== 1 ||
|
|
1552
|
+
acceptedBridge.evidenceRef?.evidenceRefId !== evidenceRefs[0]?.evidenceRefId ||
|
|
1553
|
+
sha256Jcs(acceptedBridge.evidenceRef) !== sha256Jcs(evidenceRefs[0])
|
|
1554
|
+
) {
|
|
1555
|
+
fail(
|
|
1556
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1557
|
+
'Observation custody is not the exact accepted live-evidence bridge.',
|
|
1558
|
+
);
|
|
815
1559
|
}
|
|
816
1560
|
const checkpoint = assertOperatingConnectorCheckpointV2(connectorCheckpoint);
|
|
817
1561
|
protocol('operating-artifact', artifact);
|
|
818
|
-
if (
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1562
|
+
if (
|
|
1563
|
+
observation.ingestion.ingestionId !== ingestion.ingestionId ||
|
|
1564
|
+
observation.ingestion.ingestionHash !== ingestion.ingestionHash ||
|
|
1565
|
+
observation.checkpoint.checkpointId !== checkpoint.checkpointId ||
|
|
1566
|
+
observation.checkpoint.checkpointHash !== checkpoint.checkpointHash ||
|
|
1567
|
+
observation.artifact.artifactId !== artifact.artifactId ||
|
|
1568
|
+
observation.artifact.recordDigest !== sha256Jcs(artifact) ||
|
|
1569
|
+
artifact.canonicalHash !== sha256Jcs(ingestion) ||
|
|
1570
|
+
ingestion.providerRegistrationHash !== observation.providerRegistrationHash ||
|
|
1571
|
+
!sameValue(ingestion.provider, observation.provider)
|
|
1572
|
+
) {
|
|
1573
|
+
fail(
|
|
1574
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1575
|
+
'Evidence observation changed live-ingestion Artifact or provider custody.',
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1578
|
+
const refs = evidenceRefs
|
|
1579
|
+
.map((entry) => {
|
|
1580
|
+
protocol('operating-evidence-ref', entry);
|
|
1581
|
+
return { evidenceRefId: entry.evidenceRefId, recordDigest: sha256Jcs(entry) };
|
|
1582
|
+
})
|
|
1583
|
+
.sort((left, right) => left.evidenceRefId.localeCompare(right.evidenceRefId));
|
|
1584
|
+
const claimedRefs = [...observation.evidenceRefs].sort((left, right) =>
|
|
1585
|
+
left.evidenceRefId.localeCompare(right.evidenceRefId),
|
|
1586
|
+
);
|
|
1587
|
+
if (!sameValue(refs, claimedRefs))
|
|
1588
|
+
fail(
|
|
1589
|
+
'LIVE_EVIDENCE_BASE_RECORD_MISMATCH',
|
|
1590
|
+
'Evidence observation changed EvidenceRef membership or bytes.',
|
|
1591
|
+
);
|
|
831
1592
|
if (observation.status === 'observed') {
|
|
832
1593
|
currentAt(observation.observedAt, observation.freshUntil, 'Observation');
|
|
833
|
-
if (metricObservation === undefined)
|
|
1594
|
+
if (metricObservation === undefined)
|
|
1595
|
+
fail(
|
|
1596
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1597
|
+
'Observed evidence requires the exact canonical metric observation.',
|
|
1598
|
+
);
|
|
834
1599
|
protocol('operating-metric-observation', metricObservation);
|
|
835
|
-
exactDigest(
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
1600
|
+
exactDigest(
|
|
1601
|
+
metricObservation,
|
|
1602
|
+
observation.metricObservation.recordDigest,
|
|
1603
|
+
'Metric observation',
|
|
1604
|
+
);
|
|
1605
|
+
same(
|
|
1606
|
+
[
|
|
1607
|
+
metricObservation.observationId,
|
|
1608
|
+
metricObservation.metricId,
|
|
1609
|
+
metricObservation.value,
|
|
1610
|
+
metricObservation.unit,
|
|
1611
|
+
metricObservation.observedAt,
|
|
1612
|
+
metricObservation.sourceArtifactId,
|
|
1613
|
+
metricObservation.evidenceRefIds,
|
|
1614
|
+
],
|
|
1615
|
+
[
|
|
1616
|
+
observation.metricObservation.recordId,
|
|
1617
|
+
observation.metricId,
|
|
1618
|
+
observation.value,
|
|
1619
|
+
observation.unit,
|
|
1620
|
+
observation.observedAt,
|
|
1621
|
+
observation.artifact.artifactId,
|
|
1622
|
+
observation.evidenceRefs.map((entry) => entry.evidenceRefId),
|
|
1623
|
+
],
|
|
1624
|
+
'Metric observation',
|
|
1625
|
+
);
|
|
1626
|
+
} else if (
|
|
1627
|
+
(observation.status === 'absent' && observation.absences.length === 0) ||
|
|
1628
|
+
(observation.status === 'contradicted' && observation.contradictions.length === 0)
|
|
1629
|
+
) {
|
|
1630
|
+
fail(
|
|
1631
|
+
'LIVE_EVIDENCE_FALSE_PASS',
|
|
1632
|
+
'Non-observed evidence must retain its typed absence or contradiction.',
|
|
1633
|
+
);
|
|
840
1634
|
}
|
|
841
1635
|
return freeze(clone(observation));
|
|
842
1636
|
}
|
|
843
1637
|
|
|
844
1638
|
function observationCustodyFor(observation, custody) {
|
|
845
|
-
const matches = custody.filter(
|
|
846
|
-
|
|
1639
|
+
const matches = custody.filter(
|
|
1640
|
+
(entry) => entry?.evidenceObservationId === observation.evidenceObservationId,
|
|
1641
|
+
);
|
|
1642
|
+
if (matches.length !== 1)
|
|
1643
|
+
fail(
|
|
1644
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1645
|
+
'Each evidence observation requires one exact custody bundle.',
|
|
1646
|
+
{ evidenceObservationId: observation.evidenceObservationId },
|
|
1647
|
+
);
|
|
847
1648
|
return matches[0];
|
|
848
1649
|
}
|
|
849
1650
|
|
|
850
|
-
function canonicalEvaluationInputs({
|
|
851
|
-
|
|
1651
|
+
function canonicalEvaluationInputs({
|
|
1652
|
+
evaluation,
|
|
1653
|
+
plan,
|
|
1654
|
+
evidenceObservations,
|
|
1655
|
+
metricObservations,
|
|
1656
|
+
observationCustody,
|
|
1657
|
+
}) {
|
|
1658
|
+
if (!Array.isArray(observationCustody))
|
|
1659
|
+
fail(
|
|
1660
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1661
|
+
'Outcome evaluation requires exact observation custody bundles.',
|
|
1662
|
+
);
|
|
852
1663
|
const ids = new Set();
|
|
853
|
-
const normalizedEvidence = evidenceObservations
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1664
|
+
const normalizedEvidence = evidenceObservations
|
|
1665
|
+
.map((entry) => {
|
|
1666
|
+
if (ids.has(entry.evidenceObservationId))
|
|
1667
|
+
fail(
|
|
1668
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1669
|
+
'Duplicate evidence observation identity is forbidden.',
|
|
1670
|
+
{ evidenceObservationId: entry.evidenceObservationId },
|
|
1671
|
+
);
|
|
1672
|
+
ids.add(entry.evidenceObservationId);
|
|
1673
|
+
const custody = observationCustodyFor(entry, observationCustody);
|
|
1674
|
+
const metricObservation =
|
|
1675
|
+
entry.metricObservation === null
|
|
1676
|
+
? undefined
|
|
1677
|
+
: metricObservations.find(
|
|
1678
|
+
(candidate) => candidate.observationId === entry.metricObservation.recordId,
|
|
1679
|
+
);
|
|
1680
|
+
return assertOperatingEvidenceObservationV2(entry, {
|
|
1681
|
+
measurementPlan: plan,
|
|
1682
|
+
metricObservation,
|
|
1683
|
+
...custody,
|
|
1684
|
+
});
|
|
1685
|
+
})
|
|
1686
|
+
.sort((left, right) => left.evidenceObservationId.localeCompare(right.evidenceObservationId));
|
|
1687
|
+
if (
|
|
1688
|
+
normalizedEvidence.length !== evaluation.observations.length ||
|
|
1689
|
+
observationCustody.length !== normalizedEvidence.length
|
|
1690
|
+
) {
|
|
862
1691
|
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Evaluation observation membership changed.');
|
|
863
1692
|
}
|
|
864
1693
|
const wrappers = normalizedEvidence.map((entry) => ({
|
|
@@ -872,72 +1701,216 @@ function canonicalEvaluationInputs({ evaluation, plan, evidenceObservations, met
|
|
|
872
1701
|
freshUntil: entry.freshUntil,
|
|
873
1702
|
status: entry.status,
|
|
874
1703
|
}));
|
|
875
|
-
if (!sameValue(evaluation.observations, wrappers))
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
1704
|
+
if (!sameValue(evaluation.observations, wrappers))
|
|
1705
|
+
fail(
|
|
1706
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1707
|
+
'Evaluation wrappers are not the canonical unique observation set.',
|
|
1708
|
+
);
|
|
1709
|
+
const inWindow = normalizedEvidence.filter(
|
|
1710
|
+
(entry) =>
|
|
1711
|
+
Date.parse(entry.observedAt) >= Date.parse(plan.window.from) &&
|
|
1712
|
+
Date.parse(entry.observedAt) <= Date.parse(plan.window.to),
|
|
1713
|
+
);
|
|
1714
|
+
const observed = inWindow.filter(
|
|
1715
|
+
(entry) =>
|
|
1716
|
+
entry.status === 'observed' &&
|
|
1717
|
+
Date.parse(entry.freshUntil) > Date.parse(evaluation.evaluatedAt),
|
|
1718
|
+
);
|
|
1719
|
+
const absences = inWindow.flatMap((entry) =>
|
|
1720
|
+
entry.absences.map((absence) => absence.detailsHash),
|
|
1721
|
+
);
|
|
1722
|
+
for (const entry of inWindow.filter(
|
|
1723
|
+
(item) =>
|
|
1724
|
+
item.status === 'observed' &&
|
|
1725
|
+
Date.parse(item.freshUntil) <= Date.parse(evaluation.evaluatedAt),
|
|
1726
|
+
)) {
|
|
1727
|
+
absences.push(
|
|
1728
|
+
sha256Jcs({
|
|
1729
|
+
kind: 'stale',
|
|
1730
|
+
evidenceObservationId: entry.evidenceObservationId,
|
|
1731
|
+
observationHash: entry.observationHash,
|
|
1732
|
+
evaluatedAt: evaluation.evaluatedAt,
|
|
1733
|
+
}),
|
|
1734
|
+
);
|
|
882
1735
|
}
|
|
883
1736
|
const contradictions = inWindow.flatMap((entry) => entry.contradictions);
|
|
884
1737
|
return {
|
|
885
|
-
normalizedEvidence,
|
|
886
|
-
|
|
1738
|
+
normalizedEvidence,
|
|
1739
|
+
wrappers,
|
|
1740
|
+
inWindow,
|
|
1741
|
+
observed,
|
|
1742
|
+
absences: [...new Set(absences)].sort(),
|
|
1743
|
+
contradictions: [...new Set(contradictions)].sort(),
|
|
887
1744
|
};
|
|
888
1745
|
}
|
|
889
1746
|
|
|
890
|
-
export function assertOperatingOutcomeEvaluationV2(
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1747
|
+
export function assertOperatingOutcomeEvaluationV2(
|
|
1748
|
+
evaluation,
|
|
1749
|
+
{
|
|
1750
|
+
measurementPlan,
|
|
1751
|
+
verificationPlan,
|
|
1752
|
+
outcome,
|
|
1753
|
+
evidenceObservations,
|
|
1754
|
+
metricObservations = [],
|
|
1755
|
+
observationCustody,
|
|
1756
|
+
previousEvaluation,
|
|
1757
|
+
} = {},
|
|
1758
|
+
) {
|
|
894
1759
|
protocol('operating-outcome-evaluation', evaluation);
|
|
895
1760
|
safePortable(evaluation);
|
|
896
1761
|
selfHash(evaluation, 'evaluationHash');
|
|
897
|
-
if (
|
|
1762
|
+
if (
|
|
1763
|
+
measurementPlan === undefined ||
|
|
1764
|
+
verificationPlan === undefined ||
|
|
1765
|
+
outcome === undefined ||
|
|
1766
|
+
!Array.isArray(evidenceObservations)
|
|
1767
|
+
)
|
|
1768
|
+
fail(
|
|
1769
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1770
|
+
'Outcome evaluation requires its exact plan, Outcome, and evidence observations.',
|
|
1771
|
+
);
|
|
898
1772
|
const plan = assertOperatingMeasurementPlanV2(measurementPlan, { verificationPlan });
|
|
899
|
-
if (
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Evaluation changed its
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
1773
|
+
if (
|
|
1774
|
+
plan.planHash !== evaluation.measurementPlan.recordDigest ||
|
|
1775
|
+
plan.measurementPlanId !== evaluation.measurementPlan.recordId
|
|
1776
|
+
)
|
|
1777
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Evaluation changed its measurement plan.');
|
|
1778
|
+
const canonical = canonicalEvaluationInputs({
|
|
1779
|
+
evaluation,
|
|
1780
|
+
plan,
|
|
1781
|
+
evidenceObservations,
|
|
1782
|
+
metricObservations,
|
|
1783
|
+
observationCustody,
|
|
1784
|
+
});
|
|
1785
|
+
if (
|
|
1786
|
+
!sameValue(
|
|
1787
|
+
[
|
|
1788
|
+
evaluation.window,
|
|
1789
|
+
evaluation.operator,
|
|
1790
|
+
evaluation.unit,
|
|
1791
|
+
evaluation.dimension,
|
|
1792
|
+
evaluation.baseline,
|
|
1793
|
+
evaluation.target,
|
|
1794
|
+
evaluation.minimumEvidence,
|
|
1795
|
+
],
|
|
1796
|
+
[
|
|
1797
|
+
plan.window,
|
|
1798
|
+
plan.target.operator,
|
|
1799
|
+
plan.metric.unit,
|
|
1800
|
+
plan.metric.dimension,
|
|
1801
|
+
plan.baseline.value,
|
|
1802
|
+
plan.target.value,
|
|
1803
|
+
plan.minimumEvidence,
|
|
1804
|
+
],
|
|
1805
|
+
)
|
|
1806
|
+
) {
|
|
1807
|
+
fail(
|
|
1808
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1809
|
+
'Evaluation changed its exact plan algebra, window, or threshold.',
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
const computedResult =
|
|
1813
|
+
canonical.absences.length > 0 ||
|
|
1814
|
+
canonical.contradictions.length > 0 ||
|
|
1815
|
+
canonical.observed.length < plan.minimumEvidence
|
|
1816
|
+
? 'insufficient-evidence'
|
|
1817
|
+
: canonical.observed.every((entry) =>
|
|
1818
|
+
compare(plan.target.operator, entry.value, plan.target.value),
|
|
1819
|
+
)
|
|
1820
|
+
? 'passed'
|
|
1821
|
+
: 'failed';
|
|
1822
|
+
const computedConfidence =
|
|
1823
|
+
canonical.inWindow.length === 0
|
|
1824
|
+
? 0
|
|
1825
|
+
: canonical.observed.length / Math.max(canonical.inWindow.length, plan.minimumEvidence);
|
|
908
1826
|
const computedInputDigest = sha256Jcs(canonical.wrappers.map((entry) => entry.observationHash));
|
|
909
|
-
const computedProviders = [
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1827
|
+
const computedProviders = [
|
|
1828
|
+
...new Map(
|
|
1829
|
+
canonical.inWindow.map((entry) => [
|
|
1830
|
+
`${entry.provider.id}@${entry.provider.version}`,
|
|
1831
|
+
entry.provider,
|
|
1832
|
+
]),
|
|
1833
|
+
).values(),
|
|
1834
|
+
].sort((a, b) => `${a.id}@${a.version}`.localeCompare(`${b.id}@${b.version}`));
|
|
1835
|
+
if (
|
|
1836
|
+
evaluation.result !== computedResult ||
|
|
1837
|
+
evaluation.confidence !== computedConfidence ||
|
|
1838
|
+
evaluation.exactInputDigest !== computedInputDigest ||
|
|
1839
|
+
!sameValue(evaluation.providerVersions, computedProviders) ||
|
|
1840
|
+
!sameValue(evaluation.absences, canonical.absences) ||
|
|
1841
|
+
!sameValue(evaluation.contradictions, canonical.contradictions)
|
|
1842
|
+
)
|
|
1843
|
+
fail(
|
|
1844
|
+
'LIVE_EVIDENCE_FALSE_PASS',
|
|
1845
|
+
'Outcome result, confidence, input digest, provider, absence, or contradiction truth is not deterministic from bound evidence.',
|
|
1846
|
+
);
|
|
913
1847
|
if (verificationPlan !== undefined) {
|
|
914
1848
|
protocol('operating-action-verification-plan', verificationPlan);
|
|
915
1849
|
exactDigest(verificationPlan, evaluation.verificationPlan.recordDigest, 'Verification plan');
|
|
916
|
-
same(
|
|
1850
|
+
same(
|
|
1851
|
+
[verificationPlan.verificationPlanId, verificationPlan.actionId, verificationPlan.metricId],
|
|
1852
|
+
[evaluation.verificationPlan.recordId, evaluation.actionId, evaluation.metricId],
|
|
1853
|
+
'Evaluation verification plan',
|
|
1854
|
+
);
|
|
917
1855
|
}
|
|
918
1856
|
if (outcome !== undefined) {
|
|
919
1857
|
protocol('operating-outcome', outcome);
|
|
920
1858
|
exactDigest(outcome, evaluation.outcome.recordDigest, 'Outcome');
|
|
921
|
-
const status =
|
|
922
|
-
|
|
1859
|
+
const status =
|
|
1860
|
+
evaluation.result === 'passed'
|
|
1861
|
+
? 'succeeded'
|
|
1862
|
+
: evaluation.result === 'failed'
|
|
1863
|
+
? 'failed'
|
|
1864
|
+
: 'insufficient-evidence';
|
|
1865
|
+
same(
|
|
1866
|
+
[outcome.outcomeId, outcome.actionId, outcome.verificationPlanId, outcome.status],
|
|
1867
|
+
[
|
|
1868
|
+
evaluation.outcome.recordId,
|
|
1869
|
+
evaluation.actionId,
|
|
1870
|
+
evaluation.verificationPlan.recordId,
|
|
1871
|
+
status,
|
|
1872
|
+
],
|
|
1873
|
+
'Outcome evaluation',
|
|
1874
|
+
);
|
|
923
1875
|
}
|
|
924
1876
|
if (evaluation.previousEvaluationHash === null) {
|
|
925
|
-
if (previousEvaluation !== undefined && previousEvaluation !== null)
|
|
1877
|
+
if (previousEvaluation !== undefined && previousEvaluation !== null)
|
|
1878
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Initial evaluation cannot carry a predecessor.');
|
|
926
1879
|
} else {
|
|
927
|
-
if (previousEvaluation === undefined || previousEvaluation === null)
|
|
1880
|
+
if (previousEvaluation === undefined || previousEvaluation === null)
|
|
1881
|
+
fail(
|
|
1882
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
1883
|
+
'Reevaluation requires the exact immutable predecessor.',
|
|
1884
|
+
);
|
|
928
1885
|
protocol('operating-outcome-evaluation', previousEvaluation);
|
|
929
1886
|
selfHash(previousEvaluation, 'evaluationHash');
|
|
930
|
-
if (
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1887
|
+
if (
|
|
1888
|
+
previousEvaluation.evaluationHash !== evaluation.previousEvaluationHash ||
|
|
1889
|
+
!sameValue(
|
|
1890
|
+
[
|
|
1891
|
+
previousEvaluation.measurementPlan,
|
|
1892
|
+
previousEvaluation.verificationPlan,
|
|
1893
|
+
previousEvaluation.outcome,
|
|
1894
|
+
],
|
|
1895
|
+
[evaluation.measurementPlan, evaluation.verificationPlan, evaluation.outcome],
|
|
1896
|
+
) ||
|
|
1897
|
+
Date.parse(previousEvaluation.evaluatedAt) >= Date.parse(evaluation.evaluatedAt) ||
|
|
1898
|
+
previousEvaluation.exactInputDigest === evaluation.exactInputDigest
|
|
1899
|
+
) {
|
|
1900
|
+
fail(
|
|
1901
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1902
|
+
'Reevaluation predecessor, lineage, time, or changed evidence custody is invalid.',
|
|
1903
|
+
);
|
|
936
1904
|
}
|
|
937
1905
|
}
|
|
938
|
-
if (
|
|
939
|
-
|
|
940
|
-
|
|
1906
|
+
if (
|
|
1907
|
+
evaluation.revisit.required !== (evaluation.result !== 'passed') ||
|
|
1908
|
+
!sameValue(evaluation.revisit.decisionIds, verificationPlan.revisitDecisionIds)
|
|
1909
|
+
) {
|
|
1910
|
+
fail(
|
|
1911
|
+
'LIVE_EVIDENCE_BINDING_MISMATCH',
|
|
1912
|
+
'Evaluation revisit truth changed from its result or verification plan.',
|
|
1913
|
+
);
|
|
941
1914
|
}
|
|
942
1915
|
return freeze(clone(evaluation));
|
|
943
1916
|
}
|
|
@@ -952,68 +1925,214 @@ function compare(operator, value, target) {
|
|
|
952
1925
|
}
|
|
953
1926
|
|
|
954
1927
|
export function evaluateOperatingOutcomeV2({
|
|
955
|
-
plan,
|
|
956
|
-
|
|
1928
|
+
plan,
|
|
1929
|
+
observations,
|
|
1930
|
+
metricObservations,
|
|
1931
|
+
observationCustody,
|
|
1932
|
+
evaluationId,
|
|
1933
|
+
outcome,
|
|
1934
|
+
verificationPlan,
|
|
1935
|
+
evaluatedAt,
|
|
1936
|
+
previousEvaluation = null,
|
|
957
1937
|
}) {
|
|
958
1938
|
const normalizedPlan = assertOperatingMeasurementPlanV2(plan, { verificationPlan });
|
|
959
|
-
const normalized = observations
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1939
|
+
const normalized = observations
|
|
1940
|
+
.map((entry) => {
|
|
1941
|
+
const custody = observationCustodyFor(entry, observationCustody);
|
|
1942
|
+
return assertOperatingEvidenceObservationV2(entry, {
|
|
1943
|
+
measurementPlan: normalizedPlan,
|
|
1944
|
+
metricObservation:
|
|
1945
|
+
entry.metricObservation === null
|
|
1946
|
+
? undefined
|
|
1947
|
+
: metricObservations.find(
|
|
1948
|
+
(candidate) => candidate.observationId === entry.metricObservation.recordId,
|
|
1949
|
+
),
|
|
1950
|
+
...custody,
|
|
1951
|
+
});
|
|
1952
|
+
})
|
|
1953
|
+
.sort((left, right) => left.evidenceObservationId.localeCompare(right.evidenceObservationId));
|
|
1954
|
+
const inWindow = normalized.filter(
|
|
1955
|
+
(entry) =>
|
|
1956
|
+
Date.parse(entry.observedAt) >= Date.parse(plan.window.from) &&
|
|
1957
|
+
Date.parse(entry.observedAt) <= Date.parse(plan.window.to),
|
|
1958
|
+
);
|
|
1959
|
+
const observed = inWindow.filter(
|
|
1960
|
+
(entry) =>
|
|
1961
|
+
entry.status === 'observed' && Date.parse(entry.freshUntil) > Date.parse(evaluatedAt),
|
|
1962
|
+
);
|
|
1963
|
+
const absences = inWindow.flatMap((entry) =>
|
|
1964
|
+
entry.absences.map((absence) => absence.detailsHash),
|
|
1965
|
+
);
|
|
1966
|
+
for (const entry of inWindow.filter(
|
|
1967
|
+
(item) => item.status === 'observed' && Date.parse(item.freshUntil) <= Date.parse(evaluatedAt),
|
|
1968
|
+
)) {
|
|
1969
|
+
absences.push(
|
|
1970
|
+
sha256Jcs({
|
|
1971
|
+
kind: 'stale',
|
|
1972
|
+
evidenceObservationId: entry.evidenceObservationId,
|
|
1973
|
+
observationHash: entry.observationHash,
|
|
1974
|
+
evaluatedAt,
|
|
1975
|
+
}),
|
|
1976
|
+
);
|
|
970
1977
|
}
|
|
971
1978
|
const contradictions = inWindow.flatMap((entry) => entry.contradictions);
|
|
972
1979
|
let result = 'insufficient-evidence';
|
|
973
|
-
if (
|
|
974
|
-
|
|
1980
|
+
if (
|
|
1981
|
+
absences.length === 0 &&
|
|
1982
|
+
contradictions.length === 0 &&
|
|
1983
|
+
observed.length >= plan.minimumEvidence
|
|
1984
|
+
) {
|
|
1985
|
+
result = observed.every((entry) =>
|
|
1986
|
+
compare(plan.target.operator, entry.value, plan.target.value),
|
|
1987
|
+
)
|
|
1988
|
+
? 'passed'
|
|
1989
|
+
: 'failed';
|
|
975
1990
|
}
|
|
976
1991
|
const evaluation = {
|
|
977
|
-
kind: 'operating-outcome-evaluation',
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1992
|
+
kind: 'operating-outcome-evaluation',
|
|
1993
|
+
schemaVersion: '1.0.0',
|
|
1994
|
+
protocolVersion: '2.0.0',
|
|
1995
|
+
evaluationId,
|
|
1996
|
+
previousEvaluationHash: previousEvaluation?.evaluationHash ?? null,
|
|
1997
|
+
measurementPlan: {
|
|
1998
|
+
contractId: 'operating-measurement-plan',
|
|
1999
|
+
schemaVersion: '1.0.0',
|
|
2000
|
+
protocolVersion: '2.0.0',
|
|
2001
|
+
recordId: plan.measurementPlanId,
|
|
2002
|
+
recordDigest: plan.planHash,
|
|
2003
|
+
},
|
|
2004
|
+
verificationPlan: {
|
|
2005
|
+
contractId: 'operating-action-verification-plan',
|
|
2006
|
+
schemaVersion: '1.0.0',
|
|
2007
|
+
protocolVersion: '2.0.0',
|
|
2008
|
+
recordId: verificationPlan.verificationPlanId,
|
|
2009
|
+
recordDigest: sha256Jcs(verificationPlan),
|
|
2010
|
+
},
|
|
2011
|
+
outcome: {
|
|
2012
|
+
contractId: 'operating-outcome',
|
|
2013
|
+
schemaVersion: '1.0.0',
|
|
2014
|
+
protocolVersion: '2.0.0',
|
|
2015
|
+
recordId: outcome.outcomeId,
|
|
2016
|
+
recordDigest: sha256Jcs(outcome),
|
|
2017
|
+
},
|
|
2018
|
+
actionId: plan.action.actionId,
|
|
2019
|
+
metricId: plan.metric.metricId,
|
|
2020
|
+
observations: normalized.map((entry) => ({
|
|
2021
|
+
evidenceObservationId: entry.evidenceObservationId,
|
|
2022
|
+
observationId: entry.metricObservation?.recordId ?? null,
|
|
2023
|
+
observationHash: entry.observationHash,
|
|
2024
|
+
metricObservationDigest: entry.metricObservation?.recordDigest ?? null,
|
|
2025
|
+
value: entry.value,
|
|
2026
|
+
unit: entry.unit,
|
|
2027
|
+
observedAt: entry.observedAt,
|
|
2028
|
+
freshUntil: entry.freshUntil,
|
|
2029
|
+
status: entry.status,
|
|
2030
|
+
})),
|
|
2031
|
+
providerVersions: [
|
|
2032
|
+
...new Map(
|
|
2033
|
+
inWindow.map((entry) => [`${entry.provider.id}@${entry.provider.version}`, entry.provider]),
|
|
2034
|
+
).values(),
|
|
2035
|
+
].sort((a, b) => `${a.id}@${a.version}`.localeCompare(`${b.id}@${b.version}`)),
|
|
2036
|
+
window: clone(plan.window),
|
|
2037
|
+
operator: plan.target.operator,
|
|
2038
|
+
unit: plan.metric.unit,
|
|
2039
|
+
dimension: plan.metric.dimension,
|
|
2040
|
+
baseline: plan.baseline.value,
|
|
2041
|
+
target: clone(plan.target.value),
|
|
2042
|
+
minimumEvidence: plan.minimumEvidence,
|
|
2043
|
+
exactInputDigest: sha256Jcs(normalized.map((entry) => entry.observationHash)),
|
|
2044
|
+
result,
|
|
2045
|
+
confidence:
|
|
2046
|
+
inWindow.length === 0 ? 0 : observed.length / Math.max(inWindow.length, plan.minimumEvidence),
|
|
2047
|
+
absences: [...new Set(absences)].sort(),
|
|
2048
|
+
contradictions: [...new Set(contradictions)].sort(),
|
|
2049
|
+
evaluatedAt,
|
|
2050
|
+
revisit: {
|
|
2051
|
+
required: result !== 'passed',
|
|
2052
|
+
condition: result === 'passed' ? null : 'Evidence did not prove the declared target.',
|
|
2053
|
+
decisionIds: clone(verificationPlan.revisitDecisionIds),
|
|
2054
|
+
},
|
|
990
2055
|
};
|
|
991
2056
|
evaluation.evaluationHash = sha256Jcs(evaluation);
|
|
992
|
-
return assertOperatingOutcomeEvaluationV2(evaluation, {
|
|
993
|
-
|
|
2057
|
+
return assertOperatingOutcomeEvaluationV2(evaluation, {
|
|
2058
|
+
measurementPlan: normalizedPlan,
|
|
2059
|
+
verificationPlan,
|
|
2060
|
+
outcome,
|
|
2061
|
+
evidenceObservations: normalized,
|
|
2062
|
+
metricObservations,
|
|
2063
|
+
observationCustody,
|
|
2064
|
+
previousEvaluation,
|
|
2065
|
+
});
|
|
994
2066
|
}
|
|
995
2067
|
|
|
996
|
-
export function assertOperatingLearningReceiptV2(
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
2068
|
+
export function assertOperatingLearningReceiptV2(
|
|
2069
|
+
receipt,
|
|
2070
|
+
{
|
|
2071
|
+
learning,
|
|
2072
|
+
outcome,
|
|
2073
|
+
evaluation,
|
|
2074
|
+
measurementPlan,
|
|
2075
|
+
verificationPlan,
|
|
2076
|
+
evidenceObservations,
|
|
2077
|
+
metricObservations,
|
|
2078
|
+
observationCustody,
|
|
2079
|
+
previousEvaluation,
|
|
2080
|
+
} = {},
|
|
2081
|
+
) {
|
|
1000
2082
|
protocol('operating-learning-receipt', receipt);
|
|
1001
2083
|
safePortable(receipt);
|
|
1002
2084
|
selfHash(receipt, 'receiptHash');
|
|
1003
|
-
if (
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
2085
|
+
if (
|
|
2086
|
+
learning === undefined ||
|
|
2087
|
+
outcome === undefined ||
|
|
2088
|
+
evaluation === undefined ||
|
|
2089
|
+
measurementPlan === undefined ||
|
|
2090
|
+
verificationPlan === undefined ||
|
|
2091
|
+
!Array.isArray(evidenceObservations) ||
|
|
2092
|
+
!Array.isArray(metricObservations) ||
|
|
2093
|
+
!Array.isArray(observationCustody)
|
|
2094
|
+
) {
|
|
2095
|
+
fail(
|
|
2096
|
+
'LIVE_EVIDENCE_BASE_RECORD_REQUIRED',
|
|
2097
|
+
'A certifying Learning receipt requires exact Learning, Outcome, evaluation, plan, and observation custody.',
|
|
2098
|
+
);
|
|
1008
2099
|
}
|
|
1009
2100
|
protocol('operating-learning', learning);
|
|
1010
2101
|
exactDigest(learning, receipt.learning.recordDigest, 'Learning');
|
|
1011
|
-
same(
|
|
2102
|
+
same(
|
|
2103
|
+
[
|
|
2104
|
+
learning.learningId,
|
|
2105
|
+
learning.outcomeId,
|
|
2106
|
+
learning.assumptionIds,
|
|
2107
|
+
learning.decisionIds,
|
|
2108
|
+
learning.evidenceRefIds,
|
|
2109
|
+
],
|
|
2110
|
+
[
|
|
2111
|
+
receipt.learning.recordId,
|
|
2112
|
+
receipt.outcome.recordId,
|
|
2113
|
+
receipt.assumptionIds,
|
|
2114
|
+
receipt.decisionIds,
|
|
2115
|
+
receipt.evidenceRefIds,
|
|
2116
|
+
],
|
|
2117
|
+
'Learning receipt',
|
|
2118
|
+
);
|
|
1012
2119
|
same(sha256Jcs(learning.statement), receipt.statementDigest, 'Learning statement digest');
|
|
1013
2120
|
protocol('operating-outcome', outcome);
|
|
1014
2121
|
exactDigest(outcome, receipt.outcome.recordDigest, 'Learning outcome');
|
|
1015
|
-
assertOperatingOutcomeEvaluationV2(evaluation, {
|
|
1016
|
-
|
|
1017
|
-
|
|
2122
|
+
assertOperatingOutcomeEvaluationV2(evaluation, {
|
|
2123
|
+
measurementPlan,
|
|
2124
|
+
verificationPlan,
|
|
2125
|
+
outcome,
|
|
2126
|
+
evidenceObservations,
|
|
2127
|
+
metricObservations,
|
|
2128
|
+
observationCustody,
|
|
2129
|
+
previousEvaluation,
|
|
2130
|
+
});
|
|
2131
|
+
if (
|
|
2132
|
+
evaluation.evaluationId !== receipt.evaluation.evaluationId ||
|
|
2133
|
+
evaluation.evaluationHash !== receipt.evaluation.evaluationHash ||
|
|
2134
|
+
evaluation.result !== receipt.evaluation.result
|
|
2135
|
+
)
|
|
2136
|
+
fail('LIVE_EVIDENCE_BINDING_MISMATCH', 'Learning receipt changed the evaluation result.');
|
|
1018
2137
|
return freeze(clone(receipt));
|
|
1019
2138
|
}
|