@contentauth/c2pa-node 0.5.3 → 0.5.5

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.lock CHANGED
@@ -213,7 +213,7 @@ version = "0.4.27"
213
213
  source = "registry+https://github.com/rust-lang/crates.io-index"
214
214
  checksum = "ddb939d66e4ae03cee6091612804ba446b12878410cfa17f785f4dd67d4014e8"
215
215
  dependencies = [
216
- "brotli",
216
+ "brotli 8.0.1",
217
217
  "flate2",
218
218
  "futures-core",
219
219
  "memchr",
@@ -257,9 +257,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
257
257
 
258
258
  [[package]]
259
259
  name = "atree"
260
- version = "0.5.2"
260
+ version = "0.5.4"
261
261
  source = "registry+https://github.com/rust-lang/crates.io-index"
262
- checksum = "132573478eb9ff973c6f75d0ed425ac12da77d266506483345f46743ecc83a98"
262
+ checksum = "239d25181cb40f1955529367ee495e35d03aab4e578028f41e7abc8b21c367a8"
263
263
 
264
264
  [[package]]
265
265
  name = "autocfg"
@@ -397,6 +397,17 @@ dependencies = [
397
397
  "generic-array",
398
398
  ]
399
399
 
400
+ [[package]]
401
+ name = "brotli"
402
+ version = "7.0.0"
403
+ source = "registry+https://github.com/rust-lang/crates.io-index"
404
+ checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd"
405
+ dependencies = [
406
+ "alloc-no-stdlib",
407
+ "alloc-stdlib",
408
+ "brotli-decompressor 4.0.3",
409
+ ]
410
+
400
411
  [[package]]
401
412
  name = "brotli"
402
413
  version = "8.0.1"
@@ -405,7 +416,17 @@ checksum = "9991eea70ea4f293524138648e41ee89b0b2b12ddef3b255effa43c8056e0e0d"
405
416
  dependencies = [
406
417
  "alloc-no-stdlib",
407
418
  "alloc-stdlib",
408
- "brotli-decompressor",
419
+ "brotli-decompressor 5.0.0",
420
+ ]
421
+
422
+ [[package]]
423
+ name = "brotli-decompressor"
424
+ version = "4.0.3"
425
+ source = "registry+https://github.com/rust-lang/crates.io-index"
426
+ checksum = "a334ef7c9e23abf0ce748e8cd309037da93e606ad52eb372e4ce327a0dcfbdfd"
427
+ dependencies = [
428
+ "alloc-no-stdlib",
429
+ "alloc-stdlib",
409
430
  ]
410
431
 
411
432
  [[package]]
@@ -495,9 +516,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
495
516
 
496
517
  [[package]]
497
518
  name = "c2pa"
498
- version = "0.77.0"
519
+ version = "0.82.1"
499
520
  source = "registry+https://github.com/rust-lang/crates.io-index"
500
- checksum = "fe6c3fcc525dcac6cde7d020cc4d3065b2d2042e48efc096baba97876b276f41"
521
+ checksum = "8e96917bbbabdb4dd15030b67e4694b6751d618768fe88ad57f98aad7fd8e751"
501
522
  dependencies = [
502
523
  "asn1-rs",
503
524
  "async-generic",
@@ -505,6 +526,7 @@ dependencies = [
505
526
  "atree",
506
527
  "base64",
507
528
  "bcder",
529
+ "brotli 7.0.0",
508
530
  "byteorder",
509
531
  "byteordered",
510
532
  "bytes",
@@ -522,6 +544,7 @@ dependencies = [
522
544
  "extfmt",
523
545
  "getrandom 0.2.16",
524
546
  "getrandom 0.3.4",
547
+ "glob",
525
548
  "hex",
526
549
  "hex-literal",
527
550
  "http",
@@ -1426,6 +1449,12 @@ version = "0.31.1"
1426
1449
  source = "registry+https://github.com/rust-lang/crates.io-index"
1427
1450
  checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
1428
1451
 
1452
+ [[package]]
1453
+ name = "glob"
1454
+ version = "0.3.3"
1455
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1456
+ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
1457
+
1429
1458
  [[package]]
1430
1459
  name = "group"
1431
1460
  version = "0.13.0"
package/Cargo.toml CHANGED
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
11
11
  [dependencies]
12
12
  async-trait = "0.1.77"
13
13
  ciborium = "0.2.2"
14
- c2pa = { version = "0.77.0", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto", "default_http"] }
14
+ c2pa = { version = "0.82.1", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto", "default_http"] }
15
15
  futures = "0.3"
16
16
  image = "0.25.6"
17
17
  neon = { version = "1.0.0", default-features = false, features = [
package/README.md CHANGED
@@ -45,6 +45,18 @@ This command will download precompiled binaries for the following systems:
45
45
  - Windows x86
46
46
  - Windows ARM
47
47
 
48
+ ## Documentation
49
+
50
+ Complete API documentation is generated from TypeScript source using [TypeDoc](https://typedoc.org/) and published to GitHub Pages at [https://contentauth.github.io/c2pa-node-v2/](https://contentauth.github.io/c2pa-node-v2/).
51
+
52
+ To generate documentation locally:
53
+
54
+ ```bash
55
+ pnpm build:docs
56
+ ```
57
+
58
+ This generates HTML documentation in the `docs/` directory. The `docs/` directory is not checked into version control. It's automatically generated and published to GitHub Pages whenever a new release is published.
59
+
48
60
  ## Components
49
61
 
50
62
  ### Reader
@@ -241,6 +253,125 @@ const ingredient = builder.addIngredientFromReader(sourceReader);
241
253
  console.log(ingredient.title); // Contains ingredient metadata
242
254
  ```
243
255
 
256
+ #### Adding Ingredients from Archives (.c2pa files)
257
+
258
+ 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`.
259
+
260
+ There are two types of archives sharing the same binary format:
261
+
262
+ - **Builder archives** (working store archives): Serialized snapshots of a `Builder`, created by `builder.toArchive()`. They can contain multiple ingredients.
263
+ - **Ingredient archives**: Contain exactly one ingredient from a source asset. They carry the provenance history for reuse in other manifests.
264
+
265
+ ##### Reading an archive and adding its ingredients
266
+
267
+ ```javascript
268
+ import { Reader, Builder } from '@contentauth/c2pa-node';
269
+ import * as fs from 'node:fs/promises';
270
+
271
+ // Read the archive using the application/c2pa MIME type
272
+ const archiveBuffer = await fs.readFile('ingredients.c2pa');
273
+ const reader = await Reader.fromAsset(
274
+ { buffer: archiveBuffer, mimeType: 'application/c2pa' },
275
+ { verify: { verify_after_reading: false } }
276
+ );
277
+
278
+ // Get the ingredients from the active manifest
279
+ const activeManifest = reader.getActive();
280
+ const ingredients = activeManifest.ingredients;
281
+
282
+ // Create a new builder with the ingredients from the archive
283
+ const builder = Builder.withJson({
284
+ claim_generator_info: [{ name: 'my-app', version: '1.0.0' }],
285
+ ingredients: ingredients,
286
+ });
287
+
288
+ // Transfer binary resources (thumbnails, manifest_data) for each ingredient
289
+ for (const ingredient of ingredients) {
290
+ if (ingredient.thumbnail) {
291
+ const resource = await reader.resourceToAsset(ingredient.thumbnail.identifier, { buffer: null });
292
+ await builder.addResource(ingredient.thumbnail.identifier, {
293
+ buffer: resource.buffer,
294
+ mimeType: ingredient.thumbnail.format,
295
+ });
296
+ }
297
+ if (ingredient.manifest_data) {
298
+ const resource = await reader.resourceToAsset(ingredient.manifest_data.identifier, { buffer: null });
299
+ await builder.addResource(ingredient.manifest_data.identifier, {
300
+ buffer: resource.buffer,
301
+ mimeType: 'application/c2pa',
302
+ });
303
+ }
304
+ }
305
+
306
+ // Sign the manifest
307
+ const signer = LocalSigner.newSigner(cert, key, 'es256');
308
+ builder.sign(signer, inputAsset, outputAsset);
309
+ ```
310
+
311
+ ##### Selecting specific ingredients from an archive
312
+
313
+ When an archive contains multiple ingredients, you can filter to include only the ones you need:
314
+
315
+ ```javascript
316
+ const reader = await Reader.fromAsset(
317
+ { buffer: archiveBuffer, mimeType: 'application/c2pa' },
318
+ { verify: { verify_after_reading: false } }
319
+ );
320
+
321
+ const activeManifest = reader.getActive();
322
+ const allIngredients = activeManifest.ingredients;
323
+
324
+ // Select only the ingredients you want (e.g., by title or instance_id)
325
+ const selected = allIngredients.filter(
326
+ (ing) => ing.title === 'photo_1.jpg' || ing.instance_id === 'catalog:logo'
327
+ );
328
+
329
+ // Build with only the selected ingredients
330
+ const builder = Builder.withJson({
331
+ claim_generator_info: [{ name: 'my-app', version: '1.0.0' }],
332
+ ingredients: selected,
333
+ });
334
+
335
+ // Transfer resources only for selected ingredients
336
+ for (const ingredient of selected) {
337
+ if (ingredient.thumbnail) {
338
+ const resource = await reader.resourceToAsset(ingredient.thumbnail.identifier, { buffer: null });
339
+ await builder.addResource(ingredient.thumbnail.identifier, {
340
+ buffer: resource.buffer,
341
+ mimeType: ingredient.thumbnail.format,
342
+ });
343
+ }
344
+ if (ingredient.manifest_data) {
345
+ const resource = await reader.resourceToAsset(ingredient.manifest_data.identifier, { buffer: null });
346
+ await builder.addResource(ingredient.manifest_data.identifier, {
347
+ buffer: resource.buffer,
348
+ mimeType: 'application/c2pa',
349
+ });
350
+ }
351
+ }
352
+ ```
353
+
354
+ ##### Building an ingredient archive
355
+
356
+ To create an ingredient archive, add ingredients to a `Builder` and save it as an archive:
357
+
358
+ ```javascript
359
+ const builder = Builder.new();
360
+
361
+ // Add ingredients with stable instance_id for later catalog lookups
362
+ await builder.addIngredient(
363
+ JSON.stringify({
364
+ title: 'photo-A.jpg',
365
+ relationship: 'componentOf',
366
+ instance_id: 'catalog:photo-A',
367
+ }),
368
+ { path: 'photo-A.jpg' }
369
+ );
370
+
371
+ // Save as a .c2pa archive
372
+ await builder.toArchive({ path: 'ingredient-catalog.c2pa' });
373
+ ```
374
+
244
375
  #### Creating and Reusing Builder Archives
245
376
 
246
377
  Builder archives allow you to save a builder's state (including ingredients) and reuse it later:
@@ -506,3 +637,14 @@ const builder = Builder.new(urlSettings);
506
637
  - `generate_c2pa_archive` - Whether to generate C2PA archive format
507
638
 
508
639
  **Note:** Settings are passed as per-instance configuration. There are no global settings that affect all Readers and Builders.
640
+
641
+
642
+ ### Build and use custom binary
643
+ **Build rust binary:**
644
+ ```
645
+ npm run build:rust
646
+ ```
647
+ **Use custom rust binary:**
648
+ ```bash
649
+ export C2PA_LIBRARY_PATH=<path-to-binary-folder>/index.node
650
+ ```
package/dist/Builder.js CHANGED
@@ -166,6 +166,9 @@ export class Builder {
166
166
  updateManifestProperty(property, value) {
167
167
  getNeonBinary().builderUpdateManifestProperty.call(this.builder, property, value);
168
168
  }
169
+ addRedaction(uri, reason) {
170
+ getNeonBinary().builderAddRedaction.call(this.builder, uri, reason);
171
+ }
169
172
  getHandle() {
170
173
  return this.builder;
171
174
  }
@@ -467,60 +467,77 @@ describe("Builder", () => {
467
467
  customBool: true,
468
468
  customObject: {
469
469
  nested: "value",
470
- count: 123
470
+ count: 123,
471
471
  },
472
- customArray: ["item1", "item2", "item3"]
473
- }
472
+ customArray: ["item1", "item2", "item3"],
473
+ },
474
474
  };
475
475
  yield builder.addIngredient(JSON.stringify(ingredient));
476
476
  const definition = builder.getManifestDefinition();
477
477
  expect(definition.ingredients).toHaveLength(1);
478
478
  expect(definition.ingredients[0]).toMatchObject(ingredient);
479
479
  }));
480
- it("should perform redaction workflow like test_redaction_async", () => __awaiter(void 0, void 0, void 0, function* () {
481
- // This test mirrors the Rust test_redaction_async test
482
- // Create a reader to get the parent manifest label from the existing source
483
- const reader = yield Reader.fromAsset(source);
484
- expect(reader).not.toBeNull();
485
- const parentManifestLabel = reader.activeLabel();
486
- expect(parentManifestLabel).toBeDefined();
487
- // Create a redacted URI for the assertion we are going to redact
488
- // Using a common assertion label that might exist
489
- const assertionLabel = "stds.schema-org.CreativeWork";
490
- const redactedUri = `contentauth:urn:uuid:${parentManifestLabel}/c2pa.assertions/${assertionLabel}`;
491
- // Create a builder with edit intent and redactions
492
- const redactionManifestDefinition = {
493
- claim_generator: "test-generator",
494
- claim_generator_info: [
495
- {
496
- name: "c2pa_test",
497
- version: "1.0.0",
498
- },
499
- ],
500
- title: "Test_Redaction_Manifest",
501
- format: "image/jpeg",
502
- instance_id: "1234",
503
- intent: "edit",
504
- redactions: [redactedUri],
505
- assertions: [
506
- {
507
- label: "org.test.assertion",
508
- data: {},
509
- },
510
- ],
511
- resources: { resources: {} },
480
+ it("should redact a thumbnail from an ingredient manifest", () => __awaiter(void 0, void 0, void 0, function* () {
481
+ var _a;
482
+ const signerConfig = {
483
+ alg: "es256",
484
+ certs: [publicKey],
485
+ reserveSize: 10000,
486
+ tsaUrl: undefined,
487
+ directCoseHandling: false,
512
488
  };
513
- const builder = Builder.withJson(redactionManifestDefinition);
514
- // Add a redacted action
515
- const redactedAction = {
516
- actions: [
517
- {
518
- action: "c2pa.redacted",
519
- },
520
- ],
489
+ const testSigner = new TestSigner(privateKey);
490
+ const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
491
+ // Sign source asset with a thumbnail
492
+ const step1Builder = Builder.withJson({
493
+ claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
494
+ title: "Asset With Thumbnail",
495
+ format: "image/jpeg",
496
+ instance_id: "thumb-step1-1234",
497
+ thumbnail: { format: "image/jpeg", identifier: "thumbnail.jpg" },
498
+ });
499
+ yield step1Builder.addResource("thumbnail.jpg", {
500
+ mimeType: "image/jpeg",
501
+ buffer: testThumbnail,
502
+ });
503
+ const step1Dest = { buffer: null };
504
+ yield step1Builder.signAsync(signer, source, step1Dest);
505
+ const step1Asset = {
506
+ buffer: step1Dest.buffer,
507
+ mimeType: "image/jpeg",
521
508
  };
522
- builder.addAssertion("c2pa.actions", redactedAction, "Cbor");
523
- // Use the callback signer like the other test
509
+ // Verify thumbnail exists in original manifest
510
+ const originalReader = yield Reader.fromAsset(step1Asset);
511
+ expect(originalReader).not.toBeNull();
512
+ const parentLabel = originalReader.activeLabel();
513
+ expect(parentLabel).toBeDefined();
514
+ const originalManifest = originalReader.getActive();
515
+ expect(originalManifest === null || originalManifest === void 0 ? void 0 : originalManifest.thumbnail).toBeDefined();
516
+ expect(originalManifest === null || originalManifest === void 0 ? void 0 : originalManifest.thumbnail).not.toBeNull();
517
+ // Redact the thumbnail
518
+ const thumbnailUri = `self#jumbf=/c2pa/${parentLabel}/c2pa.assertions/c2pa.thumbnail.claim`;
519
+ const redactionBuilder = Builder.withJson({
520
+ claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
521
+ title: "Redacted Thumbnail Manifest",
522
+ format: "image/jpeg",
523
+ instance_id: "thumb-step2-1234",
524
+ });
525
+ redactionBuilder.setIntent("update");
526
+ redactionBuilder.addRedaction(thumbnailUri, "c2pa.PII.present");
527
+ const step2Dest = { buffer: null };
528
+ yield redactionBuilder.signAsync(signer, step1Asset, step2Dest);
529
+ const finalReader = yield Reader.fromAsset({
530
+ buffer: step2Dest.buffer,
531
+ mimeType: "image/jpeg",
532
+ });
533
+ expect(finalReader).not.toBeNull();
534
+ const store = finalReader.json();
535
+ const parentManifest = (_a = store.manifests) === null || _a === void 0 ? void 0 : _a[parentLabel];
536
+ expect(parentManifest).toBeDefined();
537
+ expect(parentManifest === null || parentManifest === void 0 ? void 0 : parentManifest.thumbnail).toBeUndefined();
538
+ }));
539
+ it("should redact an assertion from an ingredient manifest", () => __awaiter(void 0, void 0, void 0, function* () {
540
+ var _a, _b;
524
541
  const signerConfig = {
525
542
  alg: "es256",
526
543
  certs: [publicKey],
@@ -530,31 +547,78 @@ describe("Builder", () => {
530
547
  };
531
548
  const testSigner = new TestSigner(privateKey);
532
549
  const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
533
- // Sign the manifest with the original image as input
534
- const dest = { buffer: null };
535
- const outputBuffer = yield builder.signAsync(signer, source, dest);
536
- expect(outputBuffer.length).toBeGreaterThan(0);
537
- // Verify the result by reading the signed manifest
538
- const signedReader = yield Reader.fromAsset({
539
- buffer: dest.buffer,
550
+ // Sign source asset with multiple distinct assertions
551
+ const piiLabel = "stds.schema-org.CreativeWork";
552
+ const retainedLabel = "org.contentauth.retained";
553
+ const step1Builder = Builder.withJson({
554
+ claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
555
+ title: "Asset With Multiple Assertions",
556
+ format: "image/jpeg",
557
+ instance_id: "assert-step1-1234",
558
+ assertions: [
559
+ {
560
+ label: piiLabel,
561
+ data: {
562
+ "@context": "http://schema.org/",
563
+ "@type": "CreativeWork",
564
+ author: [{ "@type": "Person", name: "John Doe" }],
565
+ },
566
+ },
567
+ {
568
+ label: retainedLabel,
569
+ data: { keep: true },
570
+ },
571
+ ],
572
+ });
573
+ const step1Dest = { buffer: null };
574
+ yield step1Builder.signAsync(signer, source, step1Dest);
575
+ const step1Asset = {
576
+ buffer: step1Dest.buffer,
540
577
  mimeType: "image/jpeg",
578
+ };
579
+ // Verify both assertions exist in original manifest
580
+ const originalReader = yield Reader.fromAsset(step1Asset);
581
+ expect(originalReader).not.toBeNull();
582
+ const parentLabel = originalReader.activeLabel();
583
+ expect(parentLabel).toBeDefined();
584
+ const originalStore = originalReader.json();
585
+ const originalLabels = originalStore.manifests[parentLabel].assertions.map((a) => a.label);
586
+ expect(originalLabels).toContain(piiLabel);
587
+ expect(originalLabels).toContain(retainedLabel);
588
+ // Redact only the PII assertion
589
+ const redactionUri = `self#jumbf=/c2pa/${parentLabel}/c2pa.assertions/${piiLabel}`;
590
+ const redactionBuilder = Builder.withJson({
591
+ claim_generator_info: [{ name: "c2pa_test", version: "1.0.0" }],
592
+ title: "Redacted Assertion Manifest",
593
+ format: "image/jpeg",
594
+ instance_id: "assert-step2-1234",
541
595
  });
542
- expect(signedReader).not.toBeNull();
543
- expect(signedReader).toBeDefined();
544
- // Check that the manifest was created successfully
545
- const activeManifest = signedReader.getActive();
546
- expect(activeManifest).toBeDefined();
547
- // Verify the redacted action was added
548
- const assertions = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions;
549
- const actionsAssertion = assertions === null || assertions === void 0 ? void 0 : assertions.find((a) => a.label === "c2pa.actions.v2");
550
- expect(actionsAssertion).toBeDefined();
551
- if (actionsAssertion && isActionsAssertion(actionsAssertion)) {
552
- const actions = actionsAssertion.data.actions;
553
- const redactedAction = actions.find((a) => a.action === "c2pa.redacted");
554
- expect(redactedAction).toBeDefined();
555
- expect(redactedAction === null || redactedAction === void 0 ? void 0 : redactedAction.action).toBe("c2pa.redacted");
556
- }
596
+ redactionBuilder.setIntent("update");
597
+ redactionBuilder.addRedaction(redactionUri, "c2pa.PII.present");
598
+ const step2Dest = { buffer: null };
599
+ yield redactionBuilder.signAsync(signer, step1Asset, step2Dest);
600
+ const finalReader = yield Reader.fromAsset({
601
+ buffer: step2Dest.buffer,
602
+ mimeType: "image/jpeg",
603
+ });
604
+ expect(finalReader).not.toBeNull();
605
+ const store = finalReader.json();
606
+ const parentManifest = (_a = store.manifests) === null || _a === void 0 ? void 0 : _a[parentLabel];
607
+ expect(parentManifest).toBeDefined();
608
+ const assertionLabels = (_b = parentManifest === null || parentManifest === void 0 ? void 0 : parentManifest.assertions) === null || _b === void 0 ? void 0 : _b.map((a) => a.label);
609
+ // PII assertion removed, retained assertion still present
610
+ expect(assertionLabels).not.toContain(piiLabel);
611
+ expect(assertionLabels).toContain(retainedLabel);
557
612
  }));
613
+ it("should add redactions via addRedaction method", () => {
614
+ const uri1 = "self#jumbf=/c2pa/test-label/c2pa.assertions/cawg.identity";
615
+ const uri2 = "self#jumbf=/c2pa/test-label/c2pa.assertions/stds.schema-org.CreativeWork";
616
+ const builder = Builder.new();
617
+ builder.addRedaction(uri1, "c2pa.PII.present");
618
+ builder.addRedaction(uri2, "c2pa.PII.present");
619
+ const definition = builder.getManifestDefinition();
620
+ expect(definition.redactions).toEqual([uri1, uri2]);
621
+ });
558
622
  it("should test builder remote url", () => __awaiter(void 0, void 0, void 0, function* () {
559
623
  // This test mirrors the Rust test_builder_remote_url test
560
624
  // Create a simple manifest definition similar to simple_manifest_json()
package/dist/Reader.js CHANGED
@@ -52,12 +52,13 @@ export class Reader {
52
52
  return (_a = manifestStore.active_manifest) !== null && _a !== void 0 ? _a : undefined;
53
53
  }
54
54
  getActive() {
55
+ var _a;
55
56
  const manifestStore = this.json();
56
57
  const activeManifest = manifestStore.active_manifest;
57
58
  if (!activeManifest) {
58
59
  return undefined;
59
60
  }
60
- return manifestStore.manifests[activeManifest];
61
+ return (_a = manifestStore.manifests) === null || _a === void 0 ? void 0 : _a[activeManifest];
61
62
  }
62
63
  getHandle() {
63
64
  return this.reader;
@@ -48,7 +48,7 @@ describe("Reader", () => {
48
48
  "instance_id": "xmp.iid:813ee422-9736-4cdc-9be6-4e35ed8e41cb",
49
49
  "thumbnail": {
50
50
  "format": "image/jpeg",
51
- "identifier": "self#jumbf=c2pa.assertions/c2pa.thumbnail.ingredient.jpeg"
51
+ "identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf/c2pa.assertions/c2pa.thumbnail.ingredient.jpeg"
52
52
  },
53
53
  "relationship": "parentOf",
54
54
  "label": "c2pa.ingredient"
package/dist/Settings.js CHANGED
@@ -20,21 +20,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  // each license.
21
21
  import * as fs from "fs-extra";
22
22
  import fetch from "node-fetch";
23
+ function snakeCaseify(object) {
24
+ return Object.entries(object).reduce((result, [key, val]) => {
25
+ result[snakeCase(key)] =
26
+ typeof val === "object" && val !== null ? snakeCaseify(val) : val;
27
+ return result;
28
+ }, {});
29
+ }
30
+ function snakeCase(str) {
31
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
32
+ }
23
33
  /**
24
34
  * Create a Settings object with trust configuration.
25
35
  * @param trustConfig The trust configuration
26
36
  * @returns Settings object that can be passed to Reader/Builder
27
37
  */
28
38
  export function createTrustSettings(trustConfig) {
29
- return {
30
- trust: {
31
- verify_trust_list: trustConfig.verifyTrustList,
32
- user_anchors: trustConfig.userAnchors,
33
- trust_anchors: trustConfig.trustAnchors,
34
- trust_config: trustConfig.trustConfig,
35
- allowed_list: trustConfig.allowedList,
36
- },
37
- };
39
+ return { trust: Object.assign({}, trustConfig) };
38
40
  }
39
41
  /**
40
42
  * Create a settings object with CAWG trust configuration.
@@ -42,15 +44,7 @@ export function createTrustSettings(trustConfig) {
42
44
  * @returns Settings object that can be passed to Reader/Builder
43
45
  */
44
46
  export function createCawgTrustSettings(trustConfig) {
45
- return {
46
- cawg_trust: {
47
- verify_trust_list: trustConfig.verifyTrustList,
48
- user_anchors: trustConfig.userAnchors,
49
- trust_anchors: trustConfig.trustAnchors,
50
- trust_config: trustConfig.trustConfig,
51
- allowed_list: trustConfig.allowedList,
52
- },
53
- };
47
+ return { cawgTrust: Object.assign({}, trustConfig) };
54
48
  }
55
49
  /**
56
50
  * Create a settings object with verify configuration.
@@ -58,18 +52,7 @@ export function createCawgTrustSettings(trustConfig) {
58
52
  * @returns Settings object that can be passed to Reader/Builder
59
53
  */
60
54
  export function createVerifySettings(verifyConfig) {
61
- return {
62
- verify: {
63
- verify_after_reading: verifyConfig.verifyAfterReading,
64
- verify_after_sign: verifyConfig.verifyAfterSign,
65
- verify_trust: verifyConfig.verifyTrust,
66
- verify_timestamp_trust: verifyConfig.verifyTimestampTrust,
67
- ocsp_fetch: verifyConfig.ocspFetch,
68
- remote_manifest_fetch: verifyConfig.remoteManifestFetch,
69
- skip_ingredient_conflict_resolution: verifyConfig.skipIngredientConflictResolution,
70
- strict_v1_validation: verifyConfig.strictV1Validation,
71
- },
72
- };
55
+ return { verify: Object.assign({}, verifyConfig) };
73
56
  }
74
57
  /**
75
58
  * Merge multiple settings objects into one.
@@ -83,8 +66,8 @@ export function mergeSettings(...settings) {
83
66
  if (setting.trust) {
84
67
  merged.trust = Object.assign(Object.assign({}, merged.trust), setting.trust);
85
68
  }
86
- if (setting.cawg_trust) {
87
- merged.cawg_trust = Object.assign(Object.assign({}, merged.cawg_trust), setting.cawg_trust);
69
+ if (setting.cawgTrust) {
70
+ merged.cawgTrust = Object.assign(Object.assign({}, merged.cawgTrust), setting.cawgTrust);
88
71
  }
89
72
  if (setting.verify) {
90
73
  merged.verify = Object.assign(Object.assign({}, merged.verify), setting.verify);
@@ -97,11 +80,12 @@ export function mergeSettings(...settings) {
97
80
  }
98
81
  /**
99
82
  * Convert a settings object to a JSON string.
83
+ * Converts camelCase keys to snake_case to match the c2pa-rs settings format.
100
84
  * @param settings The settings object
101
- * @returns JSON string representation
85
+ * @returns JSON string representation with snake_case keys
102
86
  */
103
87
  export function settingsToJson(settings) {
104
- return JSON.stringify(settings);
88
+ return JSON.stringify(snakeCaseify(settings));
105
89
  }
106
90
  /**
107
91
  * Load settings from a TOML or JSON file.