Spaces:
Running
Running
Real demos, C2PA reading, OCR and lowest-bit false-positive fixes
Browse filesFiles changed (14)
- .gitattributes+3
- .gitignore+1
- README.md+10-1
- app.js+20-3
- demo/README.mdAdded+13
- demo/alpine-lake-chatgpt.pngAdded
- demo/neon-waves-chatgpt.pngAdded
- demo/ribbons-c2pa.jpgAdded
- index.html+5-1
- lib/forensics.js+6-2
- lib/metadata.js+140-6
- lib/pipeline.js+6-1
- style.css+2-1
- tests/forensics.test.mjs+49
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines33343536373832 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textdemo/alpine-lake-chatgpt.png filter=lfs diff=lfs merge=lfs -textdemo/neon-waves-chatgpt.png filter=lfs diff=lfs merge=lfs -textdemo/ribbons-c2pa.jpg filter=lfs diff=lfs merge=lfs -text
1node_modules/12node_modules/.DS_Store
23 unmodified lines242526272829309 unmodified lines40414243444523 unmodified lines| Layer | How | Model ||---|---|---|| File structure | Metadata (EXIF, XMP, PNG text), C2PA provenance, non-standard blocks, data appended after the image | none || Lowest bits | Message extraction in common orderings, chi-square attack, aligned-pair analysis of flat areas | none || Frequency | 2-D FFT; isolated peaks reveal grids, halftone, moiré and frequency watermarks | none || Colour | Palette (k-means), saturation, histogram gaps, lowest-bit colour twins | none |9 unmodified lines(OPFS), because the default Cache API can refuse single files near 1 GB.Visitors can remove them with one click.## Limits- JPEG and WebP compression rewrite the lowest bits, so hidden-bit results on23 unmodified lines24252627282930319 unmodified lines414243444546474849505152535423 unmodified lines| Layer | How | Model ||---|---|---|| File structure | Metadata (EXIF, XMP, PNG text), AI-generation prompts, non-standard blocks, data appended after the image | none || Content credentials | C2PA manifest: declared source (e.g. AI-generated), the tool that made it, and recorded steps such as an added invisible watermark. Not signature-verified | none || Lowest bits | Message extraction in common orderings, chi-square attack, aligned-pair analysis of flat areas | none || Frequency | 2-D FFT; isolated peaks reveal grids, halftone, moiré and frequency watermarks | none || Colour | Palette (k-means), saturation, histogram gaps, lowest-bit colour twins | none |9 unmodified lines(OPFS), because the default Cache API can refuse single files near 1 GB.Visitors can remove them with one click.## DemosFour one-click demos: two ChatGPT images whose credentials declare themAI-generated and watermarked, a real photo with an edit history, and a samplewith planted hidden content. See [`demo/README.md`](demo/README.md).Source and screenshots: [github.com/GHeart01/pattern-finder](https://github.com/GHeart01/pattern-finder)## Limits- JPEG and WebP compression rewrite the lowest bits, so hidden-bit results on
47 unmodified lines4849505152532 unmodified lines5657585960616 unmodified lines68697071727324 unmodified lines9899100101102103104129 unmodified lines234235236237238239240241242243244245102 unmodified lines34834935035135235335416 unmodified lines37137237337437537647 unmodified linestry { localStorage.setItem(manifestKey(m), JSON.stringify([...fileUrls[m]])); } catch {}};async function showStorage() {const parts = [];let total = 0;2 unmodified linesif (!urls.length) continue;const s = await cacheStatus(urls);total = s.bytes;parts.push(`${MODEL_NAMES[m]} ${s.complete ? "saved" : "partly saved (will finish downloading next time)"}`);}if (!total) { $("storage").hidden = true; return; }6 unmodified linesawait call("unload");try { await clearCache(); } catch {}for (const m of ["florence", "qwen"]) { try { localStorage.removeItem(manifestKey(m)); } catch {} }$("storage-text").textContent = "Downloaded models removed from this device.";$("clear").hidden = true;});24 unmodified lineslisteners.add((m) => {if (m.type === "file" && fileUrls[m.model]) fileUrls[m.model].add(`https://huggingface.co/${m.repo}/resolve/main/${m.file}`);if (m.type === "progress") {bar(m.loaded / m.total, `Downloading ${MODEL_NAMES[m.model]}… ${(m.loaded / 1e6).toFixed(0)} / ${(m.total / 1e6).toFixed(0)} MB (only the first time)`);}if (m.type === "status" && m.status === "loading") bar(null, `Loading ${MODEL_NAMES[m.model]}…`);if (m.type === "status" && m.status === "ready") {129 unmodified lineslet running = false;let stopped = false;async function analyze(file) {if (running) return;running = true;stopped = false;$("file").disabled = $("sample").disabled = true;const useOcr = $("use-ocr").checked;const useVlm = $("use-vlm").checked && !$("use-vlm").disabled;const S = {102 unmodified lines} finally {$("stop").hidden = true;running = false;$("file").disabled = $("sample").disabled = false;showStorage();}}16 unmodified linesif (f) analyze(f);});$("sample").addEventListener("click", () => analyze(makeSample()));$("stop").addEventListener("click", () => {stopped = true;$("stop").hidden = true;47 unmodified lines48495051525354552 unmodified lines585960616263646 unmodified lines7172737475767724 unmodified lines102103104105106107108109110111129 unmodified lines241242243244245246247248249250251252253254255102 unmodified lines35835936036136236336416 unmodified lines38138238338438538638738838939039139239347 unmodified linestry { localStorage.setItem(manifestKey(m), JSON.stringify([...fileUrls[m]])); } catch {}};const storedModels = new Set();async function showStorage() {const parts = [];let total = 0;2 unmodified linesif (!urls.length) continue;const s = await cacheStatus(urls);total = s.bytes;if (s.complete) storedModels.add(m); else storedModels.delete(m);parts.push(`${MODEL_NAMES[m]} ${s.complete ? "saved" : "partly saved (will finish downloading next time)"}`);}if (!total) { $("storage").hidden = true; return; }6 unmodified linesawait call("unload");try { await clearCache(); } catch {}for (const m of ["florence", "qwen"]) { try { localStorage.removeItem(manifestKey(m)); } catch {} }storedModels.clear();$("storage-text").textContent = "Downloaded models removed from this device.";$("clear").hidden = true;});24 unmodified lineslisteners.add((m) => {if (m.type === "file" && fileUrls[m.model]) fileUrls[m.model].add(`https://huggingface.co/${m.repo}/resolve/main/${m.file}`);if (m.type === "progress") {const mb = `${(m.loaded / 1e6).toFixed(0)} / ${(m.total / 1e6).toFixed(0)} MB`;bar(m.loaded / m.total, storedModels.has(m.model)? `Loading ${MODEL_NAMES[m.model]} from this device… ${mb}`: `Downloading ${MODEL_NAMES[m.model]}… ${mb} (only the first time)`);}if (m.type === "status" && m.status === "loading") bar(null, `Loading ${MODEL_NAMES[m.model]}…`);if (m.type === "status" && m.status === "ready") {129 unmodified lineslet running = false;let stopped = false;const setInputs = (on) => {for (const b of [$("file"), $("sample"), ...document.querySelectorAll("button.demo")]) b.disabled = !on;};async function analyze(file) {if (running) return;running = true;stopped = false;setInputs(false);const useOcr = $("use-ocr").checked;const useVlm = $("use-vlm").checked && !$("use-vlm").disabled;const S = {102 unmodified lines} finally {$("stop").hidden = true;running = false;setInputs(true);showStorage();}}16 unmodified linesif (f) analyze(f);});$("sample").addEventListener("click", () => analyze(makeSample()));// Real demo images in demo/ (see demo/README.md for where they come from).for (const b of document.querySelectorAll("button.demo")) {b.addEventListener("click", async () => {const blob = await (await fetch(new URL(b.dataset.src, import.meta.url))).blob();analyze(new File([blob], b.dataset.src.split("/").pop(), { type: blob.type }));});}$("stop").addEventListener("click", () => {stopped = true;$("stop").hidden = true;
12345678910111213# Demo images
- `alpine-lake-chatgpt.png` and `neon-waves-chatgpt.png`: images generated with ChatGPT. Their C2PA content credentials declare them AI-generated by the OpenAI Media Service API and record an invisible watermark.
- `ribbons-c2pa.jpg`: a real photo carrying C2PA content credentials that record it being opened and colour-adjusted. From the [c2pa-rs](https://github.com/contentauth/c2pa-rs) test fixtures (`CA.jpg`), © Adobe and C2PA contributors, licensed MIT / Apache-2.0.
The "sample with hidden content" image is generated in the browser by[`lib/sample.js`](../lib/sample.js), so it isn't stored here.22 unmodified lines2324252627282922 unmodified lines<span class="drop-sub">PNG keeps hidden data intact. JPEG and WebP compression destroy most of it.</span></label><div class="row-actions"><button type="button" class="secondary" id="sample">Try a sample with hidden content</button></div><div class="options">22 unmodified lines232425262728293031323322 unmodified lines<span class="drop-sub">PNG keeps hidden data intact. JPEG and WebP compression destroy most of it.</span></label><div class="row-actions"><span class="demo-label">Or try a demo:</span><button type="button" class="secondary" id="sample">Planted hidden content</button><button type="button" class="secondary demo" data-src="demo/alpine-lake-chatgpt.png">ChatGPT image: alpine lake</button><button type="button" class="secondary demo" data-src="demo/neon-waves-chatgpt.png">ChatGPT image: neon waves</button><button type="button" class="secondary demo" data-src="demo/ribbons-c2pa.jpg">Edited photo with credentials</button></div><div class="options">
46 unmodified lines474849505152539 unmodified lines6364656667686946 unmodified lines// Hiding data in the lowest bit of a flat patch turns v into {v, v^1}: an// "aligned" pair (2k, 2k+1). Dithering and sensor noise produce aligned and// misaligned pairs (2k-1, 2k) about equally often. A strong excess of aligned// pairs is the fingerprint of LSB embedding.function flatBlockNoise(img, block = 8) {const { width, height, data } = img;let constant = 0, aligned = 0, misaligned = 0;9 unmodified lines}}if (hi === lo) constant++;else if (hi - lo === 1) (lo % 2 === 0 ? aligned++ : misaligned++);}}}46 unmodified lines47484950515253549 unmodified lines6465666768697071727346 unmodified lines// Hiding data in the lowest bit of a flat patch turns v into {v, v^1}: an// "aligned" pair (2k, 2k+1). Dithering and sensor noise produce aligned and// misaligned pairs (2k-1, 2k) about equally often. A strong excess of aligned// pairs is the fingerprint of LSB embedding. Found on a real image: noise in// near-black areas clips to {0, 1}, so blocks touching 0 or 255 are ignored.function flatBlockNoise(img, block = 8) {const { width, height, data } = img;let constant = 0, aligned = 0, misaligned = 0;9 unmodified lines}}if (hi === lo) constant++;// Skip blocks touching 0 or 255: noise clipped at pure black (or// white) can only flicker between 0 and 1 (254 and 255), which looks// "aligned" without any hidden data.else if (hi - lo === 1 && lo > 0 && hi < 255) (lo % 2 === 0 ? aligned++ : misaligned++);}}}
132 unmodified lines13313413513613713828 unmodified lines16716816917017117227 unmodified lines20020120220320420520619 unmodified lines2262272282292302312322332345 unmodified lines24024124224324424524619 unmodified lines266267268269270271272273274275132 unmodified lines}}// ---------------------------------------------------------------------------// PNG28 unmodified linesObject.assign(r.fields, parseExif(data));} else if (type === "caBX") {r.provenance = "C2PA content credentials present";} else if (type === "iDOT") {r.fields["Saved by"] = "macOS (Apple iDOT block, typical of screenshots)";} else if (!PNG_KNOWN.has(type)) {27 unmodified linesr.structure.push(`${name} (${len} B)`);if (marker === 0xe1 && latin1(data, 0, 6) === "Exif\0\0") Object.assign(r.fields, parseExif(data.subarray(6)));else if (marker === 0xe1 && latin1(data, 0, 28) === "http://ns.adobe.com/xap/1.0/") Object.assign(r.fields, summarizeXmp(utf8(data)));else if (marker === 0xeb && latin1(data, 0, 2) === "JP") r.provenance = "C2PA content credentials present (JUMBF)";else if (marker === 0xfe) r.text.push({ key: "Comment", value: utf8(data) });else if (marker >= 0xe0 && marker <= 0xef && ![0xe0, 0xe1, 0xe2, 0xed, 0xee, 0xeb].includes(marker)) {r.unknownChunks.push({ type: name, length: len, strings: strings(data, 6, 5) });19 unmodified linesconst type = latin1(b, i, i + 4), len = u32le(b, i + 4);const data = b.subarray(i + 8, i + 8 + len);r.structure.push(`${type.trim()} (${len} B)`);if (type === "EXIF") Object.assign(r.fields, parseExif(latin1(data, 0, 6) === "Exif\0\0" ? data.subarray(6) : data));else if (type === "XMP ") Object.assign(r.fields, summarizeXmp(utf8(data)));else if (!["VP8 ", "VP8L", "VP8X", "ALPH", "ANIM", "ANMF", "ICCP"].includes(type)) {r.unknownChunks.push({ type: type.trim(), length: len, strings: strings(data, 6, 5) });}i += 8 + len + (len & 1);5 unmodified linesexport async function analyzeContainer(bytes) {const format = detectFormat(bytes);const r = { format, structure: [], fields: {}, text: [], unknownChunks: [], provenance: null, trailing: null };try {if (format === "png") await parsePng(bytes, r);else if (format === "jpeg") await parseJpeg(bytes, r);19 unmodified linestext: c.strings.length ? c.strings.join("\n") : undefined,});}for (const t of r.text) {findings.push({ severity: "low", title: `Embedded text: ${t.key || "(no key)"}`, text: t.value.slice(0, 2000) });}if (r.provenance) findings.push({ severity: "info", title: r.provenance, detail: "The file carries signed provenance data (who made or edited it)." });if (r.fields["AI-generated"]) findings.push({ severity: "info", title: "Metadata says the image is AI-generated" });if (r.fields["GPS location"]) findings.push({ severity: "info", title: "Metadata includes a GPS location" });r.findings = findings;132 unmodified lines13313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522628 unmodified lines25525625725825926026127 unmodified lines28929029129229329429529629729819 unmodified lines3183193203213223233243253263275 unmodified lines33333433533633733833919 unmodified lines359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409132 unmodified lines}}// ---------------------------------------------------------------------------// C2PA content credentials. The manifest is CBOR inside JUMBF boxes; instead// of a full parser, find known keys and read the CBOR text that follows.// The signature is NOT verified here.function cborText(b, i) {const h = b[i];let len, start;if (h >= 0x60 && h <= 0x77) { len = h - 0x60; start = i + 1; }else if (h === 0x78) { len = b[i + 1]; start = i + 2; }else if (h === 0x79) { len = u16be(b, i + 1); start = i + 3; }else return null;if (start + len > b.length) return null;return utf8(b.subarray(start, start + len));}function* keyPositions(b, key) {const k = new TextEncoder().encode(key);const header = k.length < 24 ? [0x60 + k.length] : [0x78, k.length];const pat = [...header, ...k];outer: for (let i = 0; i + pat.length <= b.length; i++) {for (let j = 0; j < pat.length; j++) if (b[i + j] !== pat[j]) continue outer;yield i + pat.length; // position of the value}}// Text value of `key`, or of a "name" key shortly after it (for values that// are maps such as softwareAgent or claim_generator_info).function valuesOf(b, key) {const out = [];for (const at of keyPositions(b, key)) {let v = cborText(b, at);if (v === null) {const window = b.subarray(at, Math.min(b.length, at + 64));for (const nameAt of keyPositions(window, "name")) { v = cborText(window, nameAt); break; }}if (v) out.push(v);}return [...new Set(out)];}const SOURCE_TYPES = {trainedAlgorithmicMedia: "AI-generated",compositeWithTrainedAlgorithmicMedia: "edited or combined with AI",algorithmicallyEnhanced: "algorithmically enhanced",algorithmicMedia: "computer-generated (not AI)",digitalCapture: "camera capture",computationalCapture: "camera capture with computational processing",digitalArt: "digital art",composite: "composite of several images",screenCapture: "screenshot",};const ACTIONS = {created: "created",opened: "opened",edited: "edited",converted: "converted to another format",color_adjustments: "colour adjusted",cropped: "cropped",resized: "resized",placed: "combined with another image",watermarked: "invisible watermark added","watermarked.bound": "invisible watermark added","watermarked.unbound": "invisible watermark added",};export function readC2pa(chunks) {if (!chunks.length) return null;const total = chunks.reduce((n, c) => n + c.length, 0);const b = new Uint8Array(total);let o = 0;for (const c of chunks) { b.set(c, o); o += c.length; }const generators = [...valuesOf(b, "claim_generator"), ...valuesOf(b, "claim_generator_info")];const sources = valuesOf(b, "digitalSourceType").map((u) => u.split("/").pop());const actions = valuesOf(b, "action").filter((a) => a.startsWith("c2pa.")).map((a) => a.slice(5));const agents = valuesOf(b, "softwareAgent");const ai = sources.some((t) => t === "trainedAlgorithmicMedia" || t === "compositeWithTrainedAlgorithmicMedia");return {generators: [...new Set(generators)].slice(0, 4),sources: [...new Set(sources)],sourceLabels: [...new Set(sources.map((t) => SOURCE_TYPES[t] ?? t))],actions: [...new Set(actions)],agents: agents.slice(0, 4),ai,};}// ---------------------------------------------------------------------------// PNG28 unmodified linesObject.assign(r.fields, parseExif(data));} else if (type === "caBX") {r.provenance = "C2PA content credentials present";r.c2paChunks.push(data);} else if (type === "iDOT") {r.fields["Saved by"] = "macOS (Apple iDOT block, typical of screenshots)";} else if (!PNG_KNOWN.has(type)) {27 unmodified linesr.structure.push(`${name} (${len} B)`);if (marker === 0xe1 && latin1(data, 0, 6) === "Exif\0\0") Object.assign(r.fields, parseExif(data.subarray(6)));else if (marker === 0xe1 && latin1(data, 0, 28) === "http://ns.adobe.com/xap/1.0/") Object.assign(r.fields, summarizeXmp(utf8(data)));else if (marker === 0xeb && latin1(data, 0, 2) === "JP") {r.provenance = "C2PA content credentials present (JUMBF)";r.c2paChunks.push(data);}else if (marker === 0xfe) r.text.push({ key: "Comment", value: utf8(data) });else if (marker >= 0xe0 && marker <= 0xef && ![0xe0, 0xe1, 0xe2, 0xed, 0xee, 0xeb].includes(marker)) {r.unknownChunks.push({ type: name, length: len, strings: strings(data, 6, 5) });19 unmodified linesconst type = latin1(b, i, i + 4), len = u32le(b, i + 4);const data = b.subarray(i + 8, i + 8 + len);r.structure.push(`${type.trim()} (${len} B)`);if (type === "C2PA") { r.provenance = "C2PA content credentials present"; r.c2paChunks.push(data); }else if (type === "EXIF") Object.assign(r.fields, parseExif(latin1(data, 0, 6) === "Exif\0\0" ? data.subarray(6) : data));else if (type === "XMP ") Object.assign(r.fields, summarizeXmp(utf8(data)));else if (!["VP8 ", "VP8L", "VP8X", "ALPH", "ANIM", "ANMF", "ICCP", "C2PA"].includes(type)) {r.unknownChunks.push({ type: type.trim(), length: len, strings: strings(data, 6, 5) });}i += 8 + len + (len & 1);5 unmodified linesexport async function analyzeContainer(bytes) {const format = detectFormat(bytes);const r = { format, structure: [], fields: {}, text: [], unknownChunks: [], provenance: null, trailing: null, c2paChunks: [] };try {if (format === "png") await parsePng(bytes, r);else if (format === "jpeg") await parseJpeg(bytes, r);19 unmodified linestext: c.strings.length ? c.strings.join("\n") : undefined,});}// PNG/JPEG text fields: AI-generation settings, ordinary metadata copied// in by converters (ImageMagick writes dozens of exif:* fields), and the// rest, which may be a message.const STANDARD = /^(date:|exif:|icc:|xmp:|png:|tiff:|photoshop:|8bim:|jpeg:)|^(Software|Creation Time|Author|Title|Copyright|Source|Description|Disclaimer|Warning|XML:com\.adobe\.xmp)$/i;let standard = 0;for (const t of r.text) {const v = t.value ?? "";if (t.key === "parameters" && /Steps:\s*\d+/.test(v)) {findings.push({ severity: "medium", title: "Stable Diffusion generation prompt and settings are embedded", text: v.slice(0, 2000) });} else if ((t.key === "prompt" || t.key === "workflow") && /class_type|"nodes"/.test(v)) {findings.push({ severity: "medium", title: `ComfyUI ${t.key} is embedded (the image was generated with AI)`, text: v.slice(0, 600) });} else if (STANDARD.test(t.key)) {standard++;} else {findings.push({ severity: "low", title: `Embedded text: ${t.key || "(no key)"}`, text: v.slice(0, 2000) });}}if (standard) findings.push({ severity: "info", title: `${standard} ordinary metadata field${standard === 1 ? "" : "s"} stored as text`, detail: "Camera, date or colour-profile details copied in by the software that saved the file." });r.c2pa = readC2pa(r.c2paChunks);delete r.c2paChunks;if (r.c2pa) {const c = r.c2pa;const made = [...c.agents, ...c.generators].filter((v, i, a) => a.indexOf(v) === i);const parts = [];if (c.sourceLabels.length) parts.push(`Declared source: ${c.sourceLabels.join(", ")}.`);if (made.length) parts.push(`Made or signed with: ${made.join("; ")}.`);if (c.actions.length) parts.push(`Recorded steps: ${[...new Set(c.actions.map((a) => ACTIONS[a] ?? a))].join(", ")}.`);parts.push("The signature isn't checked here; verify it at contentcredentials.org/verify.");findings.push({severity: c.ai ? "medium" : "info",title: c.ai ? "Content credentials say this image was made with AI" : "Content credentials (C2PA) present",detail: parts.join(" "),});if (c.sourceLabels.length) r.fields["Declared source (C2PA)"] = c.sourceLabels.join(", ");if (made.length) r.fields["Made with (C2PA)"] = made.join("; ");if (c.actions.some((a) => a.startsWith("watermarked"))) {findings.push({severity: "medium",title: "Content credentials record an invisible watermark",detail: "The maker says it embedded a watermark that can't be seen. This tool can't decode those (they need the maker's detector), but its spectrum and lowest-bit checks may show traces.",});}} else if (r.provenance) {findings.push({ severity: "info", title: r.provenance, detail: "The file carries signed provenance data (who made or edited it)." });}if (r.fields["AI-generated"]) findings.push({ severity: "info", title: "Metadata says the image is AI-generated" });if (r.fields["GPS location"]) findings.push({ severity: "info", title: "Metadata includes a GPS location" });r.findings = findings;
60 unmodified lines6162636465666760 unmodified lines// Florence-2 sometimes "reads" texture or image edges as strings like// "0.0.1.0-0.00-0-1.00.0", often with a flat, zero-height box.export function isOcrNoise(text, box) {if (box.x1 - box.x0 < 6 || box.y1 - box.y0 < 5) return true;const hasLetters = /\p{L}/u.test(text);const digits = new Set(text.match(/\p{N}/gu) ?? []);if (!hasLetters && digits.size <= 2 && text.length > 5) return true;60 unmodified lines61626364656667686970717260 unmodified lines// Florence-2 sometimes "reads" texture or image edges as strings like// "0.0.1.0-0.00-0-1.00.0", often with a flat, zero-height box.export function isOcrNoise(text, box) {const w = box.x1 - box.x0, h = box.y1 - box.y0;if (w < 6 || h < 5) return true;// A line of several characters is wider than it is tall. Florence-2 can// "read" a phrase into a tall, narrow strip of scenery (a tree, a// reflection); those boxes are much taller than wide.if ((text.match(/[\p{L}\p{N}]/gu) ?? []).length >= 4 && h > w * 1.5) return true;const hasLetters = /\p{L}/u.test(text);const digits = new Set(text.match(/\p{N}/gu) ?? []);if (!hasLetters && digits.size <= 2 && text.length > 5) return true;
62 unmodified lines6364656667686962 unmodified lines.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }.drop-main { font-weight: 600; }.drop-sub { color: var(--muted); font-size: 13px; }.row-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }button {font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;62 unmodified lines636465666768697062 unmodified lines.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }.drop-main { font-weight: 600; }.drop-sub { color: var(--muted); font-size: 13px; }.row-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }.demo-label { color: var(--muted); font-size: 14px; margin-right: 4px; }button {font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
293 unmodified lines294295296297293 unmodified linesassert.ok(!isOcrNoise("Harbour at dawn", { x0: 120, y0: 120, x1: 600, y1: 190 }));assert.ok(!isOcrNoise("2024-03-15", { x0: 10, y0: 10, x1: 200, y1: 40 }));assert.ok(!isOcrNoise("MEET AT NOON", { x0: 170, y0: 800, x1: 650, y1: 860 }));});293 unmodified lines294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346293 unmodified linesassert.ok(!isOcrNoise("Harbour at dawn", { x0: 120, y0: 120, x1: 600, y1: 190 }));assert.ok(!isOcrNoise("2024-03-15", { x0: 10, y0: 10, x1: 200, y1: 40 }));assert.ok(!isOcrNoise("MEET AT NOON", { x0: 170, y0: 800, x1: 650, y1: 860 }));// From a real run: a phrase "read" into a full-height strip of scenery.assert.ok(isOcrNoise("COURTESY OF THE WATER", { x0: 0, y0: 0, x1: 95, y1: 768 }));});import { readC2pa } from "../lib/metadata.js";// Minimal CBOR text string, as C2PA manifests store them.const cborText = (s) => {const b = new TextEncoder().encode(s);return [...(b.length < 24 ? [0x60 + b.length] : [0x78, b.length]), ...b];};test("C2PA: AI-generated declaration, generator and actions are read", () => {const bytes = new Uint8Array([0xa2, ...cborText("claim_generator"), ...cborText("ExampleAI Image Studio/2.1"),...cborText("actions"), 0x81, 0xa3,...cborText("action"), ...cborText("c2pa.created"),...cborText("digitalSourceType"), ...cborText("http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia"),...cborText("softwareAgent"), 0xa1, ...cborText("name"), ...cborText("ExampleAI Model 3"),]);const c = readC2pa([bytes]);assert.equal(c.ai, true);assert.deepEqual(c.sourceLabels, ["AI-generated"]);assert.deepEqual(c.actions, ["created"]);assert.deepEqual(c.agents, ["ExampleAI Model 3"]);assert.ok(c.generators.includes("ExampleAI Image Studio/2.1"));});test("PNG text: SD prompt flagged, standard metadata grouped", async () => {const png = encode({ ...photo(), channels: 4, depth: 8, text: {parameters: "a lighthouse at dawn\\nSteps: 30, Sampler: Euler a, CFG scale: 7","exif:Make": "Canon", "exif:Model": "EOS", "date:create": "2024-01-01",} });const r = await analyzeContainer(png);const t = r.findings.map((f) => f.title);assert.ok(t.includes("Stable Diffusion generation prompt and settings are embedded"), t.join(";"));assert.ok(t.includes("3 ordinary metadata fields stored as text"), t.join(";"));assert.ok(!t.some((x) => x.startsWith("Embedded text: exif")));});test("near-black noise (clipped at 0) is not hidden data", () => {// Like a dark AI-generated background: noise around 0.5 clips to {0, 1}.const r = rng(11);const data = new Uint8ClampedArray(W * H * 4);for (let i = 0; i < data.length; i += 4) {data[i] = r() < 0.5 ? 0 : 1; data[i + 1] = r() < 0.5 ? 0 : 1; data[i + 2] = 20 + (r() < 0.5 ? 0 : 1) * 0;data[i + 3] = 255;}assert.deepEqual(titles(analyzeLsb({ width: W, height: H, data })), []);});
.gitattributes+3
.gitignore+1
README.md+10-1
app.js+20-3
demo/README.mdAdded+13
demo/alpine-lake-chatgpt.pngAdded

Large File Pointer Details
- SHA256: 81097747bee4c85ce17dd08bf234567408a97f869bd8d3843d71082f6da9fc3d
- Pointer size: 132 Bytes
- Size of remote file: 2.89 MB
demo/neon-waves-chatgpt.pngAdded

Large File Pointer Details
- SHA256: 29826e02f9849ba96ff8c4689a4409262d6f6ae0471372ff3e33fdc2d3e2e7f9
- Pointer size: 132 Bytes
- Size of remote file: 2.61 MB
demo/ribbons-c2pa.jpgAdded

Large File Pointer Details
- SHA256: e71bff58fc57640803e6e65f7534e2fb0c2f99018c85276cc14b30f04427cc76
- Pointer size: 131 Bytes
- Size of remote file: 167 kB
index.html+5-1
lib/forensics.js+6-2
lib/metadata.js+140-6
lib/pipeline.js+6-1
style.css+2-1
tests/forensics.test.mjs+49