@contentauth/c2pa-node 0.5.4 → 0.6.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/Cargo.toml +2 -1
- package/README.md +145 -7
- package/dist/Builder.js +63 -80
- package/dist/Builder.spec.js +251 -202
- package/dist/IdentityAssertion.js +8 -18
- package/dist/IdentityAssertion.spec.js +28 -35
- package/dist/Reader.js +13 -28
- package/dist/Reader.spec.js +53 -64
- package/dist/Settings.js +16 -29
- package/dist/Settings.spec.js +47 -62
- package/dist/Signer.js +4 -13
- package/dist/Signer.spec.js +35 -43
- package/dist/Trustmark.js +8 -22
- package/dist/Trustmark.spec.js +50 -65
- package/dist/binary.js +2 -1
- package/dist/index.node +0 -0
- package/dist/types/Builder.d.ts +2 -1
- package/dist/types/types.d.ts +11 -1
- package/package.json +54 -51
- package/scripts/postinstall.cjs +18 -1
- package/src/lib.rs +4 -0
- package/src/neon_builder.rs +30 -6
- package/src/neon_reader.rs +4 -2
- package/src/neon_trustmark.rs +74 -30
- package/src/utils.rs +8 -6
- package/Cargo.lock +0 -5050
- package/LICENSE +0 -21
package/dist/Trustmark.spec.js
CHANGED
|
@@ -3,15 +3,6 @@
|
|
|
3
3
|
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
4
4
|
// or the MIT license (http://opensource.org/licenses/MIT),
|
|
5
5
|
// at your option.
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
6
|
// Unless required by applicable law or agreed to in writing,
|
|
16
7
|
// this software is distributed on an "AS IS" BASIS, WITHOUT
|
|
17
8
|
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
|
|
@@ -24,19 +15,17 @@ import sharp from "sharp";
|
|
|
24
15
|
import { Trustmark } from "./Trustmark.js";
|
|
25
16
|
const tempDir = path.join(__dirname, "..", "tmp");
|
|
26
17
|
// Helper function to convert raw RGB pixel data to JPEG format
|
|
27
|
-
function rawRgbToJpeg(rawRgbData, width, height) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
// Convert to JPEG format
|
|
38
|
-
return yield image.jpeg().toBuffer();
|
|
18
|
+
async function rawRgbToJpeg(rawRgbData, width, height) {
|
|
19
|
+
// Create a sharp image from raw RGB data
|
|
20
|
+
const image = sharp(rawRgbData, {
|
|
21
|
+
raw: {
|
|
22
|
+
width,
|
|
23
|
+
height,
|
|
24
|
+
channels: 3, // RGB
|
|
25
|
+
},
|
|
39
26
|
});
|
|
27
|
+
// Convert to JPEG format
|
|
28
|
+
return await image.jpeg().toBuffer();
|
|
40
29
|
}
|
|
41
30
|
describe("Trustmark", () => {
|
|
42
31
|
let trustmark;
|
|
@@ -48,99 +37,95 @@ describe("Trustmark", () => {
|
|
|
48
37
|
version: "BCH_3", // Tolerates 3 bit flips
|
|
49
38
|
modelPath: path.join(tempDir, "trustmark_models"), // Use temporary directory for model path
|
|
50
39
|
};
|
|
51
|
-
beforeAll(() =>
|
|
52
|
-
|
|
40
|
+
beforeAll(async () => {
|
|
41
|
+
await fs.ensureDir(tempDir);
|
|
53
42
|
// Use an actual test image from fixtures directory
|
|
54
|
-
testImage =
|
|
43
|
+
testImage = await fs.readFile("./tests/fixtures/A.jpg");
|
|
55
44
|
// Get image dimensions for converting raw pixel data
|
|
56
|
-
const imageInfo =
|
|
45
|
+
const imageInfo = await sharp(testImage).metadata();
|
|
57
46
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
47
|
testImageWidth = imageInfo.width;
|
|
59
48
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
49
|
testImageHeight = imageInfo.height;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Note: In a real test environment, you would need a valid model file
|
|
64
|
-
// For now, we'll mock the trustmark creation or handle the case where model doesn't exist
|
|
65
|
-
trustmark = yield Trustmark.newTrustmark(trustmarkConfig);
|
|
66
|
-
}));
|
|
50
|
+
trustmark = await Trustmark.newTrustmark(trustmarkConfig);
|
|
51
|
+
});
|
|
67
52
|
describe("newTrustmark", () => {
|
|
68
|
-
it("should create a new trustmark instance with valid config", () =>
|
|
53
|
+
it("should create a new trustmark instance with valid config", async () => {
|
|
69
54
|
// This test will be skipped if the model file doesn't exist
|
|
70
55
|
expect(trustmark).toBeDefined();
|
|
71
56
|
expect(typeof trustmark.encode).toBe("function");
|
|
72
57
|
expect(typeof trustmark.decode).toBe("function");
|
|
73
|
-
})
|
|
74
|
-
it("should throw error with invalid config", () =>
|
|
58
|
+
});
|
|
59
|
+
it("should throw error with invalid config", async () => {
|
|
75
60
|
const invalidConfig = {
|
|
76
61
|
variant: "X", // Invalid variant
|
|
77
62
|
version: "BCH_3", // Valid version
|
|
78
63
|
};
|
|
79
|
-
|
|
80
|
-
})
|
|
64
|
+
await expect(Trustmark.newTrustmark(invalidConfig)).rejects.toThrow("Watermark configuration error: invalid variant");
|
|
65
|
+
});
|
|
81
66
|
});
|
|
82
67
|
describe("encode", () => {
|
|
83
|
-
it("should encode a watermark into an image with default watermark", () =>
|
|
68
|
+
it("should encode a watermark into an image with default watermark", async () => {
|
|
84
69
|
const strength = 0.9;
|
|
85
|
-
const encodedImage =
|
|
70
|
+
const encodedImage = await trustmark.encode(testImage, strength);
|
|
86
71
|
expect(encodedImage).toBeDefined();
|
|
87
72
|
expect(Buffer.isBuffer(encodedImage)).toBe(true);
|
|
88
73
|
expect(encodedImage.length).toBeGreaterThan(0);
|
|
89
74
|
// The encoded image should be different from the original
|
|
90
75
|
expect(encodedImage).not.toEqual(testImage);
|
|
91
|
-
})
|
|
92
|
-
it("should encode a watermark into an image with custom watermark", () =>
|
|
76
|
+
});
|
|
77
|
+
it("should encode a watermark into an image with custom watermark", async () => {
|
|
93
78
|
const strength = 0.95;
|
|
94
79
|
const customWatermark = "0101000011001";
|
|
95
|
-
const encodedImage =
|
|
80
|
+
const encodedImage = await trustmark.encode(testImage, strength, customWatermark);
|
|
96
81
|
expect(encodedImage).toBeDefined();
|
|
97
82
|
expect(Buffer.isBuffer(encodedImage)).toBe(true);
|
|
98
83
|
expect(encodedImage.length).toBeGreaterThan(0);
|
|
99
|
-
})
|
|
100
|
-
it("should throw error with invalid strength values", () =>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
})
|
|
104
|
-
it("should throw error with empty image buffer", () =>
|
|
84
|
+
});
|
|
85
|
+
it("should throw error with invalid strength values", async () => {
|
|
86
|
+
await expect(trustmark.encode(testImage, -0.1)).rejects.toThrow("Watermark configuration error: strength must be between 0.0 and 1.0");
|
|
87
|
+
await expect(trustmark.encode(testImage, 1.1)).rejects.toThrow("Watermark configuration error: strength must be between 0.0 and 1.0");
|
|
88
|
+
});
|
|
89
|
+
it("should throw error with empty image buffer", async () => {
|
|
105
90
|
const emptyBuffer = Buffer.alloc(0);
|
|
106
|
-
|
|
107
|
-
})
|
|
91
|
+
await expect(trustmark.encode(emptyBuffer, 0.5)).rejects.toThrow("The image format could not be determined");
|
|
92
|
+
});
|
|
108
93
|
});
|
|
109
94
|
describe("decode", () => {
|
|
110
|
-
it("should decode a watermark from an encoded image", () =>
|
|
95
|
+
it("should decode a watermark from an encoded image", async () => {
|
|
111
96
|
const strength = 0.8;
|
|
112
97
|
const customWatermark = "0101000011001";
|
|
113
98
|
// First encode a watermark
|
|
114
|
-
const rawPixelData =
|
|
99
|
+
const rawPixelData = await trustmark.encode(testImage, strength, customWatermark);
|
|
115
100
|
// Convert raw pixel data to JPEG format for decoding
|
|
116
|
-
const encodedImage =
|
|
101
|
+
const encodedImage = await rawRgbToJpeg(rawPixelData, testImageWidth, testImageHeight);
|
|
117
102
|
// Then decode it
|
|
118
|
-
const decodedWatermark =
|
|
103
|
+
const decodedWatermark = await trustmark.decode(encodedImage);
|
|
119
104
|
expect(decodedWatermark).toBeDefined();
|
|
120
105
|
expect(typeof decodedWatermark).toBe("string");
|
|
121
106
|
expect(decodedWatermark.length).toBeGreaterThan(0);
|
|
122
107
|
// The decoded watermark should match the original
|
|
123
108
|
expect(decodedWatermark.startsWith(customWatermark)).toBeTruthy();
|
|
124
|
-
})
|
|
125
|
-
it("should decode watermark from image with generated watermark", () =>
|
|
109
|
+
});
|
|
110
|
+
it("should decode watermark from image with generated watermark", async () => {
|
|
126
111
|
const strength = 0.75;
|
|
127
112
|
// Encode with default watermark
|
|
128
|
-
const rawPixelData =
|
|
113
|
+
const rawPixelData = await trustmark.encode(testImage, strength);
|
|
129
114
|
// Convert raw pixel data to JPEG format for decoding
|
|
130
|
-
const encodedImage =
|
|
115
|
+
const encodedImage = await rawRgbToJpeg(rawPixelData, testImageWidth, testImageHeight);
|
|
131
116
|
// Decode the watermark
|
|
132
|
-
const decodedWatermark =
|
|
117
|
+
const decodedWatermark = await trustmark.decode(encodedImage);
|
|
133
118
|
expect(decodedWatermark).toBeDefined();
|
|
134
119
|
expect(typeof decodedWatermark).toBe("string");
|
|
135
120
|
expect(decodedWatermark.length).toBeGreaterThan(0);
|
|
136
|
-
})
|
|
137
|
-
it("should throw error decoding from original image (no watermark)", () =>
|
|
121
|
+
});
|
|
122
|
+
it("should throw error decoding from original image (no watermark)", async () => {
|
|
138
123
|
// Try to decode from an image that hasn't been watermarked
|
|
139
|
-
|
|
140
|
-
})
|
|
141
|
-
it("should throw error with empty image buffer", () =>
|
|
124
|
+
await expect(trustmark.decode(testImage)).rejects.toThrow("watermark is corrupt or missing");
|
|
125
|
+
});
|
|
126
|
+
it("should throw error with empty image buffer", async () => {
|
|
142
127
|
const emptyBuffer = Buffer.alloc(0);
|
|
143
|
-
|
|
144
|
-
})
|
|
128
|
+
await expect(trustmark.decode(emptyBuffer)).rejects.toThrow("The image format could not be determined");
|
|
129
|
+
});
|
|
145
130
|
});
|
|
146
131
|
});
|
package/dist/binary.js
CHANGED
|
@@ -18,7 +18,8 @@ let neon = null;
|
|
|
18
18
|
// Get the binary module (loads synchronously on first access)
|
|
19
19
|
export function getNeonBinary() {
|
|
20
20
|
if (neon === null) {
|
|
21
|
-
|
|
21
|
+
const C2PA_LIBRARY_PATH = process.env.C2PA_LIBRARY_PATH;
|
|
22
|
+
neon = require(C2PA_LIBRARY_PATH ?? "./index.node");
|
|
22
23
|
}
|
|
23
24
|
return neon;
|
|
24
25
|
}
|
package/dist/index.node
CHANGED
|
Binary file
|
package/dist/types/Builder.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuilderIntent, Ingredient, Manifest } from "@contentauth/c2pa-types";
|
|
1
|
+
import type { BuilderIntent, C2paReason, Ingredient, Manifest } from "@contentauth/c2pa-types";
|
|
2
2
|
import type { BuilderInterface, C2paSettings, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, ReaderInterface, SourceAsset, NeonBuilderHandle } from "./types.d.ts";
|
|
3
3
|
export declare class Builder implements BuilderInterface {
|
|
4
4
|
private builder;
|
|
@@ -21,5 +21,6 @@ export declare class Builder implements BuilderInterface {
|
|
|
21
21
|
signAsync(signer: CallbackSignerInterface | IdentityAssertionSignerInterface, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
|
|
22
22
|
getManifestDefinition(): Manifest;
|
|
23
23
|
updateManifestProperty(property: string, value: ClaimVersion): void;
|
|
24
|
+
addRedaction(uri: string, reason: C2paReason): void;
|
|
24
25
|
getHandle(): NeonBuilderHandle;
|
|
25
26
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
import { Buffer } from "buffer";
|
|
16
16
|
import type {
|
|
17
17
|
BuilderIntent,
|
|
18
|
+
C2paReason,
|
|
18
19
|
Ingredient,
|
|
19
20
|
Manifest,
|
|
20
21
|
ManifestStore,
|
|
21
22
|
} from "@contentauth/c2pa-types";
|
|
22
23
|
|
|
23
|
-
export type { Ingredient } from "@contentauth/c2pa-types";
|
|
24
|
+
export type { C2paReason, Ingredient } from "@contentauth/c2pa-types";
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Describes the digital signature algorithms allowed by the C2PA spec
|
|
@@ -332,6 +333,15 @@ export interface BuilderInterface {
|
|
|
332
333
|
*/
|
|
333
334
|
updateManifestProperty(property: string, value: string | ClaimVersion): void;
|
|
334
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Redact an assertion from an ingredient manifest and record the reason.
|
|
338
|
+
* Adds the URI to `definition.redactions` and appends a `c2pa.redacted` action
|
|
339
|
+
* with `parameters.redacted` pointing to the same URI.
|
|
340
|
+
* @param uri JUMBF URI of the assertion to redact (e.g. `self#jumbf=/c2pa/{label}/c2pa.assertions/{name}`)
|
|
341
|
+
* @param reason Why the assertion is being redacted. Use `"c2pa.PII.present"` for PII removal.
|
|
342
|
+
*/
|
|
343
|
+
addRedaction(uri: string, reason: C2paReason): void;
|
|
344
|
+
|
|
335
345
|
/**
|
|
336
346
|
* Get the internal handle for use with Neon bindings
|
|
337
347
|
*/
|
package/package.json
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
"name": "@contentauth/c2pa-node",
|
|
3
3
|
"repository": {
|
|
4
4
|
"type": "git",
|
|
5
|
-
"url": "git+https://github.com/contentauth/c2pa-
|
|
5
|
+
"url": "git+https://github.com/contentauth/c2pa-js.git",
|
|
6
|
+
"directory": "packages/c2pa-node"
|
|
6
7
|
},
|
|
7
|
-
"version": "0.
|
|
8
|
+
"version": "0.6.0",
|
|
8
9
|
"description": "Node.js bindings for C2PA",
|
|
9
10
|
"main": "dist/index.js",
|
|
10
11
|
"type": "module",
|
|
@@ -17,75 +18,77 @@
|
|
|
17
18
|
"Cargo.lock"
|
|
18
19
|
],
|
|
19
20
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
21
|
+
"node": ">=22"
|
|
21
22
|
},
|
|
22
|
-
"
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "run-s build:rust build:ts",
|
|
25
|
+
"build:debug": "run-s build:rust-debug build:ts",
|
|
26
|
+
"build:rust": "pnpm run build:rust-debug --release",
|
|
27
|
+
"build:rust-debug": "cargo build --message-format=json-render-diagnostics > cargo.log",
|
|
28
|
+
"build:ts": "tsc -b && cpy index.node dist && cpy index.node js-src && cpy --flat js-src/types.d.ts dist/types",
|
|
29
|
+
"ci": "run-s build:rust-debug build:ts test",
|
|
30
|
+
"clean": "rimraf dist target",
|
|
31
|
+
"cross": "pnpm run cross-build --release",
|
|
32
|
+
"cross-build": "cross build --message-format=json-render-diagnostics > cross.log",
|
|
33
|
+
"debug": "pnpm run cargo-build --",
|
|
34
|
+
"lint": "cargo clippy && pnpm eslint",
|
|
35
|
+
"postbuild:rust-debug": "neon dist < cargo.log",
|
|
36
|
+
"postcross-build": "neon dist -m /target < cross.log",
|
|
37
|
+
"postinstall": "node scripts/postinstall.cjs",
|
|
38
|
+
"test": "pnpm build:debug && vitest run --config ./vitest.config.ts",
|
|
39
|
+
"test:watch": "pnpm build:debug && vitest --config ./vitest.config.ts",
|
|
40
|
+
"test:ui": "pnpm build:debug && vitest --ui --config ./vitest.config.ts"
|
|
41
|
+
},
|
|
42
|
+
"author": "Colin Murphy <colmurph@adobe.com>, Austin Le <ale@adobe.com>",
|
|
23
43
|
"license": "MIT",
|
|
24
44
|
"devDependencies": {
|
|
25
|
-
"@changesets/cli": "^2.
|
|
26
|
-
"@contentauth/c2pa-types": "
|
|
27
|
-
"@eslint/js": "^9.
|
|
45
|
+
"@changesets/cli": "^2.31.0",
|
|
46
|
+
"@contentauth/c2pa-types": "workspace:*",
|
|
47
|
+
"@eslint/js": "^9.39.4",
|
|
28
48
|
"@neon-rs/cli": "0.1.82",
|
|
29
49
|
"@types/cli-progress": "^3.11.6",
|
|
30
|
-
"@types/debug": "^4.1.
|
|
50
|
+
"@types/debug": "^4.1.13",
|
|
31
51
|
"@types/fs-extra": "^11.0.4",
|
|
32
52
|
"@types/jest": "^29.5.14",
|
|
33
|
-
"@types/node": "^22.17
|
|
53
|
+
"@types/node": "^22.19.17",
|
|
34
54
|
"@types/unzipper": "^0.10.11",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
36
|
-
"@typescript-eslint/parser": "^8.
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^8.59.1",
|
|
56
|
+
"@typescript-eslint/parser": "^8.59.1",
|
|
37
57
|
"@vitest/ui": "^3.2.4",
|
|
38
|
-
"cbor2": "^2.0
|
|
58
|
+
"cbor2": "^2.3.0",
|
|
39
59
|
"cpy-cli": "^5.0.0",
|
|
40
|
-
"eslint": "^9.
|
|
60
|
+
"eslint": "^9.39.4",
|
|
41
61
|
"npm-run-all": "^4.1.5",
|
|
42
|
-
"rimraf": "^6.
|
|
43
|
-
"sharp": "^0.34.
|
|
44
|
-
"ts-jest": "^29.4.
|
|
45
|
-
"typedoc": "^0.28.
|
|
46
|
-
"typedoc-plugin-markdown": "^4.
|
|
47
|
-
"typescript": "^5.9.
|
|
62
|
+
"rimraf": "^6.1.3",
|
|
63
|
+
"sharp": "^0.34.5",
|
|
64
|
+
"ts-jest": "^29.4.9",
|
|
65
|
+
"typedoc": "^0.28.19",
|
|
66
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
67
|
+
"typescript": "^5.9.3",
|
|
48
68
|
"vitest": "^3.2.4"
|
|
49
69
|
},
|
|
50
70
|
"keywords": [
|
|
51
71
|
"c2pa"
|
|
52
72
|
],
|
|
53
73
|
"bugs": {
|
|
54
|
-
"url": "https://github.com/contentauth/c2pa-
|
|
74
|
+
"url": "https://github.com/contentauth/c2pa-js/issues"
|
|
55
75
|
},
|
|
56
|
-
"homepage": "https://github.com/contentauth/c2pa-node
|
|
76
|
+
"homepage": "https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-node#readme",
|
|
57
77
|
"dependencies": {
|
|
58
|
-
"cargo-cp-artifact": "^0.1.
|
|
59
|
-
"cli-progress": "^3.
|
|
60
|
-
"debug": "^4.4.
|
|
61
|
-
"fs-extra": "^11.3.
|
|
62
|
-
"mkdirp": "^3.0.
|
|
78
|
+
"cargo-cp-artifact": "^0.1.9",
|
|
79
|
+
"cli-progress": "^3.12.0",
|
|
80
|
+
"debug": "^4.4.3",
|
|
81
|
+
"fs-extra": "^11.3.4",
|
|
82
|
+
"mkdirp": "^3.0.1",
|
|
63
83
|
"node-fetch": "^3.3.2",
|
|
64
84
|
"pkg-dir": "^8.0.0",
|
|
65
|
-
"pretty-bytes": "^6.
|
|
66
|
-
"unzipper": "^0.10.
|
|
85
|
+
"pretty-bytes": "^6.1.1",
|
|
86
|
+
"unzipper": "^0.10.14"
|
|
67
87
|
},
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"build:rust-debug": "cargo build --message-format=json-render-diagnostics > cargo.log",
|
|
74
|
-
"build:ts": "tsc -b && cpy index.node dist && cpy index.node js-src && cpy --flat js-src/types.d.ts dist/types",
|
|
75
|
-
"changeset:publish": "changeset publish",
|
|
76
|
-
"ci": "run-s build:rust-debug build:ts test",
|
|
77
|
-
"ci:release": "pnpm run build && changeset tag && pnpm publish --access=public --no-git-checks",
|
|
78
|
-
"clean": "rimraf dist target",
|
|
79
|
-
"cross": "pnpm run cross-build --release",
|
|
80
|
-
"cross-build": "cross build --message-format=json-render-diagnostics > cross.log",
|
|
81
|
-
"debug": "pnpm run cargo-build --",
|
|
82
|
-
"lint": "cargo clippy && pnpm eslint",
|
|
83
|
-
"postbuild:rust-debug": "neon dist < cargo.log",
|
|
84
|
-
"postcross-build": "neon dist -m /target < cross.log",
|
|
85
|
-
"postinstall": "node scripts/postinstall.cjs",
|
|
86
|
-
"release": "run-s build changeset:publish",
|
|
87
|
-
"test": "pnpm build:debug && vitest run",
|
|
88
|
-
"test:watch": "pnpm build:debug && vitest",
|
|
89
|
-
"test:ui": "pnpm build:debug && vitest --ui"
|
|
88
|
+
"packageManager": "pnpm@10.15.0",
|
|
89
|
+
"nx": {
|
|
90
|
+
"tags": [
|
|
91
|
+
"lib"
|
|
92
|
+
]
|
|
90
93
|
}
|
|
91
|
-
}
|
|
94
|
+
}
|
package/scripts/postinstall.cjs
CHANGED
|
@@ -14,7 +14,8 @@ const cliProgress = require('cli-progress');
|
|
|
14
14
|
const unzipper = require('unzipper');
|
|
15
15
|
const os = require('node:os');
|
|
16
16
|
const { mkdirp } = require('mkdirp');
|
|
17
|
-
const
|
|
17
|
+
const path = require('node:path');
|
|
18
|
+
const { resolve } = path;
|
|
18
19
|
const { exec } = require('node:child_process');
|
|
19
20
|
const { promisify } = require('node:util');
|
|
20
21
|
// node-fetch v3 is ES module only, so we'll import it dynamically
|
|
@@ -23,6 +24,16 @@ const { promisify } = require('node:util');
|
|
|
23
24
|
|
|
24
25
|
const pExec = promisify(exec);
|
|
25
26
|
|
|
27
|
+
async function isInPnpmWorkspace(startDir) {
|
|
28
|
+
let dir = path.dirname(startDir);
|
|
29
|
+
while (true) {
|
|
30
|
+
const parent = path.dirname(dir);
|
|
31
|
+
if (parent === dir) return false;
|
|
32
|
+
if (await fileExists(path.join(parent, 'pnpm-workspace.yaml'))) return true;
|
|
33
|
+
dir = parent;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
const execCallback = (err, stdout, stderr) => {
|
|
27
38
|
if (err) {
|
|
28
39
|
console.error(`ERROR: ${err}`);
|
|
@@ -175,6 +186,12 @@ async function buildRust(root) {
|
|
|
175
186
|
async function main() {
|
|
176
187
|
const { packageDirectory } = await import('pkg-dir');
|
|
177
188
|
const appRoot = await packageDirectory(__filename);
|
|
189
|
+
|
|
190
|
+
if (await isInPnpmWorkspace(appRoot)) {
|
|
191
|
+
console.log('Skipping Rust build: package is installed inside a pnpm workspace');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
178
195
|
const distRoot = resolve(appRoot, 'dist');
|
|
179
196
|
const cargoDistPath = resolve(distRoot, 'Cargo.toml');
|
|
180
197
|
const libraryOverridePath = process.env.C2PA_LIBRARY_PATH;
|
package/src/lib.rs
CHANGED
|
@@ -81,6 +81,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|
|
81
81
|
"builderUpdateManifestProperty",
|
|
82
82
|
neon_builder::NeonBuilder::update_manifest_property,
|
|
83
83
|
)?;
|
|
84
|
+
cx.export_function(
|
|
85
|
+
"builderAddRedaction",
|
|
86
|
+
neon_builder::NeonBuilder::add_redaction,
|
|
87
|
+
)?;
|
|
84
88
|
|
|
85
89
|
// Reader
|
|
86
90
|
cx.export_function("readerNew", neon_reader::NeonReader::new)?;
|
package/src/neon_builder.rs
CHANGED
|
@@ -18,7 +18,7 @@ use crate::neon_reader::NeonReader;
|
|
|
18
18
|
use crate::neon_signer::{CallbackSignerConfig, NeonCallbackSigner, NeonLocalSigner};
|
|
19
19
|
use crate::runtime::runtime;
|
|
20
20
|
use crate::utils::parse_settings;
|
|
21
|
-
use c2pa::{Builder, BuilderIntent, Ingredient};
|
|
21
|
+
use c2pa::{assertions::Action, Builder, BuilderIntent, Ingredient};
|
|
22
22
|
use neon::context::Context as NeonContext;
|
|
23
23
|
use neon::prelude::*;
|
|
24
24
|
use neon_serde4;
|
|
@@ -60,7 +60,9 @@ impl NeonBuilder {
|
|
|
60
60
|
.with_definition(json.as_str())
|
|
61
61
|
.or_else(|err| cx.throw_error(err.to_string()))?
|
|
62
62
|
} else {
|
|
63
|
-
Builder::
|
|
63
|
+
Builder::default()
|
|
64
|
+
.with_definition(&json)
|
|
65
|
+
.or_else(|err| cx.throw_error(err.to_string()))?
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
Ok(cx.boxed(Self {
|
|
@@ -73,7 +75,7 @@ impl NeonBuilder {
|
|
|
73
75
|
let this = cx.this::<JsBox<Self>>()?;
|
|
74
76
|
let intent_str = cx.argument::<JsString>(0)?.value(&mut cx);
|
|
75
77
|
let intent: BuilderIntent = serde_json::from_str(&intent_str)
|
|
76
|
-
.or_else(|_| cx.throw_error(format!("Invalid intent: {}"
|
|
78
|
+
.or_else(|_| cx.throw_error(format!("Invalid intent: {intent_str}")))?;
|
|
77
79
|
let mut builder = rt.block_on(async { this.builder.lock().await });
|
|
78
80
|
builder.set_intent(intent);
|
|
79
81
|
Ok(cx.undefined())
|
|
@@ -127,7 +129,7 @@ impl NeonBuilder {
|
|
|
127
129
|
// For Json, expect the assertion as a string (JSON) and parse it
|
|
128
130
|
let assertion_str = cx.argument::<JsString>(1)?.value(&mut cx);
|
|
129
131
|
let assertion: serde_json::Value = serde_json::from_str(&assertion_str)
|
|
130
|
-
.or_else(|err| cx.throw_error(format!("Invalid JSON: {}"
|
|
132
|
+
.or_else(|err| cx.throw_error(format!("Invalid JSON: {err}")))?;
|
|
131
133
|
builder
|
|
132
134
|
.add_assertion(&label, &assertion)
|
|
133
135
|
.or_else(|err| cx.throw_error(err.to_string()))?;
|
|
@@ -170,6 +172,28 @@ impl NeonBuilder {
|
|
|
170
172
|
|
|
171
173
|
Ok(promise)
|
|
172
174
|
}
|
|
175
|
+
|
|
176
|
+
pub fn add_redaction(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
177
|
+
let rt = runtime();
|
|
178
|
+
let this = cx.this::<JsBox<Self>>()?;
|
|
179
|
+
let uri = cx.argument::<JsString>(0)?.value(&mut cx);
|
|
180
|
+
let reason = cx.argument::<JsString>(1)?.value(&mut cx);
|
|
181
|
+
let mut builder = rt.block_on(async { this.builder.lock().await });
|
|
182
|
+
builder
|
|
183
|
+
.definition
|
|
184
|
+
.redactions
|
|
185
|
+
.get_or_insert_with(Vec::new)
|
|
186
|
+
.push(uri.clone());
|
|
187
|
+
let action = Action::new("c2pa.redacted")
|
|
188
|
+
.set_reason(reason)
|
|
189
|
+
.set_parameter("redacted".to_owned(), uri)
|
|
190
|
+
.or_else(|err| cx.throw_error(err.to_string()))?;
|
|
191
|
+
builder
|
|
192
|
+
.add_action(action)
|
|
193
|
+
.or_else(|err| cx.throw_error(err.to_string()))?;
|
|
194
|
+
Ok(cx.undefined())
|
|
195
|
+
}
|
|
196
|
+
|
|
173
197
|
pub fn add_ingredient(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
174
198
|
let rt = runtime();
|
|
175
199
|
let this = cx.this::<JsBox<Self>>()?;
|
|
@@ -254,7 +278,7 @@ impl NeonBuilder {
|
|
|
254
278
|
// Block on acquiring the async mutex lock
|
|
255
279
|
// Settings are automatically applied when runtime() is called
|
|
256
280
|
let rt = runtime();
|
|
257
|
-
let
|
|
281
|
+
let builder = rt.block_on(async { builder.lock().await });
|
|
258
282
|
|
|
259
283
|
dest.write_stream().and_then(|mut dest_stream| {
|
|
260
284
|
builder.to_archive(&mut dest_stream)?;
|
|
@@ -302,7 +326,7 @@ impl NeonBuilder {
|
|
|
302
326
|
let builder = if let Some(context) = context_opt {
|
|
303
327
|
Builder::from_context(context).with_archive(source_stream)?
|
|
304
328
|
} else {
|
|
305
|
-
Builder::
|
|
329
|
+
Builder::default().with_archive(source_stream)?
|
|
306
330
|
};
|
|
307
331
|
Ok(builder)
|
|
308
332
|
})
|
package/src/neon_reader.rs
CHANGED
|
@@ -70,7 +70,7 @@ impl NeonReader {
|
|
|
70
70
|
.with_stream_async(&format, stream)
|
|
71
71
|
.await?
|
|
72
72
|
} else {
|
|
73
|
-
Reader::
|
|
73
|
+
Reader::default().with_stream_async(&format, stream).await?
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
Ok(reader)
|
|
@@ -130,7 +130,9 @@ impl NeonReader {
|
|
|
130
130
|
.with_manifest_data_and_stream_async(&c2pa_data, &format, stream)
|
|
131
131
|
.await?
|
|
132
132
|
} else {
|
|
133
|
-
Reader::
|
|
133
|
+
Reader::default()
|
|
134
|
+
.with_manifest_data_and_stream_async(&c2pa_data, &format, stream)
|
|
135
|
+
.await?
|
|
134
136
|
};
|
|
135
137
|
|
|
136
138
|
Ok(reader)
|