@contentauth/c2pa-node 0.10.1 → 0.12.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 CHANGED
@@ -35,5 +35,5 @@ toml = "0.8"
35
35
  thiserror = "1.0.61"
36
36
  tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
37
37
  tokio-util = "0.7.13"
38
- trustmark = "0.4.0"
38
+ trustmark = "0.5.0"
39
39
  rand = "0.8.5"
package/README.md CHANGED
@@ -59,6 +59,56 @@ For documentation builds and version-list maintenance, see
59
59
 
60
60
  ## Components
61
61
 
62
+ ### Trustmark
63
+
64
+ `Trustmark` uses TrustMark 0.5 to encode and decode watermarks. Watermark removal
65
+ is opt-in and supported for variants **P** and **Q** only. Select the variant
66
+ used to embed the watermark:
67
+
68
+ ```javascript
69
+ import { Trustmark } from '@contentauth/c2pa-node';
70
+
71
+ const trustmark = await Trustmark.newTrustmark({
72
+ variant: 'P',
73
+ version: 'BCH_5',
74
+ modelPath: './models',
75
+ loadRemover: true
76
+ });
77
+ const recoveredPng = await trustmark.remove(watermarkedImageBuffer);
78
+ ```
79
+
80
+ `loadRemover` defaults to `false`. Enabling it downloads and loads the separate
81
+ `remover_P.onnx` or `remover_Q.onnx` file in `modelPath` (default `./models`), in
82
+ addition to the encoder and decoder. Cached files are reused. This adds startup
83
+ time and memory usage; ordinary encode/decode callers do not load a remover.
84
+
85
+ `remove()` accepts an 8-bit JPEG or PNG (RGB, RGBA, or grayscale) and returns an
86
+ **encoded PNG**, preserving dimensions and alpha. This differs from `encode()`,
87
+ which returns **raw RGB8 pixels**. Unsupported formats or bit depths, malformed
88
+ images, missing removal support, and model/inference failures reject the promise;
89
+ failures are never silently treated as successful removal.
90
+
91
+ Removal rejects encoded inputs larger than **64 MiB**, dimensions larger than
92
+ **16,384 pixels** on either axis, and images with more than **32 million pixels**.
93
+ Dimensions and pixel count are checked before decoding pixels or running
94
+ inference. Decoding also has a **best-effort 128 MiB allocation budget**. These
95
+ are per-call limits, not a cap on total process memory: removal allocates additional
96
+ full-resolution buffers, and concurrent calls require additional memory.
97
+
98
+ The returned PNG is **pixel-only**. It does not copy image metadata, including
99
+ EXIF, XMP, ICC color profiles, or embedded C2PA manifests. Preserving dimensions
100
+ and alpha does not mean preserving metadata. Callers that need ordinary image
101
+ metadata must carry it forward separately using an encoder that supports it.
102
+ Existing C2PA credentials bind to the original asset and do not remain valid for
103
+ the modified pixels. Use the original asset as an ingredient and sign a new
104
+ manifest to attach valid Content Credentials to the output; do not simply copy
105
+ the original manifest.
106
+
107
+ Removal is lossy: it does not restore the original pixels or guarantee removal of
108
+ arbitrary watermarks. It can also change an image without a detectable watermark.
109
+ Remove before re-watermarking if replacing an existing identifier. Operations on
110
+ a shared remover are serialized internally.
111
+
62
112
  ### Reader
63
113
 
64
114
  The `Reader` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
@@ -95,9 +145,6 @@ const isEmbedded = reader.isEmbedded();
95
145
  const remoteUrl = reader.remoteUrl();
96
146
  ```
97
147
 
98
- > [!NOTE]
99
- > `Reader.fromAsset`/`Reader.fromManifestDataAndAsset` also accept a raw settings object in place of a `Context` (e.g. `Reader.fromAsset(inputAsset, { verify: { verify_trust: true } })`), but this is deprecated — see [Per-instance settings (deprecated)](#per-instance-settings-deprecated).
100
-
101
148
  `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.
102
149
 
103
150
  > [!WARNING]
@@ -138,9 +185,6 @@ await builder.addResource('resource://example', resourceAsset);
138
185
  const manifest = builder.sign(signer, inputAsset, outputAsset);
139
186
  ```
140
187
 
141
- > [!NOTE]
142
- > `Builder.new`/`Builder.withJson` (synchronous, taking a raw settings object in place of a `Context`) still work but are deprecated — see [Per-instance settings (deprecated)](#per-instance-settings-deprecated).
143
-
144
188
  #### Setting builder intent
145
189
 
146
190
  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:
@@ -535,11 +579,11 @@ const decodedData = await trustmark.decode(imageBuffer);
535
579
 
536
580
  ### Settings and configuration
537
581
 
538
- The library provides comprehensive settings management that can be configured per Reader/Builder instance, via a `Context`, or using helper functions. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
582
+ Configure each Reader/Builder instance with a `Context`. Settings helper functions remain available to prepare the settings object passed to its constructor. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
539
583
 
540
584
  #### Using a Context
541
585
 
542
- A `Context` (from [`c2pa-utilities`](../c2pa-utilities/README.md#context-and-settings), re-exported directly from `@contentauth/c2pa-node` so you don't need to add that package yourself) wraps `Settings` and is the recommended way to configure a `Reader` or `Builder`:
586
+ A `Context` (from [`c2pa-utilities`](../c2pa-utilities/README.md#context-and-settings), re-exported directly from `@contentauth/c2pa-node` so you don't need to add that package yourself) wraps `Settings` and is the only supported way to configure a `Reader` or `Builder`. Node, web and web's `/inline` entry point re-export the same class, so contexts and subclasses can be shared across packages:
543
587
 
544
588
  ```javascript
545
589
  import { Reader, Builder, Context } from '@contentauth/c2pa-node';
@@ -560,46 +604,30 @@ const context = new Context({
560
604
  // Pass a Context to Reader
561
605
  const reader = await Reader.fromAsset(inputAsset, context);
562
606
 
563
- // Builder has async, Context-aware counterparts to its synchronous factories below
607
+ // Builder creation resolves the Context asynchronously
564
608
  const builder = await Builder.newAsync(context);
565
609
  const builder2 = await Builder.withJsonAsync(manifestDefinition, context);
566
610
  const builder3 = await Builder.fromArchive(archiveAsset, context);
567
611
  ```
568
612
 
569
613
  > [!NOTE]
570
- > As in `c2pa-web`, URLs in a `Context`'s trust-anchor settings are fetched and resolved before the Reader or Builder is created. The deprecated raw-settings API does not resolve URLs; use a `Context` for URL-based trust anchors.
571
-
572
- #### Per-instance settings (deprecated)
614
+ > As in `c2pa-web`, URLs in a `Context`'s trust-anchor settings are fetched and resolved before the Reader or Builder is created. Successful resolution is memoized when a Context is reused.
573
615
 
574
- Passing settings directly as a JSON string, or as a raw object matching the native settings shape (snake_case keys, no defaults applied), is deprecated and will be removed in a future major version — use a `Context` instead (above). `Builder.new`/`Builder.withJson` stay synchronous for this deprecated path; prefer their `newAsync`/`withJsonAsync` counterparts with a `Context` instead.
575
-
576
- ```javascript
577
- import { Reader, Builder } from '@contentauth/c2pa-node';
578
-
579
- // Create settings object
580
- const settings = {
581
- verify: {
582
- verify_after_reading: false,
583
- verify_after_sign: false,
584
- verify_trust: true,
585
- ocsp_fetch: true
586
- },
587
- trust: {
588
- verify_trust_list: true,
589
- trust_anchors: "path/to/anchors.pem"
590
- }
591
- };
616
+ #### Migrating from deprecated settings APIs
592
617
 
593
- // Pass settings to Reader
594
- const reader = await Reader.fromAsset(inputAsset, settings);
618
+ Raw settings objects, JSON/TOML strings and `null` are no longer accepted by Reader/Builder factories. Convert configuration to the camelCase `Settings` shape and wrap it in `new Context(settings)`. Omit the context argument, or pass `new Context()`, to use defaults.
595
619
 
596
- // Pass settings to Builder
597
- const builder = Builder.new(settings);
620
+ | Removed API | Replacement |
621
+ | --- | --- |
622
+ | `Builder.new(settings)` | `await Builder.newAsync(context)` |
623
+ | `Builder.withJson(definition, settings)` | `await Builder.withJsonAsync(definition, context)` |
624
+ | `Reader.fromAsset(asset, settings)` | `await Reader.fromAsset(asset, context)` |
625
+ | `Reader.fromManifestDataAndAsset(data, asset, settings)` | `await Reader.fromManifestDataAndAsset(data, asset, context)` |
626
+ | `Builder.fromArchive(asset, settings)` | `await Builder.fromArchive(asset, context)` |
627
+ | `C2paSettings`, `SettingsContext` | `Settings` for configuration objects; `Context` for factory arguments |
628
+ | `TrustConfig`, `VerifyConfig` | `TrustSettings`, `VerifySettings` |
598
629
 
599
- // Settings can also be JSON strings
600
- const settingsJson = JSON.stringify(settings);
601
- const builder2 = Builder.new(settingsJson);
602
- ```
630
+ `Context` applies SDK defaults and resolves trust-anchor URLs; unlike the removed raw settings path, it does not pass native settings through unchanged.
603
631
 
604
632
  #### Settings helper functions
605
633
 
@@ -607,13 +635,11 @@ The library provides helper functions to create and manage settings objects:
607
635
 
608
636
  ```javascript
609
637
  import {
638
+ Context,
610
639
  createTrustSettings,
611
640
  createCawgTrustSettings,
612
641
  createVerifySettings,
613
- mergeSettings,
614
- settingsToJson,
615
- loadSettingsFromFile,
616
- loadSettingsFromUrl
642
+ mergeSettings
617
643
  } from '@contentauth/c2pa-node';
618
644
 
619
645
  // Create trust settings
@@ -645,22 +671,12 @@ const verifySettings = createVerifySettings({
645
671
  // Merge multiple settings
646
672
  const combinedSettings = mergeSettings(trustSettings, verifySettings);
647
673
 
648
- // combinedSettings is a plain Settings object — use it with a Context (recommended)...
674
+ // combinedSettings is a plain Settings object — wrap it in a Context
649
675
  const readerWithContext = await Reader.fromAsset(inputAsset, new Context(combinedSettings));
650
-
651
- // ...or convert it to a JSON string for the deprecated per-instance settings path
652
- const jsonString = settingsToJson(combinedSettings);
653
- const readerWithJson = await Reader.fromAsset(inputAsset, jsonString);
654
-
655
- // loadSettingsFromFile/loadSettingsFromUrl return a raw JSON string, not a Settings
656
- // object, so they pair with the deprecated per-instance settings path, not Context, for now.
657
- const fileSettings = await loadSettingsFromFile('./c2pa-settings.json');
658
- const reader2 = await Reader.fromAsset(inputAsset, fileSettings);
659
-
660
- const urlSettings = await loadSettingsFromUrl('https://example.com/c2pa-settings.json');
661
- const builder = Builder.new(urlSettings);
662
676
  ```
663
677
 
678
+ Low-level serialization and loading helpers remain available, but their raw JSON/TOML strings are not valid Reader/Builder factory arguments.
679
+
664
680
  #### Available settings
665
681
 
666
682
  **Trust settings:**
package/dist/Builder.js CHANGED
@@ -5,7 +5,6 @@
5
5
  // at your option.
6
6
  import { Context } from "@contentauth/c2pa-utilities";
7
7
  import { getNeonBinary } from "./binary.js";
8
- import { resolveRawSettingsForNeon, resolveSettingsForNeon } from "./Settings.js";
9
8
  import { IdentityAssertionSigner } from "./IdentityAssertion.js";
10
9
  function stringifyManifestDefinition(json) {
11
10
  try {
@@ -24,19 +23,8 @@ export class Builder {
24
23
  constructor(builder) {
25
24
  this.builder = builder;
26
25
  }
27
- /**
28
- * @deprecated Use {@link Builder.newAsync} instead, passing a `Context`. Will be removed in a
29
- * future major version.
30
- * @param settings A raw `C2paSettings` string/object.
31
- */
32
- static new(settings) {
33
- const settingsStr = resolveRawSettingsForNeon(settings);
34
- const builder = getNeonBinary().builderNew(settingsStr);
35
- return new Builder(builder);
36
- }
37
26
  /**
38
27
  * Create a Builder with a minimal manifest definition, configured by a `Context`.
39
- * Prefer this over the deprecated {@link Builder.new}.
40
28
  *
41
29
  * Resolves trust-anchor URLs in the Context before constructing the Builder.
42
30
  *
@@ -44,24 +32,12 @@ export class Builder {
44
32
  * Defaults to an empty `Context` using default settings if one is not provided.
45
33
  */
46
34
  static async newAsync(context = new Context()) {
47
- const settingsStr = await resolveSettingsForNeon(context);
35
+ const settingsStr = await context.toJson();
48
36
  const builder = getNeonBinary().builderNew(settingsStr);
49
37
  return new Builder(builder);
50
38
  }
51
39
  /**
52
- * @deprecated Use {@link Builder.withJsonAsync} instead, passing a `Context`. Will be removed
53
- * in a future version.
54
- * @param settings A raw `C2paSettings` string/object.
55
- */
56
- static withJson(json, settings) {
57
- const jsonString = stringifyManifestDefinition(json);
58
- const settingsStr = resolveRawSettingsForNeon(settings);
59
- const builder = getNeonBinary().builderWithJson(jsonString, settingsStr);
60
- return new Builder(builder);
61
- }
62
- /**
63
- * Create a Builder from a manifest definition, configured by a `Context`. Prefer this over
64
- * the deprecated {@link Builder.withJson}.
40
+ * Create a Builder from a manifest definition, configured by a `Context`.
65
41
  *
66
42
  * Resolves trust-anchor URLs in the Context before constructing the Builder.
67
43
  *
@@ -71,7 +47,7 @@ export class Builder {
71
47
  */
72
48
  static async withJsonAsync(json, context = new Context()) {
73
49
  const jsonString = stringifyManifestDefinition(json);
74
- const settingsStr = await resolveSettingsForNeon(context);
50
+ const settingsStr = await context.toJson();
75
51
  const builder = getNeonBinary().builderWithJson(jsonString, settingsStr);
76
52
  return new Builder(builder);
77
53
  }
@@ -111,12 +87,10 @@ export class Builder {
111
87
  return getNeonBinary().builderToArchive.call(this.builder, asset);
112
88
  }
113
89
  /**
114
- * @param settingsOrContext A `Context`, or (deprecated) a raw `C2paSettings` string/object. Passing a
115
- * raw `C2paSettings` value is deprecated and will be removed in a future version. `null` is treated
116
- * the same as `undefined`.
90
+ * @param context A `Context` configuring this Builder. Defaults to an empty `Context`.
117
91
  */
118
- static async fromArchive(asset, settingsOrContext) {
119
- const settingsStr = await resolveSettingsForNeon(settingsOrContext);
92
+ static async fromArchive(asset, context = new Context()) {
93
+ const settingsStr = await context.toJson();
120
94
  return new Builder(await getNeonBinary().builderFromArchive(asset, settingsStr));
121
95
  }
122
96
  sign(signer, input, output) {