agent-customs 0.0.0-stage → 1.0.1
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.md +341 -0
- package/README.md +592 -2
- package/bin/agent-customs.mjs +194 -0
- package/package.json +77 -4
- package/site/.well-known/agent-customs-key.json +13 -0
- package/site/certificate.js +944 -0
- package/site/customs/analyze.js +1224 -0
- package/site/customs/auto.js +83 -0
- package/site/customs/canary.js +270 -0
- package/site/customs/canonical.js +123 -0
- package/site/customs/capabilities.js +387 -0
- package/site/customs/diff.js +236 -0
- package/site/customs/english-words.js +153 -0
- package/site/customs/guard-notice.js +226 -0
- package/site/customs/guard-ui.js +105 -0
- package/site/customs/guard.js +259 -0
- package/site/customs/inspect.js +446 -0
- package/site/customs/judge.js +208 -0
- package/site/customs/languages.js +826 -0
- package/site/customs/locks.js +967 -0
- package/site/customs/pins.js +119 -0
- package/site/customs/protocols.js +621 -0
- package/site/customs/receipts.js +154 -0
- package/site/customs/rules.js +1470 -0
- package/site/customs/unicode.js +361 -0
- package/site/runtime/LICENSE.txt +176 -0
- package/site/runtime/generated/graph.gen.mjs +83 -0
- package/site/runtime/generated/validation.gen.mjs +70 -0
- package/site/runtime/hocon.js +262 -0
- package/site/runtime/kernel.js +237 -0
- package/site/runtime/model.js +44 -0
- package/tests/fixtures/official/NOTICE +3 -0
- package/tests/fixtures/official/guesthouse_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/guesthouse_agentified/links.json +6 -0
- package/tests/fixtures/official/guesthouse_agentified/tidewhistle_guesthouse.network.json +56 -0
- package/tests/fixtures/official/harbor_tours_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/harbor_tours_agentified/links.json +6 -0
- package/tests/fixtures/official/harbor_tours_agentified/marrow_point_harbor_tours.network.json +56 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/agent-manifest.json +78 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/links.json +6 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/pizza_restaurant_website_assistant.network.json +156 -0
- package/tools/bench.mjs +731 -0
- package/tools/external-heldout.mjs +337 -0
- package/tools/fs-fetch.mjs +19 -0
- package/tools/heldout-corpus.mjs +135 -0
- package/tools/inspect-local.mjs +88 -0
- package/tools/round2-corpus.mjs +395 -0
- package/tools/round3-corpus.mjs +192 -0
|
@@ -0,0 +1,944 @@
|
|
|
1
|
+
// certificate.js: builds and parses standalone SVG Border Clearance Certificates & Advisories
|
|
2
|
+
// styled after archival cotton-parchment diplomatic visas, with a bound passport spine,
|
|
3
|
+
// guilloche filigree, circular cancellation stamp, deterministic SHA-256 visual glyph,
|
|
4
|
+
// and an ICAO-style machine-readable zone. Zero DOM dependencies and zero network calls.
|
|
5
|
+
|
|
6
|
+
import { verifyReceipt } from "./customs/receipts.js";
|
|
7
|
+
|
|
8
|
+
const DEFAULT_THEME = {
|
|
9
|
+
spine: "#0c1d18",
|
|
10
|
+
paperTop: "#f7f1e3",
|
|
11
|
+
paperMid: "#f1e7d2",
|
|
12
|
+
paperEdge: "#e6d8bc",
|
|
13
|
+
wellPaper: "#eadec5",
|
|
14
|
+
rule: "#c8b99b",
|
|
15
|
+
ink: "#0f2019",
|
|
16
|
+
inkMuted: "#4a5b53",
|
|
17
|
+
inkDim: "#6f7d75",
|
|
18
|
+
gold: "#b88a28",
|
|
19
|
+
goldLight: "#e3c067",
|
|
20
|
+
goldDark: "#7d5912",
|
|
21
|
+
okInk: "#0f6e43",
|
|
22
|
+
okTint: "#dff2e7",
|
|
23
|
+
warnInk: "#a1550a",
|
|
24
|
+
warnTint: "#f9ead7",
|
|
25
|
+
badInk: "#a82428",
|
|
26
|
+
badTint: "#fae1e1",
|
|
27
|
+
cautionInk: "#8c6b08",
|
|
28
|
+
cautionTint: "#f7f0d4",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const VERDICT_META = {
|
|
32
|
+
CLEARED: {
|
|
33
|
+
documentTitle: "Border Clearance Certificate",
|
|
34
|
+
eyebrow: "ARTICLE VII · ENTRY AUTHORIZATION DIPLOMA",
|
|
35
|
+
stampLabel: "CLEARED",
|
|
36
|
+
mrzCode: "CLEARED",
|
|
37
|
+
toneKey: "ok",
|
|
38
|
+
clearanceAllowed: true,
|
|
39
|
+
advisoryNote: "Version-locked with SHA-256 pinning. Re-inspect live to confirm this target has not changed since issuance.",
|
|
40
|
+
},
|
|
41
|
+
HOLD: {
|
|
42
|
+
documentTitle: "Border Inspection Advisory",
|
|
43
|
+
eyebrow: "HOLD ORDER · HUMAN REVIEW REQUIRED",
|
|
44
|
+
stampLabel: "HELD",
|
|
45
|
+
mrzCode: "HELD<<",
|
|
46
|
+
toneKey: "warn",
|
|
47
|
+
clearanceAllowed: false,
|
|
48
|
+
advisoryNote: "Hold notice: human review is required before granting this network access to your key or browser session.",
|
|
49
|
+
},
|
|
50
|
+
DENIED: {
|
|
51
|
+
documentTitle: "Entry Refusal Notice",
|
|
52
|
+
eyebrow: "CUSTOMS REFUSAL · RULE VIOLATION DETECTED",
|
|
53
|
+
stampLabel: "DENIED",
|
|
54
|
+
mrzCode: "DENIED",
|
|
55
|
+
toneKey: "bad",
|
|
56
|
+
clearanceAllowed: false,
|
|
57
|
+
advisoryNote: "Access refused by deterministic border rules. Do not approve or connect this network to any live workflow.",
|
|
58
|
+
},
|
|
59
|
+
INVALID: {
|
|
60
|
+
documentTitle: "Entry Refusal Notice",
|
|
61
|
+
eyebrow: "INVALID PAPERS · SCHEMA NON-COMPLIANCE",
|
|
62
|
+
stampLabel: "INVALID",
|
|
63
|
+
mrzCode: "INVALID",
|
|
64
|
+
toneKey: "bad",
|
|
65
|
+
clearanceAllowed: false,
|
|
66
|
+
advisoryNote: "Manifest or network papers failed validation. Entry remains refused until compliant papers are published.",
|
|
67
|
+
},
|
|
68
|
+
UNREADABLE: {
|
|
69
|
+
documentTitle: "Inspection Unreadable Notice",
|
|
70
|
+
eyebrow: "PORT BLOCKED · FAIL-CLOSED SAFE DEFAULT",
|
|
71
|
+
stampLabel: "BLOCKED",
|
|
72
|
+
mrzCode: "UNREAD",
|
|
73
|
+
toneKey: "caution",
|
|
74
|
+
clearanceAllowed: false,
|
|
75
|
+
advisoryNote: "Required files could not be fetched or parsed within safety limits. Fail-closed rules prevent execution.",
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Escape XML special characters and strip disallowed control characters. */
|
|
80
|
+
export function escapeXml(value) {
|
|
81
|
+
return String(value ?? "")
|
|
82
|
+
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "")
|
|
83
|
+
.replace(/&/g, "&")
|
|
84
|
+
.replace(/</g, "<")
|
|
85
|
+
.replace(/>/g, ">")
|
|
86
|
+
.replace(/"/g, """)
|
|
87
|
+
.replace(/'/g, "'");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function normalizeHex(hex, fallback) {
|
|
91
|
+
const m = String(hex ?? "").trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
92
|
+
if (!m) return fallback;
|
|
93
|
+
const h = m[1];
|
|
94
|
+
return h.length === 3 ? `#${h[0]}${h[0]}${h[1]}${h[1]}${h[2]}${h[2]}` : `#${h.toLowerCase()}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function mixHex(hexA, hexB, weightB) {
|
|
98
|
+
const a = normalizeHex(hexA, "#0c1d18");
|
|
99
|
+
const b = normalizeHex(hexB, "#000000");
|
|
100
|
+
const w = Math.max(0, Math.min(1, weightB));
|
|
101
|
+
const ch = (s, i) => parseInt(s.slice(i, i + 2), 16);
|
|
102
|
+
const blend = (i) => Math.round(ch(a, i) * (1 - w) + ch(b, i) * w).toString(16).padStart(2, "0");
|
|
103
|
+
return `#${blend(1)}${blend(3)}${blend(5)}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function clipText(value, maxChars) {
|
|
107
|
+
const s = String(value ?? "").replace(/\s+/g, " ").trim();
|
|
108
|
+
if (s.length <= maxChars) return s;
|
|
109
|
+
const head = Math.max(8, Math.floor((maxChars - 1) * 0.65));
|
|
110
|
+
const tail = Math.max(4, maxChars - 1 - head);
|
|
111
|
+
return `${s.slice(0, head)}…${s.slice(-tail)}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function safeHttpUrl(candidate, fallback) {
|
|
115
|
+
try {
|
|
116
|
+
const parsed = new URL(String(candidate ?? "").trim());
|
|
117
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") return parsed.href;
|
|
118
|
+
} catch { /* fallback below */ }
|
|
119
|
+
return fallback;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function splitExactLines(value, maxPerLine) {
|
|
123
|
+
const s = String(value ?? "").trim();
|
|
124
|
+
if (s.length <= maxPerLine) return [s];
|
|
125
|
+
const lines = [];
|
|
126
|
+
for (let i = 0; i < s.length; i += maxPerLine) lines.push(s.slice(i, i + maxPerLine));
|
|
127
|
+
return lines;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function wrapLines(value, maxChars, maxLines) {
|
|
131
|
+
const words = String(value ?? "").replace(/\s+/g, " ").trim().split(" ").filter(Boolean);
|
|
132
|
+
if (!words.length) return [""];
|
|
133
|
+
const lines = [];
|
|
134
|
+
let cur = "";
|
|
135
|
+
let clipped = false;
|
|
136
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
137
|
+
const chunk = words[i].length > maxChars ? `${words[i].slice(0, maxChars - 1)}…` : words[i];
|
|
138
|
+
if (!cur) cur = chunk;
|
|
139
|
+
else if (cur.length + 1 + chunk.length <= maxChars) cur = `${cur} ${chunk}`;
|
|
140
|
+
else {
|
|
141
|
+
lines.push(cur);
|
|
142
|
+
if (lines.length === maxLines) { clipped = true; cur = ""; break; }
|
|
143
|
+
cur = chunk;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (cur && lines.length < maxLines) lines.push(cur);
|
|
147
|
+
if (clipped && lines.length === maxLines) {
|
|
148
|
+
const last = lines[maxLines - 1];
|
|
149
|
+
lines[maxLines - 1] = last.length >= maxChars ? `${last.slice(0, maxChars - 1)}…` : `${last}…`;
|
|
150
|
+
}
|
|
151
|
+
return lines;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function shortDate(iso) {
|
|
155
|
+
const ts = Date.parse(iso || "");
|
|
156
|
+
if (!Number.isFinite(ts)) return String(iso || "").slice(0, 10).toUpperCase();
|
|
157
|
+
try {
|
|
158
|
+
return new Date(ts).toLocaleDateString("en-GB", { day: "2-digit", month: "short", year: "numeric", timeZone: "UTC" }).toUpperCase();
|
|
159
|
+
} catch {
|
|
160
|
+
return new Date(ts).toISOString().slice(0, 10);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function compactIsoDate(iso) {
|
|
165
|
+
const ts = Date.parse(iso || "");
|
|
166
|
+
if (!Number.isFinite(ts)) return "00000000";
|
|
167
|
+
return new Date(ts).toISOString().slice(0, 10).replace(/-/g, "");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function resolveTheme(palette) {
|
|
171
|
+
const spine = normalizeHex(palette?.bgMid, DEFAULT_THEME.spine);
|
|
172
|
+
return {
|
|
173
|
+
...DEFAULT_THEME,
|
|
174
|
+
spine,
|
|
175
|
+
spineDeep: mixHex(spine, "#000000", 0.35),
|
|
176
|
+
spineEdge: mixHex(spine, "#ffffff", 0.12),
|
|
177
|
+
spineAccent: normalizeHex(palette?.cleared, "#c8f03c"),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function tonePair(t, toneKey) {
|
|
182
|
+
const map = {
|
|
183
|
+
ok: { ink: t.okInk, tint: t.okTint },
|
|
184
|
+
warn: { ink: t.warnInk, tint: t.warnTint },
|
|
185
|
+
bad: { ink: t.badInk, tint: t.badTint },
|
|
186
|
+
caution: { ink: t.cautionInk, tint: t.cautionTint },
|
|
187
|
+
};
|
|
188
|
+
return map[toneKey] || map.caution;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function buildChecksSummary(report, t) {
|
|
192
|
+
const findings = report.findings || [];
|
|
193
|
+
const byCat = (cat) => findings.filter((f) => f.category === cat);
|
|
194
|
+
const c = report.conformance || { passed: 0, total: 0, failed: 0, warned: 0 };
|
|
195
|
+
const contraband = byCat("contraband").filter((f) => f.severity !== "info");
|
|
196
|
+
const external = (report.itinerary || []).filter((s) => !s.sameSite);
|
|
197
|
+
const privacy = report.privacy || [];
|
|
198
|
+
const hasSecret = byCat("privacy").some((f) => f.rule === "S-SECRET");
|
|
199
|
+
const idFindings = byCat("identity").filter((f) => f.rule !== "D-DRIFT");
|
|
200
|
+
|
|
201
|
+
const statusFor = (list, fallbackMark = "✓", fallbackColor = t.okInk) => {
|
|
202
|
+
if (list.some((f) => f.severity === "critical" || f.severity === "high")) return { glyph: "✕", color: t.badInk };
|
|
203
|
+
if (list.some((f) => f.severity === "medium" || f.severity === "low")) return { glyph: "!", color: t.warnInk };
|
|
204
|
+
return { glyph: fallbackMark, color: fallbackColor };
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const pColor = c.failed ? t.badInk : c.warned ? t.cautionInk : t.okInk;
|
|
208
|
+
const pGlyph = c.failed ? "✕" : c.warned ? "!" : "✓";
|
|
209
|
+
const sContra = statusFor(contraband);
|
|
210
|
+
const sItin = external.length && !byCat("itinerary").length ? { glyph: "•", color: t.inkMuted } : statusFor(byCat("itinerary"));
|
|
211
|
+
const sPriv = statusFor(byCat("privacy"));
|
|
212
|
+
const sId = statusFor(idFindings);
|
|
213
|
+
|
|
214
|
+
return [
|
|
215
|
+
{ num: "01", name: "PAPERS", value: `${c.passed}/${c.total} pass`, sub: c.failed ? `${c.failed} failed` : c.warned ? `${c.warned} warn` : "Spec compliant", glyph: pGlyph, color: pColor },
|
|
216
|
+
{ num: "02", name: "CONTRABAND", value: contraband.length ? `${contraband.length} flagged` : "None found", sub: contraband.length ? "Prompt / script" : "Clean copy", glyph: sContra.glyph, color: sContra.color },
|
|
217
|
+
{ num: "03", name: "ITINERARY", value: external.length ? `${external.length} external` : "Stays home", sub: external.length ? clipText(external.map((s) => s.host).join(", "), 24) : "Local origin", glyph: sItin.glyph, color: sItin.color },
|
|
218
|
+
{ num: "04", name: "PRIVACY", value: hasSecret ? "Leaks secret" : privacy.length ? `${privacy.length} rule(s)` : "No leaks", sub: hasSecret ? "Public key" : privacy.length ? "Shared data" : "Closed context", glyph: sPriv.glyph, color: sPriv.color },
|
|
219
|
+
{ num: "05", name: "IDENTITY", value: idFindings.length ? `${idFindings.length} alert(s)` : (report.identity?.short || "No hash"), sub: report.identity?.frontMan ? clipText(report.identity.frontMan, 24) : `${(report.identity?.agents || []).length} agent(s)`, glyph: sId.glyph, color: sId.color },
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function verificationStatus(receiptCheck, t, clearanceAllowed = true) {
|
|
224
|
+
const r = receiptCheck?.receipt;
|
|
225
|
+
if (receiptCheck?.valid && receiptCheck.matches === false) {
|
|
226
|
+
return { badge: "CHANGED SINCE SIGNED", color: t.warnInk, fill: t.warnTint, detail: `Signed stamp from ${shortDate(r?.inspectedAt)} no longer matches live hash` };
|
|
227
|
+
}
|
|
228
|
+
if (receiptCheck?.valid && receiptCheck.expired) {
|
|
229
|
+
return { badge: "SIGNED STAMP EXPIRED", color: t.warnInk, fill: t.warnTint, detail: `Key ${r?.inspector?.keyId || ""} expired ${shortDate(r?.expiresAt)}` };
|
|
230
|
+
}
|
|
231
|
+
if (receiptCheck?.valid && r) {
|
|
232
|
+
return {
|
|
233
|
+
badge: "VERIFIED ES256 SIGNATURE",
|
|
234
|
+
color: clearanceAllowed ? t.okInk : t.inkMuted,
|
|
235
|
+
fill: clearanceAllowed ? t.okTint : t.wellPaper,
|
|
236
|
+
detail: `Signed by Agent Customs · Key ${r.inspector?.keyId || "published"} · Valid through ${shortDate(r.expiresAt)}`,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return { badge: "UNSIGNED BROWSER SNAPSHOT", color: t.inkMuted, fill: t.wellPaper, detail: "Point-in-time client scan · Verify live before connecting" };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Draw a deterministic 7x7 mirrored cryptographic mosaic seal from a SHA-256 hash. */
|
|
243
|
+
function buildFingerprintCrest(hash, x, y, cellSize, color, borderColor) {
|
|
244
|
+
const hex = String(hash || "").replace(/^sha256:/i, "").replace(/[^0-9a-f]/gi, "") || "0000000000000000";
|
|
245
|
+
const cells = [];
|
|
246
|
+
for (let row = 0; row < 7; row++) {
|
|
247
|
+
for (let col = 0; col < 4; col++) {
|
|
248
|
+
const nib = parseInt(hex[(row * 4 + col) % hex.length], 16);
|
|
249
|
+
if ((nib & 1) === 1 || (row === col && (nib & 2) === 2)) {
|
|
250
|
+
const xLeft = x + col * cellSize;
|
|
251
|
+
const xRight = x + (6 - col) * cellSize;
|
|
252
|
+
const cy = y + row * cellSize;
|
|
253
|
+
cells.push(`<rect x="${xLeft}" y="${cy}" width="${cellSize - 1.5}" height="${cellSize - 1.5}" rx="2" fill="${escapeXml(color)}"/>`);
|
|
254
|
+
if (col !== 3) cells.push(`<rect x="${xRight}" y="${cy}" width="${cellSize - 1.5}" height="${cellSize - 1.5}" rx="2" fill="${escapeXml(color)}"/>`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const size = cellSize * 7;
|
|
259
|
+
return `<rect x="${x - 8}" y="${y - 8}" width="${size + 15}" height="${size + 15}" rx="8" fill="#faf5e8" stroke="${escapeXml(borderColor)}" stroke-width="1"/>${cells.join("")}`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Build radial guilloche rosette petal paths centered around (cx, cy). */
|
|
263
|
+
function buildGuillocheRosette(cx, cy, rOuter, rInner, petals = 18) {
|
|
264
|
+
const paths = [];
|
|
265
|
+
for (let i = 0; i < petals; i++) {
|
|
266
|
+
const angle = (i * 360) / petals;
|
|
267
|
+
paths.push(`<ellipse cx="${cx}" cy="${cy - (rOuter + rInner) / 2}" rx="${((rOuter - rInner) * 0.42).toFixed(1)}" ry="${((rOuter - rInner) * 0.72).toFixed(1)}" transform="rotate(${angle} ${cx} ${cy})"/>`);
|
|
268
|
+
}
|
|
269
|
+
return paths.join("");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function mrzToken(text, maxLen) {
|
|
273
|
+
return String(text ?? "")
|
|
274
|
+
.toUpperCase()
|
|
275
|
+
.replace(/[^A-Z0-9]+/g, "<")
|
|
276
|
+
.replace(/^<+|<+$/g, "")
|
|
277
|
+
.slice(0, maxLen) || "UNKNOWN";
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function buildMrzLines(report, meta, receiptCheck) {
|
|
281
|
+
const rawName = report.identity?.brand || report.identity?.network || report.target?.host || "NETWORK";
|
|
282
|
+
const line1 = `P<AGTCUSTOMS<<${meta.mrzCode}<<${mrzToken(rawName, 40)}`.padEnd(64, "<").slice(0, 64);
|
|
283
|
+
const hashToken = (report.identity?.hash || "NOHASH").replace(/[^a-zA-Z0-9]/g, "").toUpperCase().slice(0, 16);
|
|
284
|
+
const keyToken = mrzToken(receiptCheck?.valid ? receiptCheck?.receipt?.inspector?.keyId : "UNSIGNED", 12);
|
|
285
|
+
const c = report.conformance || { passed: 0, total: 0 };
|
|
286
|
+
const dateToken = compactIsoDate(report.inspectedAt);
|
|
287
|
+
const line2 = `${hashToken}<<KEY<${keyToken}<<SPEC${String(c.passed).padStart(2, "0")}OF${String(c.total).padStart(2, "0")}<<${dateToken}`.padEnd(64, "<").slice(0, 64);
|
|
288
|
+
return [line1, line2];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Derive metadata and verdict-safe presentation info for an inspection report.
|
|
293
|
+
*
|
|
294
|
+
* :param report: Inspection report object from analyzeNetwork / inspectNetworkUrl.
|
|
295
|
+
* :param receiptCheck: Optional result from verifyReceipt().
|
|
296
|
+
* :return: Structured metadata including clearanceAllowed, documentTitle, and status labels.
|
|
297
|
+
*/
|
|
298
|
+
export function certificateMeta(report, receiptCheck = null) {
|
|
299
|
+
const code = String(report?.verdict?.code || "HOLD").toUpperCase();
|
|
300
|
+
const base = VERDICT_META[code] || VERDICT_META.HOLD;
|
|
301
|
+
const sig = verificationStatus(receiptCheck, DEFAULT_THEME);
|
|
302
|
+
const hashHex = String(report?.identity?.hash || "").replace(/^sha256:/i, "").slice(0, 8).toUpperCase() || "00000000";
|
|
303
|
+
const serial = `AC-${compactIsoDate(report?.inspectedAt)}-${hashHex}`;
|
|
304
|
+
return {
|
|
305
|
+
code,
|
|
306
|
+
serial,
|
|
307
|
+
...base,
|
|
308
|
+
signedStatus: sig.badge,
|
|
309
|
+
signedDetail: sig.detail,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Build a safe download filename for a certificate or advisory.
|
|
315
|
+
*
|
|
316
|
+
* :param report: Inspection report object.
|
|
317
|
+
* :param ext: File extension ("png" or "svg").
|
|
318
|
+
* :return: Clean slugged filename.
|
|
319
|
+
*/
|
|
320
|
+
export function certificateFilename(report, ext = "png") {
|
|
321
|
+
const meta = certificateMeta(report);
|
|
322
|
+
const name = (report?.identity?.brand || report?.identity?.network || report?.target?.host || "network")
|
|
323
|
+
.toLowerCase()
|
|
324
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
325
|
+
.replace(/^-+|-+$/g, "")
|
|
326
|
+
.slice(0, 36) || "network";
|
|
327
|
+
const stamp = meta.code.toLowerCase();
|
|
328
|
+
const date = new Date(Date.parse(report?.inspectedAt || "") || Date.now()).toISOString().slice(0, 10);
|
|
329
|
+
const safeExt = String(ext || "png").toLowerCase().replace(/[^a-z0-9]/g, "") || "png";
|
|
330
|
+
return `agent-customs-${name}-${stamp}-${date}.${safeExt}`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Render an inspection report as a bespoke archival-parchment SVG certificate or advisory.
|
|
335
|
+
*
|
|
336
|
+
* :param report: Full report returned by inspectNetworkUrl / desk.latest.
|
|
337
|
+
* :param options.receiptCheck: Optional result from verifyReceipt().
|
|
338
|
+
* :param options.signedReceipt: Optional full signed receipt object embedded in SVG metadata.
|
|
339
|
+
* :param options.verifyUrl: Re-check permalink shown on the certificate.
|
|
340
|
+
* :param options.theme: Optional palette overrides (bgMid tints the bound spine).
|
|
341
|
+
* :return: Complete SVG XML markup string.
|
|
342
|
+
*/
|
|
343
|
+
export function certificateSvg(report, { receiptCheck = null, signedReceipt = null, verifyUrl = "", theme = null } = {}) {
|
|
344
|
+
const t = resolveTheme(theme);
|
|
345
|
+
const meta = certificateMeta(report, receiptCheck);
|
|
346
|
+
const pair = tonePair(t, meta.toneKey);
|
|
347
|
+
const sig = verificationStatus(receiptCheck, t, meta.clearanceAllowed);
|
|
348
|
+
|
|
349
|
+
const title = report?.identity?.brand || report?.identity?.network || report?.target?.host || "Inspected Network";
|
|
350
|
+
const url = report?.target?.url || "Unknown URL";
|
|
351
|
+
const summaryLines = wrapLines(report?.verdict?.summary || "", 66, 2);
|
|
352
|
+
const checks = buildChecksSummary(report, t);
|
|
353
|
+
const fullHash = report?.identity?.hash || "n/a (failed before hashing)";
|
|
354
|
+
const fallbackVerify = `https://montbaga.github.io/agent-customs/?inspect=${encodeURIComponent(url)}`;
|
|
355
|
+
const recheckUrl = safeHttpUrl(verifyUrl, fallbackVerify);
|
|
356
|
+
const recheckLines = splitExactLines(recheckUrl, recheckUrl.length > 148 ? Math.max(115, Math.ceil(recheckUrl.length / 2)) : 148);
|
|
357
|
+
const recheckTextMarkup = recheckLines.length === 1
|
|
358
|
+
? `<text x="202" y="797" class="mono" font-size="11.8" font-weight="700" text-decoration="underline" fill="${escapeXml(pair.ink)}">${escapeXml(recheckLines[0])}</text>`
|
|
359
|
+
: recheckLines.slice(0, 2).map((ln, idx) => `<text x="202" y="${789 + idx * 14}" class="mono" font-size="10.2" font-weight="700" text-decoration="underline" fill="${escapeXml(pair.ink)}">${escapeXml(ln)}</text>`).join("");
|
|
360
|
+
const [mrz1, mrz2] = buildMrzLines(report, meta, receiptCheck);
|
|
361
|
+
const inspectedDate = shortDate(report?.inspectedAt);
|
|
362
|
+
const inspectedTime = report?.inspectedAt ? String(report.inspectedAt).slice(0, 19).replace("T", " ") + "Z" : "—";
|
|
363
|
+
const agentCount = (report?.identity?.agents || []).length;
|
|
364
|
+
const frontAgent = report?.identity?.frontMan || "none";
|
|
365
|
+
const profile = report?.profile || "Open Agentic Web MVP 0.2";
|
|
366
|
+
const pillW = Math.max(230, Math.min(330, sig.badge.length * 8.1 + 44));
|
|
367
|
+
const pillX = 1336 - pillW;
|
|
368
|
+
|
|
369
|
+
// Ledger cells across x=188..1336 (width 1148 => 5 columns x 229.6px each)
|
|
370
|
+
const colW = 229.6;
|
|
371
|
+
const ledgerRows = checks.map((c, idx) => {
|
|
372
|
+
const cx = 188 + idx * colW;
|
|
373
|
+
const divider = idx > 0 ? `<line x1="${cx.toFixed(1)}" y1="400" x2="${cx.toFixed(1)}" y2="516" stroke="${escapeXml(t.rule)}" stroke-width="1"/>` : "";
|
|
374
|
+
return `${divider}
|
|
375
|
+
<text x="${(cx + 16).toFixed(1)}" y="422" class="mono" font-size="10.5" letter-spacing="1.4" fill="${escapeXml(t.inkDim)}">${escapeXml(c.num)} · ${escapeXml(c.name)}</text>
|
|
376
|
+
<circle cx="${(cx + 26).toFixed(1)}" cy="456" r="11" fill="none" stroke="${escapeXml(c.color)}" stroke-width="1.6"/>
|
|
377
|
+
<text x="${(cx + 26).toFixed(1)}" y="460.5" text-anchor="middle" class="sans" font-size="13" font-weight="700" fill="${escapeXml(c.color)}">${escapeXml(c.glyph)}</text>
|
|
378
|
+
<text x="${(cx + 46).toFixed(1)}" y="461" class="sans" font-size="18.5" font-weight="700" fill="${escapeXml(t.ink)}">${escapeXml(clipText(c.value, 14))}</text>
|
|
379
|
+
<text x="${(cx + 16).toFixed(1)}" y="496" class="mono" font-size="10.5" fill="${escapeXml(c.color)}">${escapeXml(clipText(c.sub, 24))}</text>
|
|
380
|
+
`;
|
|
381
|
+
}).join("");
|
|
382
|
+
|
|
383
|
+
// Perforation dots separating document body from bottom verification & MRZ strip
|
|
384
|
+
const perfDots = Array.from({ length: 48 }, (_, i) => `<circle cx="${174 + i * 24.8}" cy="736" r="2.2" fill="${escapeXml(t.rule)}"/>`).join("");
|
|
385
|
+
const rosette = buildGuillocheRosette(1164, 244, 126, 52, 20);
|
|
386
|
+
const crestSvg = buildFingerprintCrest(fullHash, 1184, 558, 15, pair.ink, t.rule);
|
|
387
|
+
const advisoryLines = wrapLines(meta.advisoryNote, 58, 2);
|
|
388
|
+
const certMetadata = {
|
|
389
|
+
type: "agent-customs-certificate",
|
|
390
|
+
version: 1,
|
|
391
|
+
serial: meta.serial,
|
|
392
|
+
url,
|
|
393
|
+
brand: title,
|
|
394
|
+
verdict: meta.code,
|
|
395
|
+
stamp: report?.verdict?.stamp || meta.stampLabel,
|
|
396
|
+
fingerprint: report?.identity?.hash || "",
|
|
397
|
+
shortFingerprint: report?.identity?.short || "",
|
|
398
|
+
inspectedAt: report?.inspectedAt || "",
|
|
399
|
+
protocol: report?.protocol || "open-agentic-web",
|
|
400
|
+
profile,
|
|
401
|
+
signedReceipt: signedReceipt || null,
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1400 940" width="1400" height="940" role="img" aria-label="${escapeXml(meta.documentTitle)} — ${escapeXml(title)}">
|
|
405
|
+
<metadata id="agent-customs-cert">${escapeXml(JSON.stringify(certMetadata))}</metadata>
|
|
406
|
+
<defs>
|
|
407
|
+
<linearGradient id="paperBg" x1="0" y1="0" x2="1" y2="1">
|
|
408
|
+
<stop offset="0%" stop-color="${escapeXml(t.paperTop)}"/>
|
|
409
|
+
<stop offset="55%" stop-color="${escapeXml(t.paperMid)}"/>
|
|
410
|
+
<stop offset="100%" stop-color="${escapeXml(t.paperEdge)}"/>
|
|
411
|
+
</linearGradient>
|
|
412
|
+
<linearGradient id="spineBg" x1="0" y1="0" x2="0" y2="1">
|
|
413
|
+
<stop offset="0%" stop-color="${escapeXml(t.spineDeep)}"/>
|
|
414
|
+
<stop offset="50%" stop-color="${escapeXml(t.spine)}"/>
|
|
415
|
+
<stop offset="100%" stop-color="${escapeXml(t.spineDeep)}"/>
|
|
416
|
+
</linearGradient>
|
|
417
|
+
<linearGradient id="goldFoil" x1="0" y1="0" x2="1" y2="1">
|
|
418
|
+
<stop offset="0%" stop-color="${escapeXml(t.goldDark)}"/>
|
|
419
|
+
<stop offset="45%" stop-color="${escapeXml(t.goldLight)}"/>
|
|
420
|
+
<stop offset="100%" stop-color="${escapeXml(t.gold)}"/>
|
|
421
|
+
</linearGradient>
|
|
422
|
+
<pattern id="silkWave" width="180" height="90" patternUnits="userSpaceOnUse">
|
|
423
|
+
<path d="M0 45 Q 45 10 90 45 T 180 45" fill="none" stroke="${escapeXml(t.spine)}" stroke-opacity="0.045" stroke-width="0.9"/>
|
|
424
|
+
<path d="M0 45 Q 45 80 90 45 T 180 45" fill="none" stroke="${escapeXml(t.gold)}" stroke-opacity="0.05" stroke-width="0.8"/>
|
|
425
|
+
</pattern>
|
|
426
|
+
<style>
|
|
427
|
+
.sans { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
|
|
428
|
+
.serif { font-family: Georgia, 'Times New Roman', serif; }
|
|
429
|
+
.serifIt { font-family: Georgia, 'Times New Roman', serif; font-style: italic; }
|
|
430
|
+
.mono { font-family: ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, monospace; }
|
|
431
|
+
</style>
|
|
432
|
+
</defs>
|
|
433
|
+
|
|
434
|
+
<!-- Archival Cotton-Parchment Paper Base -->
|
|
435
|
+
<rect width="1400" height="940" fill="url(#paperBg)"/>
|
|
436
|
+
<rect width="1400" height="940" fill="url(#silkWave)"/>
|
|
437
|
+
|
|
438
|
+
<!-- Watermark Guilloche Rosette behind the Stamp -->
|
|
439
|
+
<g fill="none" stroke="${escapeXml(t.gold)}" stroke-opacity="0.16" stroke-width="1">
|
|
440
|
+
${rosette}
|
|
441
|
+
<circle cx="1164" cy="244" r="126"/>
|
|
442
|
+
<circle cx="1164" cy="244" r="52"/>
|
|
443
|
+
</g>
|
|
444
|
+
|
|
445
|
+
<!-- Ornate Double Diplomatic Border Frame on Paper Sheet -->
|
|
446
|
+
<rect x="160" y="24" width="1214" height="892" rx="14" fill="none" stroke="url(#goldFoil)" stroke-width="2"/>
|
|
447
|
+
<rect x="170" y="34" width="1194" height="872" rx="10" fill="none" stroke="${escapeXml(t.spine)}" stroke-opacity="0.22" stroke-width="1"/>
|
|
448
|
+
<path d="M179 62 V42 H199 M1337 42 H1357 V62 M179 878 V898 H199 M1337 898 H1357 V878" fill="none" stroke="url(#goldFoil)" stroke-width="2.2" stroke-linecap="round"/>
|
|
449
|
+
|
|
450
|
+
<!-- Left Bound Sovereign Passport Spine -->
|
|
451
|
+
<rect x="0" y="0" width="148" height="940" fill="url(#spineBg)"/>
|
|
452
|
+
<line x1="148" y1="0" x2="148" y2="940" stroke="url(#goldFoil)" stroke-width="3"/>
|
|
453
|
+
<line x1="138" y1="0" x2="138" y2="940" stroke="${escapeXml(t.goldLight)}" stroke-opacity="0.25" stroke-width="1"/>
|
|
454
|
+
|
|
455
|
+
<!-- Spine Foil Crest Medallion -->
|
|
456
|
+
<circle cx="74" cy="96" r="36" fill="none" stroke="url(#goldFoil)" stroke-width="2.2"/>
|
|
457
|
+
<circle cx="74" cy="96" r="29" fill="none" stroke="${escapeXml(t.goldLight)}" stroke-opacity="0.55" stroke-width="1" stroke-dasharray="3 3"/>
|
|
458
|
+
<path d="M61 97 L70 106 L88 86" fill="none" stroke="${escapeXml(t.spineAccent)}" stroke-width="3.4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
459
|
+
|
|
460
|
+
<!-- Vertical Embossed Spine Ledger Text -->
|
|
461
|
+
<text x="74" y="476" text-anchor="middle" transform="rotate(-90 74 476)" class="mono" font-size="11.5" font-weight="600" letter-spacing="4.0" fill="url(#goldFoil)">AGENT CUSTOMS · OPEN AGENTIC WEB · FOLIO</text>
|
|
462
|
+
<rect x="34" y="838" width="80" height="30" rx="6" fill="none" stroke="url(#goldFoil)" stroke-opacity="0.6" stroke-width="1"/>
|
|
463
|
+
<text x="74" y="857" text-anchor="middle" class="mono" font-size="11" letter-spacing="1.4" fill="${escapeXml(t.goldLight)}">${escapeXml(meta.code)}</text>
|
|
464
|
+
|
|
465
|
+
<!-- Document Header Band (inside parchment) -->
|
|
466
|
+
<text x="192" y="76" class="sans" font-size="13" font-weight="700" letter-spacing="2.4" fill="${escapeXml(t.ink)}">AGENT CUSTOMS AUTHORITY</text>
|
|
467
|
+
<text x="192" y="96" class="mono" font-size="11" letter-spacing="1.2" fill="${escapeXml(t.inkMuted)}">SERIAL NO. ${escapeXml(meta.serial)} · ISSUED ${escapeXml(inspectedDate)}</text>
|
|
468
|
+
|
|
469
|
+
<!-- Cryptographic Seal Pill -->
|
|
470
|
+
<rect x="${pillX}" y="58" width="${pillW}" height="34" rx="17" fill="${escapeXml(sig.fill)}" stroke="${escapeXml(sig.color)}" stroke-width="1.4"/>
|
|
471
|
+
<circle cx="${pillX + 19}" cy="75" r="4.5" fill="${escapeXml(sig.color)}"/>
|
|
472
|
+
<text x="${pillX + 32}" y="79" class="mono" font-size="10.8" font-weight="700" letter-spacing="0.9" fill="${escapeXml(sig.color)}">${escapeXml(sig.badge)}</text>
|
|
473
|
+
|
|
474
|
+
<line x1="192" y1="114" x2="1336" y2="114" stroke="${escapeXml(t.rule)}" stroke-width="1.2"/>
|
|
475
|
+
|
|
476
|
+
<!-- Main Archival Headline & Network Title -->
|
|
477
|
+
<text x="192" y="148" class="mono" font-size="11" letter-spacing="2.0" fill="${escapeXml(t.goldDark)}">${escapeXml(meta.eyebrow)}</text>
|
|
478
|
+
<text x="192" y="206" class="serifIt" font-size="50" font-weight="700" fill="${escapeXml(t.ink)}">${escapeXml(meta.documentTitle)}</text>
|
|
479
|
+
<text x="192" y="254" class="sans" font-size="28" font-weight="700" letter-spacing="-0.4" fill="${escapeXml(pair.ink)}">${escapeXml(clipText(title, 38))}</text>
|
|
480
|
+
<text x="192" y="284" class="mono" font-size="13" fill="${escapeXml(t.inkMuted)}">${escapeXml(clipText(url, 84))}</text>
|
|
481
|
+
<text x="192" y="320" class="sans" font-size="15" fill="${escapeXml(t.ink)}">${escapeXml(summaryLines[0] || "")}</text>
|
|
482
|
+
<text x="192" y="342" class="sans" font-size="15" fill="${escapeXml(t.ink)}">${escapeXml(summaryLines[1] || "")}</text>
|
|
483
|
+
|
|
484
|
+
<!-- Circular Wet-Ink Embossed Customs Cancellation Stamp -->
|
|
485
|
+
<g transform="translate(1164, 244) rotate(-8)">
|
|
486
|
+
<circle cx="0" cy="0" r="102" fill="${escapeXml(pair.tint)}" fill-opacity="0.72" stroke="${escapeXml(pair.ink)}" stroke-width="4.2"/>
|
|
487
|
+
<circle cx="0" cy="0" r="91" fill="none" stroke="${escapeXml(pair.ink)}" stroke-width="1.4" stroke-dasharray="5 3.5"/>
|
|
488
|
+
<circle cx="0" cy="0" r="74" fill="none" stroke="${escapeXml(pair.ink)}" stroke-opacity="0.45" stroke-width="1"/>
|
|
489
|
+
<text x="0" y="-44" text-anchor="middle" class="mono" font-size="10.5" font-weight="700" letter-spacing="2.2" fill="${escapeXml(pair.ink)}">BORDER CONTROL</text>
|
|
490
|
+
<line x1="-54" y1="-31" x2="54" y2="-31" stroke="${escapeXml(pair.ink)}" stroke-opacity="0.4" stroke-width="1"/>
|
|
491
|
+
<text x="0" y="11" text-anchor="middle" class="mono" font-size="33" font-weight="700" letter-spacing="2.4" fill="${escapeXml(pair.ink)}">${escapeXml(meta.stampLabel)}</text>
|
|
492
|
+
<line x1="-54" y1="26" x2="54" y2="26" stroke="${escapeXml(pair.ink)}" stroke-opacity="0.4" stroke-width="1"/>
|
|
493
|
+
<text x="0" y="48" text-anchor="middle" class="mono" font-size="11.5" font-weight="700" letter-spacing="1.6" fill="${escapeXml(pair.ink)}">${escapeXml(inspectedDate)}</text>
|
|
494
|
+
<text x="0" y="66" text-anchor="middle" class="mono" font-size="8.5" letter-spacing="1.4" fill="${escapeXml(pair.ink)}">SHA-256 LOCKED</text>
|
|
495
|
+
</g>
|
|
496
|
+
|
|
497
|
+
<!-- Five Checks Engraved Ledger Table -->
|
|
498
|
+
<text x="192" y="382" class="mono" font-size="11" letter-spacing="1.8" fill="${escapeXml(t.inkDim)}">DETERMINISTIC PORT-OF-ENTRY LEDGER (5 OF 5 CHECKS)</text>
|
|
499
|
+
<rect x="188" y="394" width="1148" height="128" rx="8" fill="#fbf7ee" stroke="${escapeXml(t.rule)}" stroke-width="1.3"/>
|
|
500
|
+
${ledgerRows}
|
|
501
|
+
|
|
502
|
+
<!-- Cryptographic Proof Box + Deterministic Visual Hash Coat of Arms -->
|
|
503
|
+
<rect x="188" y="536" width="1148" height="188" rx="10" fill="#fbf7ee" stroke="${escapeXml(t.rule)}" stroke-width="1.3"/>
|
|
504
|
+
<text x="212" y="562" class="mono" font-size="10.8" letter-spacing="1.5" fill="${escapeXml(t.inkDim)}">CANONICAL IDENTITY HASH & CRYPTOGRAPHIC ATTESTATION</text>
|
|
505
|
+
|
|
506
|
+
<!-- Canonical SHA-256 Strip -->
|
|
507
|
+
<rect x="212" y="574" width="932" height="34" rx="6" fill="${escapeXml(t.wellPaper)}" stroke="${escapeXml(t.rule)}"/>
|
|
508
|
+
<text x="228" y="596" class="mono" font-size="12.5" font-weight="700" fill="${escapeXml(t.ink)}">${escapeXml(clipText(fullHash, 74))}</text>
|
|
509
|
+
|
|
510
|
+
<!-- Facts Grid inside Verification Panel -->
|
|
511
|
+
<text x="212" y="629" class="mono" font-size="10" letter-spacing="1.1" fill="${escapeXml(t.inkDim)}">FRONT AGENT</text>
|
|
512
|
+
<text x="212" y="647" class="mono" font-size="12.5" font-weight="700" fill="${escapeXml(t.ink)}">${escapeXml(clipText(`${frontAgent} (${agentCount} agent${agentCount === 1 ? "" : "s"})`, 34))}</text>
|
|
513
|
+
|
|
514
|
+
<text x="532" y="629" class="mono" font-size="10" letter-spacing="1.1" fill="${escapeXml(t.inkDim)}">INSPECTED TIMESTAMP (UTC)</text>
|
|
515
|
+
<text x="532" y="647" class="mono" font-size="12.5" font-weight="700" fill="${escapeXml(t.ink)}">${escapeXml(inspectedTime)}</text>
|
|
516
|
+
|
|
517
|
+
<text x="772" y="629" class="mono" font-size="10" letter-spacing="1.1" fill="${escapeXml(t.inkDim)}">SPEC PROFILE</text>
|
|
518
|
+
<text x="772" y="647" class="mono" font-size="11.5" font-weight="700" fill="${escapeXml(t.ink)}">${escapeXml(clipText(profile, 52))}</text>
|
|
519
|
+
|
|
520
|
+
<text x="212" y="677" class="sans" font-size="13" fill="${escapeXml(t.inkMuted)}">${escapeXml(advisoryLines[0] || "")} ${escapeXml(advisoryLines[1] || "")}</text>
|
|
521
|
+
<text x="212" y="701" class="mono" font-size="11.5" font-weight="700" fill="${escapeXml(sig.color)}">ATTESTATION: ${escapeXml(sig.detail)}</text>
|
|
522
|
+
|
|
523
|
+
<!-- Unique Deterministic Visual Hash Crest (top-right inside proof panel) -->
|
|
524
|
+
${crestSvg}
|
|
525
|
+
<text x="1236" y="683" text-anchor="middle" class="mono" font-size="9.5" letter-spacing="1.2" fill="${escapeXml(t.inkDim)}">HASH EMBLEM</text>
|
|
526
|
+
<text x="1236" y="700" text-anchor="middle" class="mono" font-size="10" font-weight="700" fill="${escapeXml(pair.ink)}">${escapeXml(report?.identity?.short || "")}</text>
|
|
527
|
+
|
|
528
|
+
<!-- Tear-line Perforation & High-Contrast Clickable Exact Re-Verify Strip -->
|
|
529
|
+
${perfDots}
|
|
530
|
+
<a href="${escapeXml(recheckUrl)}" target="_blank">
|
|
531
|
+
<rect x="188" y="746" width="1148" height="64" rx="8" fill="#fffdf8" stroke="${escapeXml(pair.ink)}" stroke-width="1.6"/>
|
|
532
|
+
<rect x="202" y="756" width="132" height="22" rx="5" fill="${escapeXml(pair.ink)}"/>
|
|
533
|
+
<text x="268" y="771" text-anchor="middle" class="mono" font-size="10.5" font-weight="700" letter-spacing="1.1" fill="#fffdf8">RE-VERIFY LIVE</text>
|
|
534
|
+
<text x="346" y="771" class="sans" font-size="12" font-weight="700" fill="${escapeXml(t.ink)}">Click to run a fresh check and open the live result page</text>
|
|
535
|
+
<text x="1322" y="771" text-anchor="end" class="sans" font-size="12" font-weight="700" fill="${escapeXml(pair.ink)}">Open live result ↗</text>
|
|
536
|
+
${recheckTextMarkup}
|
|
537
|
+
</a>
|
|
538
|
+
|
|
539
|
+
<!-- ICAO Machine-Readable Zone -->
|
|
540
|
+
<rect x="188" y="820" width="1148" height="70" rx="8" fill="${escapeXml(t.wellPaper)}" stroke="${escapeXml(t.rule)}" stroke-width="1"/>
|
|
541
|
+
<text x="210" y="849" class="mono" font-size="18" font-weight="600" letter-spacing="2.8" fill="${escapeXml(t.ink)}">${escapeXml(mrz1)}</text>
|
|
542
|
+
<text x="210" y="876" class="mono" font-size="18" font-weight="600" letter-spacing="2.8" fill="${escapeXml(pair.ink)}">${escapeXml(mrz2)}</text>
|
|
543
|
+
</svg>`;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Wrap a rendered certificate SVG in a printable HTML document.
|
|
548
|
+
*/
|
|
549
|
+
export function certificateHtml(svg, title = "Agent Customs Certificate") {
|
|
550
|
+
return `<!doctype html>
|
|
551
|
+
<html lang="en">
|
|
552
|
+
<head>
|
|
553
|
+
<meta charset="utf-8">
|
|
554
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
555
|
+
<title>${escapeXml(title)}</title>
|
|
556
|
+
<style>
|
|
557
|
+
body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #0c1d18; }
|
|
558
|
+
svg { width: min(100%, 1120px); height: auto; border-radius: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, .55); }
|
|
559
|
+
@media print { body { background: #fff; padding: 0; } svg { width: 100%; box-shadow: none; } }
|
|
560
|
+
</style>
|
|
561
|
+
</head>
|
|
562
|
+
<body>
|
|
563
|
+
${svg}
|
|
564
|
+
</body>
|
|
565
|
+
</html>`;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function unescapeXml(value) {
|
|
569
|
+
return String(value ?? "")
|
|
570
|
+
.replace(/"/g, "\"")
|
|
571
|
+
.replace(/'/g, "'")
|
|
572
|
+
.replace(/</g, "<")
|
|
573
|
+
.replace(/>/g, ">")
|
|
574
|
+
.replace(/&/g, "&");
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const MRZ_VERDICT_MAP = {
|
|
578
|
+
CLEARED: "CLEARED",
|
|
579
|
+
CONDITIONS: "CONDITIONS",
|
|
580
|
+
HOLD: "HOLD",
|
|
581
|
+
DENIED: "DENIED",
|
|
582
|
+
INVALID: "INVALID",
|
|
583
|
+
UNREAD: "UNREADABLE",
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Parse an Agent Customs SVG, HTML, ES256 signed JSON receipt, or exported JSON report.
|
|
588
|
+
*
|
|
589
|
+
* :param text: Raw file text dropped or selected by a user.
|
|
590
|
+
* :return: Normalized metadata descriptor, or null when unrecognized.
|
|
591
|
+
*/
|
|
592
|
+
export function parseVerificationFile(text) {
|
|
593
|
+
const raw = String(text ?? "").trim();
|
|
594
|
+
if (!raw) return null;
|
|
595
|
+
|
|
596
|
+
if (raw.startsWith("{")) {
|
|
597
|
+
try {
|
|
598
|
+
const doc = JSON.parse(raw);
|
|
599
|
+
if (doc?.type === "agent-customs-receipt" || (doc?.receipt?.type === "agent-customs-receipt" && doc?.signature)) {
|
|
600
|
+
const signed = doc.receipt ? doc : { receipt: doc, signature: null };
|
|
601
|
+
const r = signed.receipt;
|
|
602
|
+
return {
|
|
603
|
+
kind: "receipt",
|
|
604
|
+
url: r.network || "",
|
|
605
|
+
brand: "",
|
|
606
|
+
verdict: r.verdict || "",
|
|
607
|
+
stamp: r.stamp || r.verdict || "",
|
|
608
|
+
fingerprint: r.fingerprint || "",
|
|
609
|
+
shortFingerprint: r.fingerprint ? String(r.fingerprint).replace(/^sha256:/, "").slice(0, 12) : "",
|
|
610
|
+
inspectedAt: r.inspectedAt || "",
|
|
611
|
+
expiresAt: r.expiresAt || "",
|
|
612
|
+
protocol: "open-agentic-web",
|
|
613
|
+
profile: "",
|
|
614
|
+
signedReceipt: signed.signature ? signed : null,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
if (doc?.type === "agent-customs-certificate" && doc?.url) {
|
|
618
|
+
return { kind: "certificate", ...doc };
|
|
619
|
+
}
|
|
620
|
+
if (doc?.tool === "Agent Customs" && doc?.target?.url) {
|
|
621
|
+
return {
|
|
622
|
+
kind: "snapshot",
|
|
623
|
+
url: doc.target.url,
|
|
624
|
+
brand: doc.identity?.brand || "",
|
|
625
|
+
verdict: doc.verdict?.code || "",
|
|
626
|
+
stamp: doc.verdict?.stamp || "",
|
|
627
|
+
fingerprint: doc.identity?.hash || "",
|
|
628
|
+
shortFingerprint: doc.identity?.short || "",
|
|
629
|
+
inspectedAt: doc.inspectedAt || "",
|
|
630
|
+
expiresAt: "",
|
|
631
|
+
protocol: doc.protocol || "open-agentic-web",
|
|
632
|
+
profile: doc.profile || "",
|
|
633
|
+
signedReceipt: null,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
} catch {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// HTML export or page embedding either JSON metadata or the certificate SVG.
|
|
643
|
+
if (/<!doctype\s+html|<html\b/i.test(raw)) {
|
|
644
|
+
const scriptMatch = raw.match(/<script[^>]+id=["']agent-customs-cert["'][^>]*>([\s\S]*?)<\/script>/i);
|
|
645
|
+
if (scriptMatch) {
|
|
646
|
+
const fromScript = parseVerificationFile(scriptMatch[1]);
|
|
647
|
+
if (fromScript) return { ...fromScript, kind: "html" };
|
|
648
|
+
}
|
|
649
|
+
const svgStart = raw.search(/<svg\b/i);
|
|
650
|
+
const svgEnd = raw.toLowerCase().lastIndexOf("</svg>");
|
|
651
|
+
if (svgStart >= 0 && svgEnd > svgStart) {
|
|
652
|
+
const fromSvg = parseVerificationFile(raw.slice(svgStart, svgEnd + 6));
|
|
653
|
+
if (fromSvg) return { ...fromSvg, kind: "html" };
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (!/<svg\b/i.test(raw)) return null;
|
|
658
|
+
|
|
659
|
+
const metaMatch = raw.match(/<metadata\s+id=["']agent-customs-cert["'][^>]*>([\s\S]*?)<\/metadata>/i);
|
|
660
|
+
if (metaMatch) {
|
|
661
|
+
try {
|
|
662
|
+
const parsed = JSON.parse(unescapeXml(metaMatch[1]));
|
|
663
|
+
if (parsed?.type === "agent-customs-certificate") {
|
|
664
|
+
return {
|
|
665
|
+
kind: "certificate",
|
|
666
|
+
url: parsed.url || "",
|
|
667
|
+
brand: parsed.brand || "",
|
|
668
|
+
verdict: parsed.verdict || "",
|
|
669
|
+
stamp: parsed.stamp || parsed.verdict || "",
|
|
670
|
+
fingerprint: parsed.fingerprint || "",
|
|
671
|
+
shortFingerprint: parsed.shortFingerprint || "",
|
|
672
|
+
inspectedAt: parsed.inspectedAt || "",
|
|
673
|
+
expiresAt: parsed.signedReceipt?.receipt?.expiresAt || "",
|
|
674
|
+
protocol: parsed.protocol || "",
|
|
675
|
+
profile: parsed.profile || "",
|
|
676
|
+
signedReceipt: parsed.signedReceipt || null,
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
} catch { /* fall through to text extraction for edited metadata */ }
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Fallback parser for certificates without <metadata>.
|
|
683
|
+
let url = "";
|
|
684
|
+
const hrefMatch = raw.match(/<a[^>]+href=["']([^"']+\?inspect=[^"']+)["']/i);
|
|
685
|
+
if (hrefMatch) {
|
|
686
|
+
try {
|
|
687
|
+
const parsedUrl = new URL(unescapeXml(hrefMatch[1]));
|
|
688
|
+
url = parsedUrl.searchParams.get("inspect") || "";
|
|
689
|
+
} catch { /* ignore malformed fallback link */ }
|
|
690
|
+
}
|
|
691
|
+
const hashMatch = raw.match(/sha256:[0-9a-f]{64}/i);
|
|
692
|
+
const fingerprint = hashMatch ? hashMatch[0].toLowerCase() : "";
|
|
693
|
+
const mrzMatch = raw.match(/P<AGTCUSTOMS<<([A-Z]+)<</);
|
|
694
|
+
const verdict = mrzMatch ? (MRZ_VERDICT_MAP[mrzMatch[1]] || "") : "";
|
|
695
|
+
const issuedMatch = raw.match(/ISSUED\s+([0-9]{2}\s+[A-Z]{3}\s+[0-9]{4})/);
|
|
696
|
+
if (!url && !fingerprint && !verdict) return null;
|
|
697
|
+
|
|
698
|
+
return {
|
|
699
|
+
kind: "certificate",
|
|
700
|
+
legacy: true,
|
|
701
|
+
url,
|
|
702
|
+
brand: "",
|
|
703
|
+
verdict,
|
|
704
|
+
stamp: verdict,
|
|
705
|
+
fingerprint,
|
|
706
|
+
shortFingerprint: fingerprint ? fingerprint.replace(/^sha256:/, "").slice(0, 12) : "",
|
|
707
|
+
inspectedAt: issuedMatch ? issuedMatch[1] : "",
|
|
708
|
+
expiresAt: "",
|
|
709
|
+
protocol: "",
|
|
710
|
+
profile: "",
|
|
711
|
+
signedReceipt: null,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
async function inflatePdfStream(slice) {
|
|
716
|
+
if (typeof DecompressionStream !== "function") return "";
|
|
717
|
+
for (const format of ["deflate", "deflate-raw"]) {
|
|
718
|
+
try {
|
|
719
|
+
const stream = new Blob([slice]).stream().pipeThrough(new DecompressionStream(format));
|
|
720
|
+
const buf = await new Response(stream).arrayBuffer();
|
|
721
|
+
if (buf.byteLength > 4 * 1024 * 1024) continue;
|
|
722
|
+
return new TextDecoder("latin1").decode(buf);
|
|
723
|
+
} catch { /* try fallback format or skip non-zlib stream */ }
|
|
724
|
+
}
|
|
725
|
+
return "";
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Extract verification links or SHA-256 hashes from a PDF byte buffer.
|
|
730
|
+
* Browser Print-to-PDF preserves link annotations (/URI) even when text is outlined as glyphs.
|
|
731
|
+
*/
|
|
732
|
+
async function parsePdfVerification(bytes) {
|
|
733
|
+
const latin1 = new TextDecoder("latin1").decode(bytes);
|
|
734
|
+
const chunks = [latin1];
|
|
735
|
+
|
|
736
|
+
// Collect FlateDecode streams safely (bounded count & size).
|
|
737
|
+
const streamRe = /stream\r?\n/g;
|
|
738
|
+
let count = 0;
|
|
739
|
+
let m;
|
|
740
|
+
while ((m = streamRe.exec(latin1)) !== null && count < 24) {
|
|
741
|
+
const headerSlice = latin1.slice(Math.max(0, m.index - 400), m.index);
|
|
742
|
+
const start = m.index + m[0].length;
|
|
743
|
+
const end = latin1.indexOf("endstream", start);
|
|
744
|
+
if (end < 0) break;
|
|
745
|
+
if (/\/FlateDecode\b/.test(headerSlice)) {
|
|
746
|
+
let streamEnd = end;
|
|
747
|
+
while (streamEnd > start && (latin1[streamEnd - 1] === "\n" || latin1[streamEnd - 1] === "\r")) streamEnd -= 1;
|
|
748
|
+
if (streamEnd > start && streamEnd - start < 2 * 1024 * 1024) {
|
|
749
|
+
const text = await inflatePdfStream(bytes.subarray(start, streamEnd));
|
|
750
|
+
if (text) chunks.push(text);
|
|
751
|
+
count += 1;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
streamRe.lastIndex = end + 9;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const combined = chunks.join("\n");
|
|
758
|
+
// Extract /URI (...) annotations first, which Chromium preserves reliably on Print -> Save as PDF.
|
|
759
|
+
let url = "";
|
|
760
|
+
const uriRe = /\/URI\s*\(([^)]{6,2048})\)/g;
|
|
761
|
+
while ((m = uriRe.exec(combined)) !== null) {
|
|
762
|
+
const unescaped = m[1].replace(/\\([\\()])/g, "$1");
|
|
763
|
+
if (/[?&]inspect=/.test(unescaped)) {
|
|
764
|
+
try {
|
|
765
|
+
url = new URL(unescaped).searchParams.get("inspect") || "";
|
|
766
|
+
if (url) break;
|
|
767
|
+
} catch { /* keep searching */ }
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (!url) {
|
|
771
|
+
const inspectMatch = combined.match(/https?:\/\/[^\s)"'<>]+\?inspect=([^\s)"'<>]+)/);
|
|
772
|
+
if (inspectMatch) {
|
|
773
|
+
try { url = decodeURIComponent(inspectMatch[1]); } catch { url = inspectMatch[1]; }
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
const hashMatch = combined.match(/sha256:[0-9a-f]{64}/i);
|
|
778
|
+
const fingerprint = hashMatch ? hashMatch[0].toLowerCase() : "";
|
|
779
|
+
const mrzMatch = combined.match(/P<AGTCUSTOMS<<([A-Z]+)<</);
|
|
780
|
+
const verdict = mrzMatch ? (MRZ_VERDICT_MAP[mrzMatch[1]] || "") : "";
|
|
781
|
+
|
|
782
|
+
if (!url && !fingerprint) return { ok: false, pdfUnsupported: true };
|
|
783
|
+
|
|
784
|
+
return {
|
|
785
|
+
ok: true,
|
|
786
|
+
kind: "pdf",
|
|
787
|
+
pdfExtracted: true,
|
|
788
|
+
url,
|
|
789
|
+
brand: "",
|
|
790
|
+
verdict,
|
|
791
|
+
stamp: verdict,
|
|
792
|
+
fingerprint,
|
|
793
|
+
shortFingerprint: fingerprint ? fingerprint.replace(/^sha256:/, "").slice(0, 12) : "",
|
|
794
|
+
inspectedAt: "",
|
|
795
|
+
expiresAt: "",
|
|
796
|
+
protocol: "",
|
|
797
|
+
profile: "",
|
|
798
|
+
signedReceipt: null,
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Parse .svg, .json, .html, or .pdf verification inputs.
|
|
804
|
+
*/
|
|
805
|
+
export async function parseAnyVerificationFile(input, fileName = "") {
|
|
806
|
+
if (typeof input === "string") {
|
|
807
|
+
if (input.startsWith("%PDF-")) return parsePdfVerification(new TextEncoder().encode(input));
|
|
808
|
+
return parseVerificationFile(input);
|
|
809
|
+
}
|
|
810
|
+
let bytes = null;
|
|
811
|
+
let name = fileName;
|
|
812
|
+
if (typeof Blob !== "undefined" && input instanceof Blob) {
|
|
813
|
+
name = name || input.name || "";
|
|
814
|
+
bytes = new Uint8Array(await input.arrayBuffer());
|
|
815
|
+
} else if (input instanceof Uint8Array) {
|
|
816
|
+
bytes = input;
|
|
817
|
+
} else if (input instanceof ArrayBuffer) {
|
|
818
|
+
bytes = new Uint8Array(input);
|
|
819
|
+
} else if (input?.bytes instanceof Uint8Array) {
|
|
820
|
+
bytes = input.bytes;
|
|
821
|
+
name = name || input.name || "";
|
|
822
|
+
}
|
|
823
|
+
if (!bytes) return null;
|
|
824
|
+
|
|
825
|
+
const isPdf = /\.pdf$/i.test(name) || new TextDecoder("latin1").decode(bytes.subarray(0, 5)) === "%PDF-";
|
|
826
|
+
if (isPdf) return parsePdfVerification(bytes);
|
|
827
|
+
return parseVerificationFile(new TextDecoder("utf-8").decode(bytes));
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Cryptographically verify a parsed certificate/receipt and compare it with a live report.
|
|
832
|
+
*
|
|
833
|
+
* :param input: Raw string, File/Blob, ArrayBuffer, or Uint8Array (.svg, .json, .html, .pdf).
|
|
834
|
+
* :param options.fileName: Optional filename hint for binary inputs.
|
|
835
|
+
* :param options.publicJwk: Agent Customs' ES256 public JWK for signature verification.
|
|
836
|
+
* :param options.lookupSignedReceipt: Optional async (url) => signedReceipt fallback.
|
|
837
|
+
* :param options.now: Reference date for expiry checks.
|
|
838
|
+
* :param options.liveReport: Optional live report from inspectNetworkUrl for drift checking.
|
|
839
|
+
* :return: Structured verification result.
|
|
840
|
+
*/
|
|
841
|
+
export async function verifyDroppedArtifact(input, { fileName = "", publicJwk = null, lookupSignedReceipt = null, now = new Date(), liveReport = null } = {}) {
|
|
842
|
+
const parsed = await parseAnyVerificationFile(input, fileName);
|
|
843
|
+
if (!parsed || parsed.pdfUnsupported) {
|
|
844
|
+
return {
|
|
845
|
+
ok: false,
|
|
846
|
+
status: "invalid",
|
|
847
|
+
reason: parsed?.pdfUnsupported
|
|
848
|
+
? "No readable verification link or receipt found in this PDF. Browser 'Save as PDF' outlines text as vector shapes and drops cryptographic signatures — use .svg, .json, or .html for signature verification."
|
|
849
|
+
: "Unrecognized file. Choose an Agent Customs .svg certificate, .json receipt, .html export, or .pdf print.",
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
let signedCandidate = parsed.signedReceipt || null;
|
|
854
|
+
let signedSource = parsed.signedReceipt ? "embedded" : null;
|
|
855
|
+
// Never promote a PDF (which drops signatures/hashes on print) to "verified" via remote receipt lookup.
|
|
856
|
+
if (!signedCandidate && !parsed.pdfExtracted && parsed.fingerprint && typeof lookupSignedReceipt === "function" && parsed.url) {
|
|
857
|
+
try {
|
|
858
|
+
const published = await lookupSignedReceipt(parsed.url);
|
|
859
|
+
if (published) {
|
|
860
|
+
signedCandidate = published;
|
|
861
|
+
signedSource = "published";
|
|
862
|
+
}
|
|
863
|
+
} catch { /* leave unsigned */ }
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
let sigCheck = null;
|
|
867
|
+
let tampered = false;
|
|
868
|
+
if (signedCandidate && publicJwk) {
|
|
869
|
+
sigCheck = await verifyReceipt(signedCandidate, publicJwk, { now, fingerprint: parsed.fingerprint || null });
|
|
870
|
+
if (!sigCheck.valid) tampered = true;
|
|
871
|
+
// Detect if certificate fields were altered while keeping an authentic receipt block.
|
|
872
|
+
if (sigCheck.valid && signedSource === "embedded" && sigCheck.receipt) {
|
|
873
|
+
const r = sigCheck.receipt;
|
|
874
|
+
const hashMismatch = parsed.fingerprint && r.fingerprint && parsed.fingerprint !== r.fingerprint;
|
|
875
|
+
const urlMismatch = parsed.url && r.network && parsed.url !== r.network;
|
|
876
|
+
const verdictMismatch = parsed.verdict && r.verdict && parsed.verdict !== r.verdict;
|
|
877
|
+
if (hashMismatch || urlMismatch || verdictMismatch) {
|
|
878
|
+
tampered = true;
|
|
879
|
+
sigCheck = { ...sigCheck, valid: false, reason: "Certificate fields were modified after the receipt was signed." };
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
let liveStatus = "unchecked";
|
|
885
|
+
let liveSummary = "";
|
|
886
|
+
if (liveReport) {
|
|
887
|
+
if (liveReport.failure) {
|
|
888
|
+
liveStatus = "unreadable";
|
|
889
|
+
liveSummary = liveReport.verdict?.summary || "Could not reach the live endpoint.";
|
|
890
|
+
} else if (parsed.fingerprint && liveReport.identity?.hash) {
|
|
891
|
+
const same = parsed.fingerprint === liveReport.identity.hash;
|
|
892
|
+
liveStatus = same ? "match" : "changed";
|
|
893
|
+
liveSummary = same
|
|
894
|
+
? `Live endpoint matches exact SHA-256 fingerprint (${liveReport.identity.short}).`
|
|
895
|
+
: `Live endpoint changed: certificate locked ${parsed.shortFingerprint || parsed.fingerprint.slice(0, 12)}, live now ${liveReport.identity.short} (${liveReport.verdict?.stamp}).`;
|
|
896
|
+
} else if (parsed.url) {
|
|
897
|
+
liveStatus = "live-checked";
|
|
898
|
+
liveSummary = parsed.pdfExtracted
|
|
899
|
+
? `Live site returned ${liveReport.verdict?.stamp} (${liveReport.identity?.short || "no hash"}) — printed PDF has no SHA-256 hash to match offline.`
|
|
900
|
+
: `Live inspection returned ${liveReport.verdict?.stamp} (${liveReport.identity?.short || "no hash"}).`;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
let status = "unsigned";
|
|
905
|
+
let headline = parsed.pdfExtracted
|
|
906
|
+
? "PDF has no ES256 signature (extracted link)"
|
|
907
|
+
: "Unsigned browser snapshot";
|
|
908
|
+
let detail = parsed.pdfExtracted
|
|
909
|
+
? "Browser Print-to-PDF drops ES256 signatures. Extracted the re-verify target from the PDF — check the live result below, or use .svg / .json / .html for offline signature proof."
|
|
910
|
+
: "This file contains no ES256 cryptographic signature, only the inspection metadata recorded at export.";
|
|
911
|
+
|
|
912
|
+
if (tampered) {
|
|
913
|
+
status = "tampered";
|
|
914
|
+
headline = "Signature check failed";
|
|
915
|
+
detail = sigCheck?.reason || "This certificate or receipt was altered after signing.";
|
|
916
|
+
} else if (liveStatus === "changed") {
|
|
917
|
+
status = "changed";
|
|
918
|
+
headline = "Website changed since issued";
|
|
919
|
+
detail = liveSummary;
|
|
920
|
+
} else if (sigCheck?.valid && sigCheck.expired) {
|
|
921
|
+
status = "expired";
|
|
922
|
+
headline = "Valid signature, but stamp expired";
|
|
923
|
+
detail = `Signed by Agent Customs on ${String(sigCheck.receipt.inspectedAt).slice(0, 10)}, expired on ${String(sigCheck.receipt.expiresAt).slice(0, 10)}. Re-inspect live to refresh.`;
|
|
924
|
+
} else if (sigCheck?.valid) {
|
|
925
|
+
status = "verified";
|
|
926
|
+
headline = signedSource === "published" ? "Verified against published ES256 receipt" : "Verified ES256 signature";
|
|
927
|
+
detail = liveStatus === "match"
|
|
928
|
+
? "Cryptographically signed by Agent Customs and confirmed unchanged against live endpoint."
|
|
929
|
+
: `Cryptographically signed by Agent Customs (valid until ${String(sigCheck.receipt.expiresAt).slice(0, 10)}).`;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
return {
|
|
933
|
+
ok: true,
|
|
934
|
+
status,
|
|
935
|
+
headline,
|
|
936
|
+
detail,
|
|
937
|
+
artifact: parsed,
|
|
938
|
+
signature: sigCheck,
|
|
939
|
+
signedSource,
|
|
940
|
+
liveStatus,
|
|
941
|
+
liveSummary,
|
|
942
|
+
liveReport,
|
|
943
|
+
};
|
|
944
|
+
}
|