@contentauth/c2pa-node 0.10.0 → 0.11.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/README.md CHANGED
@@ -95,9 +95,6 @@ const isEmbedded = reader.isEmbedded();
95
95
  const remoteUrl = reader.remoteUrl();
96
96
  ```
97
97
 
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
98
  `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
99
 
103
100
  > [!WARNING]
@@ -138,9 +135,6 @@ await builder.addResource('resource://example', resourceAsset);
138
135
  const manifest = builder.sign(signer, inputAsset, outputAsset);
139
136
  ```
140
137
 
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
138
  #### Setting builder intent
145
139
 
146
140
  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 +529,11 @@ const decodedData = await trustmark.decode(imageBuffer);
535
529
 
536
530
  ### Settings and configuration
537
531
 
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.
532
+ 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
533
 
540
534
  #### Using a Context
541
535
 
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`:
536
+ 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
537
 
544
538
  ```javascript
545
539
  import { Reader, Builder, Context } from '@contentauth/c2pa-node';
@@ -560,46 +554,30 @@ const context = new Context({
560
554
  // Pass a Context to Reader
561
555
  const reader = await Reader.fromAsset(inputAsset, context);
562
556
 
563
- // Builder has async, Context-aware counterparts to its synchronous factories below
557
+ // Builder creation resolves the Context asynchronously
564
558
  const builder = await Builder.newAsync(context);
565
559
  const builder2 = await Builder.withJsonAsync(manifestDefinition, context);
566
560
  const builder3 = await Builder.fromArchive(archiveAsset, context);
567
561
  ```
568
562
 
569
563
  > [!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.
564
+ > 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.
571
565
 
572
- #### Per-instance settings (deprecated)
566
+ #### Migrating from deprecated settings APIs
573
567
 
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.
568
+ 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.
575
569
 
576
- ```javascript
577
- import { Reader, Builder } from '@contentauth/c2pa-node';
570
+ | Removed API | Replacement |
571
+ | --- | --- |
572
+ | `Builder.new(settings)` | `await Builder.newAsync(context)` |
573
+ | `Builder.withJson(definition, settings)` | `await Builder.withJsonAsync(definition, context)` |
574
+ | `Reader.fromAsset(asset, settings)` | `await Reader.fromAsset(asset, context)` |
575
+ | `Reader.fromManifestDataAndAsset(data, asset, settings)` | `await Reader.fromManifestDataAndAsset(data, asset, context)` |
576
+ | `Builder.fromArchive(asset, settings)` | `await Builder.fromArchive(asset, context)` |
577
+ | `C2paSettings`, `SettingsContext` | `Settings` for configuration objects; `Context` for factory arguments |
578
+ | `TrustConfig`, `VerifyConfig` | `TrustSettings`, `VerifySettings` |
578
579
 
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
- };
592
-
593
- // Pass settings to Reader
594
- const reader = await Reader.fromAsset(inputAsset, settings);
595
-
596
- // Pass settings to Builder
597
- const builder = Builder.new(settings);
598
-
599
- // Settings can also be JSON strings
600
- const settingsJson = JSON.stringify(settings);
601
- const builder2 = Builder.new(settingsJson);
602
- ```
580
+ `Context` applies SDK defaults and resolves trust-anchor URLs; unlike the removed raw settings path, it does not pass native settings through unchanged.
603
581
 
604
582
  #### Settings helper functions
605
583
 
@@ -607,13 +585,11 @@ The library provides helper functions to create and manage settings objects:
607
585
 
608
586
  ```javascript
609
587
  import {
588
+ Context,
610
589
  createTrustSettings,
611
590
  createCawgTrustSettings,
612
591
  createVerifySettings,
613
- mergeSettings,
614
- settingsToJson,
615
- loadSettingsFromFile,
616
- loadSettingsFromUrl
592
+ mergeSettings
617
593
  } from '@contentauth/c2pa-node';
618
594
 
619
595
  // Create trust settings
@@ -645,22 +621,12 @@ const verifySettings = createVerifySettings({
645
621
  // Merge multiple settings
646
622
  const combinedSettings = mergeSettings(trustSettings, verifySettings);
647
623
 
648
- // combinedSettings is a plain Settings object — use it with a Context (recommended)...
624
+ // combinedSettings is a plain Settings object — wrap it in a Context
649
625
  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
626
  ```
663
627
 
628
+ Low-level serialization and loading helpers remain available, but their raw JSON/TOML strings are not valid Reader/Builder factory arguments.
629
+
664
630
  #### Available settings
665
631
 
666
632
  **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) {
@@ -122,7 +122,7 @@ describe("Builder", () => {
122
122
  assertions: [],
123
123
  resources: { resources: {} },
124
124
  };
125
- const builder = Builder.withJson(test_definition);
125
+ const builder = await Builder.withJsonAsync(test_definition);
126
126
  await builder.addIngredient(parent_json, source);
127
127
  builder.addAssertion("org.test.assertion", "assertion");
128
128
  await builder.addResource(thumbnail_ref.identifier, {
@@ -142,8 +142,8 @@ describe("Builder", () => {
142
142
  });
143
143
  describe("Sign and Archive", () => {
144
144
  let builder;
145
- beforeEach(() => {
146
- builder = Builder.withJson(manifestDefinition);
145
+ beforeEach(async () => {
146
+ builder = await Builder.withJsonAsync(manifestDefinition);
147
147
  builder.updateManifestProperty("claim_version", 2);
148
148
  builder.setIntent("edit");
149
149
  });
@@ -197,7 +197,8 @@ describe("Builder", () => {
197
197
  const reader = await Reader.fromAsset(dest);
198
198
  expect(reader).not.toBeNull();
199
199
  const activeManifest = reader.getActive();
200
- const cborAssertion = activeManifest?.assertions?.find((a) => a.label === "c2pa.actions.v2");
200
+ const cborAssertion = activeManifest?.assertions?.find((assertion) => isActionsAssertion(assertion) &&
201
+ assertion.data.actions.some((action) => action.action === "c2pa.edited"));
201
202
  expect(cborAssertion).toBeDefined();
202
203
  if (isActionsAssertion(cborAssertion)) {
203
204
  const actions = cborAssertion.data.actions.map((a) => a.action);
@@ -246,12 +247,12 @@ describe("Builder", () => {
246
247
  expect(stats.size).toBeGreaterThan(0);
247
248
  });
248
249
  it("should construct reader directly from builder archive buffer", async () => {
249
- const settings = JSON.stringify({
250
+ const context = new Context({
250
251
  builder: {
251
- generate_c2pa_archive: true,
252
+ generateC2paArchive: true,
252
253
  },
253
254
  verify: {
254
- verify_after_reading: false,
255
+ verifyAfterReading: false,
255
256
  },
256
257
  });
257
258
  // Create a builder
@@ -267,7 +268,7 @@ describe("Builder", () => {
267
268
  assertions: [],
268
269
  resources: { resources: {} },
269
270
  };
270
- const testBuilder = Builder.withJson(simpleManifestDefinition, settings);
271
+ const testBuilder = await Builder.withJsonAsync(simpleManifestDefinition, context);
271
272
  // Add an ingredient
272
273
  await testBuilder.addIngredient(parent_json, source);
273
274
  // Create an archive from the builder written to a buffer
@@ -282,7 +283,7 @@ describe("Builder", () => {
282
283
  const reader = await Reader.fromAsset({
283
284
  buffer: archive.buffer,
284
285
  mimeType: "application/c2pa",
285
- }, settings);
286
+ }, context);
286
287
  expect(reader).not.toBeNull();
287
288
  });
288
289
  it("should sign data with callback to file", async () => {
@@ -476,7 +477,7 @@ describe("Builder", () => {
476
477
  ],
477
478
  resources: { resources: {} },
478
479
  };
479
- const builder = Builder.withJson(manifestDefinition);
480
+ const builder = await Builder.withJsonAsync(manifestDefinition);
480
481
  const ingredientJson = '{"title": "Test Ingredient"}';
481
482
  const testThumbnail = await fs.readFile("./tests/fixtures/thumbnail.jpg");
482
483
  await builder.addIngredient(ingredientJson, {
@@ -506,7 +507,7 @@ describe("Builder", () => {
506
507
  expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
507
508
  });
508
509
  it("should add ingredient with custom metadata", async () => {
509
- const builder = Builder.new();
510
+ const builder = await Builder.newAsync();
510
511
  const ingredient = {
511
512
  title: "Test Ingredient",
512
513
  format: "image/jpeg",
@@ -539,7 +540,7 @@ describe("Builder", () => {
539
540
  const testSigner = new TestSigner(privateKey);
540
541
  const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
541
542
  // Sign source asset with a thumbnail
542
- const step1Builder = Builder.withJson({
543
+ const step1Builder = await Builder.withJsonAsync({
543
544
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
544
545
  title: "Asset With Thumbnail",
545
546
  format: "image/jpeg",
@@ -569,7 +570,7 @@ describe("Builder", () => {
569
570
  expect(originalManifest?.thumbnail).not.toBeNull();
570
571
  // Redact the thumbnail
571
572
  const thumbnailUri = `self#jumbf=/c2pa/${parentLabel}/c2pa.assertions/c2pa.thumbnail.claim`;
572
- const redactionBuilder = Builder.withJson({
573
+ const redactionBuilder = await Builder.withJsonAsync({
573
574
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
574
575
  title: "Redacted Thumbnail Manifest",
575
576
  format: "image/jpeg",
@@ -602,7 +603,7 @@ describe("Builder", () => {
602
603
  // Sign source asset with multiple distinct assertions
603
604
  const piiLabel = "stds.schema-org.CreativeWork";
604
605
  const retainedLabel = "org.contentauth.retained";
605
- const step1Builder = Builder.withJson({
606
+ const step1Builder = await Builder.withJsonAsync({
606
607
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
607
608
  title: "Asset With Multiple Assertions",
608
609
  format: "image/jpeg",
@@ -642,7 +643,7 @@ describe("Builder", () => {
642
643
  expect(originalLabels).toContain(retainedLabel);
643
644
  // Redact only the PII assertion
644
645
  const redactionUri = `self#jumbf=/c2pa/${parentLabel}/c2pa.assertions/${piiLabel}`;
645
- const redactionBuilder = Builder.withJson({
646
+ const redactionBuilder = await Builder.withJsonAsync({
646
647
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
647
648
  title: "Redacted Assertion Manifest",
648
649
  format: "image/jpeg",
@@ -665,18 +666,18 @@ describe("Builder", () => {
665
666
  expect(assertionLabels).not.toContain(piiLabel);
666
667
  expect(assertionLabels).toContain(retainedLabel);
667
668
  });
668
- it("should add redactions via addRedaction method", () => {
669
+ it("should add redactions via addRedaction method", async () => {
669
670
  const uri1 = "self#jumbf=/c2pa/test-label/c2pa.assertions/cawg.identity";
670
671
  const uri2 = "self#jumbf=/c2pa/test-label/c2pa.assertions/stds.schema-org.CreativeWork";
671
- const builder = Builder.new();
672
+ const builder = await Builder.newAsync();
672
673
  builder.addRedaction(uri1, "c2pa.PII.present");
673
674
  builder.addRedaction(uri2, "c2pa.PII.present");
674
675
  const definition = builder.getManifestDefinition();
675
676
  expect(definition.redactions).toEqual([uri1, uri2]);
676
677
  });
677
- it("should set a label", () => {
678
+ it("should set a label", async () => {
678
679
  const label = "urn:c2pa:00000000-0000-4000-8000-000000000000";
679
- const builder = Builder.new();
680
+ const builder = await Builder.newAsync();
680
681
  builder.updateManifestProperty("label", label);
681
682
  expect(builder.getManifestDefinition().label).toBe(label);
682
683
  });
@@ -705,7 +706,7 @@ describe("Builder", () => {
705
706
  },
706
707
  ],
707
708
  };
708
- const builder = Builder.withJson(simpleManifestDefinition);
709
+ const builder = await Builder.withJsonAsync(simpleManifestDefinition);
709
710
  // Set remote URL and no embed flag like the Rust test
710
711
  builder.setRemoteUrl("http://my_remote_url");
711
712
  builder.setNoEmbed(true);
@@ -760,7 +761,7 @@ describe("Builder", () => {
760
761
  assertions: [],
761
762
  resources: { resources: {} },
762
763
  };
763
- const builder = Builder.withJson(simpleManifestDefinition);
764
+ const builder = await Builder.withJsonAsync(simpleManifestDefinition);
764
765
  builder.setIntent({ create: "http://c2pa.org/digitalsourcetype/empty" });
765
766
  // Add an action using addAction method
766
767
  // The action needs to be a structured object matching the c2pa Action type
@@ -776,7 +777,8 @@ describe("Builder", () => {
776
777
  const reader = await Reader.fromAsset(dest);
777
778
  expect(reader).not.toBeNull();
778
779
  const activeManifest = reader.getActive();
779
- const actionsAssertion = activeManifest?.assertions?.find((a) => a.label === "c2pa.actions.v2");
780
+ const actionsAssertion = activeManifest?.assertions?.find((assertion) => isActionsAssertion(assertion) &&
781
+ assertion.data.actions.some((action) => action.action === "c2pa.edited"));
780
782
  expect(actionsAssertion).toBeDefined();
781
783
  if (isActionsAssertion(actionsAssertion)) {
782
784
  const actions = actionsAssertion.data.actions;
@@ -814,7 +816,7 @@ describe("Builder", () => {
814
816
  ],
815
817
  resources: { resources: {} },
816
818
  };
817
- const builder = Builder.withJson(simpleManifestDefinition);
819
+ const builder = await Builder.withJsonAsync(simpleManifestDefinition);
818
820
  // Add an ingredient using addIngredient method
819
821
  const ingredientJson = JSON.stringify({
820
822
  title: "Test Ingredient via addIngredient",
@@ -839,7 +841,7 @@ describe("Builder", () => {
839
841
  expect(addedIngredient?.relationship).toBe("componentOf");
840
842
  });
841
843
  it("should add ingredient from reader", async () => {
842
- const builder1 = Builder.new();
844
+ const builder1 = await Builder.newAsync();
843
845
  builder1.setIntent("edit");
844
846
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
845
847
  const dest1 = {
@@ -853,7 +855,7 @@ describe("Builder", () => {
853
855
  });
854
856
  expect(reader).not.toBeNull();
855
857
  // Create a new builder and add ingredient from the reader
856
- const builder2 = Builder.new();
858
+ const builder2 = await Builder.newAsync();
857
859
  builder2.setIntent("edit");
858
860
  const ingredient = builder2.addIngredientFromReader(reader);
859
861
  expect(ingredient).toBeDefined();
@@ -878,10 +880,11 @@ describe("Builder", () => {
878
880
  }, 30000);
879
881
  });
880
882
  describe("Context", () => {
881
- it("newAsync() with no context behaves like new()", async () => {
883
+ it("newAsync() with no context uses an empty Context", async () => {
882
884
  const builder = await Builder.newAsync();
883
885
  const definition = builder.getManifestDefinition();
884
- expect(definition).toEqual(Builder.new().getManifestDefinition());
886
+ const configured = await Builder.newAsync(new Context());
887
+ expect(definition).toEqual(configured.getManifestDefinition());
885
888
  });
886
889
  it("newAsync(context) applies the Context's settings", async () => {
887
890
  const dest = { path: path.join(tempDir, "context_new_signed.jpg") };
@@ -965,8 +968,8 @@ describe("Builder", () => {
965
968
  const manifestStore = reader.json();
966
969
  expect(manifestStore.validation_status ?? []).not.toContainEqual(expect.objectContaining({ code: "signingCredential.untrusted" }));
967
970
  });
968
- it("fromArchive(asset, context) accepts a Context in place of the deprecated raw settings", async () => {
969
- const builder = Builder.withJson(manifestDefinition);
971
+ it("fromArchive(asset, context) restores a Builder with a Context", async () => {
972
+ const builder = await Builder.withJsonAsync(manifestDefinition);
970
973
  await builder.addIngredient(parent_json, source);
971
974
  await builder.addResource("thumbnail.jpg", {
972
975
  mimeType: "jpeg",
@@ -1007,8 +1010,8 @@ describe("Builder", () => {
1007
1010
  ],
1008
1011
  resources: { resources: {} },
1009
1012
  });
1010
- it("filterActions keeps the inception action and drops excluded actions", () => {
1011
- const builder = Builder.withJson(actionsManifest());
1013
+ it("filterActions keeps the inception action and drops excluded actions", async () => {
1014
+ const builder = await Builder.withJsonAsync(actionsManifest());
1012
1015
  // The predicate only keeps c2pa.edited; c2pa.created must survive regardless
1013
1016
  // because it is the inception action.
1014
1017
  builder.filterActions((action) => action.action === "c2pa.edited");
@@ -1020,8 +1023,8 @@ describe("Builder", () => {
1020
1023
  expect(names).toContain("c2pa.edited");
1021
1024
  expect(names).not.toContain("c2pa.color_adjustments");
1022
1025
  });
1023
- it("filterActions surfaces an error thrown by the predicate", () => {
1024
- const builder = Builder.withJson(actionsManifest());
1026
+ it("filterActions surfaces an error thrown by the predicate", async () => {
1027
+ const builder = await Builder.withJsonAsync(actionsManifest());
1025
1028
  expect(() => builder.filterActions((action) => {
1026
1029
  if (action.action === "c2pa.color_adjustments") {
1027
1030
  throw new Error("boom from predicate");
@@ -1029,14 +1032,14 @@ describe("Builder", () => {
1029
1032
  return true;
1030
1033
  })).toThrow("boom from predicate");
1031
1034
  });
1032
- it("filterActions surfaces a non-boolean predicate return", () => {
1033
- const builder = Builder.withJson(actionsManifest());
1035
+ it("filterActions surfaces a non-boolean predicate return", async () => {
1036
+ const builder = await Builder.withJsonAsync(actionsManifest());
1034
1037
  expect(() =>
1035
1038
  // Returning a non-boolean is a programming error and must not be coerced.
1036
1039
  builder.filterActions(() => "yes")).toThrow(/must return a boolean/);
1037
1040
  });
1038
- it("filterIngredients prunes orphans and passes provenance to the predicate", () => {
1039
- const builder = Builder.withJson({
1041
+ it("filterIngredients prunes orphans and passes provenance to the predicate", async () => {
1042
+ const builder = await Builder.withJsonAsync({
1040
1043
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1041
1044
  title: "Test_FilterIngredients",
1042
1045
  format: "image/jpeg",
@@ -1074,8 +1077,8 @@ describe("Builder", () => {
1074
1077
  const definition = builder.getManifestDefinition();
1075
1078
  expect(definition.ingredients ?? []).toHaveLength(0);
1076
1079
  });
1077
- it("filterIngredients surfaces an error thrown by the predicate", () => {
1078
- const builder = Builder.withJson({
1080
+ it("filterIngredients surfaces an error thrown by the predicate", async () => {
1081
+ const builder = await Builder.withJsonAsync({
1079
1082
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1080
1083
  title: "Test_FilterIngredientsThrow",
1081
1084
  format: "image/jpeg",
@@ -1092,8 +1095,8 @@ describe("Builder", () => {
1092
1095
  throw new Error("ingredient boom");
1093
1096
  })).toThrow("ingredient boom");
1094
1097
  });
1095
- it("filterActionsAndIngredients rescues an edited action for a kept ingredient", () => {
1096
- const builder = Builder.withJson({
1098
+ it("filterActionsAndIngredients rescues an edited action for a kept ingredient", async () => {
1099
+ const builder = await Builder.withJsonAsync({
1097
1100
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1098
1101
  title: "Test_FilterActionsAndIngredients",
1099
1102
  format: "image/jpeg",
@@ -1133,8 +1136,8 @@ describe("Builder", () => {
1133
1136
  expect(names).toContain("c2pa.edited");
1134
1137
  expect(definition.ingredients ?? []).toHaveLength(1);
1135
1138
  });
1136
- it("filterActionsAndIngredients drops unreferenced and unrescued", () => {
1137
- const builder = Builder.withJson(actionsManifest());
1139
+ it("filterActionsAndIngredients drops unreferenced and unrescued", async () => {
1140
+ const builder = await Builder.withJsonAsync(actionsManifest());
1138
1141
  builder.addIngredient(JSON.stringify({
1139
1142
  title: "orphan",
1140
1143
  format: "image/jpeg",
@@ -1150,14 +1153,14 @@ describe("Builder", () => {
1150
1153
  expect(names).not.toContain("c2pa.color_adjustments");
1151
1154
  expect(definition.ingredients ?? []).toHaveLength(0);
1152
1155
  });
1153
- it("filterActionsAndIngredients surfaces an error thrown by either predicate", () => {
1154
- const builder = Builder.withJson(actionsManifest());
1156
+ it("filterActionsAndIngredients surfaces an error thrown by either predicate", async () => {
1157
+ const builder = await Builder.withJsonAsync(actionsManifest());
1155
1158
  expect(() => builder.filterActionsAndIngredients(() => {
1156
1159
  throw new Error("action predicate boom");
1157
1160
  }, () => false)).toThrow("action predicate boom");
1158
1161
  });
1159
- it("updateAssertion updates exact label matches in order and preserves metadata", () => {
1160
- const builder = Builder.withJson({
1162
+ it("updateAssertion updates exact label matches in order and preserves metadata", async () => {
1163
+ const builder = await Builder.withJsonAsync({
1161
1164
  ...actionsManifest(),
1162
1165
  assertions: [
1163
1166
  { label: "org.test.note", data: { value: 1 }, kind: "Cbor" },
@@ -1179,7 +1182,7 @@ describe("Builder", () => {
1179
1182
  ]);
1180
1183
  });
1181
1184
  it("updateAssertion preserves JSON and CBOR kinds when signing", async () => {
1182
- const builder = Builder.withJson({
1185
+ const builder = await Builder.withJsonAsync({
1183
1186
  ...actionsManifest(),
1184
1187
  assertions: [
1185
1188
  ...actionsManifest().assertions,
@@ -1210,8 +1213,8 @@ describe("Builder", () => {
1210
1213
  }),
1211
1214
  ]));
1212
1215
  });
1213
- it("updateAssertion skips null and undefined results without dropping other updates", () => {
1214
- const builder = Builder.withJson({
1216
+ it("updateAssertion skips null and undefined results without dropping other updates", async () => {
1217
+ const builder = await Builder.withJsonAsync({
1215
1218
  ...actionsManifest(),
1216
1219
  assertions: [
1217
1220
  { label: "org.test.note", data: { value: 1 }, kind: "Json" },
@@ -1225,8 +1228,8 @@ describe("Builder", () => {
1225
1228
  });
1226
1229
  expect(builder.getManifestDefinition().assertions.map((a) => a.data)).toEqual([{ value: 1 }, { value: 2 }, { value: 33 }]);
1227
1230
  });
1228
- it("updateAssertion is atomic on callback failure and ignores missing labels", () => {
1229
- const builder = Builder.withJson({
1231
+ it("updateAssertion is atomic on callback failure and ignores missing labels", async () => {
1232
+ const builder = await Builder.withJsonAsync({
1230
1233
  ...actionsManifest(),
1231
1234
  assertions: [
1232
1235
  { label: "org.test.note", data: { value: 1 } },
@@ -1252,8 +1255,8 @@ describe("Builder", () => {
1252
1255
  });
1253
1256
  expect(calls).toBe(0);
1254
1257
  });
1255
- it("updateActions patches a parameter on an existing action", () => {
1256
- const builder = Builder.withJson(actionsManifest());
1258
+ it("updateActions patches a parameter on an existing action", async () => {
1259
+ const builder = await Builder.withJsonAsync(actionsManifest());
1257
1260
  builder.updateActions((actions) => actions.map((action) => action.action === "c2pa.created"
1258
1261
  ? {
1259
1262
  ...action,
@@ -1273,12 +1276,12 @@ describe("Builder", () => {
1273
1276
  ]);
1274
1277
  expect(patched[0].parameters.patchMe).toBe("patch-test");
1275
1278
  });
1276
- it("updateActions adds a new parameter alongside the existing ones", () => {
1279
+ it("updateActions adds a new parameter alongside the existing ones", async () => {
1277
1280
  const manifest = actionsManifest();
1278
1281
  manifest.assertions[0].data.actions[1].parameters = {
1279
1282
  existingValue: "kept",
1280
1283
  };
1281
- const builder = Builder.withJson(manifest);
1284
+ const builder = await Builder.withJsonAsync(manifest);
1282
1285
  builder.updateActions((actions) => actions.map((action) => action.action === "c2pa.edited"
1283
1286
  ? {
1284
1287
  ...action,
@@ -1303,8 +1306,8 @@ describe("Builder", () => {
1303
1306
  expect(updated[0].parameters?.addedValue).toBeUndefined();
1304
1307
  expect(updated[2].parameters?.addedValue).toBeUndefined();
1305
1308
  });
1306
- it("updateActions is no-op when there is no actions assertion", () => {
1307
- const builder = Builder.withJson({
1309
+ it("updateActions is no-op when there is no actions assertion", async () => {
1310
+ const builder = await Builder.withJsonAsync({
1308
1311
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1309
1312
  title: "Test_NoActions",
1310
1313
  format: "image/jpeg",
@@ -1321,10 +1324,10 @@ describe("Builder", () => {
1321
1324
  const definition = builder.getManifestDefinition();
1322
1325
  expect((definition.assertions ?? []).filter((a) => a.label.startsWith("c2pa.actions"))).toHaveLength(0);
1323
1326
  });
1324
- it("updateActions drops an assertion whose transform returns an empty list", () => {
1327
+ it("updateActions drops an assertion whose transform returns an empty list", async () => {
1325
1328
  // (this means there could be no actions, so in non-test code, something after such a call
1326
1329
  // should make sure the manifest is still valid and inception actions are here as needed!)
1327
- const builder = Builder.withJson({
1330
+ const builder = await Builder.withJsonAsync({
1328
1331
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1329
1332
  title: "Test_TwoAssertions",
1330
1333
  format: "image/jpeg",
@@ -1356,8 +1359,8 @@ describe("Builder", () => {
1356
1359
  expect(actionsAssertions[0].label).toBe("c2pa.actions");
1357
1360
  expect(actionsAssertions[0].data.actions.map((a) => a.action)).toEqual(["c2pa.created"]);
1358
1361
  });
1359
- it("updateActions rewrites every actions assertion under its own label", () => {
1360
- const builder = Builder.withJson({
1362
+ it("updateActions rewrites every actions assertion under its own label", async () => {
1363
+ const builder = await Builder.withJsonAsync({
1361
1364
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1362
1365
  title: "Test_MultiAssertion",
1363
1366
  format: "image/jpeg",
@@ -1403,8 +1406,8 @@ describe("Builder", () => {
1403
1406
  expect(actions[0].parameters.addedValue).toBe("added-value");
1404
1407
  }
1405
1408
  });
1406
- it("updateActions preserves the created flag", () => {
1407
- const builder = Builder.withJson({
1409
+ it("updateActions preserves the created flag", async () => {
1410
+ const builder = await Builder.withJsonAsync({
1408
1411
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1409
1412
  title: "Test_CreatedFlag",
1410
1413
  format: "image/jpeg",
@@ -1440,7 +1443,7 @@ describe("Builder", () => {
1440
1443
  expect(actionsAssertions[0].data.actions.map((a) => a.action)).toEqual(["c2pa.created"]);
1441
1444
  });
1442
1445
  it("updateActions produces a signable manifest", async () => {
1443
- const builder = Builder.withJson({
1446
+ const builder = await Builder.withJsonAsync({
1444
1447
  claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
1445
1448
  title: "Test_UpdateActionsSign",
1446
1449
  format: "image/jpeg",
@@ -1478,8 +1481,8 @@ describe("Builder", () => {
1478
1481
  expect(codes).not.toContain("assertion.action.malformed");
1479
1482
  expect(codes).not.toContain("assertion.action.ingredientMismatch");
1480
1483
  });
1481
- it("updateActions preserves action order when transform patches in place", () => {
1482
- const builder = Builder.withJson(actionsManifest());
1484
+ it("updateActions preserves action order when transform patches in place", async () => {
1485
+ const builder = await Builder.withJsonAsync(actionsManifest());
1483
1486
  // Patch the middle entry; the transform never reorders.
1484
1487
  builder.updateActions((actions) => actions.map((action) => action.action === "c2pa.edited"
1485
1488
  ? { ...action, parameters: { note: "patched" } }
@@ -1493,13 +1496,13 @@ describe("Builder", () => {
1493
1496
  "c2pa.color_adjustments",
1494
1497
  ]);
1495
1498
  });
1496
- it("updateActions surfaces an error thrown by transform", () => {
1497
- const builder = Builder.withJson(actionsManifest());
1499
+ it("updateActions surfaces an error thrown by transform", async () => {
1500
+ const builder = await Builder.withJsonAsync(actionsManifest());
1498
1501
  expect(() => builder.updateActions(() => {
1499
1502
  throw new Error("transform boom");
1500
1503
  })).toThrow("transform boom");
1501
1504
  });
1502
- it("updateActions preserves allActionsIncluded/softwareAgents/templates/metadata not seen by transform", () => {
1505
+ it("updateActions preserves allActionsIncluded/softwareAgents/templates/metadata not seen by transform", async () => {
1503
1506
  const manifest = actionsManifest();
1504
1507
  manifest.assertions[0].data.allActionsIncluded = true;
1505
1508
  manifest.assertions[0].data.softwareAgents = [
@@ -1511,7 +1514,7 @@ describe("Builder", () => {
1511
1514
  manifest.assertions[0].data.metadata = {
1512
1515
  dataSource: { type: "humanEdits" },
1513
1516
  };
1514
- const builder = Builder.withJson(manifest);
1517
+ const builder = await Builder.withJsonAsync(manifest);
1515
1518
  // transform only ever sees/returns the flattened actions list, never the sibling fields.
1516
1519
  builder.updateActions((actions) => actions);
1517
1520
  const definition = builder.getManifestDefinition();
@@ -6,6 +6,8 @@
6
6
  import fs from "fs-extra";
7
7
  import * as crypto from "crypto";
8
8
  import { spawnSync } from "child_process";
9
+ import { once } from "node:events";
10
+ import { createServer } from "node:http";
9
11
  import { encodeSignerPayload } from "./index.js";
10
12
  class TestSigner {
11
13
  privateKey;
@@ -117,7 +119,7 @@ describe("IdentityAssertionBuilder", () => {
117
119
  buffer: null,
118
120
  };
119
121
  // Create the manifest builder
120
- const builder = Builder.withJson(manifestDefinition);
122
+ const builder = await Builder.withJsonAsync(manifestDefinition);
121
123
  // Add the required resources
122
124
  await builder.addResource("thumbnail.jpg", {
123
125
  mimeType: "image/jpeg",
@@ -140,6 +142,56 @@ describe("IdentityAssertionBuilder", () => {
140
142
  mimeType: "image/jpeg",
141
143
  });
142
144
  });
145
+ it("forwards timestamp requests and failures through the identity signer", async () => {
146
+ const { CallbackSigner } = await import("./Signer.js");
147
+ const { Builder } = await import("./Builder.js");
148
+ const { IdentityAssertionSigner } = await import("./IdentityAssertion.js");
149
+ const requests = [];
150
+ const server = createServer((request, response) => {
151
+ requests.push({
152
+ method: request.method,
153
+ marker: request.headers["x-c2pa-preflight"],
154
+ });
155
+ request.resume();
156
+ response.writeHead(503).end("Timestamp service unavailable");
157
+ });
158
+ server.listen(0, "127.0.0.1");
159
+ await once(server, "listening");
160
+ try {
161
+ const address = server.address();
162
+ if (!address || typeof address === "string") {
163
+ throw new Error("Expected a TCP timestamp test server");
164
+ }
165
+ const testSigner = new TestSigner(await fs.readFile("./tests/fixtures/certs/es256.pem"));
166
+ const signer = CallbackSigner.newSigner({
167
+ alg: "es256",
168
+ certs: [await fs.readFile("./tests/fixtures/certs/es256.pub")],
169
+ reserveSize: 10000,
170
+ tsaUrl: `http://127.0.0.1:${address.port}`,
171
+ tsaHeaders: [["x-c2pa-preflight", "identity-signer"]],
172
+ directCoseHandling: false,
173
+ }, testSigner.sign);
174
+ const builder = await Builder.withJsonAsync({
175
+ claim_generator_info: [{ name: "c2pa_test", version: "2.0.0" }],
176
+ format: "image/jpeg",
177
+ assertions: manifestDefinition.assertions,
178
+ });
179
+ await expect(builder.signAsync(IdentityAssertionSigner.new(signer.getHandle()), {
180
+ buffer: await fs.readFile("./tests/fixtures/CA.jpg"),
181
+ mimeType: "image/jpeg",
182
+ }, { buffer: null })).rejects.toThrow(/timestamp|503/i);
183
+ expect(requests).toContainEqual({
184
+ method: "POST",
185
+ marker: "identity-signer",
186
+ });
187
+ }
188
+ finally {
189
+ server.closeAllConnections();
190
+ await new Promise((resolve, reject) => {
191
+ server.close((error) => (error ? reject(error) : resolve()));
192
+ });
193
+ }
194
+ });
143
195
  });
144
196
  describe("CallbackCredentialHolder accessors", () => {
145
197
  it("returns reserveSize and sigType set on the constructor", async () => {
@@ -224,7 +276,7 @@ describe("handles reserveSize", () => {
224
276
  }, c2paTestSigner.sign);
225
277
  const cawgTestSigner = new TestCawgSigner(c2paTestSigner);
226
278
  const cawgSigner = CallbackCredentialHolder.newCallbackCredentialHolder(reserveSize, "cawg.x509.cose", cawgTestSigner.sign);
227
- const builder = Builder.withJson({
279
+ const builder = await Builder.withJsonAsync({
228
280
  claim_generator_info: [{ name: "c2pa_test", version: "2.0.0" }],
229
281
  title: "Test_Manifest",
230
282
  format: "image/jpeg",
package/dist/Reader.js CHANGED
@@ -3,9 +3,9 @@
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 { Context } from "@contentauth/c2pa-utilities";
6
7
  import { getNeonBinary } from "./binary.js";
7
8
  import { validateSourceAssetSize } from "./assetSize.js";
8
- import { resolveSdkConfig, resolveSettingsForNeon } from "./Settings.js";
9
9
  export class Reader {
10
10
  reader;
11
11
  constructor(reader) {
@@ -24,24 +24,20 @@ export class Reader {
24
24
  return getNeonBinary().readerResourceToAsset.call(this.reader, uri, asset);
25
25
  }
26
26
  /**
27
- * @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object. Passing a
28
- * raw `C2paSettings` value is deprecated and will be removed in a future version. `null` is treated
29
- * the same as `undefined`.
27
+ * @param context A `Context` configuring this Reader. Defaults to an empty `Context`.
30
28
  */
31
- static async fromAsset(asset, settingsOrContext) {
32
- await validateSourceAssetSize(asset, resolveSdkConfig(settingsOrContext));
33
- const settingsStr = await resolveSettingsForNeon(settingsOrContext);
29
+ static async fromAsset(asset, context = new Context()) {
30
+ await validateSourceAssetSize(asset, context.sdkConfig);
31
+ const settingsStr = await context.toJson();
34
32
  const reader = await getNeonBinary().readerFromAsset(asset, settingsStr);
35
33
  return reader ? new Reader(reader) : null;
36
34
  }
37
35
  /**
38
- * @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object. Passing a
39
- * raw `C2paSettings` value is deprecated and will be removed in a future version. `null` is treated
40
- * the same as `undefined`.
36
+ * @param context A `Context` configuring this Reader. Defaults to an empty `Context`.
41
37
  */
42
- static async fromManifestDataAndAsset(manifestData, asset, settingsOrContext) {
43
- await validateSourceAssetSize(asset, resolveSdkConfig(settingsOrContext));
44
- const settingsStr = await resolveSettingsForNeon(settingsOrContext);
38
+ static async fromManifestDataAndAsset(manifestData, asset, context = new Context()) {
39
+ await validateSourceAssetSize(asset, context.sdkConfig);
40
+ const settingsStr = await context.toJson();
45
41
  const reader = await getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset, settingsStr);
46
42
  return new Reader(reader);
47
43
  }
@@ -71,7 +71,7 @@ describe("Reader", () => {
71
71
  "parameters": {
72
72
  "ingredient": {
73
73
  "url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
74
- "hash": "5dNlxTKe4afGAicpJa1hF1R3mBZKE+Bl0xmh0McXuO4="
74
+ "hash": "b64'5dNlxTKe4afGAicpJa1hF1R3mBZKE+Bl0xmh0McXuO4='"
75
75
  }
76
76
  }
77
77
  },
@@ -175,27 +175,6 @@ describe("Reader", () => {
175
175
  expect(json.manifests).toEqual(manifestStore.manifests);
176
176
  expect(json.validation_status[0].code).toEqual("signingCredential.untrusted");
177
177
  });
178
- it("should read from manifest data and file with settings context", async () => {
179
- const manifestData = await fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
180
- const buffer = await fs.readFile("./tests/fixtures/CA.jpg");
181
- const settings = {
182
- verify: {
183
- verify_after_reading: false,
184
- verify_trust: false,
185
- },
186
- };
187
- const reader = await Reader.fromManifestDataAndAsset(manifestData, {
188
- buffer,
189
- mimeType: "jpeg",
190
- }, settings);
191
- expect(reader).not.toBeNull();
192
- const json = reader.json();
193
- // Settings should affect validation behavior
194
- // With verify_after_reading: false, validation_status should be undefined
195
- expect(json.validation_status).toBeUndefined();
196
- expect(json.manifests).toBeDefined();
197
- expect(json.active_manifest).toEqual(manifestStore.active_manifest);
198
- });
199
178
  it("should read from manifest data and file with a Context", async () => {
200
179
  const manifestData = await fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
201
180
  const buffer = await fs.readFile("./tests/fixtures/CA.jpg");
@@ -211,8 +190,6 @@ describe("Reader", () => {
211
190
  }, context);
212
191
  expect(reader).not.toBeNull();
213
192
  const json = reader.json();
214
- // Same effect as the raw-settings equivalent above: verifyAfterReading: false means
215
- // validation_status should be undefined.
216
193
  expect(json.validation_status).toBeUndefined();
217
194
  expect(json.manifests).toBeDefined();
218
195
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
@@ -268,17 +245,17 @@ describe("Reader", () => {
268
245
  expect(signatureInfo.alg).toBe("Ed25519");
269
246
  expect(signatureInfo.issuer).toBe("C2PA Test Signing Cert");
270
247
  expect(signatureInfo.cert_serial_number).toBe("638838410810235485828984295321338730070538954823");
271
- expect(signatureInfo.revocation_status).toBe(true);
248
+ expect(signatureInfo.revocation_status).toBeUndefined();
272
249
  // Verify signer_payload values
273
250
  expect(signerPayload.sig_type).toBe("cawg.x509.cose");
274
251
  expect(signerPayload.referenced_assertions).toHaveLength(2);
275
252
  expect(signerPayload.referenced_assertions[0]).toEqual({
276
253
  url: "self#jumbf=c2pa.assertions/cawg.training-mining",
277
- hash: "rBBgURB+/0Bc2Uk3+blNpYTGQTxOwzXQ2xhjA3gsqI4=",
254
+ hash: Array.from(Buffer.from("rBBgURB+/0Bc2Uk3+blNpYTGQTxOwzXQ2xhjA3gsqI4=", "base64")),
278
255
  });
279
256
  expect(signerPayload.referenced_assertions[1]).toEqual({
280
257
  url: "self#jumbf=c2pa.assertions/c2pa.hash.data",
281
- hash: "sASozh9KFSkW+cyMI0Pw5KYoD2qn7MkUEq9jUUhe/sM=",
258
+ hash: Array.from(Buffer.from("sASozh9KFSkW+cyMI0Pw5KYoD2qn7MkUEq9jUUhe/sM=", "base64")),
282
259
  });
283
260
  });
284
261
  it("should return null when reading an asset without C2PA metadata", async () => {
package/dist/Settings.js CHANGED
@@ -10,7 +10,6 @@
10
10
  // specific language governing permissions and limitations under
11
11
  // each license.
12
12
  import fs from "fs-extra";
13
- import { Context } from "@contentauth/c2pa-utilities";
14
13
  /**
15
14
  * This file contains only Settings functions that are unique to the Node SDK.
16
15
  *
@@ -26,41 +25,3 @@ export async function loadSettingsFromFile(filePath) {
26
25
  const content = await fs.readFile(filePath, "utf8");
27
26
  return content;
28
27
  }
29
- /**
30
- * Reads the SDK config out of a settings argument.
31
- *
32
- * Only a `Context` carries an SDK config so the deprecated raw `C2paSettings` forms always
33
- * resolve to `undefined`, leaving this package's defaults in place.
34
- *
35
- * @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object.
36
- * @returns The `Context`'s SDK config, or `undefined` if there is none.
37
- */
38
- export function resolveSdkConfig(settingsOrContext) {
39
- return settingsOrContext instanceof Context
40
- ? settingsOrContext.sdkConfig
41
- : undefined;
42
- }
43
- /**
44
- * Resolves Context settings, including any trust-anchor URLs, before passing them to the native
45
- * library. Deprecated raw settings retain their existing pass-through behavior.
46
- */
47
- export async function resolveSettingsForNeon(settingsOrContext) {
48
- if (settingsOrContext == null) {
49
- return undefined;
50
- }
51
- if (settingsOrContext instanceof Context) {
52
- return settingsOrContext.toJson();
53
- }
54
- return typeof settingsOrContext === "string"
55
- ? settingsOrContext
56
- : JSON.stringify(settingsOrContext);
57
- }
58
- /**
59
- * Resolves deprecated raw settings for the synchronous Builder factories.
60
- */
61
- export function resolveRawSettingsForNeon(settings) {
62
- if (settings == null) {
63
- return undefined;
64
- }
65
- return typeof settings === "string" ? settings : JSON.stringify(settings);
66
- }
@@ -6,9 +6,7 @@
6
6
  import fs from "fs-extra";
7
7
  import * as path from "path";
8
8
  import * as os from "os";
9
- import { Context, DEFAULT_SETTINGS, mergeSettings, settingsToJson, } from "@contentauth/c2pa-utilities";
10
- import { vi } from "vitest";
11
- import { loadSettingsFromFile, resolveRawSettingsForNeon, resolveSdkConfig, resolveSettingsForNeon, } from "./Settings.js";
9
+ import { loadSettingsFromFile } from "./Settings.js";
12
10
  describe("Settings", () => {
13
11
  describe("loadSettingsFromFile", () => {
14
12
  let tempDir;
@@ -48,80 +46,4 @@ verify_after_sign = false`;
48
46
  await expect(loadSettingsFromFile(filePath)).rejects.toThrow();
49
47
  });
50
48
  });
51
- describe("resolveRawSettingsForNeon", () => {
52
- it("returns undefined when omitted", () => {
53
- expect(resolveRawSettingsForNeon(undefined)).toBeUndefined();
54
- });
55
- it("returns undefined when null is passed in", () => {
56
- // A plain-JS caller can pass `null` explicitly.
57
- // It must not fall through to JSON.stringify(null), which would send the
58
- // native library the literal string "null" instead of "no settings".
59
- expect(resolveRawSettingsForNeon(null)).toBeUndefined();
60
- });
61
- it("passes raw settings through unchanged", () => {
62
- const rawSettings = { verify: { verify_trust: false } };
63
- const result = resolveRawSettingsForNeon(rawSettings);
64
- expect(JSON.parse(result)).toEqual(rawSettings);
65
- });
66
- it("passes raw settings JSON through unchanged", () => {
67
- const json = JSON.stringify({ verify: { verify_trust: false } });
68
- expect(resolveRawSettingsForNeon(json)).toBe(json);
69
- });
70
- });
71
- describe("resolveSettingsForNeon", () => {
72
- it("returns undefined when omitted", async () => {
73
- expect(await resolveSettingsForNeon(undefined)).toBeUndefined();
74
- });
75
- it("returns undefined when null is passed in", async () => {
76
- expect(await resolveSettingsForNeon(null)).toBeUndefined();
77
- });
78
- it("applies defaults for an empty Context", async () => {
79
- const result = await resolveSettingsForNeon(new Context());
80
- expect(JSON.parse(result)).toEqual(JSON.parse(settingsToJson(DEFAULT_SETTINGS)));
81
- });
82
- it("does not serialize a Context's SDK config", async () => {
83
- const result = await resolveSettingsForNeon(new Context(undefined, { maxSizeInBytes: 42 }));
84
- expect(JSON.parse(result)).toEqual(JSON.parse(settingsToJson(DEFAULT_SETTINGS)));
85
- });
86
- it("merges a Context's settings with defaults", async () => {
87
- const settings = { verify: { verifyTrust: false } };
88
- const result = await resolveSettingsForNeon(new Context(settings));
89
- expect(JSON.parse(result)).toEqual(JSON.parse(settingsToJson(mergeSettings(DEFAULT_SETTINGS, settings))));
90
- });
91
- it("fetches trust-anchor URLs before returning Context settings", async () => {
92
- const pem = "-----BEGIN CERTIFICATE-----\nanchor\n-----END CERTIFICATE-----";
93
- const fetch = vi.fn(async () => new Response(pem));
94
- vi.stubGlobal("fetch", fetch);
95
- try {
96
- const result = await resolveSettingsForNeon(new Context({
97
- trust: { trustAnchors: "https://example.com/anchors.pem" },
98
- }));
99
- expect(fetch).toHaveBeenCalledOnce();
100
- expect(JSON.parse(result).trust.anchors[0].trust_anchors).toBe(pem);
101
- }
102
- finally {
103
- vi.unstubAllGlobals();
104
- }
105
- });
106
- it("keeps deprecated raw settings unchanged", async () => {
107
- const rawSettings = { verify: { verify_trust: false } };
108
- const result = await resolveSettingsForNeon(rawSettings);
109
- expect(JSON.parse(result)).toEqual(rawSettings);
110
- });
111
- });
112
- describe("resolveSdkConfig", () => {
113
- it("returns a Context's SDK config", () => {
114
- const sdkConfig = { maxSizeInBytes: 42 };
115
- expect(resolveSdkConfig(new Context(undefined, sdkConfig))).toEqual(sdkConfig);
116
- });
117
- it("returns undefined when a Context carries no SDK config", () => {
118
- expect(resolveSdkConfig(new Context())).toBeUndefined();
119
- });
120
- it("returns undefined for the deprecated raw settings forms", () => {
121
- expect(resolveSdkConfig(undefined)).toBeUndefined();
122
- expect(resolveSdkConfig(null)).toBeUndefined();
123
- expect(resolveSdkConfig({ verify: { verifyTrust: false } })).toBeUndefined();
124
- expect(resolveSdkConfig('{"verify":{"verify_trust":false}}')).toBeUndefined();
125
- });
126
- });
127
49
  });
@@ -121,7 +121,7 @@ describe("CallbackSigner", () => {
121
121
  ],
122
122
  resources: { resources: {} },
123
123
  };
124
- const builder = Builder.withJson(manifestDefinition);
124
+ const builder = await Builder.withJsonAsync(manifestDefinition);
125
125
  builder.setIntent({ create: "http://c2pa.org/digitalsourcetype/empty" });
126
126
  const source = {
127
127
  buffer: await fs.readFile("./tests/fixtures/CA.jpg"),
package/dist/index.node CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/index.node
3
- size: 52232544 bytes
4
- sha256: 700dc336e16341cfabe26173ab8611648a599c33b8ad163602f7c749e7da4191
3
+ size: 52308208 bytes
4
+ sha256: 7e41cbc95437421ac1c07a968e02d10a43ba1e864453d28fb33ea18d0ae50c52
@@ -1,18 +1,11 @@
1
1
  import type { Action, BuilderIntent, C2paReason, Ingredient, Manifest, ManifestStore } from "@contentauth/c2pa-types";
2
2
  import { Context } from "@contentauth/c2pa-utilities";
3
- import type { BuilderInterface, C2paSettings, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, ReaderInterface, SourceAsset, NeonBuilderHandle } from "./types.d.ts";
3
+ import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, ReaderInterface, SourceAsset, NeonBuilderHandle } from "./types.d.ts";
4
4
  export declare class Builder implements BuilderInterface {
5
5
  private builder;
6
6
  constructor(builder: NeonBuilderHandle);
7
- /**
8
- * @deprecated Use {@link Builder.newAsync} instead, passing a `Context`. Will be removed in a
9
- * future major version.
10
- * @param settings A raw `C2paSettings` string/object.
11
- */
12
- static new(settings?: C2paSettings): Builder;
13
7
  /**
14
8
  * Create a Builder with a minimal manifest definition, configured by a `Context`.
15
- * Prefer this over the deprecated {@link Builder.new}.
16
9
  *
17
10
  * Resolves trust-anchor URLs in the Context before constructing the Builder.
18
11
  *
@@ -21,14 +14,7 @@ export declare class Builder implements BuilderInterface {
21
14
  */
22
15
  static newAsync(context?: Context): Promise<Builder>;
23
16
  /**
24
- * @deprecated Use {@link Builder.withJsonAsync} instead, passing a `Context`. Will be removed
25
- * in a future version.
26
- * @param settings A raw `C2paSettings` string/object.
27
- */
28
- static withJson(json: Manifest, settings?: C2paSettings): Builder;
29
- /**
30
- * Create a Builder from a manifest definition, configured by a `Context`. Prefer this over
31
- * the deprecated {@link Builder.withJson}.
17
+ * Create a Builder from a manifest definition, configured by a `Context`.
32
18
  *
33
19
  * Resolves trust-anchor URLs in the Context before constructing the Builder.
34
20
  *
@@ -47,11 +33,9 @@ export declare class Builder implements BuilderInterface {
47
33
  addIngredientFromReader(reader: ReaderInterface): Ingredient;
48
34
  toArchive(asset: DestinationAsset): Promise<void>;
49
35
  /**
50
- * @param settingsOrContext A `Context`, or (deprecated) a raw `C2paSettings` string/object. Passing a
51
- * raw `C2paSettings` value is deprecated and will be removed in a future version. `null` is treated
52
- * the same as `undefined`.
36
+ * @param context A `Context` configuring this Builder. Defaults to an empty `Context`.
53
37
  */
54
- static fromArchive(asset: SourceAsset, settingsOrContext?: C2paSettings | Context | null): Promise<Builder>;
38
+ static fromArchive(asset: SourceAsset, context?: Context): Promise<Builder>;
55
39
  sign(signer: LocalSignerInterface, input: SourceAsset, output: DestinationAsset): Buffer;
56
40
  signFile(signer: LocalSignerInterface, filePath: string, output: DestinationAsset): Buffer;
57
41
  signConfigAsync(callback: (data: Buffer) => Promise<Buffer>, signerConfig: JsCallbackSignerConfig, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
@@ -1,6 +1,6 @@
1
1
  import type { Manifest, ManifestStore } from "@contentauth/c2pa-types";
2
- import type { Context } from "@contentauth/c2pa-utilities";
3
- import type { C2paSettings, DestinationAsset, ReaderInterface, ResourceAsset, SourceAsset, NeonReaderHandle } from "./types.d.ts";
2
+ import { Context } from "@contentauth/c2pa-utilities";
3
+ import type { DestinationAsset, ReaderInterface, ResourceAsset, SourceAsset, NeonReaderHandle } from "./types.d.ts";
4
4
  export declare class Reader implements ReaderInterface {
5
5
  private reader;
6
6
  constructor(reader: NeonReaderHandle);
@@ -9,17 +9,13 @@ export declare class Reader implements ReaderInterface {
9
9
  isEmbedded(): boolean;
10
10
  resourceToAsset(uri: string, asset: DestinationAsset): Promise<ResourceAsset>;
11
11
  /**
12
- * @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object. Passing a
13
- * raw `C2paSettings` value is deprecated and will be removed in a future version. `null` is treated
14
- * the same as `undefined`.
12
+ * @param context A `Context` configuring this Reader. Defaults to an empty `Context`.
15
13
  */
16
- static fromAsset(asset: SourceAsset, settingsOrContext?: C2paSettings | Context | null): Promise<Reader | null>;
14
+ static fromAsset(asset: SourceAsset, context?: Context): Promise<Reader | null>;
17
15
  /**
18
- * @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object. Passing a
19
- * raw `C2paSettings` value is deprecated and will be removed in a future version. `null` is treated
20
- * the same as `undefined`.
16
+ * @param context A `Context` configuring this Reader. Defaults to an empty `Context`.
21
17
  */
22
- static fromManifestDataAndAsset(manifestData: Buffer, asset: SourceAsset, settingsOrContext?: C2paSettings | Context | null): Promise<Reader>;
18
+ static fromManifestDataAndAsset(manifestData: Buffer, asset: SourceAsset, context?: Context): Promise<Reader>;
23
19
  activeLabel(): string | undefined;
24
20
  getActive(): Manifest | undefined;
25
21
  getHandle(): NeonReaderHandle;
@@ -1,5 +1,3 @@
1
- import { Context, type SdkConfig } from "@contentauth/c2pa-utilities";
2
- import type { C2paSettings } from "./types.d.ts";
3
1
  /**
4
2
  * This file contains only Settings functions that are unique to the Node SDK.
5
3
  *
@@ -12,22 +10,3 @@ import type { C2paSettings } from "./types.d.ts";
12
10
  * @returns Settings as a string (TOML or JSON depending on file extension)
13
11
  */
14
12
  export declare function loadSettingsFromFile(filePath: string): Promise<string>;
15
- /**
16
- * Reads the SDK config out of a settings argument.
17
- *
18
- * Only a `Context` carries an SDK config so the deprecated raw `C2paSettings` forms always
19
- * resolve to `undefined`, leaving this package's defaults in place.
20
- *
21
- * @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object.
22
- * @returns The `Context`'s SDK config, or `undefined` if there is none.
23
- */
24
- export declare function resolveSdkConfig(settingsOrContext: C2paSettings | Context | null | undefined): SdkConfig | undefined;
25
- /**
26
- * Resolves Context settings, including any trust-anchor URLs, before passing them to the native
27
- * library. Deprecated raw settings retain their existing pass-through behavior.
28
- */
29
- export declare function resolveSettingsForNeon(settingsOrContext: C2paSettings | Context | null | undefined): Promise<string | undefined>;
30
- /**
31
- * Resolves deprecated raw settings for the synchronous Builder factories.
32
- */
33
- export declare function resolveRawSettingsForNeon(settings: C2paSettings | null | undefined): string | undefined;
@@ -194,12 +194,6 @@ export interface HashedUri {
194
194
  alg?: string;
195
195
  }
196
196
 
197
- /**
198
- * Optional settings that can be provided when creating a Reader or Builder.
199
- * Can be a JSON string or a settings object.
200
- */
201
- export type C2paSettings = string | object;
202
-
203
197
  export interface BuilderInterface {
204
198
  /**
205
199
  * An intent lets the API know what kind of manifest to create.
@@ -536,27 +530,3 @@ export interface TrustmarkConfig {
536
530
  version: TrustmarkVersion;
537
531
  modelPath?: string;
538
532
  }
539
-
540
- import type {
541
- Settings as _Settings,
542
- TrustSettings as _TrustSettings,
543
- VerifySettings as _VerifySettings
544
- } from "@contentauth/c2pa-utilities";
545
-
546
- /**
547
- * @deprecated Use `TrustSettings` instead, which encapsulates both normal trust and CAWG trust settings.
548
- * Kept as an alias for backwards compatibility.
549
- */
550
- export type TrustConfig = _TrustSettings;
551
-
552
- /**
553
- * @deprecated Use `VerifySettings` instead.
554
- * Kept as an alias for backwards compatibility.
555
- */
556
- export type VerifyConfig = _VerifySettings;
557
-
558
- /**
559
- * @deprecated Use `Settings` instead.
560
- * Kept as an alias for backwards compatibility.
561
- */
562
- 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.10.0",
8
+ "version": "0.11.0",
9
9
  "description": "Node.js bindings for C2PA",
10
10
  "main": "dist/index.js",
11
11
  "type": "module",
@@ -64,8 +64,8 @@
64
64
  "pkg-dir": "^8.0.0",
65
65
  "pretty-bytes": "^6.1.1",
66
66
  "unzipper": "^0.10.14",
67
- "@contentauth/c2pa-types": "0.7.8",
68
- "@contentauth/c2pa-utilities": "0.4.0"
67
+ "@contentauth/c2pa-types": "0.8.0",
68
+ "@contentauth/c2pa-utilities": "0.5.1"
69
69
  },
70
70
  "nx": {
71
71
  "tags": [
@@ -135,9 +135,13 @@ impl AsyncSigner for NeonIdentityAssertionSigner {
135
135
  c2pa::AsyncSigner::timestamp_request_body(&*self.signer.read().unwrap(), message)
136
136
  }
137
137
 
138
- async fn send_timestamp_request(&self, message: &[u8]) -> Option<Result<Vec<u8>, c2pa::Error>> {
138
+ async fn send_timestamp_request(
139
+ &self,
140
+ message: &[u8],
141
+ context: &c2pa::Context,
142
+ ) -> Option<Result<Vec<u8>, c2pa::Error>> {
139
143
  let signer = self.signer.read().unwrap().clone();
140
- c2pa::AsyncSigner::send_timestamp_request(&signer, message).await
144
+ c2pa::AsyncSigner::send_timestamp_request(&signer, message, context).await
141
145
  }
142
146
 
143
147
  fn dynamic_assertions(&self) -> Vec<Box<dyn AsyncDynamicAssertion>> {