@contentauth/c2pa-node 0.5.5 → 0.6.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.
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
29
- // Create a sharp image from raw RGB data
30
- const image = sharp(rawRgbData, {
31
- raw: {
32
- width,
33
- height,
34
- channels: 3, // RGB
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,95 +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(() => __awaiter(void 0, void 0, void 0, function* () {
52
- yield fs.ensureDir(tempDir);
40
+ beforeAll(async () => {
41
+ await fs.ensureDir(tempDir);
53
42
  // Use an actual test image from fixtures directory
54
- testImage = yield fs.readFile("./tests/fixtures/A.jpg");
43
+ testImage = await fs.readFile("./tests/fixtures/A.jpg");
55
44
  // Get image dimensions for converting raw pixel data
56
- const imageInfo = yield sharp(testImage).metadata();
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
- trustmark = yield Trustmark.newTrustmark(trustmarkConfig);
62
- }));
50
+ trustmark = await Trustmark.newTrustmark(trustmarkConfig);
51
+ }, 30000);
63
52
  describe("newTrustmark", () => {
64
- it("should create a new trustmark instance with valid config", () => __awaiter(void 0, void 0, void 0, function* () {
53
+ it("should create a new trustmark instance with valid config", async () => {
65
54
  // This test will be skipped if the model file doesn't exist
66
55
  expect(trustmark).toBeDefined();
67
56
  expect(typeof trustmark.encode).toBe("function");
68
57
  expect(typeof trustmark.decode).toBe("function");
69
- }));
70
- it("should throw error with invalid config", () => __awaiter(void 0, void 0, void 0, function* () {
58
+ });
59
+ it("should throw error with invalid config", async () => {
71
60
  const invalidConfig = {
72
61
  variant: "X", // Invalid variant
73
62
  version: "BCH_3", // Valid version
74
63
  };
75
- yield expect(Trustmark.newTrustmark(invalidConfig)).rejects.toThrow("Watermark configuration error: invalid variant");
76
- }));
64
+ await expect(Trustmark.newTrustmark(invalidConfig)).rejects.toThrow("Watermark configuration error: invalid variant");
65
+ });
77
66
  });
78
67
  describe("encode", () => {
79
- it("should encode a watermark into an image with default watermark", () => __awaiter(void 0, void 0, void 0, function* () {
68
+ it("should encode a watermark into an image with default watermark", async () => {
80
69
  const strength = 0.9;
81
- const encodedImage = yield trustmark.encode(testImage, strength);
70
+ const encodedImage = await trustmark.encode(testImage, strength);
82
71
  expect(encodedImage).toBeDefined();
83
72
  expect(Buffer.isBuffer(encodedImage)).toBe(true);
84
73
  expect(encodedImage.length).toBeGreaterThan(0);
85
74
  // The encoded image should be different from the original
86
75
  expect(encodedImage).not.toEqual(testImage);
87
- }));
88
- it("should encode a watermark into an image with custom watermark", () => __awaiter(void 0, void 0, void 0, function* () {
76
+ }, 30000);
77
+ it("should encode a watermark into an image with custom watermark", async () => {
89
78
  const strength = 0.95;
90
79
  const customWatermark = "0101000011001";
91
- const encodedImage = yield trustmark.encode(testImage, strength, customWatermark);
80
+ const encodedImage = await trustmark.encode(testImage, strength, customWatermark);
92
81
  expect(encodedImage).toBeDefined();
93
82
  expect(Buffer.isBuffer(encodedImage)).toBe(true);
94
83
  expect(encodedImage.length).toBeGreaterThan(0);
95
- }));
96
- it("should throw error with invalid strength values", () => __awaiter(void 0, void 0, void 0, function* () {
97
- yield expect(trustmark.encode(testImage, -0.1)).rejects.toThrow("Watermark configuration error: strength must be between 0.0 and 1.0");
98
- yield expect(trustmark.encode(testImage, 1.1)).rejects.toThrow("Watermark configuration error: strength must be between 0.0 and 1.0");
99
- }));
100
- it("should throw error with empty image buffer", () => __awaiter(void 0, void 0, void 0, function* () {
84
+ }, 30000);
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
+ }, 30000);
89
+ it("should throw error with empty image buffer", async () => {
101
90
  const emptyBuffer = Buffer.alloc(0);
102
- yield expect(trustmark.encode(emptyBuffer, 0.5)).rejects.toThrow("The image format could not be determined");
103
- }));
91
+ await expect(trustmark.encode(emptyBuffer, 0.5)).rejects.toThrow("The image format could not be determined");
92
+ }, 30000);
104
93
  });
105
94
  describe("decode", () => {
106
- it("should decode a watermark from an encoded image", () => __awaiter(void 0, void 0, void 0, function* () {
95
+ it("should decode a watermark from an encoded image", async () => {
107
96
  const strength = 0.8;
108
97
  const customWatermark = "0101000011001";
109
98
  // First encode a watermark
110
- const rawPixelData = yield trustmark.encode(testImage, strength, customWatermark);
99
+ const rawPixelData = await trustmark.encode(testImage, strength, customWatermark);
111
100
  // Convert raw pixel data to JPEG format for decoding
112
- const encodedImage = yield rawRgbToJpeg(rawPixelData, testImageWidth, testImageHeight);
101
+ const encodedImage = await rawRgbToJpeg(rawPixelData, testImageWidth, testImageHeight);
113
102
  // Then decode it
114
- const decodedWatermark = yield trustmark.decode(encodedImage);
103
+ const decodedWatermark = await trustmark.decode(encodedImage);
115
104
  expect(decodedWatermark).toBeDefined();
116
105
  expect(typeof decodedWatermark).toBe("string");
117
106
  expect(decodedWatermark.length).toBeGreaterThan(0);
118
107
  // The decoded watermark should match the original
119
108
  expect(decodedWatermark.startsWith(customWatermark)).toBeTruthy();
120
- }));
121
- it("should decode watermark from image with generated watermark", () => __awaiter(void 0, void 0, void 0, function* () {
109
+ }, 30000);
110
+ it("should decode watermark from image with generated watermark", async () => {
122
111
  const strength = 0.75;
123
112
  // Encode with default watermark
124
- const rawPixelData = yield trustmark.encode(testImage, strength);
113
+ const rawPixelData = await trustmark.encode(testImage, strength);
125
114
  // Convert raw pixel data to JPEG format for decoding
126
- const encodedImage = yield rawRgbToJpeg(rawPixelData, testImageWidth, testImageHeight);
115
+ const encodedImage = await rawRgbToJpeg(rawPixelData, testImageWidth, testImageHeight);
127
116
  // Decode the watermark
128
- const decodedWatermark = yield trustmark.decode(encodedImage);
117
+ const decodedWatermark = await trustmark.decode(encodedImage);
129
118
  expect(decodedWatermark).toBeDefined();
130
119
  expect(typeof decodedWatermark).toBe("string");
131
120
  expect(decodedWatermark.length).toBeGreaterThan(0);
132
- }));
133
- it("should throw error decoding from original image (no watermark)", () => __awaiter(void 0, void 0, void 0, function* () {
121
+ }, 30000);
122
+ it("should throw error decoding from original image (no watermark)", async () => {
134
123
  // Try to decode from an image that hasn't been watermarked
135
- yield expect(trustmark.decode(testImage)).rejects.toThrow("watermark is corrupt or missing");
136
- }));
137
- it("should throw error with empty image buffer", () => __awaiter(void 0, void 0, void 0, function* () {
124
+ await expect(trustmark.decode(testImage)).rejects.toThrow("watermark is corrupt or missing");
125
+ }, 30000);
126
+ it("should throw error with empty image buffer", async () => {
138
127
  const emptyBuffer = Buffer.alloc(0);
139
- yield expect(trustmark.decode(emptyBuffer)).rejects.toThrow("The image format could not be determined");
140
- }));
128
+ await expect(trustmark.decode(emptyBuffer)).rejects.toThrow("The image format could not be determined");
129
+ }, 30000);
141
130
  });
142
131
  });
package/dist/binary.js CHANGED
@@ -19,7 +19,7 @@ let neon = null;
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 !== null && C2PA_LIBRARY_PATH !== void 0 ? C2PA_LIBRARY_PATH : "./index.node");
22
+ neon = require(C2PA_LIBRARY_PATH ?? "./index.node");
23
23
  }
24
24
  return neon;
25
25
  }
package/dist/index.node CHANGED
Binary file
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-node-v2.git"
5
+ "url": "git+https://github.com/contentauth/c2pa-js.git",
6
+ "directory": "packages/c2pa-node"
6
7
  },
7
- "version": "0.5.5",
8
+ "version": "0.6.1",
8
9
  "description": "Node.js bindings for C2PA",
9
10
  "main": "dist/index.js",
10
11
  "type": "module",
@@ -17,13 +18,12 @@
17
18
  "Cargo.lock"
18
19
  ],
19
20
  "engines": {
20
- "node": ">=18.20.2"
21
+ "node": ">=22"
21
22
  },
22
- "author": "Colin Murphy <colmurph@adobe.com>",
23
+ "author": "Colin Murphy <colmurph@adobe.com>, Austin Le <ale@adobe.com>",
23
24
  "license": "MIT",
24
25
  "devDependencies": {
25
26
  "@changesets/cli": "^2.31.0",
26
- "@contentauth/c2pa-types": "^0.4.4",
27
27
  "@eslint/js": "^9.39.4",
28
28
  "@neon-rs/cli": "0.1.82",
29
29
  "@types/cli-progress": "^3.11.6",
@@ -45,15 +45,16 @@
45
45
  "typedoc": "^0.28.19",
46
46
  "typedoc-plugin-markdown": "^4.11.0",
47
47
  "typescript": "^5.9.3",
48
- "vitest": "^3.2.4"
48
+ "vitest": "^3.2.4",
49
+ "@contentauth/c2pa-types": "0.7.1"
49
50
  },
50
51
  "keywords": [
51
52
  "c2pa"
52
53
  ],
53
54
  "bugs": {
54
- "url": "https://github.com/contentauth/c2pa-node-v2/issues"
55
+ "url": "https://github.com/contentauth/c2pa-js/issues"
55
56
  },
56
- "homepage": "https://github.com/contentauth/c2pa-node-v2#readme",
57
+ "homepage": "https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-node#readme",
57
58
  "dependencies": {
58
59
  "cargo-cp-artifact": "^0.1.9",
59
60
  "cli-progress": "^3.12.0",
@@ -65,16 +66,18 @@
65
66
  "pretty-bytes": "^6.1.1",
66
67
  "unzipper": "^0.10.14"
67
68
  },
69
+ "nx": {
70
+ "tags": [
71
+ "lib"
72
+ ]
73
+ },
68
74
  "scripts": {
69
75
  "build": "run-s build:rust build:ts",
70
76
  "build:debug": "run-s build:rust-debug build:ts",
71
- "build:docs": "typedoc",
72
77
  "build:rust": "pnpm run build:rust-debug --release",
73
78
  "build:rust-debug": "cargo build --message-format=json-render-diagnostics > cargo.log",
74
79
  "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
80
  "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
81
  "clean": "rimraf dist target",
79
82
  "cross": "pnpm run cross-build --release",
80
83
  "cross-build": "cross build --message-format=json-render-diagnostics > cross.log",
@@ -83,9 +86,8 @@
83
86
  "postbuild:rust-debug": "neon dist < cargo.log",
84
87
  "postcross-build": "neon dist -m /target < cross.log",
85
88
  "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"
89
+ "test": "pnpm build:debug && vitest run --config ./vitest.config.ts",
90
+ "test:watch": "pnpm build:debug && vitest --config ./vitest.config.ts",
91
+ "test:ui": "pnpm build:debug && vitest --ui --config ./vitest.config.ts"
90
92
  }
91
93
  }
@@ -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 { resolve } = require('node:path');
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;