@fungi.computer/darkroom 0.5.7 → 0.5.9
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The admitted Computer file read and generated output share this launch bound. */
|
|
2
2
|
export declare const maximumPrintDownloadBytes: number;
|
|
3
3
|
/** Why a lossless public image export was refused. */
|
|
4
|
-
export type ProvenanceExportFailure = "too-large" | "
|
|
4
|
+
export type ProvenanceExportFailure = "too-large" | "invalid-image" | "unsupported-format";
|
|
5
5
|
/** A refusal to export unsafe, unsupported or oversized image bytes. */
|
|
6
6
|
export declare class ProvenanceExportError extends Error {
|
|
7
7
|
/** Bounded refusal reason. */
|
|
@@ -3,6 +3,7 @@ import ExifReader from "exifreader";
|
|
|
3
3
|
import { createRiffContainer, parseRiff } from "@fungi.computer/ts-webp";
|
|
4
4
|
import { replacePngXmp } from "./provenance-png.js";
|
|
5
5
|
import { replaceJpegXmp } from "./provenance-jpeg.js";
|
|
6
|
+
import { hasC2paSignature } from "./provenance-signed.js";
|
|
6
7
|
import { publicProvenancePacket } from "./provenance-xmp.js";
|
|
7
8
|
/** The admitted Computer file read and generated output share this launch bound. */
|
|
8
9
|
export const maximumPrintDownloadBytes = 32 * 1024 * 1024;
|
|
@@ -53,11 +54,10 @@ function replaceWebpXmp(bytes, xmp) {
|
|
|
53
54
|
export async function stripPrivateProvenance(bytes) {
|
|
54
55
|
if (bytes.length > maximumPrintDownloadBytes)
|
|
55
56
|
throw new ProvenanceExportError("too-large");
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
throw new ProvenanceExportError("signed-image");
|
|
57
|
+
// Embed never writes Prints XMP into a C2PA-signed image, so a signed file
|
|
58
|
+
// holds nothing private to remove. Export its stored bytes unchanged, which
|
|
59
|
+
// also keeps the provider's Content Credentials valid.
|
|
60
|
+
const signed = hasC2paSignature(bytes);
|
|
61
61
|
try {
|
|
62
62
|
const metadata = await ExifReader.loadView(new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), {
|
|
63
63
|
expanded: true,
|
|
@@ -76,7 +76,7 @@ export async function stripPrivateProvenance(bytes) {
|
|
|
76
76
|
type: `image/${format}`,
|
|
77
77
|
extension: format === "jpeg" ? "jpg" : format,
|
|
78
78
|
};
|
|
79
|
-
if (format === "gif" && !metadata.xmp)
|
|
79
|
+
if (signed || (format === "gif" && !metadata.xmp))
|
|
80
80
|
return { bytes, ...mime };
|
|
81
81
|
const packet = publicProvenancePacket(metadata.xmp?._raw ?? metadata.pngText?.["XML:com.adobe.xmp"]?.value);
|
|
82
82
|
const output = format === "png"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Conservative C2PA detection shared by embed and export. This is not
|
|
2
|
+
* signature validation: any C2PA marker means the file is provider-signed and
|
|
3
|
+
* Prints leaves its bytes untouched. */
|
|
4
|
+
export function hasC2paSignature(bytes) {
|
|
5
|
+
const text = new TextDecoder("latin1").decode(bytes);
|
|
6
|
+
return text.includes("c2pa") || text.includes("caBX");
|
|
7
|
+
}
|
package/dist/provenance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Buffer as NodeBuffer } from "node:buffer";
|
|
2
2
|
import { replacePngXmp } from "./provenance-png.js";
|
|
3
3
|
import { replaceJpegXmp } from "./provenance-jpeg.js";
|
|
4
|
+
import { hasC2paSignature } from "./provenance-signed.js";
|
|
4
5
|
import { reportCatchFailure } from "./failure.js";
|
|
5
6
|
// The XMP builder and WebP muxer load on the first embed: a Worker that hosts
|
|
6
7
|
// this module never pays to evaluate them at startup.
|
|
@@ -39,8 +40,7 @@ async function embedWebp(bytes, xmp) {
|
|
|
39
40
|
export async function embedProvenance(bytes, format, facts) {
|
|
40
41
|
if (format === "gif" || format === "mp4")
|
|
41
42
|
return { bytes, embedded: false, reason: "unsupported-format" };
|
|
42
|
-
if (
|
|
43
|
-
NodeBuffer.from(bytes).includes("caBX"))
|
|
43
|
+
if (hasC2paSignature(bytes))
|
|
44
44
|
return { bytes, embedded: false, reason: "signed-image" };
|
|
45
45
|
try {
|
|
46
46
|
const xmp = await packet(facts);
|
|
@@ -73,7 +73,7 @@ Bounded refusal reason.
|
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
75
|
type ProvenanceExportFailure =
|
|
76
|
-
"too-large" | "
|
|
76
|
+
"too-large" | "invalid-image" | "unsupported-format";
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
Why a lossless public image export was refused.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/darkroom",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Media generation, durable output retention and provenance with host-owned authority and billing",
|
|
6
6
|
"type": "module",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"exifreader": "4.46.0",
|
|
60
60
|
"@fungi.computer/ts-webp": "0.1.6",
|
|
61
61
|
"@xmldom/xmldom": "0.9.12",
|
|
62
|
-
"@fungi.computer/agar": "0.
|
|
62
|
+
"@fungi.computer/agar": "0.10.0",
|
|
63
63
|
"@fungi.computer/capnweb": "0.12.0-fungi.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|