@action-state-group/capsule-viewer 0.0.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/LICENSE-BSD-3-Clause +28 -0
- package/README.md +94 -1
- package/dist/alias-interpreters.d.ts +18 -0
- package/dist/alias-interpreters.js +50 -0
- package/dist/alias-interpreters.js.map +1 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +25 -0
- package/dist/browser.js.map +1 -0
- package/dist/builtin-manifests.d.ts +51 -0
- package/dist/builtin-manifests.js +196 -0
- package/dist/builtin-manifests.js.map +1 -0
- package/dist/compliance-presentation.d.ts +51 -0
- package/dist/compliance-presentation.js +140 -0
- package/dist/compliance-presentation.js.map +1 -0
- package/dist/compliance-styles.d.ts +1 -0
- package/dist/compliance-styles.js +104 -0
- package/dist/compliance-styles.js.map +1 -0
- package/dist/compliance-view.d.ts +46 -0
- package/dist/compliance-view.js +828 -0
- package/dist/compliance-view.js.map +1 -0
- package/dist/compliance.d.ts +121 -0
- package/dist/compliance.js +412 -0
- package/dist/compliance.js.map +1 -0
- package/dist/composed-styles.d.ts +12 -0
- package/dist/composed-styles.js +20 -0
- package/dist/composed-styles.js.map +1 -0
- package/dist/composed-view.d.ts +24 -0
- package/dist/composed-view.js +186 -0
- package/dist/composed-view.js.map +1 -0
- package/dist/contract-report-wording.d.ts +195 -0
- package/dist/contract-report-wording.js +1141 -0
- package/dist/contract-report-wording.js.map +1 -0
- package/dist/contract-report.d.ts +92 -0
- package/dist/contract-report.js +63 -0
- package/dist/contract-report.js.map +1 -0
- package/dist/emitter-shell.html +310 -0
- package/dist/emitter.d.ts +105 -0
- package/dist/emitter.js +329 -0
- package/dist/emitter.js.map +1 -0
- package/dist/evidence-graph-view.d.ts +149 -0
- package/dist/evidence-graph-view.js +2718 -0
- package/dist/evidence-graph-view.js.map +1 -0
- package/dist/evidence-graph.iife.js +18159 -0
- package/dist/frame-tokens.generated.d.ts +3 -0
- package/dist/frame-tokens.generated.js +5 -0
- package/dist/frame-tokens.generated.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/outcome-report-presentation.d.ts +48 -0
- package/dist/outcome-report-presentation.js +90 -0
- package/dist/outcome-report-presentation.js.map +1 -0
- package/dist/outcome-report-styles.d.ts +1 -0
- package/dist/outcome-report-styles.js +228 -0
- package/dist/outcome-report-styles.js.map +1 -0
- package/dist/outcome-report-view.d.ts +78 -0
- package/dist/outcome-report-view.js +1488 -0
- package/dist/outcome-report-view.js.map +1 -0
- package/dist/presentation-builder.d.ts +296 -0
- package/dist/presentation-builder.js +646 -0
- package/dist/presentation-builder.js.map +1 -0
- package/dist/presentation-fragment.d.ts +129 -0
- package/dist/presentation-fragment.js +213 -0
- package/dist/presentation-fragment.js.map +1 -0
- package/dist/presentation-mount.d.ts +26 -0
- package/dist/presentation-mount.js +45 -0
- package/dist/presentation-mount.js.map +1 -0
- package/dist/presentation-registry.d.ts +277 -0
- package/dist/presentation-registry.js +416 -0
- package/dist/presentation-registry.js.map +1 -0
- package/dist/record-content.d.ts +68 -0
- package/dist/record-content.js +153 -0
- package/dist/record-content.js.map +1 -0
- package/dist/record-dating.d.ts +10 -0
- package/dist/record-dating.js +76 -0
- package/dist/record-dating.js.map +1 -0
- package/dist/report-front-styles.d.ts +9 -0
- package/dist/report-front-styles.js +55 -0
- package/dist/report-front-styles.js.map +1 -0
- package/dist/report-front.d.ts +78 -0
- package/dist/report-front.js +274 -0
- package/dist/report-front.js.map +1 -0
- package/dist/report-levels.d.ts +206 -0
- package/dist/report-levels.js +739 -0
- package/dist/report-levels.js.map +1 -0
- package/dist/report-provenance.d.ts +111 -0
- package/dist/report-provenance.js +535 -0
- package/dist/report-provenance.js.map +1 -0
- package/dist/viewer-build.d.ts +37 -0
- package/dist/viewer-build.js +29 -0
- package/dist/viewer-build.js.map +1 -0
- package/dist/wording/contract-report-eu-ai-act.en.json +295 -0
- package/dist/wording/contract-report-outcomes.en.json +394 -0
- package/package.json +48 -4
|
@@ -0,0 +1,2718 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
import { AGENT_INPUT_ORIGINALS_EXTENSION, BOOK_PAYLOADS_EXTENSION, buildVerifiedBundleContext, carriedCapsuleCommitment, committedDigest, disclosureOf, logCoordinates, PUBLISHED_CAPSULE_RECORD_TYPE, recordTimes, resolveCarriedInput, isVerifiedBundleContext, REQUIREMENT_CLAIM, readOutcomeReportTerms, withCountersigners, } from "@action-state-group/agent-action-capsule";
|
|
3
|
+
import { BUILTIN_MANIFEST_COMPOSED, BUILTIN_MANIFEST_EVALUATION_SUMMARY_GRAPH, BUILTIN_MANIFEST_NO_AGGREGATE, BUILTIN_MANIFEST_REPORT_ROWS, BUILTIN_MANIFEST_RESULT, BUILTIN_MANIFEST_RESULT_COMPLIANCE, BUILTIN_MANIFEST_RESULT_CONTRACT_REPORT, BUILTIN_MANIFEST_RESULT_OUTCOME_REPORT, } from "./builtin-manifests.js";
|
|
4
|
+
import { classifyCountersignatures, declaredProducerKeys, } from "@action-state-group/agent-action-capsule";
|
|
5
|
+
import { buildEvidenceGraph, EvidenceGraphError, zoneStatement, } from "@action-state-group/agent-action-capsule";
|
|
6
|
+
import { digestCapability } from "@action-state-group/agent-action-capsule";
|
|
7
|
+
import { renderContractReport, } from "./contract-report.js";
|
|
8
|
+
import { readOutcomeReportPresentation, } from "./outcome-report-presentation.js";
|
|
9
|
+
import { composedSectionModule } from "./composed-view.js";
|
|
10
|
+
import { DEFAULT_WORDS } from "./contract-report-wording.js";
|
|
11
|
+
import { RECORD_CONTENT_CSS, renderContent } from "./record-content.js";
|
|
12
|
+
import { deferBody, recordAddress, revealRecord, revealRecordsByHash, } from "./report-levels.js";
|
|
13
|
+
import { readCompliancePresentation, } from "./compliance-presentation.js";
|
|
14
|
+
import { readPresentationBlock } from "@action-state-group/agent-action-capsule";
|
|
15
|
+
import { bundleVerified, PresentationAmbiguityError, PresentationRegistry, presentationExtensionRows, presentationRefusalNotices, } from "./presentation-registry.js";
|
|
16
|
+
import { aacInterpreters, aliasExtensionRows, } from "./alias-interpreters.js";
|
|
17
|
+
import { buildReportRows, } from "@action-state-group/agent-action-capsule";
|
|
18
|
+
import { buildResultRoot, isResultRoot, UNVERIFIED_KEY_LABEL, utcDateOf, } from "@action-state-group/agent-action-capsule";
|
|
19
|
+
import { buildVerificationPageModel, CHECKED_ON_THIS_PAGE, CHECKS_SCOPE_LINE, FAILED_ON_THIS_PAGE, FULL_VERIFIER_LINE, NOT_CHECKED_ON_THIS_PAGE, RECEIPT_GRADE_DISPLAY, VERIFICATION_BANNER_LINES, verificationBanner, verificationCheckWords, } from "@action-state-group/agent-action-capsule";
|
|
20
|
+
function element(tag, text) {
|
|
21
|
+
const value = document.createElement(tag);
|
|
22
|
+
if (text !== undefined)
|
|
23
|
+
value.textContent = text;
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function display(value) {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.stringify(value);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return String(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function appendValue(parent, label, value) {
|
|
35
|
+
parent.append(element("dt", label));
|
|
36
|
+
parent.append(element("dd", display(value)));
|
|
37
|
+
}
|
|
38
|
+
// A written time is printed exactly as the source wrote it. When it states no
|
|
39
|
+
// zone, a visible marker follows it; no zone is ever assigned and no `Z` or
|
|
40
|
+
// UTC label is ever printed on a time that did not carry one.
|
|
41
|
+
function renderTime(value) {
|
|
42
|
+
const zone = zoneStatement(value);
|
|
43
|
+
const time = element("span", value);
|
|
44
|
+
time.dataset.tz = zone;
|
|
45
|
+
if (zone === "not-stated") {
|
|
46
|
+
const marker = element("span", " (timezone not stated)");
|
|
47
|
+
marker.dataset.tzMarker = "not-stated";
|
|
48
|
+
time.append(marker);
|
|
49
|
+
}
|
|
50
|
+
return time;
|
|
51
|
+
}
|
|
52
|
+
function appendTime(parent, label, value, absent) {
|
|
53
|
+
parent.append(element("dt", label));
|
|
54
|
+
const cell = element("dd");
|
|
55
|
+
if (value === undefined) {
|
|
56
|
+
cell.textContent = absent;
|
|
57
|
+
cell.dataset.time = "not-stated";
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
cell.append(renderTime(value));
|
|
61
|
+
}
|
|
62
|
+
parent.append(cell);
|
|
63
|
+
}
|
|
64
|
+
const recordsWord = (count) => `${count} ${count === 1 ? "record" : "records"}`;
|
|
65
|
+
const evaluationsWord = (count) => `${count} ${count === 1 ? "evaluation" : "evaluations"}`;
|
|
66
|
+
const requirementsWord = (count) => `${count} ${count === 1 ? "requirement" : "requirements"}`;
|
|
67
|
+
// The banner is drawn from AAC's banner model alone (presentation contract
|
|
68
|
+
// section 6.2) and precedes every row in the DOM; a bundle that fails the
|
|
69
|
+
// page's own checks gets the refusal line here and no rows at all, so a
|
|
70
|
+
// reader never meets a payload before the verdict on the bundle that carries
|
|
71
|
+
// it. It is a pill in the page's top bar: `data-verify` is the state the
|
|
72
|
+
// reader is told (`verified` only for a `valid` verdict), `data-verdict` the
|
|
73
|
+
// strict verdict and `data-checkpoint` what became of the checkpoint
|
|
74
|
+
// signature. Its line is the core's fixed text for the state; the details
|
|
75
|
+
// line under the bar names the findings. The bar also says, from the
|
|
76
|
+
// verification section, how many checks passed, and links down to it.
|
|
77
|
+
function renderVerificationBanner(root, model, coverage) {
|
|
78
|
+
const bar = element("div");
|
|
79
|
+
// A failed bundle's bar is a callout on every page, with or without a
|
|
80
|
+
// report's frame (the shell's .cv-failed); in a report's frame an
|
|
81
|
+
// incomplete one takes its own colours (.cv-incomplete). data-verify
|
|
82
|
+
// stays the banner's.
|
|
83
|
+
bar.className =
|
|
84
|
+
model.state === "failed"
|
|
85
|
+
? "cv-shell-bar cv-failed"
|
|
86
|
+
: model.state === "incomplete"
|
|
87
|
+
? "cv-shell-bar cv-incomplete"
|
|
88
|
+
: "cv-shell-bar";
|
|
89
|
+
const banner = element("span", model.line);
|
|
90
|
+
banner.className = "cv-pill";
|
|
91
|
+
banner.dataset.verify = model.state;
|
|
92
|
+
banner.dataset.verdict = model.verdict;
|
|
93
|
+
banner.dataset.checkpoint = model.checkpoint;
|
|
94
|
+
banner.dataset.uncheckpointed = String(model.uncheckpointed);
|
|
95
|
+
bar.append(banner);
|
|
96
|
+
// The verification section's own summary line, filled in once that
|
|
97
|
+
// section is drawn (at the end of renderEvidenceGraph), and a link down
|
|
98
|
+
// to the section.
|
|
99
|
+
const summary = element("span");
|
|
100
|
+
summary.className = "cv-shell-detail";
|
|
101
|
+
summary.dataset.verifySummary = "";
|
|
102
|
+
bar.append(summary);
|
|
103
|
+
if (model.refusal === undefined && coverage.uncheckpointed > 0) {
|
|
104
|
+
const note = element("span", `${coverage.uncheckpointed} of ${recordsWord(coverage.total)} not in the checkpoint`);
|
|
105
|
+
note.className = "cv-shell-note";
|
|
106
|
+
note.dataset.uncheckpointedNote = "";
|
|
107
|
+
bar.append(note);
|
|
108
|
+
}
|
|
109
|
+
const link = element("a", CHECKED_SECTION_TITLE);
|
|
110
|
+
link.className = "cv-shell-link";
|
|
111
|
+
link.setAttribute("href", `#${CHECKED_SECTION_ID}`);
|
|
112
|
+
link.addEventListener("click", () => {
|
|
113
|
+
const section = root.ownerDocument.getElementById(CHECKED_SECTION_ID);
|
|
114
|
+
if (section instanceof root.ownerDocument.defaultView.HTMLDetailsElement)
|
|
115
|
+
section.open = true;
|
|
116
|
+
});
|
|
117
|
+
bar.append(link);
|
|
118
|
+
root.append(bar);
|
|
119
|
+
if (model.detail !== "") {
|
|
120
|
+
const detail = element("p", model.detail);
|
|
121
|
+
detail.className = "cv-banner-detail";
|
|
122
|
+
detail.dataset.bannerDetail = "";
|
|
123
|
+
root.append(detail);
|
|
124
|
+
}
|
|
125
|
+
if (model.refusal === undefined)
|
|
126
|
+
return bar;
|
|
127
|
+
const refusal = element("p", model.refusal);
|
|
128
|
+
refusal.dataset.refusal = "unverified-bundle";
|
|
129
|
+
root.append(refusal);
|
|
130
|
+
return bar;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Draw the `checking` state into `root`, replacing what it held: the
|
|
134
|
+
* banner alone, with no verdict and no row, until the checks finish
|
|
135
|
+
* (presentation contract section 6.2). Returns that banner's bar.
|
|
136
|
+
*/
|
|
137
|
+
export function renderChecking(root) {
|
|
138
|
+
const bar = element("div");
|
|
139
|
+
bar.className = "cv-shell-bar";
|
|
140
|
+
const banner = element("span", VERIFICATION_BANNER_LINES.checking);
|
|
141
|
+
banner.className = "cv-pill";
|
|
142
|
+
banner.dataset.verify = "checking";
|
|
143
|
+
bar.append(banner);
|
|
144
|
+
root.replaceChildren(bar);
|
|
145
|
+
return bar;
|
|
146
|
+
}
|
|
147
|
+
/** The words a page says when this viewer cannot verify the bundle at all. */
|
|
148
|
+
export const UNABLE_TO_VERIFY_LINES = {
|
|
149
|
+
banner: VERIFICATION_BANNER_LINES.unable,
|
|
150
|
+
reason: "This viewer cannot compute the SHA-256 digests the checks need, so nothing was checked and no records are shown. This is not a failed check: the file may well be valid.",
|
|
151
|
+
command: "To check this file, run:",
|
|
152
|
+
noCommand: "To check this file, open it from a secure (https) page, or check it with a verifier outside this viewer.",
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Render the "unable to verify in this viewer" state into `root`: drawn,
|
|
156
|
+
* in place of any verification result, when this runtime has no SHA-256
|
|
157
|
+
* (`digestCapability() === "none"`). It never says the bundle failed, and
|
|
158
|
+
* it shows no record. `verifyCommand` is the exact command a reader runs
|
|
159
|
+
* to check the file elsewhere; without one, the page says where to check
|
|
160
|
+
* it instead.
|
|
161
|
+
*/
|
|
162
|
+
export function renderUnableToVerify(root, options = {}) {
|
|
163
|
+
root.replaceChildren();
|
|
164
|
+
const banner = element("p", UNABLE_TO_VERIFY_LINES.banner);
|
|
165
|
+
banner.dataset.verify = "unable";
|
|
166
|
+
const reason = element("p", UNABLE_TO_VERIFY_LINES.reason);
|
|
167
|
+
reason.dataset.refusal = "unable-to-verify";
|
|
168
|
+
root.append(banner, reason);
|
|
169
|
+
if (options.verifyCommand === undefined) {
|
|
170
|
+
root.append(element("p", UNABLE_TO_VERIFY_LINES.noCommand));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const command = element("code", options.verifyCommand);
|
|
174
|
+
command.dataset.verifyCommand = "";
|
|
175
|
+
const block = element("pre");
|
|
176
|
+
block.append(command);
|
|
177
|
+
root.append(element("p", UNABLE_TO_VERIFY_LINES.command), block);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The one line a closed "How this page was checked" section shows, so what
|
|
181
|
+
* this page did not check stays in view with it folded: how many of the
|
|
182
|
+
* checks passed (or failed), how many records the file carries, and the
|
|
183
|
+
* signatures or other checks this page did not run.
|
|
184
|
+
*/
|
|
185
|
+
export function checkedSummaryLine(verified, model) {
|
|
186
|
+
const total = model.checks.length;
|
|
187
|
+
const failed = model.checks.filter((c) => c.status === "fail").length;
|
|
188
|
+
const passed = model.checks.filter((c) => c.status === "pass").length;
|
|
189
|
+
const notRun = total - failed - passed;
|
|
190
|
+
// A failure can sit outside the numbered checks (a disclosure that does not
|
|
191
|
+
// match its digest, say, or a provenance error outside both counts): a
|
|
192
|
+
// bundle that did not verify never reads as passed.
|
|
193
|
+
// The page's own lists repeat the numbered checks' ground (digests,
|
|
194
|
+
// record rules, closure, range, membership); a failure there is counted
|
|
195
|
+
// only once, as the numbered check it shows up in.
|
|
196
|
+
const pageFailed = model.checkLists.failed.filter((id) => !NUMBERED_CHECK_GROUND.has(id)).length;
|
|
197
|
+
// Numbered checks that did not run are always said, so none reads as
|
|
198
|
+
// passed or failed.
|
|
199
|
+
const notRunNote = notRun > 0 ? `, ${notRun} not run` : "";
|
|
200
|
+
const leads = [];
|
|
201
|
+
if (failed > 0)
|
|
202
|
+
leads.push(`${failed} of ${total} checks failed${notRunNote}`);
|
|
203
|
+
if (pageFailed > 0)
|
|
204
|
+
leads.push(`${pageFailed} ${pageFailed === 1 ? "check" : "checks"} on this page failed`);
|
|
205
|
+
if (failed === 0 && pageFailed === 0)
|
|
206
|
+
leads.push(verified
|
|
207
|
+
? `${passed} of ${total} checks passed${notRunNote}`
|
|
208
|
+
: SUMMARY_NOT_VERIFIED);
|
|
209
|
+
if (failed === 0 && (pageFailed > 0 || !verified) && notRun > 0)
|
|
210
|
+
leads.push(`${notRun} of ${total} checks not run`);
|
|
211
|
+
const parts = [...leads, recordsWord(model.records.length)];
|
|
212
|
+
// Only the signature checks that are in the not-checked list are named, each
|
|
213
|
+
// by its own words: a signature check that ran (or failed) is never said to
|
|
214
|
+
// be unchecked, so the summary cannot contradict the lists under it.
|
|
215
|
+
const signatures = model.checkLists.notChecked.flatMap((id) => {
|
|
216
|
+
const words = SIGNATURE_CHECKS.get(id);
|
|
217
|
+
return words === undefined ? [] : [words];
|
|
218
|
+
});
|
|
219
|
+
const others = model.checkLists.notChecked.length - signatures.length;
|
|
220
|
+
if (signatures.length > 0)
|
|
221
|
+
parts.push(`${signatures.length === 1
|
|
222
|
+
? signatures[0]
|
|
223
|
+
: `${signatures.slice(0, -1).join(", ")} and ${signatures.at(-1)}`} not checked here`);
|
|
224
|
+
if (others > 0)
|
|
225
|
+
parts.push(`${others} other ${others === 1 ? "check" : "checks"} not run here`);
|
|
226
|
+
return parts.join(" · ");
|
|
227
|
+
}
|
|
228
|
+
/** The summary's lead for a bundle that failed outside every counted check. */
|
|
229
|
+
export const SUMMARY_NOT_VERIFIED = "the bundle did not verify";
|
|
230
|
+
const NUMBERED_CHECK_GROUND = new Set([
|
|
231
|
+
"record-digests",
|
|
232
|
+
"record-rules",
|
|
233
|
+
"closure",
|
|
234
|
+
"range",
|
|
235
|
+
"membership",
|
|
236
|
+
]);
|
|
237
|
+
const SIGNATURE_CHECKS = new Map([
|
|
238
|
+
["checkpoint-signature", "checkpoint signature"],
|
|
239
|
+
["producer-signatures", "producer signatures"],
|
|
240
|
+
["cited-signers", "cited signers' signatures"],
|
|
241
|
+
["countersignatures", "countersignatures"],
|
|
242
|
+
]);
|
|
243
|
+
/** The folded verification section's heading. */
|
|
244
|
+
export const CHECKED_SECTION_TITLE = "How this page was checked";
|
|
245
|
+
/** The folded verification section's id, the banner link's target. */
|
|
246
|
+
const CHECKED_SECTION_ID = "cv-checked";
|
|
247
|
+
// presentation/v1 is rendered here, in the header only, and nowhere else in
|
|
248
|
+
// this module. Only readPresentationBlock's three known fields ever reach
|
|
249
|
+
// the DOM -- the chrome rule holds structurally, not by a rendering-site
|
|
250
|
+
// convention that a future edit could bypass.
|
|
251
|
+
function renderPresentationHeader(root, bundle) {
|
|
252
|
+
const presentation = readPresentationBlock(bundle);
|
|
253
|
+
if (presentation === undefined)
|
|
254
|
+
return;
|
|
255
|
+
const header = element("header");
|
|
256
|
+
header.dataset.presentation = "header";
|
|
257
|
+
if (presentation.logoDataUrl !== undefined) {
|
|
258
|
+
const logo = document.createElement("img");
|
|
259
|
+
logo.src = presentation.logoDataUrl;
|
|
260
|
+
logo.alt = presentation.producerDisplayName ?? "producer logo";
|
|
261
|
+
header.append(logo);
|
|
262
|
+
}
|
|
263
|
+
if (presentation.producerDisplayName !== undefined) {
|
|
264
|
+
const name = element("span", presentation.producerDisplayName);
|
|
265
|
+
name.dataset.presentationField = "producer-display-name";
|
|
266
|
+
header.append(name);
|
|
267
|
+
}
|
|
268
|
+
if (presentation.title !== undefined) {
|
|
269
|
+
const title = element("strong", presentation.title);
|
|
270
|
+
title.dataset.presentationField = "title";
|
|
271
|
+
header.append(title);
|
|
272
|
+
}
|
|
273
|
+
root.append(header);
|
|
274
|
+
}
|
|
275
|
+
function stampText(stamp) {
|
|
276
|
+
switch (stamp.kind) {
|
|
277
|
+
case "hollow":
|
|
278
|
+
return "Countersigned: none";
|
|
279
|
+
case "unverified":
|
|
280
|
+
return stamp.reason === "no-ed25519"
|
|
281
|
+
? `a ${stamp.type} countersignature is present; its signature is not checked in this viewer`
|
|
282
|
+
: `a ${stamp.type} countersignature is present; this viewer does not verify that type`;
|
|
283
|
+
case "invalid":
|
|
284
|
+
return "a countersignature is present but failed to verify";
|
|
285
|
+
case "not-independent":
|
|
286
|
+
return `countersigned by the producer — not independent · recomputed ${stamp.statement.recomputedAt}`;
|
|
287
|
+
case "unresolved-signer":
|
|
288
|
+
return `countersigned by an unlisted signer, not in any countersigner list consulted · recomputed ${stamp.statement.recomputedAt}`;
|
|
289
|
+
case "resolved":
|
|
290
|
+
return `Countersigned by ${stamp.name} · recomputed ${stamp.statement.recomputedAt}`;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Each check and result is the signer's statement, listed as the signer gave
|
|
294
|
+
// it: never totalled, never presented as this viewer's own finding.
|
|
295
|
+
function renderSignerStatement(item, signer, statement) {
|
|
296
|
+
const label = element("p", `${signer}'s statement of what it recomputed:`);
|
|
297
|
+
item.append(label);
|
|
298
|
+
const checks = element("ul");
|
|
299
|
+
checks.dataset.countersignStatement = "checks";
|
|
300
|
+
statement.checks.forEach((check) => {
|
|
301
|
+
const row = element("li", `${check.name}: ${check.result}`);
|
|
302
|
+
row.dataset.checkResult = check.result;
|
|
303
|
+
checks.append(row);
|
|
304
|
+
});
|
|
305
|
+
item.append(checks);
|
|
306
|
+
if (statement.receipt === "unverified") {
|
|
307
|
+
const receipt = element("p", "receipt present, not checked by this viewer");
|
|
308
|
+
receipt.dataset.countersignReceipt = "unverified";
|
|
309
|
+
item.append(receipt);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function renderStamps(host, stamps) {
|
|
313
|
+
host.append(element("h4", "Countersignatures"));
|
|
314
|
+
const list = element("ul");
|
|
315
|
+
stamps.forEach((stamp) => {
|
|
316
|
+
const item = element("li");
|
|
317
|
+
item.dataset.stampKind = stamp.kind;
|
|
318
|
+
item.append(element("span", stampText(stamp)));
|
|
319
|
+
if (stamp.kind === "resolved") {
|
|
320
|
+
renderSignerStatement(item, stamp.name, stamp.statement);
|
|
321
|
+
}
|
|
322
|
+
else if (stamp.kind === "not-independent") {
|
|
323
|
+
renderSignerStatement(item, "The producer", stamp.statement);
|
|
324
|
+
}
|
|
325
|
+
else if (stamp.kind === "unresolved-signer") {
|
|
326
|
+
renderSignerStatement(item, "The unlisted signer", stamp.statement);
|
|
327
|
+
}
|
|
328
|
+
list.append(item);
|
|
329
|
+
});
|
|
330
|
+
host.append(list);
|
|
331
|
+
}
|
|
332
|
+
function renderReceipts(host, receipts) {
|
|
333
|
+
host.append(element("h4", "Receipts"));
|
|
334
|
+
if (receipts.length === 0) {
|
|
335
|
+
host.append(element("p", "no receipts disclosed"));
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const list = element("ul");
|
|
339
|
+
receipts.forEach((receipt) => {
|
|
340
|
+
const item = element("li", `${receipt.witness} · ${RECEIPT_GRADE_DISPLAY[receipt.grade]} · `);
|
|
341
|
+
item.append(renderTime(receipt.time));
|
|
342
|
+
list.append(item);
|
|
343
|
+
});
|
|
344
|
+
host.append(list);
|
|
345
|
+
}
|
|
346
|
+
const COVERAGE_LABEL = Object.freeze({
|
|
347
|
+
checkpointed: "checkpointed",
|
|
348
|
+
uncheckpointed: "uncheckpointed",
|
|
349
|
+
membership_invalid: "membership invalid",
|
|
350
|
+
unverified: "membership unverified",
|
|
351
|
+
});
|
|
352
|
+
// One row per supplied record, in bundle order, each with its own standing
|
|
353
|
+
// under the checkpoint. When the claim established coverage the count is
|
|
354
|
+
// stated in words above the list. When it did not, the line says so and
|
|
355
|
+
// names the verifier's reason -- never "0 records uncheckpointed" on a
|
|
356
|
+
// bundle whose memberships were never verified -- and when the claim was
|
|
357
|
+
// withheld (no checkpoint to stand under) there are no counts by status.
|
|
358
|
+
// The records list follows either way: it is where every link to a record
|
|
359
|
+
// lands.
|
|
360
|
+
function renderCheckpointCoverage(host, records, uncheckpointed, coverage, entries, depth) {
|
|
361
|
+
host.append(element("h4", "Checkpoint coverage"));
|
|
362
|
+
if (coverage.status === "established") {
|
|
363
|
+
const count = element("p", `${recordsWord(uncheckpointed)} uncheckpointed of ${recordsWord(records.length)} supplied`);
|
|
364
|
+
count.dataset.coverage = "uncheckpointed";
|
|
365
|
+
count.dataset.count = String(uncheckpointed);
|
|
366
|
+
host.append(count);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
const line = element("p", `coverage not established: ${coverage.reason}`);
|
|
370
|
+
line.dataset.coverage = "not-established";
|
|
371
|
+
line.dataset.claim = coverage.status;
|
|
372
|
+
host.append(line);
|
|
373
|
+
}
|
|
374
|
+
if (coverage.status !== "withheld")
|
|
375
|
+
host.append(renderCoverageStatusCounts(records));
|
|
376
|
+
host.append(renderRecordsList(records, entries, depth));
|
|
377
|
+
}
|
|
378
|
+
// Records in this bundle: one entry per capsule id, each with its own address
|
|
379
|
+
// (`record-<capsule id>`, from the id alone, so every packaging of the page
|
|
380
|
+
// gives the same one), and, for an evidence-book record, a second address
|
|
381
|
+
// under the id of the capsule it carries, so a link by either id lands
|
|
382
|
+
// here. An id the bundle repeats is one entry with one address. The address sits
|
|
383
|
+
// inside the entry, not on it: a browser following a link opens every
|
|
384
|
+
// closed <details> around its target, so the entry itself opens too, with
|
|
385
|
+
// no script (and, where script runs, its body is built on that toggle).
|
|
386
|
+
// Closed until a link lands on it or the reader opens it; its body is built
|
|
387
|
+
// when it opens, or before a static page is written. At depth L2 the list
|
|
388
|
+
// is open, but not its entries: there are hundreds, and each opens when a
|
|
389
|
+
// link lands on it or the reader opens it. Other parts of the page link
|
|
390
|
+
// here and never draw a record themselves. For a bundle that did not
|
|
391
|
+
// verify, the list names each record, its kind and its standing, and draws
|
|
392
|
+
// no content.
|
|
393
|
+
function renderRecordsList(records, entries, depth) {
|
|
394
|
+
const details = document.createElement("details");
|
|
395
|
+
details.dataset.records = "coverage-detail";
|
|
396
|
+
details.open = depth === "L2";
|
|
397
|
+
// One entry per capsule id, in first-listed order: a repeated id is one
|
|
398
|
+
// record listed more than once, so it gets one entry, one address and a
|
|
399
|
+
// note of how many times the bundle lists it, with each listing's status.
|
|
400
|
+
const listings = new Map();
|
|
401
|
+
for (const record of records)
|
|
402
|
+
listings.set(record.capsuleId, [
|
|
403
|
+
...(listings.get(record.capsuleId) ?? []),
|
|
404
|
+
record,
|
|
405
|
+
]);
|
|
406
|
+
const count = listings.size === records.length
|
|
407
|
+
? recordsWord(listings.size)
|
|
408
|
+
: `${recordsWord(listings.size)} (${records.length} listings)`;
|
|
409
|
+
const summary = element("summary", `Records in this bundle: ${count}, by capsule id`);
|
|
410
|
+
details.append(summary);
|
|
411
|
+
if (!entries.verified) {
|
|
412
|
+
const note = element("p", "Record content is not shown: this bundle did not verify.");
|
|
413
|
+
note.dataset.records = "not-shown";
|
|
414
|
+
details.append(note);
|
|
415
|
+
}
|
|
416
|
+
const list = element("ul");
|
|
417
|
+
list.dataset.records = "coverage";
|
|
418
|
+
// Addresses in two passes, as AAC's Result reader resolves ids: every
|
|
419
|
+
// record's own id first, then a carried capsule's id only where no record
|
|
420
|
+
// has that id (and only once), so a book record listed before the capsule
|
|
421
|
+
// it carries never takes that capsule's address.
|
|
422
|
+
const owners = new Map();
|
|
423
|
+
for (const record of records)
|
|
424
|
+
if (entries.verified && entries.read.has(record.capsuleId))
|
|
425
|
+
if (!owners.has(record.capsuleId))
|
|
426
|
+
owners.set(record.capsuleId, record.capsuleId);
|
|
427
|
+
const own = new Set(records.map((record) => record.capsuleId));
|
|
428
|
+
for (const record of records) {
|
|
429
|
+
const carried = entries.read.get(record.capsuleId)?.carriedCapsuleId;
|
|
430
|
+
if (entries.verified &&
|
|
431
|
+
carried !== undefined &&
|
|
432
|
+
!own.has(carried) &&
|
|
433
|
+
!owners.has(carried))
|
|
434
|
+
owners.set(carried, record.capsuleId);
|
|
435
|
+
}
|
|
436
|
+
const used = new Set();
|
|
437
|
+
const address = (id, holder) => {
|
|
438
|
+
const name = recordAddress(id);
|
|
439
|
+
if (owners.get(id) !== holder || used.has(name))
|
|
440
|
+
return undefined;
|
|
441
|
+
used.add(name);
|
|
442
|
+
const anchor = element("span");
|
|
443
|
+
anchor.className = "cv-record-anchor";
|
|
444
|
+
anchor.id = name;
|
|
445
|
+
return anchor;
|
|
446
|
+
};
|
|
447
|
+
for (const [capsuleId, listed] of listings) {
|
|
448
|
+
const record = listed[0];
|
|
449
|
+
const item = element("li");
|
|
450
|
+
item.dataset.capsuleId = capsuleId;
|
|
451
|
+
const kind = entries.kind(capsuleId);
|
|
452
|
+
const status = element("span");
|
|
453
|
+
listed.forEach((one, i) => {
|
|
454
|
+
if (i > 0)
|
|
455
|
+
status.append(" / ");
|
|
456
|
+
const word = element("span", COVERAGE_LABEL[one.status]);
|
|
457
|
+
word.dataset.recordStatus = one.status;
|
|
458
|
+
word.className = `seal-${one.status}`;
|
|
459
|
+
status.append(word);
|
|
460
|
+
});
|
|
461
|
+
if (listed.length > 1) {
|
|
462
|
+
item.dataset.listed = String(listed.length);
|
|
463
|
+
status.append(` · listed ${listed.length} times in this bundle`);
|
|
464
|
+
}
|
|
465
|
+
const label = `${capsuleId} · ${kind ?? "kind not stated"} · `;
|
|
466
|
+
const read = entries.read.get(capsuleId);
|
|
467
|
+
if (!entries.verified || read === undefined) {
|
|
468
|
+
item.append(document.createTextNode(label), status);
|
|
469
|
+
list.append(item);
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const fold = document.createElement("details");
|
|
473
|
+
fold.className = "cv-record";
|
|
474
|
+
fold.dataset.record = record.capsuleId;
|
|
475
|
+
const head = element("summary", label);
|
|
476
|
+
head.append(status);
|
|
477
|
+
fold.append(head);
|
|
478
|
+
const anchors = [record.capsuleId, read.carriedCapsuleId]
|
|
479
|
+
.filter((id) => id !== undefined)
|
|
480
|
+
.map((id) => address(id, record.capsuleId))
|
|
481
|
+
.filter((a) => a !== undefined);
|
|
482
|
+
fold.append(...anchors);
|
|
483
|
+
deferBody(fold, () => entries.build(record.capsuleId, read));
|
|
484
|
+
// Where script runs, the body is built after the browser scrolled to
|
|
485
|
+
// the address; bring it back into view once the body is in place.
|
|
486
|
+
fold.addEventListener("toggle", () => {
|
|
487
|
+
const hash = fold.ownerDocument.defaultView?.location?.hash;
|
|
488
|
+
const target = anchors.find((a) => hash === `#${a.id}`);
|
|
489
|
+
if (fold.open && target !== undefined)
|
|
490
|
+
target.scrollIntoView?.();
|
|
491
|
+
});
|
|
492
|
+
item.append(fold);
|
|
493
|
+
list.append(item);
|
|
494
|
+
}
|
|
495
|
+
details.append(list);
|
|
496
|
+
return details;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Each record's reading for the records list, from the verifier's resolved
|
|
500
|
+
* context: the Result's reading where a claim reaches the record, otherwise
|
|
501
|
+
* the record's own times, log position, committed digests and disclosed
|
|
502
|
+
* members, and, for an evidence-book record, the capsule it carries,
|
|
503
|
+
* checked as the Result reader checks it (`carriedCapsuleCommitment`,
|
|
504
|
+
* `resolveCarriedInput`).
|
|
505
|
+
*/
|
|
506
|
+
async function recordEntries(context, result) {
|
|
507
|
+
const read = new Map();
|
|
508
|
+
for (const record of result?.records.values() ?? []) {
|
|
509
|
+
const id = record.bookRecordId ?? record.capsuleId;
|
|
510
|
+
if (!read.has(id))
|
|
511
|
+
read.set(id, record);
|
|
512
|
+
}
|
|
513
|
+
const bundle = object(context.bundle);
|
|
514
|
+
const memberships = context.completeness.memberships;
|
|
515
|
+
const extensions = object(bundle.extensions);
|
|
516
|
+
const payloads = object(extensions[BOOK_PAYLOADS_EXTENSION]);
|
|
517
|
+
const originals = object(extensions[AGENT_INPUT_ORIGINALS_EXTENSION]);
|
|
518
|
+
for (const raw of context.records) {
|
|
519
|
+
const id = raw.capsule_id;
|
|
520
|
+
if (read.has(id))
|
|
521
|
+
continue;
|
|
522
|
+
const agentInput = disclosureOf(context, id, "agent_input");
|
|
523
|
+
const header = agentInput.state === "disclosed" &&
|
|
524
|
+
object(agentInput.payload).record_type === PUBLISHED_CAPSULE_RECORD_TYPE
|
|
525
|
+
? agentInput.payload
|
|
526
|
+
: undefined;
|
|
527
|
+
const carried = header === undefined
|
|
528
|
+
? undefined
|
|
529
|
+
: await carriedCapsuleCommitment(header, payloads);
|
|
530
|
+
const carriedInput = header === undefined
|
|
531
|
+
? undefined
|
|
532
|
+
: await resolveCarriedInput(header, payloads, originals);
|
|
533
|
+
const references = Array.isArray(raw.references) ? raw.references : [];
|
|
534
|
+
const agentInputDigest = committedDigest(raw, "agent_input");
|
|
535
|
+
const agentOutputDigest = committedDigest(raw, "agent_output");
|
|
536
|
+
const coordinates = logCoordinates(memberships, id);
|
|
537
|
+
read.set(id, {
|
|
538
|
+
...recordTimes(raw),
|
|
539
|
+
capsuleId: id,
|
|
540
|
+
agentInput,
|
|
541
|
+
agentOutput: disclosureOf(context, id, "agent_output"),
|
|
542
|
+
...(agentInputDigest === undefined ? {} : { agentInputDigest }),
|
|
543
|
+
...(agentOutputDigest === undefined ? {} : { agentOutputDigest }),
|
|
544
|
+
...(coordinates === undefined ? {} : { logCoordinates: coordinates }),
|
|
545
|
+
...(carriedInput === undefined ? {} : { carriedInput }),
|
|
546
|
+
...(carried === undefined
|
|
547
|
+
? {}
|
|
548
|
+
: {
|
|
549
|
+
carriedCapsuleId: carried.capsuleId,
|
|
550
|
+
carriedInputDigest: carried.inputDigest,
|
|
551
|
+
}),
|
|
552
|
+
cites: references.flatMap((ref) => {
|
|
553
|
+
const r = object(ref);
|
|
554
|
+
return r.citation_purpose === "acted_on" && typeof r.digest === "string"
|
|
555
|
+
? [r.digest]
|
|
556
|
+
: [];
|
|
557
|
+
}),
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return read;
|
|
561
|
+
}
|
|
562
|
+
/** A record's kind: its disclosed book header's `record_type`, else its own `action_type`. */
|
|
563
|
+
function recordKind(raw, read) {
|
|
564
|
+
const header = read?.agentInput.state === "disclosed"
|
|
565
|
+
? object(read.agentInput.payload).record_type
|
|
566
|
+
: undefined;
|
|
567
|
+
if (typeof header === "string")
|
|
568
|
+
return header;
|
|
569
|
+
const own = object(raw).action_type;
|
|
570
|
+
return typeof own === "string" ? own : undefined;
|
|
571
|
+
}
|
|
572
|
+
// Counts by seal status -- the line a reader actually needs (how many of
|
|
573
|
+
// each) without scrolling a list that is one row per record (500+ rows on a
|
|
574
|
+
// real day's book: 50 cases x 9 criteria + 50 cases + 1 Close). The full,
|
|
575
|
+
// per-capsule-id list stays available (renderCheckpointCoverage wraps it in
|
|
576
|
+
// a collapsed <details>), never removed, just not the first thing rendered.
|
|
577
|
+
function renderCoverageStatusCounts(records) {
|
|
578
|
+
const counts = new Map();
|
|
579
|
+
for (const record of records) {
|
|
580
|
+
counts.set(record.status, (counts.get(record.status) ?? 0) + 1);
|
|
581
|
+
}
|
|
582
|
+
const list = element("ul");
|
|
583
|
+
list.dataset.records = "coverage-summary";
|
|
584
|
+
for (const status of Object.keys(COVERAGE_LABEL)) {
|
|
585
|
+
const count = counts.get(status) ?? 0;
|
|
586
|
+
if (count === 0)
|
|
587
|
+
continue;
|
|
588
|
+
const item = element("li", `${recordsWord(count)} ${COVERAGE_LABEL[status]}`);
|
|
589
|
+
item.dataset.coverageStatus = status;
|
|
590
|
+
item.dataset.count = String(count);
|
|
591
|
+
list.append(item);
|
|
592
|
+
}
|
|
593
|
+
return list;
|
|
594
|
+
}
|
|
595
|
+
function renderCompletenessStatement(host, completeness) {
|
|
596
|
+
host.append(element("h4", "Completeness statement"));
|
|
597
|
+
const details = element("dl");
|
|
598
|
+
appendValue(details, "closure depth", completeness?.closureDepth ?? "unstated");
|
|
599
|
+
appendValue(details, "records mode", completeness?.recordsMode ?? "unstated");
|
|
600
|
+
appendValue(details, "payloads mode", completeness?.payloadsMode ?? "unstated");
|
|
601
|
+
appendValue(details, "suppressed fields", completeness?.suppressedFields ?? []);
|
|
602
|
+
host.append(details);
|
|
603
|
+
}
|
|
604
|
+
function renderChecks(host, checks) {
|
|
605
|
+
host.append(element("h4", "The ten checks"));
|
|
606
|
+
const list = element("ol");
|
|
607
|
+
checks.forEach((check) => {
|
|
608
|
+
const item = element("li");
|
|
609
|
+
item.dataset.checkStatus = check.status;
|
|
610
|
+
item.append(element("strong", check.name));
|
|
611
|
+
item.append(element("span", `: ${check.result}`));
|
|
612
|
+
list.append(item);
|
|
613
|
+
});
|
|
614
|
+
host.append(list);
|
|
615
|
+
}
|
|
616
|
+
// One row per extension: id, integrity, semantics. The id is the bundle's
|
|
617
|
+
// own member name, set as text only. Integrity and semantics are separate
|
|
618
|
+
// cells so "covered" can never read as "understood": an uninterpreted block
|
|
619
|
+
// says so in words (EXTENSION_NOT_INTERPRETED). A row whose meaning a refused
|
|
620
|
+
// presentation module would have applied says that instead (presentation
|
|
621
|
+
// contract section 3.2), and names the module and the reason. A refused
|
|
622
|
+
// module with no extension of its own gets one line after the table. Nothing
|
|
623
|
+
// is drawn for a bundle with no extensions and no refusal.
|
|
624
|
+
function renderExtensions(host, rows, refusals) {
|
|
625
|
+
renderExtensionTable(host, rows);
|
|
626
|
+
for (const notice of refusals) {
|
|
627
|
+
const line = element("p", notice.line);
|
|
628
|
+
line.dataset.presentationRefused = notice.id;
|
|
629
|
+
line.dataset.refusal = notice.reason;
|
|
630
|
+
host.append(line);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function renderExtensionTable(host, rows) {
|
|
634
|
+
if (rows.length === 0)
|
|
635
|
+
return;
|
|
636
|
+
host.append(element("h4", "Extensions"));
|
|
637
|
+
const table = element("table");
|
|
638
|
+
table.dataset.extensions = "";
|
|
639
|
+
const head = element("tr");
|
|
640
|
+
for (const label of ["extension", "integrity", "semantics"])
|
|
641
|
+
head.append(element("th", label));
|
|
642
|
+
const thead = element("thead");
|
|
643
|
+
thead.append(head);
|
|
644
|
+
const body = element("tbody");
|
|
645
|
+
for (const row of rows) {
|
|
646
|
+
const tr = element("tr");
|
|
647
|
+
tr.dataset.extensionId = row.id;
|
|
648
|
+
tr.dataset.integrity = row.integrity;
|
|
649
|
+
tr.dataset.semantics =
|
|
650
|
+
row.refusal !== undefined
|
|
651
|
+
? "refused"
|
|
652
|
+
: row.interpreter === undefined
|
|
653
|
+
? "uninterpreted"
|
|
654
|
+
: "interpreted";
|
|
655
|
+
// The interpreter that showed the block, as AAC's renderer wrote it.
|
|
656
|
+
if (row.interpreter !== undefined)
|
|
657
|
+
tr.dataset.interpreter = row.interpreter;
|
|
658
|
+
if (row.refusal !== undefined) {
|
|
659
|
+
tr.dataset.refusedModule = row.refusal.id;
|
|
660
|
+
tr.dataset.refusal = row.refusal.reason;
|
|
661
|
+
}
|
|
662
|
+
tr.append(element("td", row.id), element("td", row.integrity), element("td", row.semantics));
|
|
663
|
+
body.append(tr);
|
|
664
|
+
}
|
|
665
|
+
table.append(thead, body);
|
|
666
|
+
host.append(table);
|
|
667
|
+
}
|
|
668
|
+
// The page's own checks in up to three lists (presentation contract section
|
|
669
|
+
// 6.1): what ran here and passed, what ran here and failed, and what the
|
|
670
|
+
// bundle calls for that this page did not run. A list with no entries is not
|
|
671
|
+
// drawn. The not-checked list ends with the neutral pointer to a full
|
|
672
|
+
// verifier and, when the host supplied one, its own verifier text (shown as
|
|
673
|
+
// text, never markup).
|
|
674
|
+
function renderCheckLists(host, lists, verifierHint) {
|
|
675
|
+
const groups = [
|
|
676
|
+
["page", CHECKED_ON_THIS_PAGE, lists.page],
|
|
677
|
+
["failed", FAILED_ON_THIS_PAGE, lists.failed],
|
|
678
|
+
["not-checked", NOT_CHECKED_ON_THIS_PAGE, lists.notChecked],
|
|
679
|
+
];
|
|
680
|
+
for (const [which, heading, ids] of groups) {
|
|
681
|
+
if (ids.length === 0)
|
|
682
|
+
continue;
|
|
683
|
+
host.append(element("h4", heading));
|
|
684
|
+
const list = element("ul");
|
|
685
|
+
list.dataset.checks = which;
|
|
686
|
+
for (const id of ids) {
|
|
687
|
+
const item = element("li", verificationCheckWords(id, which === "not-checked" ? "notChecked" : which, lists));
|
|
688
|
+
item.dataset.check = id;
|
|
689
|
+
list.append(item);
|
|
690
|
+
}
|
|
691
|
+
host.append(list);
|
|
692
|
+
if (which === "not-checked") {
|
|
693
|
+
const pointer = element("p", FULL_VERIFIER_LINE);
|
|
694
|
+
pointer.dataset.checks = "full-verifier";
|
|
695
|
+
host.append(pointer);
|
|
696
|
+
if (verifierHint !== undefined && verifierHint !== "") {
|
|
697
|
+
const hint = element("pre", verifierHint);
|
|
698
|
+
hint.dataset.verifierHint = "";
|
|
699
|
+
host.append(hint);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const scope = element("p", CHECKS_SCOPE_LINE);
|
|
704
|
+
scope.dataset.checks = "scope";
|
|
705
|
+
host.append(scope);
|
|
706
|
+
}
|
|
707
|
+
// The viewer-owned verification page: the last page of the rendering, drawn
|
|
708
|
+
// entirely from VERIFIED data (the already-computed BundleVerificationResult
|
|
709
|
+
// and the countersignature stamp classification), never from bundle-supplied
|
|
710
|
+
// markup. It is never labeled a certificate.
|
|
711
|
+
//
|
|
712
|
+
// `styled` (true only when the outcome-report card rendered above it) draws
|
|
713
|
+
// this same page in that card's look: the section takes the card's `.oi`
|
|
714
|
+
// scope plus `.oi-vp`, and its content goes inside one `.sec` panel like
|
|
715
|
+
// every card section. Content, order and data attributes are identical
|
|
716
|
+
// either way, and it stays the last element of the rendering.
|
|
717
|
+
//
|
|
718
|
+
// `applied` is the set of extension interpreters this rendering ran; an
|
|
719
|
+
// extension row says "interpreted by" only for one of them. `refused` is
|
|
720
|
+
// every module this runtime refused that matched (page, then section).
|
|
721
|
+
async function renderVerificationPage(root, context, styled, applied, refused, citedSigners, verifierHint, depth, stamps) {
|
|
722
|
+
const { bundle, verification: verified } = context;
|
|
723
|
+
const section = element("section");
|
|
724
|
+
section.dataset.page = "verification";
|
|
725
|
+
let page = section;
|
|
726
|
+
if (styled) {
|
|
727
|
+
section.className = "oi oi-vp";
|
|
728
|
+
page = element("div");
|
|
729
|
+
page.className = "sec";
|
|
730
|
+
section.append(page);
|
|
731
|
+
}
|
|
732
|
+
page.append(element("h2", "Verification"));
|
|
733
|
+
// The strict result too, so these lists are the ones the banner's line
|
|
734
|
+
// points at (verificationBanner reads the same lists).
|
|
735
|
+
const model = buildVerificationPageModel(bundle, verified, aacInterpreters(applied), {
|
|
736
|
+
stamps,
|
|
737
|
+
citedSigners,
|
|
738
|
+
...(context.strict === undefined ? {} : { strict: context.strict }),
|
|
739
|
+
});
|
|
740
|
+
// AAC's page model carries no presentation refusals: this registry lays
|
|
741
|
+
// its refusal rows over AAC's extension rows (the integrity words from
|
|
742
|
+
// each row's own integrity) and adds a notice for each refused module
|
|
743
|
+
// with no row (presentation contract section 3.2). The deprecated cards'
|
|
744
|
+
// interpreters, which AAC 0.8.0 no longer reports, are applied first.
|
|
745
|
+
const extensions = presentationExtensionRows(aliasExtensionRows(bundle, model.extensions, applied), refused);
|
|
746
|
+
const summary = element("dl");
|
|
747
|
+
appendValue(summary, "bundle digest", model.bundleDigest ?? "uncomputable");
|
|
748
|
+
appendValue(summary, "checkpoint root", model.checkpointRoot ?? "absent");
|
|
749
|
+
appendValue(summary, "checkpoint size", model.checkpointSize ?? "absent");
|
|
750
|
+
page.append(summary);
|
|
751
|
+
renderReceipts(page, model.receipts);
|
|
752
|
+
if (model.selfWitnessed) {
|
|
753
|
+
// A checkpoint with no transparency-service receipt was witnessed by
|
|
754
|
+
// nobody but the log that produced it -- stated here in those words.
|
|
755
|
+
const witness = element("p", "self-witnessed: no transparency-service receipt");
|
|
756
|
+
witness.dataset.witness = "self";
|
|
757
|
+
page.append(witness);
|
|
758
|
+
}
|
|
759
|
+
// The content block's own styles: the records list is the core's, inside
|
|
760
|
+
// no module's frame (record-content.ts RECORD_CONTENT_CSS).
|
|
761
|
+
const contentStyle = element("style");
|
|
762
|
+
contentStyle.textContent = RECORD_CONTENT_CSS;
|
|
763
|
+
page.append(contentStyle);
|
|
764
|
+
let result;
|
|
765
|
+
try {
|
|
766
|
+
result = bundleVerified(verified) ? await resultRootOf(context) : undefined;
|
|
767
|
+
}
|
|
768
|
+
catch {
|
|
769
|
+
result = undefined;
|
|
770
|
+
}
|
|
771
|
+
const read = bundleVerified(verified)
|
|
772
|
+
? await recordEntries(context, result)
|
|
773
|
+
: new Map();
|
|
774
|
+
const rawRecords = new Map();
|
|
775
|
+
for (const raw of Array.isArray(object(bundle).records)
|
|
776
|
+
? object(bundle).records
|
|
777
|
+
: [])
|
|
778
|
+
if (typeof object(raw).capsule_id === "string")
|
|
779
|
+
rawRecords.set(object(raw).capsule_id, raw);
|
|
780
|
+
renderCheckpointCoverage(page, model.records, model.uncheckpointedCount, model.coverage, {
|
|
781
|
+
verified: bundleVerified(verified),
|
|
782
|
+
read,
|
|
783
|
+
kind: (id) => recordKind(rawRecords.get(id), read.get(id)),
|
|
784
|
+
build: (id, record) => renderRecordEntry(id, record),
|
|
785
|
+
}, depth);
|
|
786
|
+
renderStamps(page, stamps);
|
|
787
|
+
renderCompletenessStatement(page, model.completeness);
|
|
788
|
+
renderChecks(page, model.checks);
|
|
789
|
+
renderExtensions(page, extensions, presentationRefusalNotices(refused));
|
|
790
|
+
renderCheckLists(page, model.checkLists, verifierHint);
|
|
791
|
+
page.append(element("p", model.verifyIndependentlyLine));
|
|
792
|
+
// Folded into one section, closed for a bundle that verified; its summary
|
|
793
|
+
// line keeps the counts and what was not checked in view.
|
|
794
|
+
const folded = document.createElement("details");
|
|
795
|
+
folded.className = "cv-checked";
|
|
796
|
+
folded.id = CHECKED_SECTION_ID;
|
|
797
|
+
folded.dataset.checked = "";
|
|
798
|
+
// Open when the bundle did not verify, and at depth L2, where everything
|
|
799
|
+
// is open (presentation contract section 9.1).
|
|
800
|
+
folded.open = !bundleVerified(verified) || depth === "L2";
|
|
801
|
+
const line = checkedSummaryLine(bundleVerified(verified), model);
|
|
802
|
+
const heading = element("summary");
|
|
803
|
+
heading.append(element("strong", CHECKED_SECTION_TITLE), document.createTextNode(` · ${line}`));
|
|
804
|
+
folded.append(heading, section);
|
|
805
|
+
root.append(folded);
|
|
806
|
+
return line;
|
|
807
|
+
}
|
|
808
|
+
function metRate(report) {
|
|
809
|
+
const required = report.outcomes.filter((outcome) => outcome.role === "required");
|
|
810
|
+
if (required.length === 0)
|
|
811
|
+
return "met rate unavailable";
|
|
812
|
+
const passed = required.filter((outcome) => outcome.aggregate === "pass").length;
|
|
813
|
+
return `met rate ${passed}/${required.length}`;
|
|
814
|
+
}
|
|
815
|
+
function renderCalibration(calibration) {
|
|
816
|
+
const section = element("section");
|
|
817
|
+
section.append(element("h2", "Human check"));
|
|
818
|
+
if (calibration === undefined) {
|
|
819
|
+
section.append(element("p", "no human-check data"));
|
|
820
|
+
return section;
|
|
821
|
+
}
|
|
822
|
+
const details = element("dl");
|
|
823
|
+
appendValue(details, "confusion matrix", calibration.confusion);
|
|
824
|
+
appendCount(details, "agreement", calibration.agreement);
|
|
825
|
+
appendCount(details, "corrected rate", calibration.correctedRate);
|
|
826
|
+
appendValue(details, "period window", calibration.periodWindow);
|
|
827
|
+
section.append(details);
|
|
828
|
+
return section;
|
|
829
|
+
}
|
|
830
|
+
// A calibration figure is printed as the integers it is made of, "k of n";
|
|
831
|
+
// no rate is computed from them here, and a figure the producer stated only
|
|
832
|
+
// as a rate is said to be that, not converted.
|
|
833
|
+
function appendCount(parent, label, count) {
|
|
834
|
+
parent.append(element("dt", label));
|
|
835
|
+
const cell = element("dd");
|
|
836
|
+
if (count === undefined) {
|
|
837
|
+
cell.textContent = "not stated";
|
|
838
|
+
cell.dataset.count = "not-stated";
|
|
839
|
+
}
|
|
840
|
+
else if ("rate" in count) {
|
|
841
|
+
cell.textContent = "rate given, k and n not stated";
|
|
842
|
+
cell.dataset.count = "not-stated";
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
cell.textContent = `${count.k} of ${count.n}`;
|
|
846
|
+
cell.dataset.k = String(count.k);
|
|
847
|
+
cell.dataset.n = String(count.n);
|
|
848
|
+
}
|
|
849
|
+
parent.append(cell);
|
|
850
|
+
}
|
|
851
|
+
// Both of a record's times are shown, each labelled and each as written. The
|
|
852
|
+
// action time is the source's own; when the record states none it says so --
|
|
853
|
+
// the seal time (the capsule's registration timestamp) never stands in for it.
|
|
854
|
+
function renderProvenance(capsuleId, coordinates, times) {
|
|
855
|
+
const panel = element("section");
|
|
856
|
+
panel.append(element("h4", "Provenance"));
|
|
857
|
+
const details = element("dl");
|
|
858
|
+
appendValue(details, "capsule ID", capsuleId);
|
|
859
|
+
if (times.provenanceMode !== undefined)
|
|
860
|
+
appendValue(details, "provenance", times.provenanceMode);
|
|
861
|
+
appendTime(details, "action time", times.actionTime, "action time not stated");
|
|
862
|
+
appendTime(details, "seal time", times.sealTime, "seal time not stated");
|
|
863
|
+
// The seal status is this record's own: coordinates exist only for a
|
|
864
|
+
// record whose inclusion proof verified (the bundle renders only then), so
|
|
865
|
+
// a record without them sits outside the checkpoint and says so.
|
|
866
|
+
details.append(element("dt", "seal status"));
|
|
867
|
+
const seal = element("dd", coordinates === undefined ? "uncheckpointed" : "checkpointed");
|
|
868
|
+
seal.dataset.seal =
|
|
869
|
+
coordinates === undefined ? "uncheckpointed" : "checkpointed";
|
|
870
|
+
seal.className = `seal-${seal.dataset.seal}`;
|
|
871
|
+
details.append(seal);
|
|
872
|
+
if (coordinates !== undefined) {
|
|
873
|
+
appendValue(details, "log ID", coordinates.logId);
|
|
874
|
+
appendValue(details, "sequence", coordinates.seq);
|
|
875
|
+
appendValue(details, "leaf", coordinates.leafIndex);
|
|
876
|
+
}
|
|
877
|
+
panel.append(details);
|
|
878
|
+
return panel;
|
|
879
|
+
}
|
|
880
|
+
function renderJudgment(judgment) {
|
|
881
|
+
const item = element("li");
|
|
882
|
+
item.append(element("strong", `${judgment.axisId}: ${judgment.status}`));
|
|
883
|
+
item.append(element("p", judgment.rationale));
|
|
884
|
+
item.append(element("p", `evidence: ${judgment.evidenceIds.join(", ")}`));
|
|
885
|
+
return item;
|
|
886
|
+
}
|
|
887
|
+
function renderAct(act) {
|
|
888
|
+
const section = element("section");
|
|
889
|
+
section.append(element("h4", `Turn ${act.turnIdx}`));
|
|
890
|
+
if (act.agentInput !== undefined)
|
|
891
|
+
section.append(element("pre", display(act.agentInput)));
|
|
892
|
+
if (act.agentOutput !== undefined)
|
|
893
|
+
section.append(element("pre", display(act.agentOutput)));
|
|
894
|
+
section.append(renderProvenance(act.capsuleId, act.logCoordinates, act));
|
|
895
|
+
return section;
|
|
896
|
+
}
|
|
897
|
+
function object(value) {
|
|
898
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
899
|
+
? value
|
|
900
|
+
: {};
|
|
901
|
+
}
|
|
902
|
+
function renderWithheldActs(acts, host) {
|
|
903
|
+
for (const act of acts) {
|
|
904
|
+
if (act.agentInput !== undefined && act.agentOutput !== undefined)
|
|
905
|
+
continue;
|
|
906
|
+
const committed = object({
|
|
907
|
+
agent_input_digest: act.agentInputDigest,
|
|
908
|
+
agent_output_digest: act.agentOutputDigest,
|
|
909
|
+
});
|
|
910
|
+
const evidence = element("section");
|
|
911
|
+
evidence.append(element("h4", "Undisclosed payload evidence"));
|
|
912
|
+
const details = element("dl");
|
|
913
|
+
appendValue(details, "capsule ID", act.capsuleId);
|
|
914
|
+
for (const field of ["agent_input_digest", "agent_output_digest"]) {
|
|
915
|
+
if (typeof committed[field] === "string")
|
|
916
|
+
appendValue(details, field, committed[field]);
|
|
917
|
+
}
|
|
918
|
+
evidence.append(details);
|
|
919
|
+
// A supplied value that does not hash to the committed digest is never
|
|
920
|
+
// shown; the reader sees the digest above and this note, nothing else.
|
|
921
|
+
for (const [field, state] of [
|
|
922
|
+
["agent_input", act.agentInputDisclosure],
|
|
923
|
+
["agent_output", act.agentOutputDisclosure],
|
|
924
|
+
]) {
|
|
925
|
+
if (state !== "disclosure_mismatch")
|
|
926
|
+
continue;
|
|
927
|
+
const note = element("p", `${field}: the disclosed value does not match the committed digest and is withheld`);
|
|
928
|
+
note.dataset.disclosure = state;
|
|
929
|
+
evidence.append(note);
|
|
930
|
+
}
|
|
931
|
+
host.append(evidence);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function renderCase(caseNode, host) {
|
|
935
|
+
host.replaceChildren();
|
|
936
|
+
host.append(element("h3", `Case ${caseNode.caseId}`));
|
|
937
|
+
const judgments = element("ul");
|
|
938
|
+
caseNode.judgments.forEach((judgment) => judgments.append(renderJudgment(judgment)));
|
|
939
|
+
host.append(element("h4", "Axis judgments"), judgments);
|
|
940
|
+
host.append(element("h4", "Disclosed transcript"));
|
|
941
|
+
caseNode.acts.forEach((act) => host.append(renderAct(act)));
|
|
942
|
+
renderWithheldActs(caseNode.acts, host);
|
|
943
|
+
}
|
|
944
|
+
function renderReport(report, host, _records) {
|
|
945
|
+
host.replaceChildren();
|
|
946
|
+
const heading = element("h2", "Cases for ");
|
|
947
|
+
heading.append(renderTime(report.date));
|
|
948
|
+
host.append(heading);
|
|
949
|
+
const outcomes = element("ul");
|
|
950
|
+
report.outcomes.forEach((outcome) => {
|
|
951
|
+
outcomes.append(element("li", `${outcome.outcomeId} (${outcome.role}): ${outcome.aggregate ?? "unrated"}`));
|
|
952
|
+
});
|
|
953
|
+
host.append(element("h3", "Outcome rollup"), outcomes);
|
|
954
|
+
renderWithheldActs(report.withheldActs, host);
|
|
955
|
+
const cases = element("section");
|
|
956
|
+
const detail = element("section");
|
|
957
|
+
report.cases.forEach((caseNode) => {
|
|
958
|
+
const item = element("button", `${caseNode.taskId}, trial ${caseNode.trial}: ${caseNode.aggregate ?? "unrated"}`);
|
|
959
|
+
item.setAttribute("type", "button");
|
|
960
|
+
item.dataset.caseId = caseNode.caseId;
|
|
961
|
+
item.addEventListener("click", () => renderCase(caseNode, detail));
|
|
962
|
+
cases.append(item);
|
|
963
|
+
});
|
|
964
|
+
host.append(cases, detail, renderProvenance(report.capsuleId, report.logCoordinates, report));
|
|
965
|
+
}
|
|
966
|
+
// report/v1: the generic row path. Every row is rendered from its own data
|
|
967
|
+
// -- label, status, reason, citations -- never from report-specific markup,
|
|
968
|
+
// so a pack this module has never heard of (obligations, Consumer Duty,
|
|
969
|
+
// anything else) renders the same way an outcomes report does.
|
|
970
|
+
function renderCitation(citation) {
|
|
971
|
+
const section = element("section");
|
|
972
|
+
section.append(renderProvenance(citation.capsuleId, citation.logCoordinates, citation));
|
|
973
|
+
if (citation.disclosure === "disclosed") {
|
|
974
|
+
section.append(element("pre", display(citation.disclosedPayload)));
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
const note = element("p", citation.disclosure === "disclosure_mismatch"
|
|
978
|
+
? "withheld: the disclosed value does not match the committed digest"
|
|
979
|
+
: "withheld");
|
|
980
|
+
note.dataset.disclosure = citation.disclosure;
|
|
981
|
+
section.append(note);
|
|
982
|
+
}
|
|
983
|
+
return section;
|
|
984
|
+
}
|
|
985
|
+
function renderReportRow(row, host) {
|
|
986
|
+
host.replaceChildren();
|
|
987
|
+
host.append(element("h3", row.label));
|
|
988
|
+
const status = element("p", row.status.replaceAll("_", " "));
|
|
989
|
+
status.dataset.rowStatus = row.status;
|
|
990
|
+
host.append(status);
|
|
991
|
+
if (row.reason !== undefined)
|
|
992
|
+
host.append(element("p", row.reason));
|
|
993
|
+
host.append(element("h4", "Evidence"));
|
|
994
|
+
if (row.citations.length === 0) {
|
|
995
|
+
host.append(element("p", "no citation"));
|
|
996
|
+
}
|
|
997
|
+
else {
|
|
998
|
+
row.citations.forEach((citation) => host.append(renderCitation(citation)));
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
function renderReportRowsTable(reportRows, root) {
|
|
1002
|
+
const section = element("section");
|
|
1003
|
+
section.dataset.page = "report-rows";
|
|
1004
|
+
section.append(element("h1", reportRows.title ?? "Report"));
|
|
1005
|
+
const table = document.createElement("table");
|
|
1006
|
+
const detail = element("section");
|
|
1007
|
+
reportRows.rows.forEach((row) => {
|
|
1008
|
+
const tr = document.createElement("tr");
|
|
1009
|
+
const labelCell = document.createElement("td");
|
|
1010
|
+
const button = element("button", row.label);
|
|
1011
|
+
button.setAttribute("type", "button");
|
|
1012
|
+
button.dataset.rowId = row.rowId;
|
|
1013
|
+
button.addEventListener("click", () => renderReportRow(row, detail));
|
|
1014
|
+
labelCell.append(button);
|
|
1015
|
+
const statusCell = element("td", row.status.replaceAll("_", " "));
|
|
1016
|
+
statusCell.dataset.rowStatus = row.status;
|
|
1017
|
+
tr.append(labelCell, statusCell);
|
|
1018
|
+
table.append(tr);
|
|
1019
|
+
});
|
|
1020
|
+
section.append(table, detail, renderProvenance(reportRows.capsuleId, reportRows.logCoordinates, reportRows));
|
|
1021
|
+
root.append(section);
|
|
1022
|
+
}
|
|
1023
|
+
// Result v0 root: headlines from the root Result, drill-downs from the
|
|
1024
|
+
// records it cites. A cited record is drawn from its own data -- provenance,
|
|
1025
|
+
// each committed member as disclosed or as `withheld · <digest>`, and the
|
|
1026
|
+
// records it cites in turn -- so aggregate → daily → case → act is a walk
|
|
1027
|
+
// over citations, never report-specific markup.
|
|
1028
|
+
function renderCitedMember(host, field, resolution, committed, label = field) {
|
|
1029
|
+
// A value that does not match its commitment is always noted, even where
|
|
1030
|
+
// the caller has no committed digest to name (a record no claim reaches).
|
|
1031
|
+
if (resolution.state !== "disclosed" &&
|
|
1032
|
+
resolution.state !== "disclosure_mismatch" &&
|
|
1033
|
+
committed === undefined)
|
|
1034
|
+
return;
|
|
1035
|
+
host.append(element("h5", label));
|
|
1036
|
+
if (resolution.state === "disclosed") {
|
|
1037
|
+
// The core states what it established, once, beside the block; the
|
|
1038
|
+
// content module only draws the content (presentation contract 6.1).
|
|
1039
|
+
const checked = element("p", "The content shown matches the digest the record commits to.");
|
|
1040
|
+
checked.dataset.contentCheck = "digest";
|
|
1041
|
+
host.append(checked, renderContent(resolution.payload, DEFAULT_WORDS.lines));
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
// A withheld member shows the digest the record committed to; a supplied
|
|
1045
|
+
// value that does not hash to it is never shown, only noted.
|
|
1046
|
+
const note = element("p", resolution.state === "disclosure_mismatch"
|
|
1047
|
+
? committed === undefined
|
|
1048
|
+
? "withheld: the disclosed value does not match the committed digest"
|
|
1049
|
+
: `withheld · ${committed}: the disclosed value does not match the committed digest`
|
|
1050
|
+
: `withheld · ${committed}`);
|
|
1051
|
+
note.dataset.disclosure = resolution.state;
|
|
1052
|
+
host.append(note);
|
|
1053
|
+
}
|
|
1054
|
+
function renderCitedRecord(record, records, host) {
|
|
1055
|
+
const section = element("section");
|
|
1056
|
+
section.dataset.citedRecord = record.capsuleId;
|
|
1057
|
+
section.append(renderProvenance(record.capsuleId, record.logCoordinates, record));
|
|
1058
|
+
renderCitedMember(section, "agent_input", record.agentInput, record.agentInputDigest);
|
|
1059
|
+
renderCitedMember(section, "agent_output", record.agentOutput, record.agentOutputDigest);
|
|
1060
|
+
renderCarriedInput(section, record);
|
|
1061
|
+
if (record.cites.length > 0) {
|
|
1062
|
+
section.append(element("h5", "Cites"));
|
|
1063
|
+
renderCitationList(record.cites, records, section);
|
|
1064
|
+
}
|
|
1065
|
+
host.append(section);
|
|
1066
|
+
}
|
|
1067
|
+
// An evidence-book record's agent_input is the book's header; what the
|
|
1068
|
+
// capsule it carries sealed is the carried input, drawn the same way.
|
|
1069
|
+
function renderCarriedInput(host, record) {
|
|
1070
|
+
if (record.carriedInput === undefined)
|
|
1071
|
+
return;
|
|
1072
|
+
renderCitedMember(host, "agent_input", record.carriedInput, record.carriedInputDigest, "agent_input of the capsule it carries");
|
|
1073
|
+
}
|
|
1074
|
+
// A record's entry in the records section: its provenance (times, seal
|
|
1075
|
+
// status, log position), each committed member as disclosed or withheld,
|
|
1076
|
+
// the capsule it carries, and the records it cites as links to their
|
|
1077
|
+
// entries.
|
|
1078
|
+
function renderRecordEntry(capsuleId, record) {
|
|
1079
|
+
const body = element("div");
|
|
1080
|
+
body.className = "cv-record-body";
|
|
1081
|
+
body.append(renderProvenance(capsuleId, record.logCoordinates, record));
|
|
1082
|
+
renderCitedMember(body, "agent_input", record.agentInput, record.agentInputDigest);
|
|
1083
|
+
renderCitedMember(body, "agent_output", record.agentOutput, record.agentOutputDigest);
|
|
1084
|
+
renderCarriedInput(body, record);
|
|
1085
|
+
if (record.cites.length > 0) {
|
|
1086
|
+
body.append(element("h5", "Cites"));
|
|
1087
|
+
const list = element("ul");
|
|
1088
|
+
for (const id of record.cites) {
|
|
1089
|
+
const item = element("li");
|
|
1090
|
+
const link = element("a", id);
|
|
1091
|
+
link.setAttribute("href", `#${recordAddress(id)}`);
|
|
1092
|
+
link.addEventListener("click", () => revealRecord(link, id));
|
|
1093
|
+
item.append(link);
|
|
1094
|
+
list.append(item);
|
|
1095
|
+
}
|
|
1096
|
+
body.append(list);
|
|
1097
|
+
}
|
|
1098
|
+
return body;
|
|
1099
|
+
}
|
|
1100
|
+
// One row per cited id, in citation order: a record supplied in this bundle
|
|
1101
|
+
// opens under the list on click; one that is not says so and stays.
|
|
1102
|
+
function renderCitationList(ids, records, host) {
|
|
1103
|
+
const list = element("ul");
|
|
1104
|
+
const detail = element("section");
|
|
1105
|
+
for (const id of ids) {
|
|
1106
|
+
const item = element("li");
|
|
1107
|
+
const target = records.get(id);
|
|
1108
|
+
if (target === undefined) {
|
|
1109
|
+
item.textContent = `${id} · not in this bundle`;
|
|
1110
|
+
item.dataset.citation = "missing";
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
const button = element("button", id);
|
|
1114
|
+
button.setAttribute("type", "button");
|
|
1115
|
+
button.dataset.citedId = id;
|
|
1116
|
+
button.addEventListener("click", () => {
|
|
1117
|
+
detail.replaceChildren();
|
|
1118
|
+
renderCitedRecord(target, records, detail);
|
|
1119
|
+
});
|
|
1120
|
+
item.append(button);
|
|
1121
|
+
}
|
|
1122
|
+
list.append(item);
|
|
1123
|
+
}
|
|
1124
|
+
host.append(list, detail);
|
|
1125
|
+
return list;
|
|
1126
|
+
}
|
|
1127
|
+
const CLAIM_TYPE_LABEL = (claim) => claim.recognized ? claim.type : `unrecognized (${claim.type})`;
|
|
1128
|
+
// A recomputed headline number never wears the producer's value. When the
|
|
1129
|
+
// two disagree the recomputed value is drawn and a `count mismatch` marker
|
|
1130
|
+
// sits beside it; the stated value is kept on the marker's data attribute,
|
|
1131
|
+
// never in the text a reader takes as the number.
|
|
1132
|
+
function countMismatchMarker(result, field) {
|
|
1133
|
+
const mismatch = result.countMismatches.find((entry) => entry.field === field);
|
|
1134
|
+
if (mismatch === undefined)
|
|
1135
|
+
return undefined;
|
|
1136
|
+
const marker = element("span", "count mismatch");
|
|
1137
|
+
marker.dataset.countMismatch = field;
|
|
1138
|
+
marker.dataset.stated = String(mismatch.stated);
|
|
1139
|
+
marker.dataset.recomputed = String(mismatch.recomputed);
|
|
1140
|
+
return marker;
|
|
1141
|
+
}
|
|
1142
|
+
// The close state a reader sees is the one this bundle's links read
|
|
1143
|
+
// whenever the cited Close is supplied; the Result's own value is drawn
|
|
1144
|
+
// only when it is not, and then under a `producer-asserted` marker. When
|
|
1145
|
+
// the two disagree the recomputed state is drawn with a `state mismatch`
|
|
1146
|
+
// marker; the asserted value stays on the data attribute, never in the
|
|
1147
|
+
// text. AGREED carries no mark of its own -- its label and the
|
|
1148
|
+
// acknowledging peer's record are the whole affordance.
|
|
1149
|
+
function appendCloseState(parent, close, tag) {
|
|
1150
|
+
const cell = element(tag, close.state);
|
|
1151
|
+
cell.dataset.closeState = close.state;
|
|
1152
|
+
cell.dataset.closeDerivation = close.derivation;
|
|
1153
|
+
cell.dataset.assertedState = close.asserted;
|
|
1154
|
+
if (close.stateMismatch) {
|
|
1155
|
+
const marker = element("span", "state mismatch");
|
|
1156
|
+
marker.dataset.stateMismatch = "close_state";
|
|
1157
|
+
marker.dataset.asserted = close.asserted;
|
|
1158
|
+
marker.dataset.recomputed = close.state;
|
|
1159
|
+
cell.append(" ", marker);
|
|
1160
|
+
}
|
|
1161
|
+
else if (close.derivation === "producer-asserted") {
|
|
1162
|
+
const marker = element("span", "producer-asserted");
|
|
1163
|
+
marker.dataset.producerAsserted = "close_state";
|
|
1164
|
+
cell.append(" ", marker);
|
|
1165
|
+
}
|
|
1166
|
+
if (close.peerRefMismatch) {
|
|
1167
|
+
const marker = element("span", "peer_close_ref carries no such link");
|
|
1168
|
+
marker.dataset.peerRefMismatch = "peer_close_ref";
|
|
1169
|
+
cell.append(" ", marker);
|
|
1170
|
+
}
|
|
1171
|
+
parent.append(cell);
|
|
1172
|
+
return cell;
|
|
1173
|
+
}
|
|
1174
|
+
function renderClose(close, result, host) {
|
|
1175
|
+
host.append(element("h4", "Close"));
|
|
1176
|
+
const details = element("dl");
|
|
1177
|
+
if (close.period !== undefined)
|
|
1178
|
+
appendValue(details, "period", `${close.period.start} → ${close.period.end}`);
|
|
1179
|
+
details.append(element("dt", "state"));
|
|
1180
|
+
appendCloseState(details, close, "dd");
|
|
1181
|
+
details.append(element("dt", "derivation"));
|
|
1182
|
+
const derivation = element("dd", close.derivation === "recomputed"
|
|
1183
|
+
? `recomputed from ${close.links.length} counterparty ${close.links.length === 1 ? "link" : "links"} to the cited Close in this bundle${close.ignored.length === 0 ? "" : ` (${close.ignored.length} other ${close.ignored.length === 1 ? "link" : "links"} ignored)`}`
|
|
1184
|
+
: "producer-asserted: the cited Close is not a record in this bundle, so its links could not be read");
|
|
1185
|
+
derivation.dataset.closeDerivationNote = close.derivation;
|
|
1186
|
+
details.append(derivation);
|
|
1187
|
+
if (close.peer !== undefined)
|
|
1188
|
+
appendValue(details, "peer", close.peer);
|
|
1189
|
+
if (close.bookId !== undefined)
|
|
1190
|
+
appendValue(details, "book", close.bookId);
|
|
1191
|
+
// A signer is drawn as verified only when its Producer Envelope verified
|
|
1192
|
+
// under the key_id (result-root.ts `signerOf`); otherwise it carries the
|
|
1193
|
+
// label, never a bare key.
|
|
1194
|
+
if (close.keyId !== undefined) {
|
|
1195
|
+
details.append(element("dt", "signer"));
|
|
1196
|
+
const signer = element("dd", close.keyVerified === true
|
|
1197
|
+
? `${close.keyId} (verified)`
|
|
1198
|
+
: `${close.keyId} · ${UNVERIFIED_KEY_LABEL}`);
|
|
1199
|
+
signer.dataset.keyVerified = String(close.keyVerified === true);
|
|
1200
|
+
details.append(signer);
|
|
1201
|
+
}
|
|
1202
|
+
host.append(details);
|
|
1203
|
+
host.append(element("h5", "Cited Close"));
|
|
1204
|
+
renderCitationList([close.closeRef], result.records, host);
|
|
1205
|
+
if (close.peerCloseRef !== undefined) {
|
|
1206
|
+
host.append(element("h5", "Peer record"));
|
|
1207
|
+
renderCitationList([close.peerCloseRef], result.records, host);
|
|
1208
|
+
}
|
|
1209
|
+
if (close.links.length > 0) {
|
|
1210
|
+
host.append(element("h5", "Links to the cited Close"));
|
|
1211
|
+
const list = element("ul");
|
|
1212
|
+
for (const link of close.links) {
|
|
1213
|
+
const item = element("li", `${link.type} · ${link.recordId} · signer ${link.keyId} (verified)`);
|
|
1214
|
+
item.dataset.closeLink = link.type;
|
|
1215
|
+
item.dataset.linkRecord = link.recordId;
|
|
1216
|
+
list.append(item);
|
|
1217
|
+
}
|
|
1218
|
+
host.append(list);
|
|
1219
|
+
}
|
|
1220
|
+
// Inbound links that made no state -- from the Close's own book, a book
|
|
1221
|
+
// that is not the named peer, or the Close's own key -- are listed with
|
|
1222
|
+
// the reason, never counted: a reader sees why AGREED was not read.
|
|
1223
|
+
if (close.ignored.length > 0) {
|
|
1224
|
+
host.append(element("h5", "Links ignored (not from the counterparty)"));
|
|
1225
|
+
const list = element("ul");
|
|
1226
|
+
for (const link of close.ignored) {
|
|
1227
|
+
const item = element("li", `${link.type} · ${link.recordId} · ${link.reason}`);
|
|
1228
|
+
item.dataset.ignoredLink = link.type;
|
|
1229
|
+
item.dataset.linkRecord = link.recordId;
|
|
1230
|
+
list.append(item);
|
|
1231
|
+
}
|
|
1232
|
+
host.append(list);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
// The verdict a reader sees is the Result's own only when every cited id
|
|
1236
|
+
// resolves in this bundle and the claim stands. A claim that FAILED
|
|
1237
|
+
// verification (its close state is not what the links read) reads
|
|
1238
|
+
// `failed` -- never `met`, never its stated verdict, which is kept on
|
|
1239
|
+
// `data-stated-verdict` only. Otherwise an unresolved citation reads
|
|
1240
|
+
// `unsupported`. The row stays in every case.
|
|
1241
|
+
// The verdict a reader may see: never the producer's word for a claim that
|
|
1242
|
+
// failed verification or whose evidence is not in the bundle.
|
|
1243
|
+
function shownVerdict(claim) {
|
|
1244
|
+
return claim.failed
|
|
1245
|
+
? "failed"
|
|
1246
|
+
: claim.support === "supported"
|
|
1247
|
+
? claim.verdict
|
|
1248
|
+
: "unsupported";
|
|
1249
|
+
}
|
|
1250
|
+
function appendVerdict(parent, claim) {
|
|
1251
|
+
const shown = shownVerdict(claim);
|
|
1252
|
+
// A later claim's verdict is readiness only (ER section 4.3): never read
|
|
1253
|
+
// as a result that counts.
|
|
1254
|
+
const cell = element(parent.tagName === "TR" ? "td" : "dd", claim.later ? `${shown} (readiness)` : shown);
|
|
1255
|
+
cell.dataset.verdict = shown;
|
|
1256
|
+
cell.dataset.support = claim.support;
|
|
1257
|
+
if (claim.later)
|
|
1258
|
+
cell.dataset.later = "true";
|
|
1259
|
+
if (claim.failed) {
|
|
1260
|
+
cell.dataset.statedVerdict = claim.verdict;
|
|
1261
|
+
cell.className = "claim-failed";
|
|
1262
|
+
}
|
|
1263
|
+
else if (claim.support === "unsupported")
|
|
1264
|
+
cell.className = "claim-unsupported";
|
|
1265
|
+
parent.append(cell);
|
|
1266
|
+
return cell;
|
|
1267
|
+
}
|
|
1268
|
+
// A failed claim's sufficiency is the producer's word too: the cell reads
|
|
1269
|
+
// `failed`, the stated value on `data-stated-sufficiency` only.
|
|
1270
|
+
function appendSufficiency(parent, claim) {
|
|
1271
|
+
const shown = claim.failed ? "failed" : claim.sufficiency;
|
|
1272
|
+
const cell = element(parent.tagName === "TR" ? "td" : "dd", shown);
|
|
1273
|
+
cell.dataset.sufficiency = shown;
|
|
1274
|
+
if (claim.failed) {
|
|
1275
|
+
cell.dataset.statedSufficiency = claim.sufficiency;
|
|
1276
|
+
cell.className = "claim-failed";
|
|
1277
|
+
}
|
|
1278
|
+
parent.append(cell);
|
|
1279
|
+
return cell;
|
|
1280
|
+
}
|
|
1281
|
+
function renderClaim(claim, result, host) {
|
|
1282
|
+
host.replaceChildren();
|
|
1283
|
+
host.append(element("h3", `Claim ${claim.id}`));
|
|
1284
|
+
const details = element("dl");
|
|
1285
|
+
appendValue(details, "contract", claim.contractRef);
|
|
1286
|
+
appendValue(details, "requirement", claim.requirementRef);
|
|
1287
|
+
details.append(element("dt", "type"));
|
|
1288
|
+
const type = element("dd", CLAIM_TYPE_LABEL(claim));
|
|
1289
|
+
type.dataset.claimType = claim.recognized ? claim.type : "unrecognized";
|
|
1290
|
+
if (!claim.recognized)
|
|
1291
|
+
type.className = "claim-unrecognized";
|
|
1292
|
+
details.append(type);
|
|
1293
|
+
appendValue(details, "tier", claim.tier);
|
|
1294
|
+
appendValue(details, "grade", claim.grade);
|
|
1295
|
+
details.append(element("dt", "sufficiency"));
|
|
1296
|
+
appendSufficiency(details, claim);
|
|
1297
|
+
details.append(element("dt", "verdict"));
|
|
1298
|
+
appendVerdict(details, claim);
|
|
1299
|
+
host.append(details);
|
|
1300
|
+
if (claim.failed) {
|
|
1301
|
+
const note = element("p", `failed: ${claim.failure ?? "verification failed"}; sufficiency and verdict withheld`);
|
|
1302
|
+
note.dataset.claimFailed = claim.failedOn ?? "close_state";
|
|
1303
|
+
host.append(note);
|
|
1304
|
+
}
|
|
1305
|
+
if (claim.close !== undefined)
|
|
1306
|
+
renderClose(claim.close, result, host);
|
|
1307
|
+
if (claim.support === "unsupported") {
|
|
1308
|
+
const note = element("p", claim.missing.length === 0
|
|
1309
|
+
? "unsupported: this claim cites no evidence"
|
|
1310
|
+
: `unsupported: cited evidence not in this bundle: ${claim.missing.join(", ")}`);
|
|
1311
|
+
note.dataset.claimMissing = String(claim.missing.length);
|
|
1312
|
+
host.append(note);
|
|
1313
|
+
}
|
|
1314
|
+
host.append(element("h4", "Presentation"));
|
|
1315
|
+
const carrier = element("dl");
|
|
1316
|
+
appendValue(carrier, "carrier", claim.presentation.kind);
|
|
1317
|
+
appendValue(carrier, "status", claim.presentation.status);
|
|
1318
|
+
if (claim.presentation.summary !== undefined)
|
|
1319
|
+
appendValue(carrier, "summary", claim.presentation.summary);
|
|
1320
|
+
if (claim.presentation.narrative !== undefined)
|
|
1321
|
+
appendValue(carrier, "narrative", claim.presentation.narrative);
|
|
1322
|
+
host.append(carrier);
|
|
1323
|
+
// A disclosure carrier names the digests it discloses. They are drawn in
|
|
1324
|
+
// the same row shape as any other citation, resolved against this bundle;
|
|
1325
|
+
// the claim's own `evidence[]` below is the list the verdict rests on.
|
|
1326
|
+
if (claim.presentation.evidence !== undefined) {
|
|
1327
|
+
host.append(element("h5", "Carrier evidence"));
|
|
1328
|
+
const list = renderCitationList(claim.presentation.evidence, result.records, host);
|
|
1329
|
+
list.dataset.carrierEvidence = String(claim.presentation.evidence.length);
|
|
1330
|
+
}
|
|
1331
|
+
host.append(element("h4", "Proofs"));
|
|
1332
|
+
if (claim.proofs.length === 0) {
|
|
1333
|
+
host.append(element("p", "no proof cited"));
|
|
1334
|
+
}
|
|
1335
|
+
else {
|
|
1336
|
+
const proofs = element("ul");
|
|
1337
|
+
for (const proof of claim.proofs)
|
|
1338
|
+
proofs.append(element("li", `${proof.kind} · ${proof.digest} · not resolved here`));
|
|
1339
|
+
host.append(proofs);
|
|
1340
|
+
}
|
|
1341
|
+
host.append(element("h4", "Evidence"));
|
|
1342
|
+
for (const ref of claim.evidence) {
|
|
1343
|
+
const record = result.records.get(ref.digest);
|
|
1344
|
+
if (record === undefined) {
|
|
1345
|
+
const missing = element("p", `${ref.digest} · not in this bundle`);
|
|
1346
|
+
missing.dataset.evidence = "missing";
|
|
1347
|
+
host.append(missing);
|
|
1348
|
+
}
|
|
1349
|
+
else {
|
|
1350
|
+
renderCitedRecord(record, result.records, host);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
const BUCKETS = [
|
|
1355
|
+
["met", "met", "buckets.met"],
|
|
1356
|
+
["notMet", "not met", "buckets.not_met"],
|
|
1357
|
+
["notEvaluable", "not evaluable", "buckets.not_evaluable"],
|
|
1358
|
+
// ER section 4.2: drawn only when the Result carries the fourth bucket.
|
|
1359
|
+
["outOfScope", "out of scope", "buckets.out_of_scope"],
|
|
1360
|
+
];
|
|
1361
|
+
// Coverage is the first thing in the Result section after its heading, and
|
|
1362
|
+
// no number precedes it within the section; then the buckets, never a
|
|
1363
|
+
// single figure; then one row per claim with its own tier and grade. The
|
|
1364
|
+
// bundle-level verification banner, drawn before every section, is the one
|
|
1365
|
+
// thing above coverage that can carry digits ("N of M records
|
|
1366
|
+
// uncheckpointed"). Every number drawn here is the recomputed one
|
|
1367
|
+
// (`result.coverage`, `result.bucketCounts`); a producer figure the claims
|
|
1368
|
+
// do not bear out shows as a `count mismatch` marker beside the recomputed
|
|
1369
|
+
// value. `excluded as not applicable` is the one figure carried as stated:
|
|
1370
|
+
// no claim backs it, by construction. Coverage counts evaluations (one per
|
|
1371
|
+
// claim, ER §3), so the line also names how many distinct requirements the
|
|
1372
|
+
// claims cite, and an UNKNOWN count is never called unresolved requirements.
|
|
1373
|
+
/** Said above the generic Result page when a Result opted into a card whose layout cannot hold its claims (`claimsFitCard`). */
|
|
1374
|
+
export const CARD_UNFIT_NOTE = "This Result's claims don't fit the report layout, so every claim is listed below instead.";
|
|
1375
|
+
function renderResultPage(result, root) {
|
|
1376
|
+
const section = element("section");
|
|
1377
|
+
section.dataset.page = "result";
|
|
1378
|
+
section.append(element("h1", "Evidence result"));
|
|
1379
|
+
// The requirements the in-force evaluations cover: every claim of one
|
|
1380
|
+
// requirement carries the same applies_from, so a requirement is in force
|
|
1381
|
+
// or later as a whole (ER section 4.3).
|
|
1382
|
+
const requirements = new Set(result.claims
|
|
1383
|
+
.filter((claim) => !claim.later)
|
|
1384
|
+
.map((claim) => JSON.stringify([claim.contractRef, claim.requirementRef]))).size;
|
|
1385
|
+
const coverage = element("p");
|
|
1386
|
+
coverage.append(`coverage: ${evaluationsWord(result.coverage.evaluatedPopulation)} of ${requirementsWord(requirements)}`);
|
|
1387
|
+
const evaluatedMarker = countMismatchMarker(result, "evaluated_population");
|
|
1388
|
+
if (evaluatedMarker !== undefined)
|
|
1389
|
+
coverage.append(" ", evaluatedMarker);
|
|
1390
|
+
coverage.append(` · ${result.coverage.excludedNotApplicable} excluded as not applicable · ${result.coverage.unknownCount} with an unknown result`);
|
|
1391
|
+
const unknownMarker = countMismatchMarker(result, "unknown_count");
|
|
1392
|
+
if (unknownMarker !== undefined)
|
|
1393
|
+
coverage.append(" ", unknownMarker);
|
|
1394
|
+
const later = result.claims.filter((claim) => claim.later);
|
|
1395
|
+
const laterMarker = countMismatchMarker(result, "not_yet_in_force");
|
|
1396
|
+
if (later.length > 0 || laterMarker !== undefined) {
|
|
1397
|
+
coverage.append(` · ${evaluationsWord(later.length)} not yet in force`);
|
|
1398
|
+
if (laterMarker !== undefined)
|
|
1399
|
+
coverage.append(" ", laterMarker);
|
|
1400
|
+
coverage.dataset.notYetInForce = String(later.length);
|
|
1401
|
+
}
|
|
1402
|
+
coverage.dataset.coverage = "result";
|
|
1403
|
+
coverage.dataset.evaluated = String(result.coverage.evaluatedPopulation);
|
|
1404
|
+
coverage.dataset.requirements = String(requirements);
|
|
1405
|
+
coverage.dataset.excluded = String(result.coverage.excludedNotApplicable);
|
|
1406
|
+
coverage.dataset.excludedBasis = "stated";
|
|
1407
|
+
coverage.dataset.unknown = String(result.coverage.unknownCount);
|
|
1408
|
+
section.append(coverage);
|
|
1409
|
+
// ER sections 4.2 and 4.3: whenever a claim is dated, the date "in force"
|
|
1410
|
+
// is relative to; and whenever a claim is dated or the out-of-scope switch
|
|
1411
|
+
// is on, that these are the producer's copy of the contract, never checked
|
|
1412
|
+
// here.
|
|
1413
|
+
const dated = result.claims.some((claim) => claim.appliesFrom !== undefined);
|
|
1414
|
+
if (dated || result.buckets.outOfScope !== undefined) {
|
|
1415
|
+
const copied = element("p");
|
|
1416
|
+
if (dated) {
|
|
1417
|
+
// A dated Result passed validation, so generated_at parses.
|
|
1418
|
+
const date = utcDateOf(result.generatedAt) ?? result.generatedAt;
|
|
1419
|
+
copied.append(`In force as of ${date}. `);
|
|
1420
|
+
copied.dataset.asOf = date;
|
|
1421
|
+
}
|
|
1422
|
+
copied.append(dated && result.buckets.outOfScope !== undefined
|
|
1423
|
+
? "The dates and the out-of-scope switch are copied from the contract, not re-checked here."
|
|
1424
|
+
: dated
|
|
1425
|
+
? "The dates are copied from the contract, not re-checked here."
|
|
1426
|
+
: "The out-of-scope switch is copied from the contract, not re-checked here.");
|
|
1427
|
+
copied.dataset.copiedFacts = "contract";
|
|
1428
|
+
section.append(copied);
|
|
1429
|
+
}
|
|
1430
|
+
const byId = new Map(result.claims.map((claim) => [claim.id, claim]));
|
|
1431
|
+
const buckets = element("section");
|
|
1432
|
+
buckets.dataset.buckets = "verdict";
|
|
1433
|
+
buckets.append(element("h2", "Claims by verdict"));
|
|
1434
|
+
for (const [key, label, field] of BUCKETS) {
|
|
1435
|
+
const ids = result.buckets[key];
|
|
1436
|
+
if (ids === undefined)
|
|
1437
|
+
continue;
|
|
1438
|
+
const count = result.bucketCounts[key] ?? 0;
|
|
1439
|
+
const heading = element("h3", `${label}: ${count === 0 ? "none" : count}`);
|
|
1440
|
+
heading.dataset.bucketCount = String(count);
|
|
1441
|
+
heading.dataset.bucketOf = key;
|
|
1442
|
+
const marker = countMismatchMarker(result, field);
|
|
1443
|
+
if (marker !== undefined)
|
|
1444
|
+
heading.append(" ", marker);
|
|
1445
|
+
buckets.append(heading);
|
|
1446
|
+
if (ids.length === 0) {
|
|
1447
|
+
buckets.append(element("p", "none"));
|
|
1448
|
+
continue;
|
|
1449
|
+
}
|
|
1450
|
+
const list = element("ul");
|
|
1451
|
+
list.dataset.bucket = key;
|
|
1452
|
+
for (const id of ids) {
|
|
1453
|
+
const claim = byId.get(id);
|
|
1454
|
+
const item = element("li", claim?.failed
|
|
1455
|
+
? `${id} · failed`
|
|
1456
|
+
: claim?.support === "unsupported"
|
|
1457
|
+
? `${id} · unsupported`
|
|
1458
|
+
: id);
|
|
1459
|
+
item.dataset.claimRef = id;
|
|
1460
|
+
if (claim?.failed)
|
|
1461
|
+
item.className = "claim-failed";
|
|
1462
|
+
else if (claim?.support === "unsupported")
|
|
1463
|
+
item.className = "claim-unsupported";
|
|
1464
|
+
list.append(item);
|
|
1465
|
+
}
|
|
1466
|
+
buckets.append(list);
|
|
1467
|
+
}
|
|
1468
|
+
// The verifier's own state, after the producer's buckets: claims
|
|
1469
|
+
// that failed verification (a close state the links contradict). Drawn
|
|
1470
|
+
// always, `none` when empty, so a reader never has to infer from an
|
|
1471
|
+
// absent heading that nothing failed. Not a verdict bucket: a failed
|
|
1472
|
+
// claim is counted here and under no verdict, whatever bucket the
|
|
1473
|
+
// producer listed it in (that listing stays above, marked).
|
|
1474
|
+
const failedHeading = element("h3", `failed: ${result.bucketCounts.failed === 0 ? "none" : result.bucketCounts.failed}`);
|
|
1475
|
+
failedHeading.dataset.bucketCount = String(result.bucketCounts.failed);
|
|
1476
|
+
failedHeading.dataset.bucketOf = "failed";
|
|
1477
|
+
buckets.append(failedHeading);
|
|
1478
|
+
const failedIds = result.claims
|
|
1479
|
+
.filter((claim) => claim.failed)
|
|
1480
|
+
.map((claim) => claim.id);
|
|
1481
|
+
if (failedIds.length === 0)
|
|
1482
|
+
buckets.append(element("p", "none"));
|
|
1483
|
+
else {
|
|
1484
|
+
const list = element("ul");
|
|
1485
|
+
list.dataset.bucket = "failed";
|
|
1486
|
+
for (const id of failedIds) {
|
|
1487
|
+
const item = element("li", id);
|
|
1488
|
+
item.dataset.claimRef = id;
|
|
1489
|
+
item.className = "claim-failed";
|
|
1490
|
+
list.append(item);
|
|
1491
|
+
}
|
|
1492
|
+
buckets.append(list);
|
|
1493
|
+
}
|
|
1494
|
+
// ER section 4.3: claims not yet in force, their verdicts readiness only,
|
|
1495
|
+
// in no bucket above.
|
|
1496
|
+
if (later.length > 0) {
|
|
1497
|
+
const heading = element("h3", `not yet in force: ${later.length}`);
|
|
1498
|
+
heading.dataset.bucketOf = "notYetInForce";
|
|
1499
|
+
heading.dataset.bucketCount = String(later.length);
|
|
1500
|
+
buckets.append(heading);
|
|
1501
|
+
const list = element("ul");
|
|
1502
|
+
list.dataset.bucket = "notYetInForce";
|
|
1503
|
+
for (const claim of later) {
|
|
1504
|
+
const item = element("li", `${claim.id} · applies from ${claim.appliesFrom ?? ""} · readiness: ${shownVerdict(claim)}`);
|
|
1505
|
+
item.dataset.claimRef = claim.id;
|
|
1506
|
+
if (claim.failed)
|
|
1507
|
+
item.className = "claim-failed";
|
|
1508
|
+
else if (claim.support === "unsupported")
|
|
1509
|
+
item.className = "claim-unsupported";
|
|
1510
|
+
list.append(item);
|
|
1511
|
+
}
|
|
1512
|
+
buckets.append(list);
|
|
1513
|
+
}
|
|
1514
|
+
section.append(buckets);
|
|
1515
|
+
const table = document.createElement("table");
|
|
1516
|
+
table.dataset.claims = "rows";
|
|
1517
|
+
const detail = element("section");
|
|
1518
|
+
for (const claim of result.claims) {
|
|
1519
|
+
const tr = document.createElement("tr");
|
|
1520
|
+
tr.dataset.claimRow = claim.id;
|
|
1521
|
+
tr.dataset.support = claim.support;
|
|
1522
|
+
if (claim.support === "unsupported")
|
|
1523
|
+
tr.className = "claim-unsupported";
|
|
1524
|
+
if (claim.failed) {
|
|
1525
|
+
tr.classList.add("claim-failed");
|
|
1526
|
+
tr.dataset.failed = claim.failedOn ?? "close_state";
|
|
1527
|
+
}
|
|
1528
|
+
const idCell = document.createElement("td");
|
|
1529
|
+
const button = element("button", claim.id);
|
|
1530
|
+
button.setAttribute("type", "button");
|
|
1531
|
+
button.dataset.claimId = claim.id;
|
|
1532
|
+
button.addEventListener("click", () => renderClaim(claim, result, detail));
|
|
1533
|
+
idCell.append(button);
|
|
1534
|
+
tr.append(idCell, element("td", claim.requirementRef));
|
|
1535
|
+
appendSufficiency(tr, claim);
|
|
1536
|
+
appendVerdict(tr, claim);
|
|
1537
|
+
const tier = element("td", claim.tier);
|
|
1538
|
+
tier.dataset.tier = claim.tier;
|
|
1539
|
+
const grade = element("td", claim.grade);
|
|
1540
|
+
grade.dataset.grade = claim.grade;
|
|
1541
|
+
const type = element("td", CLAIM_TYPE_LABEL(claim));
|
|
1542
|
+
type.dataset.claimType = claim.recognized ? claim.type : "unrecognized";
|
|
1543
|
+
if (!claim.recognized)
|
|
1544
|
+
type.className = "claim-unrecognized";
|
|
1545
|
+
if (claim.close !== undefined) {
|
|
1546
|
+
type.append(" · ");
|
|
1547
|
+
appendCloseState(type, claim.close, "span");
|
|
1548
|
+
}
|
|
1549
|
+
tr.append(tier, grade, type);
|
|
1550
|
+
table.append(tr);
|
|
1551
|
+
}
|
|
1552
|
+
section.append(table, detail, renderProvenance(result.capsuleId, result.logCoordinates, result));
|
|
1553
|
+
root.append(section);
|
|
1554
|
+
}
|
|
1555
|
+
function renderGraph(graph, root, records) {
|
|
1556
|
+
const aggregate = element("section");
|
|
1557
|
+
aggregate.append(element("h1", "Evidence graph"));
|
|
1558
|
+
const metrics = element("dl");
|
|
1559
|
+
appendValue(metrics, "per-axis", graph.aggregate.perAxis);
|
|
1560
|
+
appendValue(metrics, "counts", graph.aggregate.counts);
|
|
1561
|
+
aggregate.append(metrics);
|
|
1562
|
+
root.append(aggregate, renderCalibration(graph.calibration));
|
|
1563
|
+
const calendar = element("section");
|
|
1564
|
+
calendar.append(element("h2", "Daily reports"));
|
|
1565
|
+
const detail = element("section");
|
|
1566
|
+
[...graph.reports]
|
|
1567
|
+
.sort((left, right) => left.date.localeCompare(right.date))
|
|
1568
|
+
.forEach((report) => {
|
|
1569
|
+
// The label is the report's date as the producer wrote it -- a bare
|
|
1570
|
+
// day stays a day, a timestamp stays a timestamp, and one that states
|
|
1571
|
+
// no zone is marked so rather than tiled under an assigned one.
|
|
1572
|
+
const tile = element("button");
|
|
1573
|
+
tile.append(renderTime(report.date), `: ${metRate(report)}`);
|
|
1574
|
+
tile.setAttribute("type", "button");
|
|
1575
|
+
tile.dataset.reportDate = report.date;
|
|
1576
|
+
tile.addEventListener("click", () => renderReport(report, detail, records));
|
|
1577
|
+
calendar.append(tile);
|
|
1578
|
+
});
|
|
1579
|
+
root.append(calendar, detail);
|
|
1580
|
+
}
|
|
1581
|
+
// ---------------------------------------------------------------------------
|
|
1582
|
+
// The built-in presentations (spec/presentation-contract-v0.md appendix A).
|
|
1583
|
+
// Which one renders is decided by their manifests (builtin-manifests.ts),
|
|
1584
|
+
// never here: each module only builds its model and draws it.
|
|
1585
|
+
// ---------------------------------------------------------------------------
|
|
1586
|
+
// A model built by canRender is kept for buildModel, per context, so a
|
|
1587
|
+
// module never builds twice and canRender stays the one place that decides.
|
|
1588
|
+
function memo(build) {
|
|
1589
|
+
const cache = new WeakMap();
|
|
1590
|
+
return (context) => {
|
|
1591
|
+
let value = cache.get(context);
|
|
1592
|
+
if (value === undefined) {
|
|
1593
|
+
value = build(context);
|
|
1594
|
+
cache.set(context, value);
|
|
1595
|
+
}
|
|
1596
|
+
return value;
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
const reportRowsOf = memo(buildReportRows);
|
|
1600
|
+
// A Result root whose document is malformed makes buildResultRoot throw. The
|
|
1601
|
+
// throw rejects renderEvidenceGraph before anything is written, exactly as
|
|
1602
|
+
// before the registry: a malformed Result is refused, never rendered as one.
|
|
1603
|
+
const resultRootOf = memo(async (context) => (await isResultRoot(context)) ? buildResultRoot(context) : undefined);
|
|
1604
|
+
// EvidenceGraphError means "no evaluation-summary graph here" (the module
|
|
1605
|
+
// declines and the fallback renders); any other error propagates.
|
|
1606
|
+
const evidenceGraphOf = memo(async (context) => {
|
|
1607
|
+
try {
|
|
1608
|
+
return await buildEvidenceGraph(context);
|
|
1609
|
+
}
|
|
1610
|
+
catch (err) {
|
|
1611
|
+
if (!(err instanceof EvidenceGraphError))
|
|
1612
|
+
throw err;
|
|
1613
|
+
return undefined;
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
function defined(value, id) {
|
|
1617
|
+
if (value === undefined)
|
|
1618
|
+
throw new Error(`${id}: buildModel called although canRender was false`);
|
|
1619
|
+
return value;
|
|
1620
|
+
}
|
|
1621
|
+
const reportRowsModule = {
|
|
1622
|
+
manifest: BUILTIN_MANIFEST_REPORT_ROWS,
|
|
1623
|
+
canRender: async (context) => (await reportRowsOf(context)) !== undefined,
|
|
1624
|
+
buildModel: async (context) => defined(await reportRowsOf(context), BUILTIN_MANIFEST_REPORT_ROWS.id),
|
|
1625
|
+
render: (model, host) => renderReportRowsTable(model, host.L1),
|
|
1626
|
+
};
|
|
1627
|
+
/**
|
|
1628
|
+
* The context's verification with AAC's strict result in its `strict`
|
|
1629
|
+
* member, where this runtime reached one: the contract report's "Witnessed
|
|
1630
|
+
* by" line reads AAC's witness status from it (report-provenance.ts), the
|
|
1631
|
+
* same result the banner reads.
|
|
1632
|
+
*/
|
|
1633
|
+
function withStrict(context) {
|
|
1634
|
+
return context.strict === undefined
|
|
1635
|
+
? context.verification
|
|
1636
|
+
: { ...context.verification, strict: context.strict };
|
|
1637
|
+
}
|
|
1638
|
+
const resultOutcomeReportModule = {
|
|
1639
|
+
manifest: BUILTIN_MANIFEST_RESULT_OUTCOME_REPORT,
|
|
1640
|
+
canRender: async (context) => readOutcomeReportPresentation(context.bundle) !== undefined &&
|
|
1641
|
+
(await isResultRoot(context)),
|
|
1642
|
+
buildModel: async (context) => ({
|
|
1643
|
+
result: defined(await resultRootOf(context), BUILTIN_MANIFEST_RESULT_OUTCOME_REPORT.id),
|
|
1644
|
+
card: defined(readOutcomeReportPresentation(context.bundle), BUILTIN_MANIFEST_RESULT_OUTCOME_REPORT.id),
|
|
1645
|
+
bundle: context.bundle,
|
|
1646
|
+
verification: withStrict(context),
|
|
1647
|
+
}),
|
|
1648
|
+
render: async (model, host) => {
|
|
1649
|
+
// The banner and the verification page take the card's look.
|
|
1650
|
+
host.setChromeClass("oi");
|
|
1651
|
+
await renderContractReport(model.result, { grouping: "lines", options: model.card }, model.bundle, model.verification, { L0: host.L0, L1: host.L1, L2: host.L2, depth: host.depth }, host.wording);
|
|
1652
|
+
},
|
|
1653
|
+
};
|
|
1654
|
+
const resultComplianceModule = {
|
|
1655
|
+
manifest: BUILTIN_MANIFEST_RESULT_COMPLIANCE,
|
|
1656
|
+
canRender: async (context) => readCompliancePresentation(context.bundle) !== undefined &&
|
|
1657
|
+
(await isResultRoot(context)),
|
|
1658
|
+
buildModel: async (context) => ({
|
|
1659
|
+
result: defined(await resultRootOf(context), BUILTIN_MANIFEST_RESULT_COMPLIANCE.id),
|
|
1660
|
+
card: defined(readCompliancePresentation(context.bundle), BUILTIN_MANIFEST_RESULT_COMPLIANCE.id),
|
|
1661
|
+
bundle: context.bundle,
|
|
1662
|
+
verification: withStrict(context),
|
|
1663
|
+
}),
|
|
1664
|
+
render: async (model, host) => {
|
|
1665
|
+
// The card draws its own frame inside the page.
|
|
1666
|
+
host.setChromeClass(COMPLIANCE_CHROME);
|
|
1667
|
+
await renderContractReport(model.result, { grouping: "groups", presentation: model.card }, model.bundle, model.verification, { L0: host.L0, L1: host.L1, L2: host.L2, depth: host.depth }, host.wording);
|
|
1668
|
+
},
|
|
1669
|
+
};
|
|
1670
|
+
/**
|
|
1671
|
+
* The contract-report module's manifest (agent-action-capsule
|
|
1672
|
+
* spec/contract-report-v1.md section 4): the same match as
|
|
1673
|
+
* `aac.builtin.result-contract-report/v0`, which it replaces in this
|
|
1674
|
+
* registry. Registering both would be an ambiguity error (presentation
|
|
1675
|
+
* contract section 4.5). It carries no `executable.wording_sha256`: the pack
|
|
1676
|
+
* is a builder input, recorded as provenance.
|
|
1677
|
+
*/
|
|
1678
|
+
export const CONTRACT_REPORT_MANIFEST = Object.freeze({
|
|
1679
|
+
...BUILTIN_MANIFEST_RESULT_CONTRACT_REPORT,
|
|
1680
|
+
id: "capsuleviewer.contract-report/v0",
|
|
1681
|
+
});
|
|
1682
|
+
/**
|
|
1683
|
+
* The data a contract report draws from, beside the empty
|
|
1684
|
+
* `contract-report/v1` block: an earlier kind's block, read by its own
|
|
1685
|
+
* reader (section 5), the outcome block first, as the built-in manifests'
|
|
1686
|
+
* precedence has it (the compliance card forbids `outcome-report/v1`).
|
|
1687
|
+
*/
|
|
1688
|
+
/** The grouping the contract-report module draws for `bundle`, or undefined when it draws the generic Result page. */
|
|
1689
|
+
export function contractReportGroupingOf(bundle) {
|
|
1690
|
+
return contractReportInput(bundle)?.grouping;
|
|
1691
|
+
}
|
|
1692
|
+
function contractReportInput(bundle) {
|
|
1693
|
+
const options = readOutcomeReportPresentation(bundle);
|
|
1694
|
+
if (options !== undefined)
|
|
1695
|
+
return { grouping: "lines", options };
|
|
1696
|
+
const presentation = readCompliancePresentation(bundle);
|
|
1697
|
+
if (presentation !== undefined)
|
|
1698
|
+
return { grouping: "groups", presentation };
|
|
1699
|
+
return undefined;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* The contract-report module (contract-report.ts), resolved on
|
|
1703
|
+
* `contract-report/v1`. `canRender` is the generic Result page's, whatever
|
|
1704
|
+
* the pack or the number of contracts (section 4), so every Result root that
|
|
1705
|
+
* opts in reaches it. A Result that carries neither grouping's data draws
|
|
1706
|
+
* the generic Result page, exactly as the built-in it replaces.
|
|
1707
|
+
*/
|
|
1708
|
+
/**
|
|
1709
|
+
* Whether every claim has a place of its own on the outcome or EU card. The
|
|
1710
|
+
* cards lay a Result out one conversation by one requirement, so they can
|
|
1711
|
+
* show a claim only when it is a requirement claim whose id names its
|
|
1712
|
+
* conversation (`<conversation>::…`), no two claims share a conversation
|
|
1713
|
+
* and a requirement (a re-judged requirement), and all cite one contract.
|
|
1714
|
+
* The EU card also needs a grouped requirement (`<group>.<test>`); the
|
|
1715
|
+
* Outcomes card needs one of the terms' check and criterion pairs
|
|
1716
|
+
* (`readOutcomeReportTerms`), since agent-action-capsule's outcome model
|
|
1717
|
+
* leaves out any other. Any other Result is drawn as the generic Result
|
|
1718
|
+
* page, which lists every claim: a card never merges a claim into another
|
|
1719
|
+
* or leaves one out (contract-report/v1 section 2).
|
|
1720
|
+
*/
|
|
1721
|
+
function claimsFitCard(result, grouping) {
|
|
1722
|
+
if (new Set(result.claims.map((c) => c.contractRef)).size > 1)
|
|
1723
|
+
return false;
|
|
1724
|
+
const placed = grouping === "lines"
|
|
1725
|
+
? new Set(readOutcomeReportTerms(result).checks.flatMap((check) => check.criteria.map((criterion) => `${check.id}.${criterion.id}`)))
|
|
1726
|
+
: undefined;
|
|
1727
|
+
const seen = new Set();
|
|
1728
|
+
for (const claim of result.claims) {
|
|
1729
|
+
if (claim.type !== REQUIREMENT_CLAIM)
|
|
1730
|
+
return false;
|
|
1731
|
+
const sep = claim.id.indexOf("::");
|
|
1732
|
+
if (sep <= 0)
|
|
1733
|
+
return false;
|
|
1734
|
+
if (placed !== undefined && !placed.has(claim.requirementRef))
|
|
1735
|
+
return false;
|
|
1736
|
+
if (grouping === "groups") {
|
|
1737
|
+
const dot = claim.requirementRef.indexOf(".");
|
|
1738
|
+
if (dot <= 0 || dot === claim.requirementRef.length - 1)
|
|
1739
|
+
return false;
|
|
1740
|
+
}
|
|
1741
|
+
const key = JSON.stringify([claim.id.slice(0, sep), claim.requirementRef]);
|
|
1742
|
+
if (seen.has(key))
|
|
1743
|
+
return false;
|
|
1744
|
+
seen.add(key);
|
|
1745
|
+
}
|
|
1746
|
+
return true;
|
|
1747
|
+
}
|
|
1748
|
+
/** Which interpreters a contract-report render ran, by the bundle it drew: set when its model is built. */
|
|
1749
|
+
const contractReportDrawn = new WeakMap();
|
|
1750
|
+
const contractReportModule = {
|
|
1751
|
+
manifest: CONTRACT_REPORT_MANIFEST,
|
|
1752
|
+
canRender: (context) => isResultRoot(context),
|
|
1753
|
+
buildModel: async (context) => {
|
|
1754
|
+
const result = defined(await resultRootOf(context), CONTRACT_REPORT_MANIFEST.id);
|
|
1755
|
+
const supported = contractReportInput(context.bundle);
|
|
1756
|
+
const input = supported !== undefined && claimsFitCard(result, supported.grouping)
|
|
1757
|
+
? supported
|
|
1758
|
+
: undefined;
|
|
1759
|
+
if (typeof context.bundle === "object" && context.bundle !== null)
|
|
1760
|
+
contractReportDrawn.set(context.bundle, input ?? null);
|
|
1761
|
+
return {
|
|
1762
|
+
result,
|
|
1763
|
+
...(input === undefined ? {} : { input }),
|
|
1764
|
+
...(supported !== undefined && input === undefined
|
|
1765
|
+
? { unfit: true }
|
|
1766
|
+
: {}),
|
|
1767
|
+
bundle: context.bundle,
|
|
1768
|
+
verification: withStrict(context),
|
|
1769
|
+
};
|
|
1770
|
+
},
|
|
1771
|
+
render: async (model, host) => {
|
|
1772
|
+
if (model.input === undefined) {
|
|
1773
|
+
if (model.unfit === true) {
|
|
1774
|
+
const note = element("p", CARD_UNFIT_NOTE);
|
|
1775
|
+
note.dataset.notice = "card-unfit";
|
|
1776
|
+
host.L1.append(note);
|
|
1777
|
+
}
|
|
1778
|
+
renderResultPage(model.result, host.L1);
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
// The report's banner takes its frame's look (a callout at the top);
|
|
1782
|
+
// the outcome report's verification page takes its look too.
|
|
1783
|
+
host.setChromeClass(model.input.grouping === "lines" ? OUTCOME_CHROME : COMPLIANCE_CHROME);
|
|
1784
|
+
await renderContractReport(model.result, model.input, model.bundle, model.verification, { L0: host.L0, L1: host.L1, L2: host.L2, depth: host.depth }, host.wording);
|
|
1785
|
+
},
|
|
1786
|
+
};
|
|
1787
|
+
const resultModule = {
|
|
1788
|
+
manifest: BUILTIN_MANIFEST_RESULT,
|
|
1789
|
+
canRender: (context) => isResultRoot(context),
|
|
1790
|
+
buildModel: async (context) => defined(await resultRootOf(context), BUILTIN_MANIFEST_RESULT.id),
|
|
1791
|
+
render: (model, host) => renderResultPage(model, host.L1),
|
|
1792
|
+
};
|
|
1793
|
+
const evaluationSummaryGraphModule = {
|
|
1794
|
+
manifest: BUILTIN_MANIFEST_EVALUATION_SUMMARY_GRAPH,
|
|
1795
|
+
canRender: async (context) => (await evidenceGraphOf(context)) !== undefined,
|
|
1796
|
+
buildModel: async (context) => {
|
|
1797
|
+
const records = object(context.bundle).records;
|
|
1798
|
+
return {
|
|
1799
|
+
graph: defined(await evidenceGraphOf(context), BUILTIN_MANIFEST_EVALUATION_SUMMARY_GRAPH.id),
|
|
1800
|
+
records: Array.isArray(records) ? records : [],
|
|
1801
|
+
};
|
|
1802
|
+
},
|
|
1803
|
+
render: (model, host) => renderGraph(model.graph, host.L1, model.records),
|
|
1804
|
+
};
|
|
1805
|
+
// The evaluation-summary/v1 aggregate is optional: a verified bundle whose
|
|
1806
|
+
// root is none of the other families (a deal root, for example) renders
|
|
1807
|
+
// without the aggregate panel and says so, instead of rendering nothing.
|
|
1808
|
+
const noAggregateModule = {
|
|
1809
|
+
manifest: BUILTIN_MANIFEST_NO_AGGREGATE,
|
|
1810
|
+
canRender: () => true,
|
|
1811
|
+
buildModel: () => null,
|
|
1812
|
+
render: (_model, host) => {
|
|
1813
|
+
const note = document.createElement("p");
|
|
1814
|
+
note.setAttribute("data-notice", "no-aggregate");
|
|
1815
|
+
note.textContent =
|
|
1816
|
+
"This bundle carries no evaluation summary, so there is no aggregate view. The records and their verification are below.";
|
|
1817
|
+
host.L1.append(note);
|
|
1818
|
+
},
|
|
1819
|
+
};
|
|
1820
|
+
// The extension interpreters each built-in module runs when it renders: a
|
|
1821
|
+
// Result page reads the book payload extensions, and each card reads its own
|
|
1822
|
+
// block. The rows table, the graph and the no-aggregate note read none.
|
|
1823
|
+
const BUILTIN_MODULE_INTERPRETERS = Object.freeze({
|
|
1824
|
+
[BUILTIN_MANIFEST_RESULT_OUTCOME_REPORT.id]: [
|
|
1825
|
+
"result-root",
|
|
1826
|
+
"outcome-report-card",
|
|
1827
|
+
],
|
|
1828
|
+
[BUILTIN_MANIFEST_RESULT_COMPLIANCE.id]: ["result-root", "compliance-card"],
|
|
1829
|
+
[BUILTIN_MANIFEST_RESULT.id]: ["result-root"],
|
|
1830
|
+
[BUILTIN_MANIFEST_COMPOSED.id]: ["aac.builtin.composed/v0"],
|
|
1831
|
+
});
|
|
1832
|
+
/**
|
|
1833
|
+
* The extension interpreters a module ran on `bundle`. The contract-report
|
|
1834
|
+
* module applies the `contract-report/v1` block it resolved on
|
|
1835
|
+
* (contract-report/v1 section 4) and runs the Result reader, plus the one
|
|
1836
|
+
* earlier kind's reader whose data it drew (contractReportInput), never both:
|
|
1837
|
+
* until their removal, earlier blocks are read by their own readers (section 5).
|
|
1838
|
+
*/
|
|
1839
|
+
function moduleInterpreters(id, bundle) {
|
|
1840
|
+
if (id === CONTRACT_REPORT_MANIFEST.id) {
|
|
1841
|
+
const drawn = typeof bundle === "object" && bundle !== null
|
|
1842
|
+
? contractReportDrawn.get(bundle)
|
|
1843
|
+
: undefined;
|
|
1844
|
+
const input = drawn === undefined ? contractReportInput(bundle) : (drawn ?? undefined);
|
|
1845
|
+
return input === undefined
|
|
1846
|
+
? ["contract-report", "result-root"]
|
|
1847
|
+
: [
|
|
1848
|
+
"contract-report",
|
|
1849
|
+
"result-root",
|
|
1850
|
+
input.grouping === "lines"
|
|
1851
|
+
? "outcome-report-card"
|
|
1852
|
+
: "compliance-card",
|
|
1853
|
+
];
|
|
1854
|
+
}
|
|
1855
|
+
return BUILTIN_MODULE_INTERPRETERS[id] ?? [];
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* The seven built-in modules, registered by default: agent-action-capsule's
|
|
1859
|
+
* seven built-in shapes, with the contract-report module in place of
|
|
1860
|
+
* `aac.builtin.result-contract-report/v0` (contract-report/v1 section 4).
|
|
1861
|
+
*/
|
|
1862
|
+
export const BUILTIN_PRESENTATIONS = Object.freeze([
|
|
1863
|
+
reportRowsModule,
|
|
1864
|
+
contractReportModule,
|
|
1865
|
+
resultOutcomeReportModule,
|
|
1866
|
+
resultComplianceModule,
|
|
1867
|
+
resultModule,
|
|
1868
|
+
evaluationSummaryGraphModule,
|
|
1869
|
+
noAggregateModule,
|
|
1870
|
+
]);
|
|
1871
|
+
/** A fresh registry holding the seven built-in modules. */
|
|
1872
|
+
export function createPresentationRegistry() {
|
|
1873
|
+
const registry = new PresentationRegistry();
|
|
1874
|
+
for (const module of BUILTIN_PRESENTATIONS)
|
|
1875
|
+
registry.register(module);
|
|
1876
|
+
return registry;
|
|
1877
|
+
}
|
|
1878
|
+
const defaultRegistry = createPresentationRegistry();
|
|
1879
|
+
/**
|
|
1880
|
+
* The built-in sections: modules resolved after the page module, in their
|
|
1881
|
+
* own registry, and rendered after its content. One today, the composition
|
|
1882
|
+
* section; see BUILTIN_MANIFEST_COMPOSED for why it is not a page module.
|
|
1883
|
+
*/
|
|
1884
|
+
export const BUILTIN_SECTIONS = Object.freeze([
|
|
1885
|
+
composedSectionModule,
|
|
1886
|
+
]);
|
|
1887
|
+
/**
|
|
1888
|
+
* A fresh section registry holding the built-in sections. The section
|
|
1889
|
+
* registry applies the presentation ABI as the page registry does: under a
|
|
1890
|
+
* `runtime` that refuses a section, the section is registered as refused,
|
|
1891
|
+
* never drawn, and every page it matches names it.
|
|
1892
|
+
*/
|
|
1893
|
+
export function createSectionRegistry(runtime) {
|
|
1894
|
+
const registry = new PresentationRegistry(runtime);
|
|
1895
|
+
for (const module of BUILTIN_SECTIONS)
|
|
1896
|
+
registry.register(module);
|
|
1897
|
+
return registry;
|
|
1898
|
+
}
|
|
1899
|
+
const defaultSections = createSectionRegistry();
|
|
1900
|
+
/**
|
|
1901
|
+
* Register a module with the registry `renderEvidenceGraph` uses by default
|
|
1902
|
+
* (the module-slot entry point). Throws when its manifest is malformed,
|
|
1903
|
+
* dead, a duplicate, or co-matchable with a registered module of its tier.
|
|
1904
|
+
* A module whose `presentation_api` this runtime does not implement (or
|
|
1905
|
+
* whose `runtime_min` it does not meet) is registered as refused: it is
|
|
1906
|
+
* never selected, and every page it would have rendered names it.
|
|
1907
|
+
*/
|
|
1908
|
+
export function registerPresentation(module) {
|
|
1909
|
+
return defaultRegistry.register(module);
|
|
1910
|
+
}
|
|
1911
|
+
/** Resolve over the default registry (spec section 4.3). */
|
|
1912
|
+
export function resolvePresentation(context, audience = DEFAULT_AUDIENCE, format = DEFAULT_FORMAT) {
|
|
1913
|
+
return defaultRegistry.resolve(context, audience, format);
|
|
1914
|
+
}
|
|
1915
|
+
/** `"*"`: no particular audience, so only modules serving every audience. */
|
|
1916
|
+
const DEFAULT_AUDIENCE = "*";
|
|
1917
|
+
const DEFAULT_FORMAT = "html";
|
|
1918
|
+
/**
|
|
1919
|
+
* True when the rendered page module checked the producer signature of the
|
|
1920
|
+
* records it cites as signers: the built-in Result page, on a Close (or a
|
|
1921
|
+
* record linking to it) that carries a `key_id` (result-root.ts `signerOf`).
|
|
1922
|
+
*/
|
|
1923
|
+
function citesCheckedSigners(selected) {
|
|
1924
|
+
if (selected === undefined || selected.module !== resultModule)
|
|
1925
|
+
return false;
|
|
1926
|
+
return selected.model.claims.some((claim) => claim.close !== undefined &&
|
|
1927
|
+
(claim.close.keyId !== undefined ||
|
|
1928
|
+
[...claim.close.links, ...claim.close.ignored].some((link) => link.keyId !== undefined)));
|
|
1929
|
+
}
|
|
1930
|
+
const OUTCOME_CHROME = "oi";
|
|
1931
|
+
const COMPLIANCE_CHROME = "cc";
|
|
1932
|
+
function presentationServices(context) {
|
|
1933
|
+
return Object.freeze({
|
|
1934
|
+
details(summary, open = false) {
|
|
1935
|
+
const details = document.createElement("details");
|
|
1936
|
+
if (open)
|
|
1937
|
+
details.open = true;
|
|
1938
|
+
details.append(element("summary", summary));
|
|
1939
|
+
return details;
|
|
1940
|
+
},
|
|
1941
|
+
badge(state) {
|
|
1942
|
+
const badge = element("span", state);
|
|
1943
|
+
badge.dataset.badge = state;
|
|
1944
|
+
return badge;
|
|
1945
|
+
},
|
|
1946
|
+
disclosure(capsuleId, member) {
|
|
1947
|
+
return disclosureOf(context, capsuleId, member).state;
|
|
1948
|
+
},
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
// The refusal for a verified bundle whose presentation could not be resolved
|
|
1952
|
+
// (an ambiguity) or failed (a module threw while rendering): the core's
|
|
1953
|
+
// words, no module content, the verification page below (contract I1).
|
|
1954
|
+
const PRESENTATION_REFUSALS = {
|
|
1955
|
+
"presentation-unresolved": "The presentation for this bundle could not be resolved. No presentation content is shown; the verification page below lists the checks.",
|
|
1956
|
+
"presentation-failed": "The presentation for this bundle failed. No presentation content is shown; the verification page below lists the checks.",
|
|
1957
|
+
};
|
|
1958
|
+
export async function renderEvidenceGraph(input, root, countersigners, options = {}) {
|
|
1959
|
+
// With no SHA-256 nothing can be verified: say so, never "failed".
|
|
1960
|
+
if (!isVerifiedBundleContext(input) && digestCapability() === "none") {
|
|
1961
|
+
renderUnableToVerify(root, options.verifyCommand === undefined
|
|
1962
|
+
? {}
|
|
1963
|
+
: { verifyCommand: options.verifyCommand });
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
if (isVerifiedBundleContext(input))
|
|
1967
|
+
return renderVerifiedContext(countersigners === undefined
|
|
1968
|
+
? input
|
|
1969
|
+
: withCountersigners(input, countersigners), root, options);
|
|
1970
|
+
// Verify first. Until the verification result is in hand the page shows
|
|
1971
|
+
// `checking` and nothing else, and no module is consulted for a bundle
|
|
1972
|
+
// that did not verify. A render that rejects while its own `checking` is
|
|
1973
|
+
// still shown puts back what `root` held before the first of the renders
|
|
1974
|
+
// still checking on it began, so it still draws nothing. When another
|
|
1975
|
+
// render on the same root is still checking, its `checking` is put back
|
|
1976
|
+
// instead; another render's `checking` that has ended never is.
|
|
1977
|
+
const group = checkingRenders.get(root) ?? {
|
|
1978
|
+
before: [...root.childNodes],
|
|
1979
|
+
active: new Set(),
|
|
1980
|
+
};
|
|
1981
|
+
checkingRenders.set(root, group);
|
|
1982
|
+
const { active } = group;
|
|
1983
|
+
const checking = renderChecking(root);
|
|
1984
|
+
active.add(checking);
|
|
1985
|
+
try {
|
|
1986
|
+
await renderVerifiedContext(await buildVerifiedBundleContext(input, {
|
|
1987
|
+
...(countersigners === undefined ? {} : { countersigners }),
|
|
1988
|
+
}), root, options);
|
|
1989
|
+
}
|
|
1990
|
+
catch (err) {
|
|
1991
|
+
if (checking.parentNode === root) {
|
|
1992
|
+
const other = [...active].find((node) => node !== checking);
|
|
1993
|
+
if (other !== undefined)
|
|
1994
|
+
root.replaceChildren(other);
|
|
1995
|
+
else
|
|
1996
|
+
root.replaceChildren(...group.before);
|
|
1997
|
+
}
|
|
1998
|
+
throw err;
|
|
1999
|
+
}
|
|
2000
|
+
finally {
|
|
2001
|
+
active.delete(checking);
|
|
2002
|
+
if (active.size === 0)
|
|
2003
|
+
checkingRenders.delete(root);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
// The side margins are not in FRAME_LOOK: the shell centres the page root and
|
|
2007
|
+
// the bar with `auto` margins, and a computed `auto` margin is its used
|
|
2008
|
+
// width, which moves by half a classic scrollbar when a module's content
|
|
2009
|
+
// makes the page scroll. They are compared to within SIDE_MARGIN_SLACK
|
|
2010
|
+
// instead, a constant no module's stylesheet can change: a module that moves
|
|
2011
|
+
// the banner by more is still caught. It assumes a classic scrollbar of up to
|
|
2012
|
+
// 18 CSS px (a native 17px at zoom 100%); at a very low page zoom the
|
|
2013
|
+
// scrollbar is wider in CSS px, and an honest module that makes the page
|
|
2014
|
+
// scroll is then discarded, which fails closed.
|
|
2015
|
+
const SIDE_MARGINS = ["margin-left", "margin-right"];
|
|
2016
|
+
const SIDE_MARGIN_SLACK = 9;
|
|
2017
|
+
// The paddings and border widths: a module that widens them pushes the words
|
|
2018
|
+
// inside out of view.
|
|
2019
|
+
const BOX_EDGES = ["top", "right", "bottom", "left"].flatMap((side) => [
|
|
2020
|
+
`padding-${side}`,
|
|
2021
|
+
`border-${side}-width`,
|
|
2022
|
+
]);
|
|
2023
|
+
// On the root's ancestors, which in the embedded format are the host page's
|
|
2024
|
+
// own elements, the offsets, paddings, border widths and a transform's
|
|
2025
|
+
// translation are compared to within the same slack: a host that places its
|
|
2026
|
+
// widget with `left: 50%`, `translateX(-50%)` or a percentage margin or
|
|
2027
|
+
// padding resolves them to used px that move with the scrollbar too. A
|
|
2028
|
+
// positioned element's `top` and `left` resolve to where it is, whichever of
|
|
2029
|
+
// its offsets set that, so they stand for `right` and `bottom`, whose used px
|
|
2030
|
+
// follow the height of the module's content and are not compared. A module can
|
|
2031
|
+
// therefore still shift the banner by up to SIDE_MARGIN_SLACK per offset of
|
|
2032
|
+
// each ancestor; `position` and a transform that was `none` are compared
|
|
2033
|
+
// exactly. Those shifts add up, so where the bar sits in the document is
|
|
2034
|
+
// bounded too: it may not rise by more than SIDE_MARGIN_SLACK, nor move
|
|
2035
|
+
// sideways by more than one assumed classic scrollbar, twice
|
|
2036
|
+
// SIDE_MARGIN_SLACK (a widget a host floats right moves by all of it).
|
|
2037
|
+
// Downward is left to the per-ancestor caps, since a scrollbar only narrows
|
|
2038
|
+
// the page and so pushes reflowing host content above the widget down; the
|
|
2039
|
+
// caps keep a module from pushing the banner off the first screen, under
|
|
2040
|
+
// fixed content of its own, through an ancestor. A host that centres a
|
|
2041
|
+
// growing widget vertically lifts the banner by itself; an honest module there
|
|
2042
|
+
// is discarded, which fails closed.
|
|
2043
|
+
const ANCESTOR_OFFSETS = [
|
|
2044
|
+
"top",
|
|
2045
|
+
"left",
|
|
2046
|
+
"margin-top",
|
|
2047
|
+
"margin-bottom",
|
|
2048
|
+
...BOX_EDGES,
|
|
2049
|
+
];
|
|
2050
|
+
const ANCESTOR_UNCOMPARED = ["right", "bottom"];
|
|
2051
|
+
// `a` is the frame now, `b` as it was before the module rendered. Words a
|
|
2052
|
+
// reader sees where the page is now must not be covered or clipped (see
|
|
2053
|
+
// readable), unless they already were before the module rendered: a host
|
|
2054
|
+
// that covered or clipped the widget itself is no module's doing.
|
|
2055
|
+
const sameLook = (a, b) => a.look === b.look &&
|
|
2056
|
+
(a.readable !== "no" || b.readable === "no") &&
|
|
2057
|
+
a.clips.length === b.clips.length &&
|
|
2058
|
+
a.clips.every((box, i) => box.width >= b.clips[i].width - 2 * SIDE_MARGIN_SLACK &&
|
|
2059
|
+
box.height >=
|
|
2060
|
+
b.clips[i].height - Math.max(0, box.bar - b.clips[i].bar) - 1) &&
|
|
2061
|
+
Math.abs(a.place[0] - b.place[0]) <= 2 * SIDE_MARGIN_SLACK &&
|
|
2062
|
+
a.place[1] - b.place[1] >= -SIDE_MARGIN_SLACK &&
|
|
2063
|
+
a.offsets.length === b.offsets.length &&
|
|
2064
|
+
a.offsets.every((m, i) => Math.abs(m - b.offsets[i]) <= SIDE_MARGIN_SLACK);
|
|
2065
|
+
// The computed properties of the banner frame a module's stylesheet must not
|
|
2066
|
+
// change (see looks in renderVerifiedContext): what decides whether the
|
|
2067
|
+
// banner and its details line are shown, where, and whether their words can
|
|
2068
|
+
// be read. Layout sizes are left out, since a module's content can change
|
|
2069
|
+
// them without touching the frame.
|
|
2070
|
+
const FRAME_LOOK = [
|
|
2071
|
+
"display",
|
|
2072
|
+
"visibility",
|
|
2073
|
+
"opacity",
|
|
2074
|
+
"color",
|
|
2075
|
+
"background-color",
|
|
2076
|
+
"background-image",
|
|
2077
|
+
"font-size",
|
|
2078
|
+
"text-indent",
|
|
2079
|
+
"position",
|
|
2080
|
+
"top",
|
|
2081
|
+
"left",
|
|
2082
|
+
"right",
|
|
2083
|
+
"bottom",
|
|
2084
|
+
"transform",
|
|
2085
|
+
"scale",
|
|
2086
|
+
"translate",
|
|
2087
|
+
"rotate",
|
|
2088
|
+
"zoom",
|
|
2089
|
+
"margin-top",
|
|
2090
|
+
"margin-bottom",
|
|
2091
|
+
...BOX_EDGES,
|
|
2092
|
+
"font-family",
|
|
2093
|
+
"-webkit-text-fill-color",
|
|
2094
|
+
"clip",
|
|
2095
|
+
"clip-path",
|
|
2096
|
+
"mask-image",
|
|
2097
|
+
"-webkit-mask-image",
|
|
2098
|
+
"filter",
|
|
2099
|
+
"mix-blend-mode",
|
|
2100
|
+
"overflow",
|
|
2101
|
+
"max-height",
|
|
2102
|
+
"max-width",
|
|
2103
|
+
"z-index",
|
|
2104
|
+
"content-visibility",
|
|
2105
|
+
"contain",
|
|
2106
|
+
];
|
|
2107
|
+
const ANCESTOR_LOOK = FRAME_LOOK.filter((name) => name !== "transform" &&
|
|
2108
|
+
!ANCESTOR_OFFSETS.includes(name) &&
|
|
2109
|
+
!ANCESTOR_UNCOMPARED.includes(name));
|
|
2110
|
+
// A computed transform split into its linear part, compared exactly, and its
|
|
2111
|
+
// translation in px, compared within the slack. Anything else (`none`) is
|
|
2112
|
+
// compared whole.
|
|
2113
|
+
function splitTransform(value) {
|
|
2114
|
+
const m = /^matrix(3d)?\((.*)\)$/.exec(value);
|
|
2115
|
+
if (m === null)
|
|
2116
|
+
return [value, []];
|
|
2117
|
+
const n = m[2].split(",").map(Number);
|
|
2118
|
+
const moves = m[1] === undefined ? [4, 5] : [12, 13, 14];
|
|
2119
|
+
return [
|
|
2120
|
+
`matrix${m[1] ?? ""}(${n.filter((_, i) => !moves.includes(i)).join(",")})`,
|
|
2121
|
+
moves.map((i) => n[i]),
|
|
2122
|
+
];
|
|
2123
|
+
}
|
|
2124
|
+
// Whether a reader sees every word of each part where the page is now: for
|
|
2125
|
+
// each character other than white space whose box is in the viewport, the
|
|
2126
|
+
// elements a hit test finds at the box's centre (`elementsFromPoint`) reach
|
|
2127
|
+
// the character's own element before anything of the root's or in <head>
|
|
2128
|
+
// that paints over it (see seeThrough): a module's content, or a module's
|
|
2129
|
+
// rule laying out <head> or <style>. Nothing is scrolled to look. A
|
|
2130
|
+
// character clipped where the page is now (a hit on an element around it
|
|
2131
|
+
// first) is passed over: a reader may have scrolled it out of a scrolling
|
|
2132
|
+
// host, and a module that shrinks a clipping box is caught by its size (see
|
|
2133
|
+
// clips in looks). The host's other elements are passed over too, so a
|
|
2134
|
+
// host's own fixed header a reader scrolls under is no module's doing. A set
|
|
2135
|
+
// of parts none of whose words is seen is "unseen", as is any off a
|
|
2136
|
+
// laid-out document (jsdom). For the test's duration a
|
|
2137
|
+
// constructed stylesheet in a layer, which adds no element a module's rule
|
|
2138
|
+
// could show, makes everything hit-testable, so an overlay with
|
|
2139
|
+
// `pointer-events: none` is still found, even with an unlayered `!important`;
|
|
2140
|
+
// one set important inline, or in the module's own layer, is not. Paint the
|
|
2141
|
+
// browser does not hit-test (an outline, a shadow, a reflection) is not
|
|
2142
|
+
// found either; see #125 for why this check targets a module's mistakes and
|
|
2143
|
+
// not a module that sets out to hide the banner.
|
|
2144
|
+
function readable(parts, root) {
|
|
2145
|
+
const doc = root.ownerDocument;
|
|
2146
|
+
const view = doc.defaultView;
|
|
2147
|
+
if (view === null || view.navigator.userAgent.includes("jsdom"))
|
|
2148
|
+
return "unseen";
|
|
2149
|
+
const tree = root.getRootNode();
|
|
2150
|
+
const scope = tree === doc ? [doc] : [doc, tree];
|
|
2151
|
+
const sheet = new view.CSSStyleSheet();
|
|
2152
|
+
sheet.replaceSync("@layer cv-hit-test{*,*::before,*::after{pointer-events:auto!important}}");
|
|
2153
|
+
for (const at of scope)
|
|
2154
|
+
at.adoptedStyleSheets = [...at.adoptedStyleSheets, sheet];
|
|
2155
|
+
// The viewport less its scrollbars: a point under a scrollbar hits nothing.
|
|
2156
|
+
const port = doc.scrollingElement ?? doc.documentElement;
|
|
2157
|
+
const [width, height] = [port.clientWidth, port.clientHeight];
|
|
2158
|
+
const range = doc.createRange();
|
|
2159
|
+
let seen = 0;
|
|
2160
|
+
try {
|
|
2161
|
+
for (const part of parts) {
|
|
2162
|
+
const text = doc.createTreeWalker(part, view.NodeFilter.SHOW_TEXT);
|
|
2163
|
+
for (let node = text.nextNode(); node !== null; node = text.nextNode()) {
|
|
2164
|
+
const own = node.parentElement;
|
|
2165
|
+
let i = 0;
|
|
2166
|
+
for (const char of node.textContent ?? "") {
|
|
2167
|
+
range.setStart(node, i);
|
|
2168
|
+
i += char.length;
|
|
2169
|
+
range.setEnd(node, i);
|
|
2170
|
+
if (/\s/.test(char))
|
|
2171
|
+
continue;
|
|
2172
|
+
for (const box of range.getClientRects()) {
|
|
2173
|
+
const x = box.left + box.width / 2;
|
|
2174
|
+
const y = box.top + box.height / 2;
|
|
2175
|
+
if (box.width <= 0 || box.height <= 0)
|
|
2176
|
+
continue;
|
|
2177
|
+
if (x < 0 || y < 0 || x >= width || y >= height)
|
|
2178
|
+
continue;
|
|
2179
|
+
let shown = false;
|
|
2180
|
+
for (const hit of tree.elementsFromPoint(x, y)) {
|
|
2181
|
+
if (own.contains(hit)) {
|
|
2182
|
+
shown = true;
|
|
2183
|
+
break;
|
|
2184
|
+
}
|
|
2185
|
+
// Clipped where it is now, by the host or inside the banner:
|
|
2186
|
+
// see clips in looks.
|
|
2187
|
+
if (hit.contains(own))
|
|
2188
|
+
break;
|
|
2189
|
+
if ((root.contains(hit) || doc.head?.contains(hit) === true) &&
|
|
2190
|
+
!seeThrough(hit, view))
|
|
2191
|
+
return "no";
|
|
2192
|
+
}
|
|
2193
|
+
if (shown)
|
|
2194
|
+
seen++;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
finally {
|
|
2201
|
+
for (const at of scope)
|
|
2202
|
+
at.adoptedStyleSheets = at.adoptedStyleSheets.filter((other) => other !== sheet);
|
|
2203
|
+
}
|
|
2204
|
+
return seen > 0 ? "yes" : "unseen";
|
|
2205
|
+
}
|
|
2206
|
+
// Whether a hit-tested element paints nothing of its own over what is under
|
|
2207
|
+
// it: it is transparent (opacity 0, on it or an ancestor), or it has no
|
|
2208
|
+
// background, border, shadow, backdrop filter, text of its own or generated
|
|
2209
|
+
// content and is not replaced content, like a module's empty full-page
|
|
2210
|
+
// container for toasts. A child that does paint is hit-tested on its own.
|
|
2211
|
+
function seeThrough(element, view) {
|
|
2212
|
+
for (let at = element; at !== null; at = at.parentElement)
|
|
2213
|
+
if (view.getComputedStyle(at).opacity === "0")
|
|
2214
|
+
return true;
|
|
2215
|
+
const style = view.getComputedStyle(element);
|
|
2216
|
+
const clear = (color) => color === "transparent" || /^rgba\(.*,\s*0\)$/.test(color);
|
|
2217
|
+
return (clear(style.backgroundColor) &&
|
|
2218
|
+
style.backgroundImage === "none" &&
|
|
2219
|
+
style.boxShadow === "none" &&
|
|
2220
|
+
style.backdropFilter === "none" &&
|
|
2221
|
+
["top", "right", "bottom", "left"].every((side) => style.getPropertyValue(`border-${side}-width`) === "0px") &&
|
|
2222
|
+
!REPLACED.has(element.localName) &&
|
|
2223
|
+
![...element.childNodes].some((child) => child.nodeType === 3 && (child.textContent ?? "").trim() !== "") &&
|
|
2224
|
+
["::before", "::after"].every((pseudo) => ["none", "normal"].includes(view.getComputedStyle(element, pseudo).content)));
|
|
2225
|
+
}
|
|
2226
|
+
const REPLACED = new Set([
|
|
2227
|
+
"img",
|
|
2228
|
+
"video",
|
|
2229
|
+
"canvas",
|
|
2230
|
+
"iframe",
|
|
2231
|
+
"object",
|
|
2232
|
+
"embed",
|
|
2233
|
+
"svg",
|
|
2234
|
+
"input",
|
|
2235
|
+
"textarea",
|
|
2236
|
+
"select",
|
|
2237
|
+
"button",
|
|
2238
|
+
"meter",
|
|
2239
|
+
"progress",
|
|
2240
|
+
]);
|
|
2241
|
+
// The linear part of the transforms applied to `element`'s content in the
|
|
2242
|
+
// viewport: its own and every ancestor's `transform`, `rotate`, `scale` and
|
|
2243
|
+
// `zoom`. A scroll offset is in its container's own px; this maps it into the
|
|
2244
|
+
// viewport px the bar's box is in. Every one of these properties is compared
|
|
2245
|
+
// exactly on the root's ancestors (see looks), so no module can change it.
|
|
2246
|
+
function linearTransform(element, view) {
|
|
2247
|
+
let matrix = new DOMMatrix();
|
|
2248
|
+
for (let at = element; at !== null; at = at.parentElement) {
|
|
2249
|
+
const style = view.getComputedStyle(at);
|
|
2250
|
+
const zoom = Number.parseFloat(style.zoom) || 1;
|
|
2251
|
+
const rotate = style.rotate === "none" ? "" : rotateFunction(style.rotate);
|
|
2252
|
+
const scale = style.scale === "none" ? "" : `scale3d(${scaleArgs(style.scale)})`;
|
|
2253
|
+
const transform = style.transform === "none" ? "" : style.transform;
|
|
2254
|
+
const local = new DOMMatrix(`${rotate} ${scale} ${transform}`.trim() || "none").scale(zoom, zoom);
|
|
2255
|
+
local.m41 = local.m42 = local.m43 = 0;
|
|
2256
|
+
matrix = local.multiply(matrix);
|
|
2257
|
+
}
|
|
2258
|
+
return matrix;
|
|
2259
|
+
}
|
|
2260
|
+
function rotateFunction(value) {
|
|
2261
|
+
const parts = value.split(/\s+/);
|
|
2262
|
+
if (parts.length === 1)
|
|
2263
|
+
return `rotate(${value})`;
|
|
2264
|
+
const angle = parts.pop();
|
|
2265
|
+
const axis = parts.length === 1
|
|
2266
|
+
? ({ x: "1 0 0", y: "0 1 0", z: "0 0 1" }[parts[0]] ?? parts[0])
|
|
2267
|
+
: parts.join(" ");
|
|
2268
|
+
return `rotate3d(${axis.split(" ").join(",")},${angle})`;
|
|
2269
|
+
}
|
|
2270
|
+
function scaleArgs(value) {
|
|
2271
|
+
const [x, y = x, z = "1"] = value.split(/\s+/);
|
|
2272
|
+
return `${x},${y},${z}`;
|
|
2273
|
+
}
|
|
2274
|
+
// Whether a box is the containing block of a `position: fixed` box inside
|
|
2275
|
+
// it, in place of the viewport.
|
|
2276
|
+
function holdsFixed(style) {
|
|
2277
|
+
return (style.transform !== "none" ||
|
|
2278
|
+
style.translate !== "none" ||
|
|
2279
|
+
style.rotate !== "none" ||
|
|
2280
|
+
style.scale !== "none" ||
|
|
2281
|
+
style.perspective !== "none" ||
|
|
2282
|
+
style.filter !== "none" ||
|
|
2283
|
+
style.backdropFilter !== "none" ||
|
|
2284
|
+
/paint|layout|strict|content/.test(style.contain) ||
|
|
2285
|
+
/transform|perspective|filter/.test(style.willChange) ||
|
|
2286
|
+
style.containerType !== "normal" ||
|
|
2287
|
+
style.contentVisibility === "auto");
|
|
2288
|
+
}
|
|
2289
|
+
// Resolves after the next frame and then the timers already due. A page
|
|
2290
|
+
// that is not shown draws no frames, so a timer stands in for the frame
|
|
2291
|
+
// there.
|
|
2292
|
+
function settled(view) {
|
|
2293
|
+
return new Promise((done) => {
|
|
2294
|
+
let waiting = true;
|
|
2295
|
+
const next = () => {
|
|
2296
|
+
if (!waiting)
|
|
2297
|
+
return;
|
|
2298
|
+
waiting = false;
|
|
2299
|
+
view.setTimeout(done, 0);
|
|
2300
|
+
};
|
|
2301
|
+
view.requestAnimationFrame(next);
|
|
2302
|
+
view.setTimeout(next, SETTLE_MS);
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
// The longest the settle waits for a frame.
|
|
2306
|
+
const SETTLE_MS = 100;
|
|
2307
|
+
// By root, the renders still verifying on it: their `checking` bars, and
|
|
2308
|
+
// what the root held before the first of them began.
|
|
2309
|
+
const checkingRenders = new WeakMap();
|
|
2310
|
+
async function renderVerifiedContext(context, root, options) {
|
|
2311
|
+
const { bundle, verification } = context;
|
|
2312
|
+
const verified = bundleVerified(verification);
|
|
2313
|
+
const registry = options.registry ?? defaultRegistry;
|
|
2314
|
+
let refusal;
|
|
2315
|
+
let selected;
|
|
2316
|
+
let resolution;
|
|
2317
|
+
try {
|
|
2318
|
+
resolution = await registry.resolve(context, options.audience ?? DEFAULT_AUDIENCE, options.format ?? DEFAULT_FORMAT);
|
|
2319
|
+
}
|
|
2320
|
+
catch (err) {
|
|
2321
|
+
if (!(err instanceof PresentationAmbiguityError))
|
|
2322
|
+
throw err;
|
|
2323
|
+
resolution = { kind: "no-presentation", refused: [] };
|
|
2324
|
+
refusal = "presentation-unresolved";
|
|
2325
|
+
}
|
|
2326
|
+
// A module this runtime refused (spec section 3.2) is never silent: the
|
|
2327
|
+
// page root names every one that matched, page and section alike, and the
|
|
2328
|
+
// verification page shows the contract's words in the extension rows
|
|
2329
|
+
// (presentationRefusalRow) or, for a module requiring no extension, in a
|
|
2330
|
+
// line after them (presentationRefusalLine).
|
|
2331
|
+
const refused = resolution.kind === "refusal" ? [] : [...resolution.refused];
|
|
2332
|
+
if (resolution.kind === "refusal" && verified)
|
|
2333
|
+
throw new Error("resolver refused a bundle that verified");
|
|
2334
|
+
if (resolution.kind === "module" && !verified)
|
|
2335
|
+
throw new Error("resolver selected a module for an unverified bundle");
|
|
2336
|
+
// A module's model is built before the page is written, so a model that
|
|
2337
|
+
// cannot be built rejects with nothing drawn (as it always has).
|
|
2338
|
+
if (resolution.kind === "module")
|
|
2339
|
+
selected = {
|
|
2340
|
+
module: resolution.module,
|
|
2341
|
+
model: await resolution.module.buildModel(context),
|
|
2342
|
+
};
|
|
2343
|
+
// The section registry is resolved the same way, after the page and only
|
|
2344
|
+
// for a verified bundle whose page resolved: a section never stands in for
|
|
2345
|
+
// a refusal (contract I1), and its ambiguity is the page's refusal too.
|
|
2346
|
+
let section;
|
|
2347
|
+
if (verified && refusal === undefined) {
|
|
2348
|
+
let sectionResolution;
|
|
2349
|
+
try {
|
|
2350
|
+
sectionResolution = await (options.sections ?? defaultSections).resolve(context, options.audience ?? DEFAULT_AUDIENCE, options.format ?? DEFAULT_FORMAT);
|
|
2351
|
+
}
|
|
2352
|
+
catch (err) {
|
|
2353
|
+
if (!(err instanceof PresentationAmbiguityError))
|
|
2354
|
+
throw err;
|
|
2355
|
+
sectionResolution = { kind: "no-presentation", refused: [] };
|
|
2356
|
+
selected = undefined;
|
|
2357
|
+
refusal = "presentation-unresolved";
|
|
2358
|
+
}
|
|
2359
|
+
// A refused section is named like a refused page module, never skipped.
|
|
2360
|
+
if (sectionResolution.kind !== "refusal")
|
|
2361
|
+
refused.push(...sectionResolution.refused);
|
|
2362
|
+
if (sectionResolution.kind === "module")
|
|
2363
|
+
section = {
|
|
2364
|
+
module: sectionResolution.module,
|
|
2365
|
+
model: await sectionResolution.module.buildModel(context),
|
|
2366
|
+
};
|
|
2367
|
+
}
|
|
2368
|
+
const stamps = await classifyCountersignatures(context.countersignatures.map((entry) => entry.value), verification.bundleDigest, declaredProducerKeys(bundle), context.countersigners);
|
|
2369
|
+
const bannerModel = verificationBanner(context, stamps);
|
|
2370
|
+
const records = object(bundle).records;
|
|
2371
|
+
const coverage = {
|
|
2372
|
+
uncheckpointed: bannerModel.uncheckpointed,
|
|
2373
|
+
total: Array.isArray(records) ? records.length : 0,
|
|
2374
|
+
};
|
|
2375
|
+
// The host's three regions, in order after the banner and the header
|
|
2376
|
+
// (presentation contract section 9.1). L2 opens with the core's
|
|
2377
|
+
// verification section, drawn last but placed first; a module's L2 detail
|
|
2378
|
+
// follows it.
|
|
2379
|
+
const depth = options.depth ?? "L0";
|
|
2380
|
+
const region = (name) => {
|
|
2381
|
+
const node = document.createElement("div");
|
|
2382
|
+
node.dataset.region = name;
|
|
2383
|
+
return node;
|
|
2384
|
+
};
|
|
2385
|
+
let regions = {
|
|
2386
|
+
L0: root,
|
|
2387
|
+
L1: root,
|
|
2388
|
+
L2: root,
|
|
2389
|
+
core: root,
|
|
2390
|
+
};
|
|
2391
|
+
let bar;
|
|
2392
|
+
const drawFrame = () => {
|
|
2393
|
+
root.replaceChildren();
|
|
2394
|
+
root.classList.remove("cv-shell-chrome");
|
|
2395
|
+
renderPresentationHeader(root, bundle);
|
|
2396
|
+
bar = renderVerificationBanner(root, bannerModel, coverage);
|
|
2397
|
+
const L2 = region("L2");
|
|
2398
|
+
const core = region("L2-core");
|
|
2399
|
+
const L2module = region("L2-module");
|
|
2400
|
+
L2.append(core, L2module);
|
|
2401
|
+
// On a failed bundle L0 and L1 are not created (presentation contract
|
|
2402
|
+
// section 9.1, I1): no module renders, and a notice goes before L2.
|
|
2403
|
+
if (verified) {
|
|
2404
|
+
regions = { L0: region("L0"), L1: region("L1"), L2: L2module, core };
|
|
2405
|
+
root.append(regions.L0, regions.L1, L2);
|
|
2406
|
+
}
|
|
2407
|
+
else {
|
|
2408
|
+
regions = { L0: root, L1: root, L2: L2module, core };
|
|
2409
|
+
root.append(L2);
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
/** A page-level notice: first in L1, or before L2 on a failed bundle. */
|
|
2413
|
+
const notice = (note) => {
|
|
2414
|
+
if (verified)
|
|
2415
|
+
regions.L1.append(note);
|
|
2416
|
+
else
|
|
2417
|
+
root.insertBefore(note, regions.core.parentElement);
|
|
2418
|
+
};
|
|
2419
|
+
drawFrame();
|
|
2420
|
+
// The banner and its details line are the core's (contract sections 3 and
|
|
2421
|
+
// 6.2). A module that, while it renders, changes their words, structure or
|
|
2422
|
+
// attributes, hides or moves them, puts anything before them but the
|
|
2423
|
+
// core's own header, or draws a second banner, is discarded for the
|
|
2424
|
+
// refusal like one that throws. The bar's summary line is empty until the
|
|
2425
|
+
// verification section fills it, after every module has rendered. These
|
|
2426
|
+
// checks catch a module's mistakes; they do not hold against module code
|
|
2427
|
+
// written to hide the banner, which the builder's pin governs (#125).
|
|
2428
|
+
const snapshot = (parts) => JSON.stringify(parts.map((part) => part.outerHTML));
|
|
2429
|
+
// How the frame looks: the computed properties that decide whether its
|
|
2430
|
+
// words can be read, for every element of each part, the root and the
|
|
2431
|
+
// root's ancestors, with the root's chrome class as given (the one
|
|
2432
|
+
// restyling a module may ask for, setChromeClass). A stylesheet a module adds that changes any of
|
|
2433
|
+
// them, hiding the banner included, is caught by comparing with this as it
|
|
2434
|
+
// was before the module rendered, so a host that was already hidden (an
|
|
2435
|
+
// inactive tab) is no module's doing. Empty off a document, where no
|
|
2436
|
+
// styles apply; the static builder renders on a root in its document for
|
|
2437
|
+
// this reason.
|
|
2438
|
+
const looks = (parts, chromed) => {
|
|
2439
|
+
const view = root.ownerDocument.defaultView;
|
|
2440
|
+
if (!root.isConnected || view === null)
|
|
2441
|
+
return {
|
|
2442
|
+
look: "",
|
|
2443
|
+
offsets: [],
|
|
2444
|
+
place: [0, 0],
|
|
2445
|
+
readable: "unseen",
|
|
2446
|
+
clips: [],
|
|
2447
|
+
};
|
|
2448
|
+
const had = root.classList.contains("cv-shell-chrome");
|
|
2449
|
+
root.classList.toggle("cv-shell-chrome", chromed);
|
|
2450
|
+
// The root's ancestors too, up to <html>: a transform, opacity, filter,
|
|
2451
|
+
// clip or offset on any of them scales, hides or moves the banner while
|
|
2452
|
+
// every value on the banner itself stays the same.
|
|
2453
|
+
const ancestors = [];
|
|
2454
|
+
for (let at = root.parentElement; at !== null; at = at.parentElement)
|
|
2455
|
+
ancestors.push(at);
|
|
2456
|
+
const elements = [
|
|
2457
|
+
...ancestors,
|
|
2458
|
+
root,
|
|
2459
|
+
...parts.flatMap((part) => [part, ...part.querySelectorAll("*")]),
|
|
2460
|
+
];
|
|
2461
|
+
// A browser also computes each element's ::before and ::after, whose
|
|
2462
|
+
// content can add words to the banner; jsdom computes no pseudo-element.
|
|
2463
|
+
const jsdom = view.navigator.userAgent.includes("jsdom");
|
|
2464
|
+
const pseudos = jsdom ? [null] : [null, "::before", "::after"];
|
|
2465
|
+
const offsets = [];
|
|
2466
|
+
const seen = JSON.stringify(elements.flatMap((element, at) => pseudos.map((pseudo) => {
|
|
2467
|
+
const style = view.getComputedStyle(element, pseudo);
|
|
2468
|
+
const ancestor = at < ancestors.length;
|
|
2469
|
+
const [transform, moves] = ancestor
|
|
2470
|
+
? splitTransform(style.getPropertyValue("transform"))
|
|
2471
|
+
: [undefined, []];
|
|
2472
|
+
offsets.push(...moves);
|
|
2473
|
+
return [
|
|
2474
|
+
...(ancestor ? ANCESTOR_LOOK : FRAME_LOOK).map((name) => style.getPropertyValue(name)),
|
|
2475
|
+
...(transform === undefined ? [] : [transform]),
|
|
2476
|
+
...[...SIDE_MARGINS, ...(ancestor ? ANCESTOR_OFFSETS : [])].flatMap((name) => {
|
|
2477
|
+
const value = style.getPropertyValue(name);
|
|
2478
|
+
const px = Number.parseFloat(value);
|
|
2479
|
+
offsets.push(Number.isNaN(px) ? 0 : px);
|
|
2480
|
+
return Number.isNaN(px) ? [value] : [];
|
|
2481
|
+
}),
|
|
2482
|
+
...(pseudo === null ? [] : [style.getPropertyValue("content")]),
|
|
2483
|
+
];
|
|
2484
|
+
})));
|
|
2485
|
+
// Where the bar sits in the document: its box plus every scroll offset
|
|
2486
|
+
// above it, so a reader's scrolling moves nothing. A scroll offset is in
|
|
2487
|
+
// its container's own px, mapped into viewport px by the transforms on
|
|
2488
|
+
// and above the container (linearTransform), which no module can
|
|
2489
|
+
// change; the viewport's own is in viewport px already.
|
|
2490
|
+
const box = parts[0].getBoundingClientRect();
|
|
2491
|
+
const place = [box.left, box.top];
|
|
2492
|
+
// A box with `position: fixed` stays put while the boxes between it and
|
|
2493
|
+
// its containing block scroll (the viewport, or the nearest ancestor that
|
|
2494
|
+
// makes one for it), so their offsets are left out.
|
|
2495
|
+
let fixed = false;
|
|
2496
|
+
for (let at = parts[0].parentElement; at !== null; at = at.parentElement) {
|
|
2497
|
+
const style = jsdom ? undefined : view.getComputedStyle(at);
|
|
2498
|
+
if (fixed && style !== undefined && holdsFixed(style))
|
|
2499
|
+
fixed = false;
|
|
2500
|
+
if (!fixed && (at.scrollLeft !== 0 || at.scrollTop !== 0)) {
|
|
2501
|
+
const move = at === root.ownerDocument.scrollingElement || jsdom
|
|
2502
|
+
? { x: at.scrollLeft, y: at.scrollTop }
|
|
2503
|
+
: linearTransform(at, view).transformPoint({
|
|
2504
|
+
x: at.scrollLeft,
|
|
2505
|
+
y: at.scrollTop,
|
|
2506
|
+
});
|
|
2507
|
+
place[0] += move.x;
|
|
2508
|
+
place[1] += move.y;
|
|
2509
|
+
}
|
|
2510
|
+
if (style?.position === "fixed")
|
|
2511
|
+
fixed = true;
|
|
2512
|
+
}
|
|
2513
|
+
const words = readable(parts, root);
|
|
2514
|
+
// The visible size of every box that clips the banner, from <html> down
|
|
2515
|
+
// to the banner's own elements: a module that shrinks one (a scrolling
|
|
2516
|
+
// host's height set to 0) clips the banner wherever the reader has
|
|
2517
|
+
// scrolled. Which boxes clip is compared exactly (`overflow` and
|
|
2518
|
+
// `contain` are in the looks). A width may shrink by one assumed classic
|
|
2519
|
+
// scrollbar, as when the page or the box itself grows one, and a height
|
|
2520
|
+
// by as much as the box's own scrollbar across its bottom grew. The size is
|
|
2521
|
+
// mapped into viewport px through the transforms on and above the box,
|
|
2522
|
+
// which no module can change.
|
|
2523
|
+
const clips = jsdom
|
|
2524
|
+
? []
|
|
2525
|
+
: elements.flatMap((element) => {
|
|
2526
|
+
const style = view.getComputedStyle(element);
|
|
2527
|
+
if (style.overflowX === "visible" &&
|
|
2528
|
+
style.overflowY === "visible" &&
|
|
2529
|
+
!/paint|strict|content/.test(style.contain) &&
|
|
2530
|
+
style.contentVisibility !== "auto")
|
|
2531
|
+
return [];
|
|
2532
|
+
// In viewport px, as the slack is: under a page zoom a scrollbar
|
|
2533
|
+
// takes more of a box's own px.
|
|
2534
|
+
const matrix = linearTransform(element, view);
|
|
2535
|
+
const across = matrix.transformPoint({ x: element.clientWidth });
|
|
2536
|
+
const down = matrix.transformPoint({ y: element.clientHeight });
|
|
2537
|
+
// The scrollbar across the box's bottom, in viewport px: the box's
|
|
2538
|
+
// height may shrink by only as much as that grows. A page's own
|
|
2539
|
+
// scrollbar leaves any other height alone. The viewport's is what
|
|
2540
|
+
// its height lacks of the window's.
|
|
2541
|
+
// The viewport's size is in viewport px already, as its scroll
|
|
2542
|
+
// offsets are.
|
|
2543
|
+
const viewport = element === root.ownerDocument.scrollingElement;
|
|
2544
|
+
const width = viewport
|
|
2545
|
+
? element.clientWidth
|
|
2546
|
+
: Math.hypot(across.x, across.y);
|
|
2547
|
+
const height = viewport
|
|
2548
|
+
? element.clientHeight
|
|
2549
|
+
: Math.hypot(down.x, down.y);
|
|
2550
|
+
const own = matrix.transformPoint({
|
|
2551
|
+
y: element instanceof view.HTMLElement && !viewport
|
|
2552
|
+
? Math.max(0, element.offsetHeight -
|
|
2553
|
+
element.clientHeight -
|
|
2554
|
+
Number.parseFloat(style.borderTopWidth) -
|
|
2555
|
+
Number.parseFloat(style.borderBottomWidth))
|
|
2556
|
+
: 0,
|
|
2557
|
+
});
|
|
2558
|
+
const bar = viewport
|
|
2559
|
+
? Math.max(0, view.innerHeight - height)
|
|
2560
|
+
: Math.hypot(own.x, own.y);
|
|
2561
|
+
return [
|
|
2562
|
+
{
|
|
2563
|
+
width,
|
|
2564
|
+
height,
|
|
2565
|
+
bar,
|
|
2566
|
+
},
|
|
2567
|
+
];
|
|
2568
|
+
});
|
|
2569
|
+
root.classList.toggle("cv-shell-chrome", had);
|
|
2570
|
+
return { look: seen, offsets, place, readable: words, clips };
|
|
2571
|
+
};
|
|
2572
|
+
const frameOf = () => {
|
|
2573
|
+
const detail = bar.nextElementSibling;
|
|
2574
|
+
const parts = [
|
|
2575
|
+
bar,
|
|
2576
|
+
...(detail?.hasAttribute("data-banner-detail") ? [detail] : []),
|
|
2577
|
+
];
|
|
2578
|
+
return {
|
|
2579
|
+
parts,
|
|
2580
|
+
header: bar.previousElementSibling,
|
|
2581
|
+
words: snapshot(parts),
|
|
2582
|
+
looks: {
|
|
2583
|
+
plain: looks(parts, false),
|
|
2584
|
+
chrome: looks(parts, true),
|
|
2585
|
+
},
|
|
2586
|
+
};
|
|
2587
|
+
};
|
|
2588
|
+
// Measured only when a module will render: it lays out the page.
|
|
2589
|
+
let frame = selected !== undefined || section !== undefined ? frameOf() : undefined;
|
|
2590
|
+
const assertFrameIntact = () => {
|
|
2591
|
+
const at = frame;
|
|
2592
|
+
const [top, detail] = at.parts;
|
|
2593
|
+
const pill = top.querySelector("[data-verify]");
|
|
2594
|
+
const banners = root.querySelectorAll("[data-verify], [data-banner-detail]");
|
|
2595
|
+
const expected = [pill, ...(detail === undefined ? [] : [detail])];
|
|
2596
|
+
if (pill === null ||
|
|
2597
|
+
banners.length !== expected.length ||
|
|
2598
|
+
expected.some((part, i) => banners[i] !== part) ||
|
|
2599
|
+
// Nodes, not elements: a bare text node before the banner is words
|
|
2600
|
+
// too. The core draws no text node at the root.
|
|
2601
|
+
root.firstChild !== (at.header ?? top) ||
|
|
2602
|
+
top.previousSibling !== at.header ||
|
|
2603
|
+
(at.header !== null && at.header.parentNode !== root) ||
|
|
2604
|
+
(detail !== undefined && detail.previousElementSibling !== top) ||
|
|
2605
|
+
top.parentNode !== root ||
|
|
2606
|
+
top.hidden ||
|
|
2607
|
+
snapshot(at.parts) !== at.words ||
|
|
2608
|
+
!sameLook(looks(at.parts, root.classList.contains("cv-shell-chrome")), root.classList.contains("cv-shell-chrome")
|
|
2609
|
+
? at.looks.chrome
|
|
2610
|
+
: at.looks.plain))
|
|
2611
|
+
throw new Error("a module altered the verification banner");
|
|
2612
|
+
};
|
|
2613
|
+
if (refused.length > 0)
|
|
2614
|
+
root.dataset.presentationRefused = refused.map((r) => r.id).join(" ");
|
|
2615
|
+
else
|
|
2616
|
+
delete root.dataset.presentationRefused;
|
|
2617
|
+
let chrome;
|
|
2618
|
+
if (selected !== undefined) {
|
|
2619
|
+
const host = {
|
|
2620
|
+
L0: regions.L0,
|
|
2621
|
+
L1: regions.L1,
|
|
2622
|
+
L2: regions.L2,
|
|
2623
|
+
depth,
|
|
2624
|
+
...(options.wording === undefined ? {} : { wording: options.wording }),
|
|
2625
|
+
setChromeClass(name) {
|
|
2626
|
+
if (name !== OUTCOME_CHROME && name !== COMPLIANCE_CHROME)
|
|
2627
|
+
throw new Error(`unknown chrome class ${JSON.stringify(name)}`);
|
|
2628
|
+
chrome = name;
|
|
2629
|
+
// The card keeps its own frame; the pill keeps its look.
|
|
2630
|
+
root.classList.add("cv-shell-chrome");
|
|
2631
|
+
},
|
|
2632
|
+
};
|
|
2633
|
+
try {
|
|
2634
|
+
await selected.module.render(selected.model, host, presentationServices(context));
|
|
2635
|
+
assertFrameIntact();
|
|
2636
|
+
}
|
|
2637
|
+
catch {
|
|
2638
|
+
// Everything the module wrote is discarded; no other module is tried.
|
|
2639
|
+
chrome = undefined;
|
|
2640
|
+
drawFrame();
|
|
2641
|
+
frame = frameOf();
|
|
2642
|
+
refusal = "presentation-failed";
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
if (refusal === undefined && resolution.kind === "no-presentation") {
|
|
2646
|
+
const note = element("p", "No presentation is available for this bundle, audience and format. The records and their verification are below.");
|
|
2647
|
+
note.dataset.notice = "no-presentation";
|
|
2648
|
+
notice(note);
|
|
2649
|
+
}
|
|
2650
|
+
// The section renders after the page module, into the same regions. If it
|
|
2651
|
+
// throws, everything any module wrote is discarded for the refusal.
|
|
2652
|
+
if (section !== undefined && refusal === undefined) {
|
|
2653
|
+
try {
|
|
2654
|
+
await section.module.render(section.model, {
|
|
2655
|
+
L0: regions.L0,
|
|
2656
|
+
L1: regions.L1,
|
|
2657
|
+
L2: regions.L2,
|
|
2658
|
+
depth,
|
|
2659
|
+
setChromeClass() {
|
|
2660
|
+
throw new Error("a section has no chrome");
|
|
2661
|
+
},
|
|
2662
|
+
}, presentationServices(context));
|
|
2663
|
+
assertFrameIntact();
|
|
2664
|
+
}
|
|
2665
|
+
catch {
|
|
2666
|
+
chrome = undefined;
|
|
2667
|
+
drawFrame();
|
|
2668
|
+
refusal = "presentation-failed";
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
// A module may still draw once its render has returned, from a timer or
|
|
2672
|
+
// the next frame: a toolbar or a modal it opens when its data is in. The
|
|
2673
|
+
// frame is checked again after the page settles, after the next frame and
|
|
2674
|
+
// then the timers already due. Anything a module draws later is out of
|
|
2675
|
+
// reach (#125). jsdom lays nothing out, so there the checks above are the
|
|
2676
|
+
// last.
|
|
2677
|
+
const view = root.ownerDocument.defaultView;
|
|
2678
|
+
if (refusal === undefined &&
|
|
2679
|
+
(selected !== undefined || section !== undefined) &&
|
|
2680
|
+
root.isConnected &&
|
|
2681
|
+
view !== null &&
|
|
2682
|
+
!view.navigator.userAgent.includes("jsdom")) {
|
|
2683
|
+
await settled(view);
|
|
2684
|
+
try {
|
|
2685
|
+
assertFrameIntact();
|
|
2686
|
+
}
|
|
2687
|
+
catch {
|
|
2688
|
+
chrome = undefined;
|
|
2689
|
+
drawFrame();
|
|
2690
|
+
refusal = "presentation-failed";
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
if (refusal !== undefined) {
|
|
2694
|
+
const note = element("p", PRESENTATION_REFUSALS[refusal]);
|
|
2695
|
+
note.dataset.refusal = refusal;
|
|
2696
|
+
notice(note);
|
|
2697
|
+
}
|
|
2698
|
+
// The interpreters this rendering actually ran (see extension-interpreters.ts):
|
|
2699
|
+
// the presentation header and the countersignature stamp always run; a
|
|
2700
|
+
// module's own interpreters only when that module rendered.
|
|
2701
|
+
const applied = new Set([
|
|
2702
|
+
"presentation-header",
|
|
2703
|
+
"countersignature-stamp",
|
|
2704
|
+
]);
|
|
2705
|
+
if (refusal === undefined)
|
|
2706
|
+
for (const ran of [selected, section])
|
|
2707
|
+
if (ran !== undefined)
|
|
2708
|
+
for (const id of moduleInterpreters(ran.module.manifest.id, context.bundle))
|
|
2709
|
+
applied.add(id);
|
|
2710
|
+
const checkedLine = await renderVerificationPage(regions.core, context, chrome === OUTCOME_CHROME, applied, refused, refusal === undefined && citesCheckedSigners(selected), options.verifierHint, depth, stamps);
|
|
2711
|
+
// The banner says the same counts as the section it links to.
|
|
2712
|
+
const summary = root.querySelector("[data-verify-summary]");
|
|
2713
|
+
if (summary !== null)
|
|
2714
|
+
summary.textContent = checkedLine;
|
|
2715
|
+
// A page opened at a record's address shows that record.
|
|
2716
|
+
revealRecordsByHash(root.ownerDocument);
|
|
2717
|
+
}
|
|
2718
|
+
//# sourceMappingURL=evidence-graph-view.js.map
|