@contentauth/c2pa-node 0.8.3 → 0.9.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/README.md CHANGED
@@ -1,14 +1,15 @@
1
- # C2PA Node.js library
1
+ # CAI Node.js library
2
2
 
3
3
  `@contentauth/c2pa-node` is a Node.js library in the [c2pa-js](https://github.com/contentauth/c2pa-js) monorepo that can:
4
+
4
5
  - Read and validate C2PA data from media files in supported formats.
5
6
  - Add signed manifests to media files in supported formats.
6
7
 
7
8
  ## Prerequisites
8
9
 
9
- To use the C2PA Node library you need Node.js **>=22**. If you need to manage multiple versions of Node on your machine, use a tool such as [nvm](https://github.com/nvm-sh/nvm).
10
+ To use the c2pa-node library, you need Node.js 22 or later. If you need to manage multiple versions of Node on your machine, use a tool such as [nvm](https://github.com/nvm-sh/nvm).
10
11
 
11
- To **build from source** you also need [Rust](https://www.rust-lang.org/tools/install). This is not required when installing the package normally — precompiled binaries are downloaded automatically during installation.
12
+ To build from source, you also need [Rust](https://www.rust-lang.org/tools/install). This is not required when installing the package normally: precompiled binaries are downloaded automatically during installation.
12
13
 
13
14
  ## Installation
14
15
 
@@ -17,19 +18,19 @@ To **build from source** you also need [Rust](https://www.rust-lang.org/tools/in
17
18
  Using npm:
18
19
 
19
20
  ```sh
20
- $ npm install @contentauth/c2pa-node
21
+ npm install @contentauth/c2pa-node
21
22
  ```
22
23
 
23
24
  Using Yarn:
24
25
 
25
26
  ```sh
26
- $ yarn add @contentauth/c2pa-node
27
+ yarn add @contentauth/c2pa-node
27
28
  ```
28
29
 
29
30
  Using pnpm:
30
31
 
31
32
  ```sh
32
- $ pnpm add @contentauth/c2pa-node
33
+ pnpm add @contentauth/c2pa-node
33
34
  ```
34
35
 
35
36
  This command will download precompiled binaries for the following systems:
@@ -90,6 +91,8 @@ const isEmbedded = reader.isEmbedded();
90
91
  const remoteUrl = reader.remoteUrl();
91
92
  ```
92
93
 
94
+ `Reader.fromAsset` and `Reader.fromManifestDataAndAsset` reject assets larger than 10 GB, throwing `AssetTooLargeError` (exported from `@contentauth/c2pa-node`). Note that for a `SourceBufferAsset`, this only rejects after the buffer is already fully allocated in memory. Pass a `FileAsset` instead for large or untrusted assets so oversized files are rejected before being read into memory.
95
+
93
96
  ### Builder
94
97
 
95
98
  The `Builder` class is the main component for creating and signing C2PA manifests. It provides methods to add assertions, resources, and ingredients to manifests, and handles the signing process. Use the `Signer` class to sign the manifests. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
@@ -124,15 +127,13 @@ await builder.addResource('resource://example', resourceAsset);
124
127
  const manifest = builder.sign(signer, inputAsset, outputAsset);
125
128
  ```
126
129
 
127
- #### Setting Builder Intent
128
-
129
- The builder intent describes the type of operation being performed on the asset. This influences how the manifest is structured and what assertions are automatically added.
130
+ #### Setting builder intent
130
131
 
131
- `create`: This is a new digital creation, a DigitalSourceType is required. The Manifest must not have a parent ingredient. A `c2pa.created` action will be added if not provided.
132
+ The builder intent describes the type of operation being performed on the asset. This influences how the manifest is structured and what assertions are automatically added. Use one of these intents:
132
133
 
133
- `edit`: This is an edit of a pre-existing parent asset. The Manifest must have a parent ingredient. A parent ingredient will be generated from the source stream if not otherwise provided. A `c2pa.opened` action will be tied to the parent ingredient.
134
-
135
- `update`: A restricted version of Edit for non-editorial changes. There must be only one ingredient, as a parent. No changes can be made to the hashed content of the parent. There are additional restrictions on the types of changes that can be made.
134
+ - `create`: Indicates the asset is a new digital creation, a `DigitalSourceType` is required. The manifest must not have a parent ingredient. A `c2pa.created` action will be added if not provided.
135
+ - `edit`: Indicates the asset is an edit of a pre-existing parent asset. The manifest must have a parent ingredient. A parent ingredient will be generated from the source stream if not otherwise provided. A `c2pa.opened` action will be tied to the parent ingredient.
136
+ - `update`: A restricted version of `edit` for non-editorial changes. There must be only one ingredient, as a parent. No changes can be made to the hashed content of the parent. There are additional restrictions on the types of changes that can be made.
136
137
 
137
138
  ```javascript
138
139
  const builder = Builder.new();
@@ -152,11 +153,11 @@ The `create` intent accepts a `DigitalSourceType` that describes the origin of t
152
153
  - `'http://cv.iptc.org/newscodes/digitalsourcetype/digitalCapture'` - Digital camera capture
153
154
  - `'http://cv.iptc.org/newscodes/digitalsourcetype/composite'` - Composite of multiple sources
154
155
 
155
- For a complete list of digital source types, see the [C2PA specification](https://c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#_digital_source_type) and [IPTC digital source type vocabulary](https://cv.iptc.org/newscodes/digitalsourcetype).
156
+ For a complete list of digital source types, see the [C2PA specification](https://c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html#_digital_source_type) and [IPTC digital source type vocabulary](https://cv.iptc.org/newscodes/digitalsourcetype).
156
157
 
157
158
  For more details on builder intents, see the [c2pa-rs Builder documentation](https://docs.rs/c2pa/latest/c2pa/struct.Builder.html).
158
159
 
159
- #### Adding Ingredients from Assets
160
+ #### Adding ingredients from assets
160
161
 
161
162
  When you have access to the ingredient asset, use `addIngredient` with an asset to include both the metadata and the asset data:
162
163
 
@@ -187,7 +188,7 @@ const definition = builder.getManifestDefinition();
187
188
  console.log(definition.ingredients); // Contains the ingredient with embedded data
188
189
  ```
189
190
 
190
- #### Adding Multiple Ingredients
191
+ #### Adding multiple ingredients
191
192
 
192
193
  You can add multiple ingredients to document complex provenance chains:
193
194
 
@@ -230,7 +231,7 @@ const definition = builder.getManifestDefinition();
230
231
  console.log(definition.ingredients.length); // 2
231
232
  ```
232
233
 
233
- #### Adding Ingredients from Readers
234
+ #### Adding ingredients from readers
234
235
 
235
236
  You can also add ingredients directly from a `Reader` object, which automatically includes the C2PA data:
236
237
 
@@ -249,7 +250,7 @@ const ingredient = builder.addIngredientFromReader(sourceReader);
249
250
  console.log(ingredient.title); // Contains ingredient metadata
250
251
  ```
251
252
 
252
- #### Adding Ingredients from Archives (.c2pa files)
253
+ #### Adding ingredients from archive files
253
254
 
254
255
  You can add ingredients from `.c2pa` archive files. Archives are binary files that contain a manifest store with ingredients and their associated resources (thumbnails, manifest data, etc.). To work with them, read the archive with `Reader` using the `application/c2pa` MIME type, then extract the ingredients and transfer their binary resources to a new `Builder`.
255
256
 
@@ -368,7 +369,7 @@ await builder.addIngredient(
368
369
  await builder.toArchive({ path: 'ingredient-catalog.c2pa' });
369
370
  ```
370
371
 
371
- #### Creating and Reusing Builder Archives
372
+ #### Creating and reusing builder archives
372
373
 
373
374
  Builder archives allow you to save a builder's state (including ingredients) and reuse it later:
374
375
 
@@ -447,7 +448,7 @@ const signer = CallbackSigner.newSigner(
447
448
  );
448
449
  ```
449
450
 
450
- ### Identity Assertion Components
451
+ ### Identity assertion components
451
452
 
452
453
  For working with identity assertions and CAWG (Content Authenticity Working Group) identities:
453
454
 
@@ -518,11 +519,11 @@ const encodedImage = await trustmark.encode(
518
519
  const decodedData = await trustmark.decode(imageBuffer);
519
520
  ```
520
521
 
521
- ### Settings and Configuration
522
+ ### Settings and configuration
522
523
 
523
524
  The library provides comprehensive settings management that can be configured per Reader/Builder instance or using helper functions. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
524
525
 
525
- #### Per-Instance Settings
526
+ #### Per-instance settings
526
527
 
527
528
  Settings can be passed directly to `Reader` and `Builder` constructors:
528
529
 
@@ -554,7 +555,7 @@ const settingsJson = JSON.stringify(settings);
554
555
  const builder2 = Builder.new(settingsJson);
555
556
  ```
556
557
 
557
- #### Settings Helper Functions
558
+ #### Settings helper functions
558
559
 
559
560
  The library provides helper functions to create and manage settings objects:
560
561
 
@@ -610,16 +611,16 @@ const urlSettings = await loadSettingsFromUrl('https://example.com/c2pa-settings
610
611
  const builder = Builder.new(urlSettings);
611
612
  ```
612
613
 
613
- #### Available Settings
614
+ #### Available settings
614
615
 
615
- **Trust Settings:**
616
+ **Trust settings:**
616
617
  - `verifyTrustList` - Whether to verify against the trust list
617
618
  - `userAnchors` - User-provided trust anchors (PEM format or path)
618
619
  - `trustAnchors` - Trust anchors for validation (PEM format or path)
619
620
  - `trustConfig` - Path to trust configuration file
620
621
  - `allowedList` - Allowed list of certificates (PEM format or path)
621
622
 
622
- **Verify Settings:**
623
+ **Verify settings:**
623
624
  - `verifyAfterReading` - Whether to verify after reading a manifest
624
625
  - `verifyAfterSign` - Whether to verify after signing a manifest
625
626
  - `verifyTrust` - Whether to verify trust during validation
@@ -629,18 +630,22 @@ const builder = Builder.new(urlSettings);
629
630
  - `skipIngredientConflictResolution` - Whether to skip ingredient conflict resolution
630
631
  - `strictV1Validation` - Whether to use strict v1 validation
631
632
 
632
- **Builder Settings:**
633
+ **Builder settings:**
633
634
  - `generate_c2pa_archive` - Whether to generate C2PA archive format
634
635
 
635
- **Note:** Settings are passed as per-instance configuration. There are no global settings that affect all Readers and Builders.
636
-
636
+ > [!NOTE]
637
+ > Settings are passed as per-instance configuration. There are no global settings that affect all Readers and Builders.
637
638
 
638
639
  ### Build and use custom binary
640
+
639
641
  **Build Rust binary:**
642
+
640
643
  ```bash
641
644
  pnpm run build:rust
642
645
  ```
646
+
643
647
  **Use custom Rust binary:**
648
+
644
649
  ```bash
645
650
  export C2PA_LIBRARY_PATH=<path-to-binary-folder>/index.node
646
651
  ```
package/dist/Reader.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // or the MIT license (http://opensource.org/licenses/MIT),
5
5
  // at your option.
6
6
  import { getNeonBinary } from "./binary.js";
7
+ import { validateSourceAssetSize } from "./assetSize.js";
7
8
  export class Reader {
8
9
  reader;
9
10
  constructor(reader) {
@@ -22,11 +23,13 @@ export class Reader {
22
23
  return getNeonBinary().readerResourceToAsset.call(this.reader, uri, asset);
23
24
  }
24
25
  static async fromAsset(asset, settings) {
26
+ await validateSourceAssetSize(asset);
25
27
  const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
26
28
  const reader = await getNeonBinary().readerFromAsset(asset, settingsStr);
27
29
  return reader ? new Reader(reader) : null;
28
30
  }
29
31
  static async fromManifestDataAndAsset(manifestData, asset, settings) {
32
+ await validateSourceAssetSize(asset);
30
33
  const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
31
34
  const reader = await getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset, settingsStr);
32
35
  return new Reader(reader);
@@ -5,7 +5,9 @@
5
5
  // at your option.
6
6
  import path from "path";
7
7
  import * as fs from "fs-extra";
8
+ import { AssetTooLargeError } from "@contentauth/c2pa-utilities";
8
9
  import { Reader } from "./Reader.js";
10
+ import { MAX_SIZE_IN_BYTES } from "./assetSize.js";
9
11
  const tempDir = path.join(__dirname, "tmp");
10
12
  describe("Reader", () => {
11
13
  const manifestStore = JSON.parse(`{
@@ -126,6 +128,12 @@ describe("Reader", () => {
126
128
  });
127
129
  expect(reader).toBeNull();
128
130
  });
131
+ it("should throw AssetTooLargeError for a file asset exceeding the max size", async () => {
132
+ const oversizedPath = path.join(tempDir, "oversized.jpg");
133
+ await fs.ensureFile(oversizedPath);
134
+ await fs.truncate(oversizedPath, MAX_SIZE_IN_BYTES + 1);
135
+ await expect(Reader.fromAsset({ path: oversizedPath })).rejects.toThrow(AssetTooLargeError);
136
+ });
129
137
  it("should read from manifest data and buffer", async () => {
130
138
  const manifestData = await fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
131
139
  const buffer = await fs.readFile("./tests/fixtures/CA.jpg");
package/dist/Settings.js CHANGED
@@ -10,74 +10,12 @@
10
10
  // specific language governing permissions and limitations under
11
11
  // each license.
12
12
  import * as fs from "fs-extra";
13
- import fetch from "node-fetch";
14
- function snakeCaseify(object) {
15
- return Object.entries(object).reduce((result, [key, val]) => {
16
- result[snakeCase(key)] =
17
- typeof val === "object" && val !== null ? snakeCaseify(val) : val;
18
- return result;
19
- }, {});
20
- }
21
- function snakeCase(str) {
22
- return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
23
- }
24
- /**
25
- * Create a Settings object with trust configuration.
26
- * @param trustConfig The trust configuration
27
- * @returns Settings object that can be passed to Reader/Builder
28
- */
29
- export function createTrustSettings(trustConfig) {
30
- return { trust: { ...trustConfig } };
31
- }
32
- /**
33
- * Create a settings object with CAWG trust configuration.
34
- * @param trustConfig The CAWG trust configuration
35
- * @returns Settings object that can be passed to Reader/Builder
36
- */
37
- export function createCawgTrustSettings(trustConfig) {
38
- return { cawgTrust: { ...trustConfig } };
39
- }
40
- /**
41
- * Create a settings object with verify configuration.
42
- * @param verifyConfig The verify configuration
43
- * @returns Settings object that can be passed to Reader/Builder
44
- */
45
- export function createVerifySettings(verifyConfig) {
46
- return { verify: { ...verifyConfig } };
47
- }
48
13
  /**
49
- * Merge multiple settings objects into one.
50
- * Later settings override earlier ones.
51
- * @param settings Settings objects to merge
52
- * @returns Merged settings object
14
+ * This file contains only Settings functions that are unique to the Node SDK.
15
+ *
16
+ * Shared Settings-related functions and types can be found in `c2pa-utilities`,
17
+ * and are re-exported by `c2pa-node` (see `index.ts`) for convenience.
53
18
  */
54
- export function mergeSettings(...settings) {
55
- const merged = {};
56
- for (const setting of settings) {
57
- if (setting.trust) {
58
- merged.trust = { ...merged.trust, ...setting.trust };
59
- }
60
- if (setting.cawgTrust) {
61
- merged.cawgTrust = { ...merged.cawgTrust, ...setting.cawgTrust };
62
- }
63
- if (setting.verify) {
64
- merged.verify = { ...merged.verify, ...setting.verify };
65
- }
66
- if (setting.builder) {
67
- merged.builder = { ...merged.builder, ...setting.builder };
68
- }
69
- }
70
- return merged;
71
- }
72
- /**
73
- * Convert a settings object to a JSON string.
74
- * Converts camelCase keys to snake_case to match the c2pa-rs settings format.
75
- * @param settings The settings object
76
- * @returns JSON string representation with snake_case keys
77
- */
78
- export function settingsToJson(settings) {
79
- return JSON.stringify(snakeCaseify(settings));
80
- }
81
19
  /**
82
20
  * Load settings from a TOML or JSON file.
83
21
  * @param filePath The path to the settings file
@@ -87,15 +25,3 @@ export async function loadSettingsFromFile(filePath) {
87
25
  const content = await fs.readFile(filePath, "utf8");
88
26
  return content;
89
27
  }
90
- /**
91
- * Load settings from a URL.
92
- * @param url The URL to fetch the settings from
93
- * @returns Settings as a string
94
- */
95
- export async function loadSettingsFromUrl(url) {
96
- const res = await fetch(url);
97
- if (!res.ok) {
98
- throw new Error(`Failed to fetch settings from URL: ${res.status} ${res.statusText}`);
99
- }
100
- return await res.text();
101
- }
@@ -3,189 +3,11 @@
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
- import { createTrustSettings, createCawgTrustSettings, createVerifySettings, mergeSettings, settingsToJson, loadSettingsFromFile, loadSettingsFromUrl, } from "./Settings.js";
7
6
  import * as fs from "fs-extra";
8
7
  import * as path from "path";
9
8
  import * as os from "os";
10
- import { vi } from "vitest";
11
- // Mock node-fetch
12
- vi.mock("node-fetch", () => ({
13
- default: vi.fn(),
14
- }));
9
+ import { loadSettingsFromFile } from "./Settings.js";
15
10
  describe("Settings", () => {
16
- it("creates trust settings", () => {
17
- const trustConfig = {
18
- verifyTrustList: true,
19
- userAnchors: "test",
20
- allowedList: "allowed",
21
- };
22
- const settings = createTrustSettings(trustConfig);
23
- expect(settings.trust).toBeDefined();
24
- expect(settings.trust?.verifyTrustList).toBe(true);
25
- expect(settings.trust?.userAnchors).toBe("test");
26
- expect(settings.trust?.allowedList).toBe("allowed");
27
- });
28
- it("creates CAWG trust settings", () => {
29
- const trustConfig = {
30
- verifyTrustList: false,
31
- trustAnchors: "anchors",
32
- };
33
- const settings = createCawgTrustSettings(trustConfig);
34
- expect(settings.cawgTrust).toBeDefined();
35
- expect(settings.cawgTrust?.verifyTrustList).toBe(false);
36
- expect(settings.cawgTrust?.trustAnchors).toBe("anchors");
37
- });
38
- it("creates verify settings", () => {
39
- const verifyConfig = {
40
- verifyAfterReading: true,
41
- verifyAfterSign: false,
42
- verifyTrust: true,
43
- verifyTimestampTrust: false,
44
- ocspFetch: true,
45
- remoteManifestFetch: false,
46
- skipIngredientConflictResolution: true,
47
- strictV1Validation: false,
48
- };
49
- const settings = createVerifySettings(verifyConfig);
50
- expect(settings.verify).toBeDefined();
51
- expect(settings.verify?.verifyAfterReading).toBe(true);
52
- expect(settings.verify?.verifyAfterSign).toBe(false);
53
- expect(settings.verify?.verifyTrust).toBe(true);
54
- expect(settings.verify?.ocspFetch).toBe(true);
55
- });
56
- it("creates verify settings with partial config", () => {
57
- const settings = createVerifySettings({
58
- verifyAfterReading: false,
59
- });
60
- expect(settings.verify).toBeDefined();
61
- expect(settings.verify?.verifyAfterReading).toBe(false);
62
- expect(settings.verify?.verifyAfterSign).toBeUndefined();
63
- expect(settings.verify?.verifyTrust).toBeUndefined();
64
- });
65
- it("merges multiple settings", () => {
66
- const trustSettings = createTrustSettings({
67
- verifyTrustList: true,
68
- userAnchors: "test",
69
- });
70
- const verifySettings = createVerifySettings({
71
- verifyAfterReading: false,
72
- verifyAfterSign: true,
73
- verifyTrust: true,
74
- verifyTimestampTrust: true,
75
- ocspFetch: false,
76
- remoteManifestFetch: true,
77
- skipIngredientConflictResolution: false,
78
- strictV1Validation: false,
79
- });
80
- const merged = mergeSettings(trustSettings, verifySettings);
81
- expect(merged.trust).toBeDefined();
82
- expect(merged.verify).toBeDefined();
83
- expect(merged.trust?.verifyTrustList).toBe(true);
84
- expect(merged.verify?.verifyAfterReading).toBe(false);
85
- });
86
- it("converts settings to JSON with snake_case keys", () => {
87
- const settings = createVerifySettings({
88
- verifyAfterReading: true,
89
- verifyAfterSign: true,
90
- verifyTrust: false,
91
- verifyTimestampTrust: true,
92
- ocspFetch: false,
93
- remoteManifestFetch: true,
94
- skipIngredientConflictResolution: false,
95
- strictV1Validation: false,
96
- });
97
- const json = settingsToJson(settings);
98
- expect(json).toContain("verify");
99
- expect(json).toContain("verify_after_reading");
100
- // Should be parseable with snake_case keys
101
- const parsed = JSON.parse(json);
102
- expect(parsed.verify.verify_after_reading).toBe(true);
103
- });
104
- it("does not include undefined values in trust settings JSON", () => {
105
- const trustConfig = {
106
- verifyTrustList: true,
107
- };
108
- const settings = createTrustSettings(trustConfig);
109
- const json = settingsToJson(settings);
110
- const parsed = JSON.parse(json);
111
- expect(parsed.trust.verify_trust_list).toBe(true);
112
- expect("user_anchors" in parsed.trust).toBe(false);
113
- expect("trust_anchors" in parsed.trust).toBe(false);
114
- expect("trust_config" in parsed.trust).toBe(false);
115
- expect("allowed_list" in parsed.trust).toBe(false);
116
- });
117
- it("does not include undefined values in CAWG trust settings JSON", () => {
118
- const trustConfig = {
119
- verifyTrustList: false,
120
- };
121
- const settings = createCawgTrustSettings(trustConfig);
122
- const json = settingsToJson(settings);
123
- const parsed = JSON.parse(json);
124
- expect(parsed.cawg_trust.verify_trust_list).toBe(false);
125
- expect("user_anchors" in parsed.cawg_trust).toBe(false);
126
- expect("trust_anchors" in parsed.cawg_trust).toBe(false);
127
- });
128
- it("does not include undefined values in verify settings JSON", () => {
129
- const verifyConfig = {
130
- verifyAfterReading: true,
131
- verifyAfterSign: false,
132
- };
133
- const settings = createVerifySettings(verifyConfig);
134
- const json = settingsToJson(settings);
135
- const parsed = JSON.parse(json);
136
- expect(parsed.verify.verify_after_reading).toBe(true);
137
- expect(parsed.verify.verify_after_sign).toBe(false);
138
- expect("verify_trust" in parsed.verify).toBe(false);
139
- expect("verify_timestamp_trust" in parsed.verify).toBe(false);
140
- expect("ocsp_fetch" in parsed.verify).toBe(false);
141
- expect("remote_manifest_fetch" in parsed.verify).toBe(false);
142
- });
143
- it("does not include undefined values when merging settings", () => {
144
- const settings1 = {
145
- trust: {
146
- verifyTrustList: true,
147
- userAnchors: "test",
148
- },
149
- };
150
- const settings2 = {
151
- trust: {
152
- verifyTrustList: true,
153
- allowedList: undefined,
154
- },
155
- verify: {
156
- verifyAfterReading: false,
157
- },
158
- };
159
- const merged = mergeSettings(settings1, settings2);
160
- const json = settingsToJson(merged);
161
- const parsed = JSON.parse(json);
162
- expect(parsed.trust.verify_trust_list).toBe(true);
163
- expect(parsed.trust.user_anchors).toBe("test");
164
- expect("allowed_list" in parsed.trust).toBe(false);
165
- expect(parsed.verify.verify_after_reading).toBe(false);
166
- });
167
- it("merges settings with later values overriding earlier ones", () => {
168
- const settings1 = createVerifySettings({
169
- verifyAfterReading: true,
170
- verifyAfterSign: true,
171
- verifyTrust: false,
172
- verifyTimestampTrust: true,
173
- ocspFetch: false,
174
- remoteManifestFetch: true,
175
- skipIngredientConflictResolution: false,
176
- strictV1Validation: false,
177
- });
178
- const settings2 = {
179
- verify: {
180
- verifyTrust: true,
181
- ocspFetch: true,
182
- },
183
- };
184
- const merged = mergeSettings(settings1, settings2);
185
- expect(merged.verify?.verifyAfterReading).toBe(true); // from settings1
186
- expect(merged.verify?.verifyTrust).toBe(true); // overridden by settings2
187
- expect(merged.verify?.ocspFetch).toBe(true); // overridden by settings2
188
- });
189
11
  describe("loadSettingsFromFile", () => {
190
12
  let tempDir;
191
13
  beforeEach(async () => {
@@ -224,38 +46,4 @@ verify_after_sign = false`;
224
46
  await expect(loadSettingsFromFile(filePath)).rejects.toThrow();
225
47
  });
226
48
  });
227
- describe("loadSettingsFromUrl", () => {
228
- beforeEach(() => {
229
- vi.clearAllMocks();
230
- });
231
- it("loads settings from a URL", async () => {
232
- const mockSettings = JSON.stringify({
233
- verify: {
234
- verify_after_reading: true,
235
- },
236
- });
237
- const fetch = (await import("node-fetch")).default;
238
- vi.mocked(fetch).mockResolvedValue({
239
- ok: true,
240
- text: async () => mockSettings,
241
- });
242
- const loaded = await loadSettingsFromUrl("https://example.com/settings.json");
243
- expect(loaded).toBe(mockSettings);
244
- expect(fetch).toHaveBeenCalledWith("https://example.com/settings.json");
245
- });
246
- it("throws error for failed fetch", async () => {
247
- const fetch = (await import("node-fetch")).default;
248
- vi.mocked(fetch).mockResolvedValue({
249
- ok: false,
250
- status: 404,
251
- statusText: "Not Found",
252
- });
253
- await expect(loadSettingsFromUrl("https://example.com/missing.json")).rejects.toThrow("Failed to fetch settings from URL: 404 Not Found");
254
- });
255
- it("throws error for network failure", async () => {
256
- const fetch = (await import("node-fetch")).default;
257
- vi.mocked(fetch).mockRejectedValue(new Error("Network error"));
258
- await expect(loadSettingsFromUrl("https://example.com/settings.json")).rejects.toThrow("Network error");
259
- });
260
- });
261
49
  });
@@ -0,0 +1,35 @@
1
+ // Copyright 2026 Adobe. All rights reserved.
2
+ // This file is licensed to you under the Apache License,
3
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
+ // or the MIT license (http://opensource.org/licenses/MIT),
5
+ // at your option.
6
+ // Unless required by applicable law or agreed to in writing,
7
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
8
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
9
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
10
+ // specific language governing permissions and limitations under
11
+ // each license.
12
+ import * as fs from "fs-extra";
13
+ import { validateAssetSize } from "@contentauth/c2pa-utilities";
14
+ // c2pa-node runs server-side, so it can reasonably support larger assets than c2pa-web,
15
+ // and may be less resource-constrained in comparison.
16
+ export const MAX_SIZE_IN_BYTES = 10 * 10 ** 9; // 10 GB
17
+ /**
18
+ * Validates a {@link SourceAsset}'s size before it's handed to the native reader.
19
+ *
20
+ * For a `FileAsset`, this rejects an oversized file before it's read into memory.
21
+ * For a `SourceBufferAsset`, the buffer is already fully allocated by the time this runs,
22
+ * so the memory cost isn't prevented, only reader construction is. Prefer `path`
23
+ * for large or untrusted assets.
24
+ *
25
+ * @throws Error if reading the `FileAsset` fails.
26
+ * @throws {AssetTooLargeError} If `sizeInBytes` exceeds the resolved limit.
27
+ */
28
+ export async function validateSourceAssetSize(asset) {
29
+ if ("buffer" in asset) {
30
+ validateAssetSize(asset.buffer.length, MAX_SIZE_IN_BYTES);
31
+ return;
32
+ }
33
+ const { size } = await fs.stat(asset.path);
34
+ validateAssetSize(size, MAX_SIZE_IN_BYTES);
35
+ }
package/dist/index.js CHANGED
@@ -10,3 +10,4 @@ export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHo
10
10
  export { Trustmark } from "./Trustmark.js";
11
11
  export { isActionsAssertion } from "./assertions.js";
12
12
  export * from "./Settings.js";
13
+ export * from '@contentauth/c2pa-utilities';
package/dist/index.node CHANGED
Binary file
@@ -1,45 +1,12 @@
1
- import type { TrustConfig, VerifyConfig, SettingsContext } from "./types.d.ts";
2
1
  /**
3
- * Create a Settings object with trust configuration.
4
- * @param trustConfig The trust configuration
5
- * @returns Settings object that can be passed to Reader/Builder
2
+ * This file contains only Settings functions that are unique to the Node SDK.
3
+ *
4
+ * Shared Settings-related functions and types can be found in `c2pa-utilities`,
5
+ * and are re-exported by `c2pa-node` (see `index.ts`) for convenience.
6
6
  */
7
- export declare function createTrustSettings(trustConfig: TrustConfig): SettingsContext;
8
- /**
9
- * Create a settings object with CAWG trust configuration.
10
- * @param trustConfig The CAWG trust configuration
11
- * @returns Settings object that can be passed to Reader/Builder
12
- */
13
- export declare function createCawgTrustSettings(trustConfig: TrustConfig): SettingsContext;
14
- /**
15
- * Create a settings object with verify configuration.
16
- * @param verifyConfig The verify configuration
17
- * @returns Settings object that can be passed to Reader/Builder
18
- */
19
- export declare function createVerifySettings(verifyConfig: VerifyConfig): SettingsContext;
20
- /**
21
- * Merge multiple settings objects into one.
22
- * Later settings override earlier ones.
23
- * @param settings Settings objects to merge
24
- * @returns Merged settings object
25
- */
26
- export declare function mergeSettings(...settings: SettingsContext[]): SettingsContext;
27
- /**
28
- * Convert a settings object to a JSON string.
29
- * Converts camelCase keys to snake_case to match the c2pa-rs settings format.
30
- * @param settings The settings object
31
- * @returns JSON string representation with snake_case keys
32
- */
33
- export declare function settingsToJson(settings: SettingsContext): string;
34
7
  /**
35
8
  * Load settings from a TOML or JSON file.
36
9
  * @param filePath The path to the settings file
37
10
  * @returns Settings as a string (TOML or JSON depending on file extension)
38
11
  */
39
12
  export declare function loadSettingsFromFile(filePath: string): Promise<string>;
40
- /**
41
- * Load settings from a URL.
42
- * @param url The URL to fetch the settings from
43
- * @returns Settings as a string
44
- */
45
- export declare function loadSettingsFromUrl(url: string): Promise<string>;
@@ -0,0 +1,14 @@
1
+ import type { SourceAsset } from "./types.d.ts";
2
+ export declare const MAX_SIZE_IN_BYTES: number;
3
+ /**
4
+ * Validates a {@link SourceAsset}'s size before it's handed to the native reader.
5
+ *
6
+ * For a `FileAsset`, this rejects an oversized file before it's read into memory.
7
+ * For a `SourceBufferAsset`, the buffer is already fully allocated by the time this runs,
8
+ * so the memory cost isn't prevented, only reader construction is. Prefer `path`
9
+ * for large or untrusted assets.
10
+ *
11
+ * @throws Error if reading the `FileAsset` fails.
12
+ * @throws {AssetTooLargeError} If `sizeInBytes` exceeds the resolved limit.
13
+ */
14
+ export declare function validateSourceAssetSize(asset: SourceAsset): Promise<void>;
@@ -6,3 +6,4 @@ export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHo
6
6
  export { Trustmark } from "./Trustmark.js";
7
7
  export { isActionsAssertion } from "./assertions.js";
8
8
  export * from "./Settings.js";
9
+ export * from '@contentauth/c2pa-utilities';
@@ -19,26 +19,18 @@ import type {
19
19
  C2paReason,
20
20
  Ingredient,
21
21
  Manifest,
22
+ ManifestAssertionKind,
22
23
  ManifestStore,
23
24
  } from "@contentauth/c2pa-types";
25
+ import type { SigningAlg } from "@contentauth/c2pa-utilities";
24
26
 
25
- export type { Action, C2paReason, Ingredient } from "@contentauth/c2pa-types";
26
-
27
- /**
28
- * Describes the digital signature algorithms allowed by the C2PA spec
29
- *
30
- * Per <https://c2pa.org/specifications/specifications/1.0/specs/C2PA_Specification.html#_digital_signatures>:
31
- *
32
- * > All digital signatures that are stored in a C2PA Manifest shall > be generated using one of the digital signature algorithms and > key types listed as described in this section
33
- */
34
- export type SigningAlg =
35
- | "es256"
36
- | "es384"
37
- | "es512"
38
- | "ps256"
39
- | "ps384"
40
- | "ps512"
41
- | "ed25519";
27
+ export type {
28
+ Action,
29
+ C2paReason,
30
+ Ingredient,
31
+ ManifestAssertionKind,
32
+ } from "@contentauth/c2pa-types";
33
+ export type { SigningAlg } from "@contentauth/c2pa-utilities";
42
34
 
43
35
  export type ClaimVersion = 1 | 2;
44
36
 
@@ -64,8 +56,6 @@ export type TrustmarkVariant =
64
56
  // Quality Trustmark model
65
57
  | "Q";
66
58
 
67
- export type ManifestAssertionKind = "Cbor" | "Json" | "Binary" | "Uri";
68
-
69
59
  /**
70
60
  * A buffer for the source asset
71
61
  */
@@ -195,7 +185,9 @@ export interface HashedUri {
195
185
  export type C2paSettings = string | object;
196
186
 
197
187
  export interface BuilderInterface {
198
- /** An intent lets the API know what kind of manifest to create.
188
+ /**
189
+ * An intent lets the API know what kind of manifest to create.
190
+ *
199
191
  * Intents are `Create`, `Edit`, or `Update`.
200
192
  * This allows the API to check that you are doing the right thing.
201
193
  * It can also do things for you, like add parent ingredients from the source asset
@@ -516,62 +508,26 @@ export interface TrustmarkConfig {
516
508
  modelPath?: string;
517
509
  }
518
510
 
511
+ import type {
512
+ Settings as _Settings,
513
+ TrustSettings as _TrustSettings,
514
+ VerifySettings as _VerifySettings
515
+ } from "@contentauth/c2pa-utilities";
516
+
519
517
  /**
520
- * Configuration for trust settings in C2PA.
521
- * Controls certificate trust validation and trust anchor management.
518
+ * @deprecated Use `TrustSettings` instead, which encapsulates both normal trust and CAWG trust settings.
519
+ * Kept as an alias for backwards compatibility.
522
520
  */
523
- export interface TrustConfig {
524
- /** Whether to verify against the trust list */
525
- verifyTrustList: boolean;
526
- /** User-provided trust anchors (PEM format or base64-encoded certificate hashes) */
527
- userAnchors?: string;
528
- /** Trust anchors for validation (PEM format or base64-encoded certificate hashes) */
529
- trustAnchors?: string;
530
- /** Trust configuration file path */
531
- trustConfig?: string;
532
- /** Allowed list of certificates (PEM format or base64-encoded certificate hashes) */
533
- allowedList?: string;
534
- }
521
+ export type TrustConfig = _TrustSettings;
535
522
 
536
523
  /**
537
- * Configuration for verification settings in C2PA.
538
- * Controls various verification behaviors and options.
524
+ * @deprecated Use `VerifySettings` instead.
525
+ * Kept as an alias for backwards compatibility.
539
526
  */
540
- export interface VerifyConfig {
541
- /** Whether to verify after reading a manifest */
542
- verifyAfterReading?: boolean;
543
- /** Whether to verify after signing a manifest */
544
- verifyAfterSign?: boolean;
545
- /** Whether to verify trust during validation */
546
- verifyTrust?: boolean;
547
- /** Whether to verify timestamp trust */
548
- verifyTimestampTrust?: boolean;
549
- /** Whether to fetch OCSP responses */
550
- ocspFetch?: boolean;
551
- /** Whether to fetch remote manifests */
552
- remoteManifestFetch?: boolean;
553
- /** Whether to skip ingredient conflict resolution */
554
- skipIngredientConflictResolution?: boolean;
555
- /** Whether to use strict v1 validation */
556
- strictV1Validation?: boolean;
557
- }
527
+ export type VerifyConfig = _VerifySettings;
558
528
 
559
529
  /**
560
- * Settings configuration object that can be passed to Reader and Builder constructors.
561
- * Only trust, verify, and builder settings are configurable from the Node SDK.
562
- * Uses snake_case internally to match the c2pa-rs settings format.
530
+ * @deprecated Use `Settings` instead.
531
+ * Kept as an alias for backwards compatibility.
563
532
  */
564
- export interface SettingsContext {
565
- /** C2PA trust configuration */
566
- trust?: TrustConfig;
567
- /** CAWG trust configuration */
568
- cawgTrust?: TrustConfig;
569
- /** Verification configuration */
570
- verify?: VerifyConfig;
571
- /** Builder configuration */
572
- builder?: {
573
- thumbnail?: {
574
- enabled?: boolean;
575
- };
576
- };
577
- }
533
+ export type SettingsContext = _Settings;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/contentauth/c2pa-js.git",
6
6
  "directory": "packages/c2pa-node"
7
7
  },
8
- "version": "0.8.3",
8
+ "version": "0.9.1",
9
9
  "description": "Node.js bindings for C2PA",
10
10
  "main": "dist/index.js",
11
11
  "type": "module",
@@ -45,8 +45,7 @@
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",
49
- "@contentauth/c2pa-types": "0.7.3"
48
+ "vitest": "^3.2.4"
50
49
  },
51
50
  "keywords": [
52
51
  "c2pa"
@@ -64,7 +63,9 @@
64
63
  "node-fetch": "^3.3.2",
65
64
  "pkg-dir": "^8.0.0",
66
65
  "pretty-bytes": "^6.1.1",
67
- "unzipper": "^0.10.14"
66
+ "unzipper": "^0.10.14",
67
+ "@contentauth/c2pa-types": "0.7.3",
68
+ "@contentauth/c2pa-utilities": "0.2.1"
68
69
  },
69
70
  "nx": {
70
71
  "tags": [