@contentauth/c2pa-node 0.2.3 → 0.3.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.lock CHANGED
@@ -436,9 +436,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
436
436
 
437
437
  [[package]]
438
438
  name = "c2pa"
439
- version = "0.64.0"
439
+ version = "0.68.0"
440
440
  source = "registry+https://github.com/rust-lang/crates.io-index"
441
- checksum = "e248764676fd065bfadda97cf5d3c847840a86c5aa905666422081c2b64f1869"
441
+ checksum = "46613af072ed8a145e9a726459074a0693aeb43c207efa0340b96967c2aced69"
442
442
  dependencies = [
443
443
  "asn1-rs",
444
444
  "async-generic",
@@ -827,9 +827,9 @@ dependencies = [
827
827
 
828
828
  [[package]]
829
829
  name = "darling"
830
- version = "0.20.11"
830
+ version = "0.21.3"
831
831
  source = "registry+https://github.com/rust-lang/crates.io-index"
832
- checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
832
+ checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0"
833
833
  dependencies = [
834
834
  "darling_core",
835
835
  "darling_macro",
@@ -837,9 +837,9 @@ dependencies = [
837
837
 
838
838
  [[package]]
839
839
  name = "darling_core"
840
- version = "0.20.11"
840
+ version = "0.21.3"
841
841
  source = "registry+https://github.com/rust-lang/crates.io-index"
842
- checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
842
+ checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4"
843
843
  dependencies = [
844
844
  "fnv",
845
845
  "ident_case",
@@ -851,9 +851,9 @@ dependencies = [
851
851
 
852
852
  [[package]]
853
853
  name = "darling_macro"
854
- version = "0.20.11"
854
+ version = "0.21.3"
855
855
  source = "registry+https://github.com/rust-lang/crates.io-index"
856
- checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
856
+ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
857
857
  dependencies = [
858
858
  "darling_core",
859
859
  "quote",
@@ -2088,9 +2088,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
2088
2088
 
2089
2089
  [[package]]
2090
2090
  name = "memchr"
2091
- version = "2.7.5"
2091
+ version = "2.7.6"
2092
2092
  source = "registry+https://github.com/rust-lang/crates.io-index"
2093
- checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
2093
+ checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
2094
2094
 
2095
2095
  [[package]]
2096
2096
  name = "minimal-lexical"
@@ -2468,12 +2468,12 @@ dependencies = [
2468
2468
 
2469
2469
  [[package]]
2470
2470
  name = "pem"
2471
- version = "3.0.5"
2471
+ version = "3.0.6"
2472
2472
  source = "registry+https://github.com/rust-lang/crates.io-index"
2473
- checksum = "38af38e8470ac9dee3ce1bae1af9c1671fffc44ddfd8bd1d0a3445bf349a8ef3"
2473
+ checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be"
2474
2474
  dependencies = [
2475
2475
  "base64 0.22.1",
2476
- "serde",
2476
+ "serde_core",
2477
2477
  ]
2478
2478
 
2479
2479
  [[package]]
@@ -3402,10 +3402,11 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
3402
3402
 
3403
3403
  [[package]]
3404
3404
  name = "serde"
3405
- version = "1.0.219"
3405
+ version = "1.0.228"
3406
3406
  source = "registry+https://github.com/rust-lang/crates.io-index"
3407
- checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
3407
+ checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
3408
3408
  dependencies = [
3409
+ "serde_core",
3409
3410
  "serde_derive",
3410
3411
  ]
3411
3412
 
@@ -3448,11 +3449,20 @@ dependencies = [
3448
3449
  "serde",
3449
3450
  ]
3450
3451
 
3452
+ [[package]]
3453
+ name = "serde_core"
3454
+ version = "1.0.228"
3455
+ source = "registry+https://github.com/rust-lang/crates.io-index"
3456
+ checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
3457
+ dependencies = [
3458
+ "serde_derive",
3459
+ ]
3460
+
3451
3461
  [[package]]
3452
3462
  name = "serde_derive"
3453
- version = "1.0.219"
3463
+ version = "1.0.228"
3454
3464
  source = "registry+https://github.com/rust-lang/crates.io-index"
3455
- checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
3465
+ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
3456
3466
  dependencies = [
3457
3467
  "proc-macro2",
3458
3468
  "quote",
@@ -3461,15 +3471,16 @@ dependencies = [
3461
3471
 
3462
3472
  [[package]]
3463
3473
  name = "serde_json"
3464
- version = "1.0.141"
3474
+ version = "1.0.145"
3465
3475
  source = "registry+https://github.com/rust-lang/crates.io-index"
3466
- checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
3476
+ checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
3467
3477
  dependencies = [
3468
3478
  "indexmap 2.10.0",
3469
3479
  "itoa",
3470
3480
  "memchr",
3471
3481
  "ryu",
3472
3482
  "serde",
3483
+ "serde_core",
3473
3484
  ]
3474
3485
 
3475
3486
  [[package]]
@@ -3495,9 +3506,9 @@ dependencies = [
3495
3506
 
3496
3507
  [[package]]
3497
3508
  name = "serde_with"
3498
- version = "3.14.0"
3509
+ version = "3.15.1"
3499
3510
  source = "registry+https://github.com/rust-lang/crates.io-index"
3500
- checksum = "f2c45cd61fefa9db6f254525d46e392b852e0e61d9a1fd36e5bd183450a556d5"
3511
+ checksum = "aa66c845eee442168b2c8134fec70ac50dc20e760769c8ba0ad1319ca1959b04"
3501
3512
  dependencies = [
3502
3513
  "base64 0.22.1",
3503
3514
  "chrono",
@@ -3506,8 +3517,7 @@ dependencies = [
3506
3517
  "indexmap 2.10.0",
3507
3518
  "schemars 0.9.0",
3508
3519
  "schemars 1.0.4",
3509
- "serde",
3510
- "serde_derive",
3520
+ "serde_core",
3511
3521
  "serde_json",
3512
3522
  "serde_with_macros",
3513
3523
  "time",
@@ -3515,9 +3525,9 @@ dependencies = [
3515
3525
 
3516
3526
  [[package]]
3517
3527
  name = "serde_with_macros"
3518
- version = "3.14.0"
3528
+ version = "3.15.1"
3519
3529
  source = "registry+https://github.com/rust-lang/crates.io-index"
3520
- checksum = "de90945e6565ce0d9a25098082ed4ee4002e047cb59892c318d66821e14bb30f"
3530
+ checksum = "b91a903660542fced4e99881aa481bdbaec1634568ee02e0b8bd57c64cb38955"
3521
3531
  dependencies = [
3522
3532
  "darling",
3523
3533
  "proc-macro2",
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.64", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto"] }
14
+ c2pa = { version = "0.68", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto"] }
15
15
  futures = "0.3"
16
16
  image = "0.25.6"
17
17
  neon = { version = "1.0.0", default-features = false, features = [
@@ -29,7 +29,7 @@ reqwest = { version = "0.12.2", default-features = false, features = [
29
29
  ] }
30
30
  serde = { version = "1.0.203", features = ["derive"] }
31
31
  serde_bytes = "0.11.15"
32
- serde_json = "1.0.117"
32
+ serde_json = "1.0.145"
33
33
  toml = "0.8"
34
34
  thiserror = "1.0.61"
35
35
  tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
package/dist/Builder.js CHANGED
@@ -37,6 +37,10 @@ export class Builder {
37
37
  const builder = getNeonBinary().builderWithJson(jsonString);
38
38
  return new Builder(builder);
39
39
  }
40
+ setIntent(intent) {
41
+ const intentString = JSON.stringify(intent);
42
+ getNeonBinary().builderSetIntent.call(this.builder, intentString);
43
+ }
40
44
  setNoEmbed(noEmbed = true) {
41
45
  getNeonBinary().builderSetNoEmbed.call(this.builder, noEmbed);
42
46
  }
@@ -179,7 +179,7 @@ describe("Builder", () => {
179
179
  const reader = yield Reader.fromAsset(dest);
180
180
  const manifestStore = reader.json();
181
181
  const activeManifest = reader.getActive();
182
- expect(manifestStore.validation_status).toBeUndefined();
182
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
183
183
  expect(manifestStore.active_manifest).not.toBeUndefined();
184
184
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
185
185
  }));
@@ -227,7 +227,7 @@ describe("Builder", () => {
227
227
  });
228
228
  const manifestStore = reader.json();
229
229
  const activeManifest = reader.getActive();
230
- expect(manifestStore.validation_status).toBeUndefined();
230
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
231
231
  expect(manifestStore.active_manifest).not.toBeUndefined();
232
232
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
233
233
  }));
@@ -248,7 +248,7 @@ describe("Builder", () => {
248
248
  const reader = yield Reader.fromAsset(dest);
249
249
  const manifestStore = reader.json();
250
250
  const activeManifest = reader.getActive();
251
- expect(manifestStore.validation_status).toBeUndefined();
251
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
252
252
  expect(manifestStore.active_manifest).not.toBeUndefined();
253
253
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
254
254
  }));
@@ -272,7 +272,7 @@ describe("Builder", () => {
272
272
  });
273
273
  const manifestStore = reader.json();
274
274
  const activeManifest = reader.getActive();
275
- expect(manifestStore.validation_status).toBeUndefined();
275
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
276
276
  expect(manifestStore.active_manifest).not.toBeUndefined();
277
277
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
278
278
  }));
@@ -297,7 +297,7 @@ describe("Builder", () => {
297
297
  });
298
298
  const manifestStore = reader.json();
299
299
  const activeManifest = reader.getActive();
300
- expect(manifestStore.validation_status).toBeUndefined();
300
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
301
301
  expect(manifestStore.active_manifest).not.toBeUndefined();
302
302
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
303
303
  }));
@@ -389,5 +389,148 @@ describe("Builder", () => {
389
389
  expect(JSON.stringify(manifestStore)).toContain("Test Ingredient");
390
390
  expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
391
391
  }));
392
+ it("should perform redaction workflow like test_redaction_async", () => __awaiter(void 0, void 0, void 0, function* () {
393
+ // This test mirrors the Rust test_redaction_async test
394
+ // Create a reader to get the parent manifest label from the existing source
395
+ const reader = yield Reader.fromAsset(source);
396
+ const parentManifestLabel = reader.activeLabel();
397
+ expect(parentManifestLabel).toBeDefined();
398
+ // Create a redacted URI for the assertion we are going to redact
399
+ // Using a common assertion label that might exist
400
+ const assertionLabel = "stds.schema-org.CreativeWork";
401
+ const redactedUri = `contentauth:urn:uuid:${parentManifestLabel}/c2pa.assertions/${assertionLabel}`;
402
+ // Create a builder with edit intent and redactions
403
+ const redactionManifestDefinition = {
404
+ claim_generator: "test-generator",
405
+ claim_generator_info: [
406
+ {
407
+ name: "c2pa_test",
408
+ version: "1.0.0",
409
+ },
410
+ ],
411
+ title: "Test_Redaction_Manifest",
412
+ format: "image/jpeg",
413
+ instance_id: "1234",
414
+ intent: "edit",
415
+ redactions: [redactedUri],
416
+ assertions: [
417
+ {
418
+ label: "org.test.assertion",
419
+ data: {},
420
+ },
421
+ ],
422
+ resources: { resources: {} },
423
+ };
424
+ const builder = Builder.withJson(redactionManifestDefinition);
425
+ // Add a redacted action
426
+ const redactedAction = {
427
+ actions: [
428
+ {
429
+ action: "c2pa.redacted",
430
+ },
431
+ ],
432
+ };
433
+ builder.addAssertion("c2pa.actions", redactedAction, "Cbor");
434
+ // Use the callback signer like the other test
435
+ const signerConfig = {
436
+ alg: "es256",
437
+ certs: [publicKey],
438
+ reserveSize: 10000,
439
+ tsaUrl: undefined,
440
+ directCoseHandling: false,
441
+ };
442
+ const testSigner = new TestSigner(privateKey);
443
+ const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
444
+ // Sign the manifest with the original image as input
445
+ const dest = { buffer: null };
446
+ const outputBuffer = yield builder.signAsync(signer, source, dest);
447
+ expect(outputBuffer.length).toBeGreaterThan(0);
448
+ // Verify the result by reading the signed manifest
449
+ const signedReader = yield Reader.fromAsset({
450
+ buffer: dest.buffer,
451
+ mimeType: "image/jpeg",
452
+ });
453
+ expect(signedReader).toBeDefined();
454
+ // Check that the manifest was created successfully
455
+ const activeManifest = signedReader.getActive();
456
+ expect(activeManifest).toBeDefined();
457
+ // Verify the redacted action was added
458
+ const assertions = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions;
459
+ const actionsAssertion = assertions === null || assertions === void 0 ? void 0 : assertions.find((a) => a.label === "c2pa.actions.v2");
460
+ expect(actionsAssertion).toBeDefined();
461
+ if (actionsAssertion && isActionsAssertion(actionsAssertion)) {
462
+ const actions = actionsAssertion.data.actions;
463
+ const redactedAction = actions.find((a) => a.action === "c2pa.redacted");
464
+ expect(redactedAction).toBeDefined();
465
+ expect(redactedAction === null || redactedAction === void 0 ? void 0 : redactedAction.action).toBe("c2pa.redacted");
466
+ }
467
+ }));
468
+ it("should test builder remote url", () => __awaiter(void 0, void 0, void 0, function* () {
469
+ // This test mirrors the Rust test_builder_remote_url test
470
+ // Create a simple manifest definition similar to simple_manifest_json()
471
+ const simpleManifestDefinition = {
472
+ claim_generator_info: [
473
+ {
474
+ name: "c2pa_test",
475
+ version: "1.0.0",
476
+ },
477
+ ],
478
+ title: "Test_Manifest",
479
+ assertions: [
480
+ {
481
+ label: "c2pa.actions",
482
+ data: {
483
+ actions: [
484
+ {
485
+ action: "c2pa.created",
486
+ digitalSourceType: "http://c2pa.org/digitalsourcetype/empty",
487
+ },
488
+ ],
489
+ },
490
+ },
491
+ ],
492
+ };
493
+ const builder = Builder.withJson(simpleManifestDefinition);
494
+ // Set remote URL and no embed flag like the Rust test
495
+ builder.setRemoteUrl("http://my_remote_url");
496
+ builder.setNoEmbed(true);
497
+ // Use the callback signer
498
+ const signerConfig = {
499
+ alg: "es256",
500
+ certs: [publicKey],
501
+ reserveSize: 10000,
502
+ tsaUrl: undefined,
503
+ directCoseHandling: false,
504
+ };
505
+ const testSigner = new TestSigner(privateKey);
506
+ const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
507
+ // Sign the Builder and write it to the output stream
508
+ const dest = { buffer: null };
509
+ const manifestData = yield builder.signAsync(signer, source, dest);
510
+ // Check to make sure we have a remote url and no manifest data embedded
511
+ // Reading the image directly should fail since no_embed = true
512
+ // Note: This might fail due to remote URL fetch, which is expected behavior
513
+ try {
514
+ yield Reader.fromAsset({
515
+ buffer: dest.buffer,
516
+ mimeType: "image/jpeg",
517
+ });
518
+ // If we get here, the test should fail because we expect no embedded manifest
519
+ expect.fail("Expected Reader.fromAsset to fail when no_embed = true");
520
+ }
521
+ catch (error) {
522
+ // This is expected - there should be no embedded manifest or remote fetch should fail
523
+ expect(error).toBeDefined();
524
+ }
525
+ // Now validate the manifest against the written asset using the separate manifest data
526
+ const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
527
+ buffer: dest.buffer,
528
+ mimeType: "image/jpeg",
529
+ });
530
+ // Check if the manifest has the expected structure
531
+ const activeManifest = reader.getActive();
532
+ expect(activeManifest).toBeDefined();
533
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
534
+ }));
392
535
  });
393
536
  });
@@ -15,26 +15,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  import path from "path";
16
16
  import * as fs from "fs-extra";
17
17
  import { Reader } from "./Reader.js";
18
+ import { patchVerifyConfig } from "./Settings.js";
18
19
  const tempDir = path.join(__dirname, "tmp");
19
20
  describe("Reader", () => {
20
21
  const manifestStore = JSON.parse(`{
21
- "active_manifest": "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4",
22
+ "active_manifest": "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf",
22
23
  "manifests": {
23
- "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4": {
24
- "claim_generator": "make_test_images/0.36.1",
24
+ "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf": {
25
+ "claim_generator": "make_test_images/0.33.1 c2pa-rs/0.33.1",
25
26
  "claim_generator_info": [
26
27
  {
27
28
  "name": "make_test_images",
28
- "version": "0.36.1",
29
- "org.cai.c2pa_rs": "0.42.0"
29
+ "version": "0.33.1"
30
+ },
31
+ {
32
+ "name": "c2pa-rs",
33
+ "version": "0.33.1"
30
34
  }
31
35
  ],
32
- "title": "CAI.jpg",
36
+ "title": "CA.jpg",
33
37
  "format": "image/jpeg",
34
- "instance_id": "xmp:iid:099bb0ad-5c66-4ad9-b0b6-6824fb26a198",
38
+ "instance_id": "xmp:iid:ba572347-db0e-4619-b6eb-d38e487da238",
35
39
  "thumbnail": {
36
40
  "format": "image/jpeg",
37
- "identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4/c2pa.assertions/c2pa.thumbnail.claim.jpeg"
41
+ "identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf/c2pa.assertions/c2pa.thumbnail.claim.jpeg"
38
42
  },
39
43
  "ingredients": [
40
44
  {
@@ -48,18 +52,6 @@ describe("Reader", () => {
48
52
  },
49
53
  "relationship": "parentOf",
50
54
  "label": "c2pa.ingredient"
51
- },
52
- {
53
- "title": "I.jpg",
54
- "format": "image/jpeg",
55
- "document_id": "xmp.did:8a00de7a-e694-43b2-a7e6-ed950421a21a",
56
- "instance_id": "xmp.iid:8a00de7a-e694-43b2-a7e6-ed950421a21a",
57
- "thumbnail": {
58
- "format": "image/jpeg",
59
- "identifier": "self#jumbf=c2pa.assertions/c2pa.thumbnail.ingredient__1.jpeg"
60
- },
61
- "relationship": "componentOf",
62
- "label": "c2pa.ingredient__1"
63
55
  }
64
56
  ],
65
57
  "assertions": [
@@ -84,15 +76,10 @@ describe("Reader", () => {
84
76
  {
85
77
  "action": "c2pa.opened",
86
78
  "parameters": {
87
- "org.cai.ingredientIds": [
88
- "xmp.iid:813ee422-9736-4cdc-9be6-4e35ed8e41cb"
89
- ],
90
- "ingredient": [
91
- {
92
- "url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
93
- "hash": "tTBD4/E0R0AjLUdJFpsVz3lE/KJUq22Vz0UGqzhEpVs="
94
- }
95
- ]
79
+ "ingredient": {
80
+ "url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
81
+ "hash": "5dNlxTKe4afGAicpJa1hF1R3mBZKE+Bl0xmh0McXuO4="
82
+ }
96
83
  }
97
84
  },
98
85
  {
@@ -100,23 +87,6 @@ describe("Reader", () => {
100
87
  "parameters": {
101
88
  "name": "brightnesscontrast"
102
89
  }
103
- },
104
- {
105
- "action": "c2pa.placed",
106
- "parameters": {
107
- "org.cai.ingredientIds": [
108
- "xmp.iid:8a00de7a-e694-43b2-a7e6-ed950421a21a"
109
- ],
110
- "ingredient": [
111
- {
112
- "url": "self#jumbf=c2pa.assertions/c2pa.ingredient__1",
113
- "hash": "EMeeY5a+lvy1msl+9i5DOcOoeQowrqD7NyV0d8fwAX0="
114
- }
115
- ]
116
- }
117
- },
118
- {
119
- "action": "c2pa.resized"
120
90
  }
121
91
  ]
122
92
  }
@@ -127,20 +97,21 @@ describe("Reader", () => {
127
97
  "issuer": "C2PA Test Signing Cert",
128
98
  "common_name": "C2PA Signer",
129
99
  "cert_serial_number": "720724073027128164015125666832722375746636448153",
130
- "time": "2025-02-04T17:38:01+00:00"
100
+ "time": "2024-08-06T21:53:37+00:00"
131
101
  },
132
- "label": "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4"
102
+ "label": "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf"
133
103
  }
134
104
  }
135
105
  }`);
136
106
  beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
107
+ patchVerifyConfig({ verifyTrust: false });
137
108
  yield fs.ensureDir(tempDir);
138
109
  }));
139
110
  afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
140
111
  yield fs.remove(tempDir);
141
112
  }));
142
113
  it("should read from an ArrayBuffer", () => __awaiter(void 0, void 0, void 0, function* () {
143
- const buffer = yield fs.readFile("./tests/fixtures/CAI.jpg");
114
+ const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
144
115
  const reader = yield Reader.fromAsset({
145
116
  buffer,
146
117
  mimeType: "jpeg",
@@ -151,15 +122,15 @@ describe("Reader", () => {
151
122
  }));
152
123
  it("should read from a file", () => __awaiter(void 0, void 0, void 0, function* () {
153
124
  const reader = yield Reader.fromAsset({
154
- path: "./tests/fixtures/CAI.jpg",
125
+ path: "./tests/fixtures/CA.jpg",
155
126
  });
156
127
  const json = reader.json();
157
128
  expect(json.manifests).toEqual(manifestStore.manifests);
158
129
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
159
130
  }));
160
131
  it("should read from manifest data and buffer", () => __awaiter(void 0, void 0, void 0, function* () {
161
- const manifestData = yield fs.readFile("./tests/fixtures/CAI/manifest_data.c2pa");
162
- const buffer = yield fs.readFile("./tests/fixtures/CAI.jpg");
132
+ const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
133
+ const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
163
134
  const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
164
135
  buffer,
165
136
  mimeType: "jpeg",
@@ -169,9 +140,9 @@ describe("Reader", () => {
169
140
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
170
141
  }));
171
142
  it("should read from manifest data and file", () => __awaiter(void 0, void 0, void 0, function* () {
172
- const manifestData = yield fs.readFile("./tests/fixtures/CAI/manifest_data.c2pa");
143
+ const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
173
144
  const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
174
- path: "./tests/fixtures/CAI.jpg",
145
+ path: "./tests/fixtures/CA.jpg",
175
146
  });
176
147
  const json = reader.json();
177
148
  expect(json.manifests).toEqual(manifestStore.manifests);
@@ -181,7 +152,7 @@ describe("Reader", () => {
181
152
  let bytesWritten = 0;
182
153
  const outputPath = path.join(tempDir, "thumbnail.jpg");
183
154
  const reader = yield Reader.fromAsset({
184
- path: "./tests/fixtures/CAI.jpg",
155
+ path: "./tests/fixtures/CA.jpg",
185
156
  });
186
157
  const activeManifest = reader.getActive();
187
158
  const uri = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.thumbnail) === null || _a === void 0 ? void 0 : _a.identifier;
@@ -190,12 +161,12 @@ describe("Reader", () => {
190
161
  path: outputPath,
191
162
  });
192
163
  }
193
- expect(bytesWritten).toBe(85281);
164
+ expect(bytesWritten).toBe(49690);
194
165
  expect(fs.existsSync(outputPath));
195
166
  }));
196
167
  it("should report manifest is embedded", () => __awaiter(void 0, void 0, void 0, function* () {
197
168
  const reader = yield Reader.fromAsset({
198
- path: "./tests/fixtures/CAI.jpg",
169
+ path: "./tests/fixtures/CA.jpg",
199
170
  });
200
171
  expect(reader.remoteUrl()).toEqual("");
201
172
  expect(reader.isEmbedded()).toBeTruthy();
@@ -207,4 +178,39 @@ describe("Reader", () => {
207
178
  expect(reader.remoteUrl()).toEqual("https://cai-manifests.adobe.com/manifests/adobe-urn-uuid-5f37e182-3687-462e-a7fb-573462780391");
208
179
  expect(reader.isEmbedded()).toBeFalsy();
209
180
  }));
181
+ it("should decode CAWG identity assertion with signature_info", () => __awaiter(void 0, void 0, void 0, function* () {
182
+ var _a;
183
+ // This test verifies that postValidateCawg() properly decodes CAWG assertions
184
+ // and extracts signature_info from the signature data, matching c2pa-js behavior
185
+ const reader = yield Reader.fromAsset({
186
+ path: "./tests/fixtures/C_with_CAWG_data.jpg",
187
+ });
188
+ // Call postValidateCawg to decode CAWG assertions
189
+ yield reader.postValidateCawg();
190
+ const activeManifest = reader.getActive();
191
+ // Find the cawg.identity assertion
192
+ const cawgIdentityAssertion = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((assertion) => assertion.label === "cawg.identity");
193
+ expect(cawgIdentityAssertion).toBeDefined();
194
+ expect(cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data).toBeDefined();
195
+ expect(cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signature_info).toBeDefined();
196
+ // Verify signature_info structure matches c2pa-js behavior
197
+ const signatureInfo = cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signature_info;
198
+ const signerPayload = cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signer_payload;
199
+ // Verify signature_info values
200
+ expect(signatureInfo.alg).toBe("Ed25519");
201
+ expect(signatureInfo.issuer).toBe("C2PA Test Signing Cert");
202
+ expect(signatureInfo.cert_serial_number).toBe("638838410810235485828984295321338730070538954823");
203
+ expect(signatureInfo.revocation_status).toBe(true);
204
+ // Verify signer_payload values
205
+ expect(signerPayload.sig_type).toBe("cawg.x509.cose");
206
+ expect(signerPayload.referenced_assertions).toHaveLength(2);
207
+ expect(signerPayload.referenced_assertions[0]).toEqual({
208
+ url: "self#jumbf=c2pa.assertions/cawg.training-mining",
209
+ hash: "rBBgURB+/0Bc2Uk3+blNpYTGQTxOwzXQ2xhjA3gsqI4=",
210
+ });
211
+ expect(signerPayload.referenced_assertions[1]).toEqual({
212
+ url: "self#jumbf=c2pa.assertions/c2pa.hash.data",
213
+ hash: "sASozh9KFSkW+cyMI0Pw5KYoD2qn7MkUEq9jUUhe/sM=",
214
+ });
215
+ }));
210
216
  });
@@ -98,7 +98,7 @@ describe("Settings", () => {
98
98
  expect(() => loadTrustConfig(emptyTrustConfig)).not.toThrow();
99
99
  // Verify settings are still intact
100
100
  const currentSettings = JSON.parse(getSettingsJson());
101
- expect(currentSettings.core.hash_alg).toBe("sha256");
101
+ expect(currentSettings.core.merkle_tree_max_proofs).toBe(5);
102
102
  expect(currentSettings.verify.verify_trust).toBe(true);
103
103
  expect(currentSettings.trust.verify_trust_list).toBe(true);
104
104
  });
package/dist/Signer.js CHANGED
@@ -76,4 +76,7 @@ export class CallbackSigner {
76
76
  timeAuthorityUrl() {
77
77
  return getNeonBinary().callbackSignerTimeAuthorityUrl.call(this.callbackSigner);
78
78
  }
79
+ directCoseHandling() {
80
+ return getNeonBinary().callbackSignerDirectCoseHandling.call(this.callbackSigner);
81
+ }
79
82
  }
@@ -21,6 +21,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
21
21
  import * as fs from "fs-extra";
22
22
  import * as crypto from "crypto";
23
23
  import { CallbackSigner } from "./Signer.js";
24
+ import { Builder } from "./Builder.js";
25
+ import { Reader } from "./Reader.js";
24
26
  class TestSigner {
25
27
  constructor(privateKey) {
26
28
  this.sign = (bytes) => __awaiter(this, void 0, void 0, function* () {
@@ -96,4 +98,65 @@ describe("CallbackSigner", () => {
96
98
  const signer = CallbackSigner.newSigner(config, (data) => __awaiter(void 0, void 0, void 0, function* () { return data; }));
97
99
  expect(signer.timeAuthorityUrl()).toBeUndefined();
98
100
  }));
101
+ it("should create valid COSE signature with buffer output", () => __awaiter(void 0, void 0, void 0, function* () {
102
+ const testSigner = new TestSigner(yield fs.readFile("./tests/fixtures/certs/es256.pem"));
103
+ const createRawSignatureCallback = () => {
104
+ return (data) => __awaiter(void 0, void 0, void 0, function* () {
105
+ // For directCoseHandling: false, return raw signature data
106
+ // The c2pa SDK will handle COSE wrapping internally
107
+ return yield testSigner.sign(data);
108
+ });
109
+ };
110
+ // Create a simple manifest
111
+ const manifestDefinition = {
112
+ vendor: "test",
113
+ claim_generator: "test-generator",
114
+ claim_generator_info: [
115
+ {
116
+ name: "c2pa_test",
117
+ version: "1.0.0",
118
+ },
119
+ ],
120
+ title: "Test_Manifest_Buffer",
121
+ format: "image/jpeg",
122
+ instance_id: "5678",
123
+ assertions: [
124
+ {
125
+ label: "org.test.assertion",
126
+ data: { message: "Buffer test with directCoseHandling: false" },
127
+ },
128
+ ],
129
+ resources: { resources: {} },
130
+ };
131
+ const builder = Builder.withJson(manifestDefinition);
132
+ const source = {
133
+ buffer: yield fs.readFile("./tests/fixtures/CA.jpg"),
134
+ mimeType: "image/jpeg",
135
+ };
136
+ const config = {
137
+ alg: "es256",
138
+ certs: [fs.readFileSync("./tests/fixtures/certs/es256.pub")],
139
+ reserveSize: 10000,
140
+ tsaUrl: undefined,
141
+ directCoseHandling: false,
142
+ };
143
+ const callback = createRawSignatureCallback();
144
+ const signer = CallbackSigner.newSigner(config, callback);
145
+ // Sign the manifest to buffer
146
+ const dest = { buffer: null };
147
+ yield builder.signAsync(signer, source, dest);
148
+ // Read the signed manifest back and verify signature is valid
149
+ const reader = yield Reader.fromAsset({
150
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
151
+ buffer: dest.buffer,
152
+ mimeType: "image/jpeg",
153
+ });
154
+ const manifestStore = reader.json();
155
+ const activeManifest = reader.getActive();
156
+ // If validation_status is undefined, the signature is valid
157
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
158
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
159
+ expect(manifestStore.active_manifest).not.toBeUndefined();
160
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest_Buffer");
161
+ }));
99
162
  });
package/dist/index.node CHANGED
Binary file
@@ -1,10 +1,11 @@
1
- import type { Manifest } from "@contentauth/c2pa-types";
1
+ import type { BuilderIntent, Manifest } from "@contentauth/c2pa-types";
2
2
  import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, SourceAsset } from "./types.d.ts";
3
3
  export declare class Builder implements BuilderInterface {
4
4
  private builder;
5
5
  private constructor();
6
6
  static new(): Builder;
7
7
  static withJson(json: Manifest): Builder;
8
+ setIntent(intent: BuilderIntent): void;
8
9
  setNoEmbed(noEmbed?: boolean): void;
9
10
  setRemoteUrl(remoteUrl: string): void;
10
11
  addAssertion(label: string, assertion: unknown, assertionKind?: ManifestAssertionKind): void;
@@ -20,4 +20,5 @@ export declare class CallbackSigner implements CallbackSignerInterface {
20
20
  certs(): Array<Buffer>;
21
21
  reserveSize(): number;
22
22
  timeAuthorityUrl(): string | undefined;
23
+ directCoseHandling(): boolean;
23
24
  }
@@ -13,7 +13,11 @@
13
13
 
14
14
  // This file contains types not included in @contentauth/c2pa-types and not directly applicable to the neon generated code (index.node.d.ts)
15
15
  import { Buffer } from "buffer";
16
- import type { Manifest, ManifestStore } from "@contentauth/c2pa-types";
16
+ import type {
17
+ BuilderIntent,
18
+ Manifest,
19
+ ManifestStore,
20
+ } from "@contentauth/c2pa-types";
17
21
  /**
18
22
  * Describes the digital signature algorithms allowed by the C2PA spec
19
23
  *
@@ -118,6 +122,7 @@ export interface CallbackSignerInterface {
118
122
  certs(): Array<Buffer>;
119
123
  reserveSize(): number;
120
124
  timeAuthorityUrl(): string | undefined;
125
+ directCoseHandling(): boolean;
121
126
  signer(): NeonCallbackSignerHandle;
122
127
  }
123
128
 
@@ -153,10 +158,8 @@ export interface JsCallbackSignerConfig {
153
158
  tsaUrl?: string;
154
159
  tsaHeaders?: Array<[string, string]>;
155
160
  tsaBody?: Buffer;
156
- // TODO: directCoseHandling is currently not implemented in the signing logic.
157
- // The field is read from config but the actual signing implementation does not
158
- // differentiate between directCoseHandling: true/false - both cases pass the
159
- // same data to the JavaScript callback regardless of this setting.
161
+ // When true, the callback function should return fully-formed COSE data.
162
+ // When false, the callback function should return raw signature data and the c2pa SDK will handle COSE wrapping.
160
163
  directCoseHandling: boolean;
161
164
  }
162
165
 
@@ -173,6 +176,7 @@ export interface HashedUri {
173
176
  }
174
177
 
175
178
  export interface BuilderInterface {
179
+ setIntent(intent: BuilderIntent): void;
176
180
  /**
177
181
  * Set the no embed flag of the manifest
178
182
  * @param noEmbed The no embed flag of the manifest
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "git+https://github.com/contentauth/c2pa-node-v2.git"
6
6
  },
7
- "version": "0.2.3",
7
+ "version": "0.3.0",
8
8
  "description": "Node.js bindings for C2PA",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
25
  "@changesets/cli": "^2.29.6",
26
- "@contentauth/c2pa-types": "^0.2.1",
26
+ "@contentauth/c2pa-types": "^0.3.1",
27
27
  "@eslint/js": "^9.33.0",
28
28
  "@neon-rs/cli": "0.1.82",
29
29
  "@types/cli-progress": "^3.11.6",
package/src/lib.rs CHANGED
@@ -32,9 +32,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
32
32
  // Builder
33
33
  cx.export_function("builderNew", neon_builder::NeonBuilder::new)?;
34
34
  cx.export_function("builderWithJson", neon_builder::NeonBuilder::with_json)?;
35
+ cx.export_function("builderSetIntent", neon_builder::NeonBuilder::set_intent)?;
35
36
  cx.export_function("builderSetNoEmbed", neon_builder::NeonBuilder::set_no_embed)?;
36
37
  cx.export_function(
37
- "builderSetRemote_url",
38
+ "builderSetRemoteUrl",
38
39
  neon_builder::NeonBuilder::set_remote_url,
39
40
  )?;
40
41
  cx.export_function(
@@ -131,6 +132,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
131
132
  "callbackSignerTimeAuthorityUrl",
132
133
  neon_signer::NeonCallbackSigner::time_authority_url,
133
134
  )?;
135
+ cx.export_function(
136
+ "callbackSignerDirectCoseHandling",
137
+ neon_signer::NeonCallbackSigner::direct_cose_handling,
138
+ )?;
134
139
 
135
140
  // Identity Assertions
136
141
  cx.export_function(
@@ -16,7 +16,7 @@ use crate::error::{as_js_error, Error};
16
16
  use crate::neon_identity_assertion_signer::NeonIdentityAssertionSigner;
17
17
  use crate::neon_signer::{CallbackSignerConfig, NeonCallbackSigner, NeonLocalSigner};
18
18
  use crate::runtime::runtime;
19
- use c2pa::Builder;
19
+ use c2pa::{Builder, BuilderIntent};
20
20
  use neon::prelude::*;
21
21
  use neon_serde4;
22
22
  use serde::{Deserialize, Serialize};
@@ -59,6 +59,17 @@ impl NeonBuilder {
59
59
  }))
60
60
  }
61
61
 
62
+ pub fn set_intent(mut cx: FunctionContext) -> JsResult<JsUndefined> {
63
+ let rt = runtime();
64
+ let this = cx.this::<JsBox<Self>>()?;
65
+ let intent_str = cx.argument::<JsString>(0)?.value(&mut cx);
66
+ let intent: BuilderIntent = serde_json::from_str(&intent_str)
67
+ .or_else(|_| cx.throw_error(format!("Invalid intent: {}", intent_str)))?;
68
+ let mut builder = rt.block_on(async { this.builder.lock().await });
69
+ builder.set_intent(intent);
70
+ Ok(cx.undefined())
71
+ }
72
+
62
73
  pub fn set_no_embed(mut cx: FunctionContext) -> JsResult<JsUndefined> {
63
74
  let rt = runtime();
64
75
  let this = cx.this::<JsBox<Self>>()?;
@@ -201,6 +201,11 @@ impl NeonCallbackSigner {
201
201
  }
202
202
  }
203
203
 
204
+ pub fn direct_cose_handling(mut cx: FunctionContext) -> JsResult<JsBoolean> {
205
+ let this = cx.this::<JsBox<Self>>()?;
206
+ Ok(cx.boolean(this.config.direct_cose_handling))
207
+ }
208
+
204
209
  pub fn sign(mut cx: FunctionContext) -> JsResult<JsPromise> {
205
210
  let rt = runtime();
206
211
  let this = cx.this::<JsBox<Self>>()?;
@@ -321,12 +326,12 @@ impl AsyncSigner for NeonCallbackSigner {
321
326
  }
322
327
 
323
328
  fn direct_cose_handling(&self) -> bool {
324
- // TODO: The direct_cose_handling field is currently not used in the signing logic.
325
- // The field is read from config and exposed via this getter, but the actual signing
326
- // implementation does not differentiate between directCoseHandling: true/false.
327
- // Both cases pass the same data to the JavaScript callback regardless of this setting.
328
329
  self.config.direct_cose_handling
329
330
  }
331
+
332
+ fn async_raw_signer(&self) -> Option<Box<&dyn AsyncRawSigner>> {
333
+ Some(Box::new(self))
334
+ }
330
335
  }
331
336
 
332
337
  impl TimeStampProvider for NeonCallbackSigner {