@contentauth/c2pa-node 0.2.3 → 0.4.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 +172 -121
- package/Cargo.toml +2 -2
- package/dist/Builder.js +13 -1
- package/dist/Builder.spec.js +250 -5
- package/dist/IdentityAssertion.spec.js +1 -2
- package/dist/Reader.js +1 -6
- package/dist/Reader.spec.js +84 -57
- package/dist/Settings.js +7 -2
- package/dist/Settings.spec.js +5 -10
- package/dist/Signer.js +3 -0
- package/dist/Signer.spec.js +63 -0
- package/dist/index.node +0 -0
- package/dist/types/Builder.d.ts +4 -2
- package/dist/types/Reader.d.ts +1 -2
- package/dist/types/Settings.d.ts +5 -0
- package/dist/types/Signer.d.ts +1 -0
- package/dist/types/types.d.ts +35 -15
- package/package.json +3 -3
- package/src/lib.rs +14 -5
- package/src/neon_builder.rs +79 -46
- package/src/neon_reader.rs +40 -39
- package/src/neon_signer.rs +9 -4
- package/src/settings.rs +24 -7
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.
|
|
14
|
+
c2pa = { version = "0.72.0", 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 = [
|
|
@@ -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.
|
|
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,12 +37,19 @@ 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
|
}
|
|
43
47
|
setRemoteUrl(remoteUrl) {
|
|
44
48
|
getNeonBinary().builderSetRemoteUrl.call(this.builder, remoteUrl);
|
|
45
49
|
}
|
|
50
|
+
addAction(actionJson) {
|
|
51
|
+
return getNeonBinary().builderAddAction.call(this.builder, actionJson);
|
|
52
|
+
}
|
|
46
53
|
addAssertion(label, assertion, assertionKind) {
|
|
47
54
|
return getNeonBinary().builderAddAssertion.call(this.builder, label, assertion, assertionKind);
|
|
48
55
|
}
|
|
@@ -53,7 +60,12 @@ export class Builder {
|
|
|
53
60
|
}
|
|
54
61
|
addIngredient(ingredientJson, ingredient) {
|
|
55
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
|
|
63
|
+
if (ingredient) {
|
|
64
|
+
return getNeonBinary().builderAddIngredientFromAsset.call(this.builder, ingredientJson, ingredient);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return getNeonBinary().builderAddIngredient.call(this.builder, ingredientJson);
|
|
68
|
+
}
|
|
57
69
|
});
|
|
58
70
|
}
|
|
59
71
|
toArchive(asset) {
|
package/dist/Builder.spec.js
CHANGED
|
@@ -177,9 +177,10 @@ describe("Builder", () => {
|
|
|
177
177
|
const bytes = builder.sign(signer, source, dest);
|
|
178
178
|
expect(bytes.length).toBeGreaterThan(0);
|
|
179
179
|
const reader = yield Reader.fromAsset(dest);
|
|
180
|
+
expect(reader).not.toBeNull();
|
|
180
181
|
const manifestStore = reader.json();
|
|
181
182
|
const activeManifest = reader.getActive();
|
|
182
|
-
expect(manifestStore.validation_status).
|
|
183
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
183
184
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
184
185
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
185
186
|
}));
|
|
@@ -200,6 +201,7 @@ describe("Builder", () => {
|
|
|
200
201
|
builder.sign(signer, source, dest);
|
|
201
202
|
// Read and verify the assertion in the signed manifest
|
|
202
203
|
const reader = yield Reader.fromAsset(dest);
|
|
204
|
+
expect(reader).not.toBeNull();
|
|
203
205
|
const activeManifest = reader.getActive();
|
|
204
206
|
const cborAssertion = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((a) => a.label === "c2pa.actions.v2");
|
|
205
207
|
expect(cborAssertion).toBeDefined();
|
|
@@ -225,9 +227,10 @@ describe("Builder", () => {
|
|
|
225
227
|
buffer: dest.buffer,
|
|
226
228
|
mimeType: "jpeg",
|
|
227
229
|
});
|
|
230
|
+
expect(reader).not.toBeNull();
|
|
228
231
|
const manifestStore = reader.json();
|
|
229
232
|
const activeManifest = reader.getActive();
|
|
230
|
-
expect(manifestStore.validation_status).
|
|
233
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
231
234
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
232
235
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
233
236
|
}));
|
|
@@ -246,9 +249,10 @@ describe("Builder", () => {
|
|
|
246
249
|
const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
|
|
247
250
|
expect(bytes.length).toBeGreaterThan(0);
|
|
248
251
|
const reader = yield Reader.fromAsset(dest);
|
|
252
|
+
expect(reader).not.toBeNull();
|
|
249
253
|
const manifestStore = reader.json();
|
|
250
254
|
const activeManifest = reader.getActive();
|
|
251
|
-
expect(manifestStore.validation_status).
|
|
255
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
252
256
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
253
257
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
254
258
|
}));
|
|
@@ -270,9 +274,10 @@ describe("Builder", () => {
|
|
|
270
274
|
buffer: dest.buffer,
|
|
271
275
|
mimeType: "jpeg",
|
|
272
276
|
});
|
|
277
|
+
expect(reader).not.toBeNull();
|
|
273
278
|
const manifestStore = reader.json();
|
|
274
279
|
const activeManifest = reader.getActive();
|
|
275
|
-
expect(manifestStore.validation_status).
|
|
280
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
276
281
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
277
282
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
278
283
|
}));
|
|
@@ -295,9 +300,10 @@ describe("Builder", () => {
|
|
|
295
300
|
buffer: dest.buffer,
|
|
296
301
|
mimeType: "jpeg",
|
|
297
302
|
});
|
|
303
|
+
expect(reader).not.toBeNull();
|
|
298
304
|
const manifestStore = reader.json();
|
|
299
305
|
const activeManifest = reader.getActive();
|
|
300
|
-
expect(manifestStore.validation_status).
|
|
306
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
301
307
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
302
308
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
303
309
|
}));
|
|
@@ -317,6 +323,7 @@ describe("Builder", () => {
|
|
|
317
323
|
const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
|
|
318
324
|
builder.sign(signer, source, dest);
|
|
319
325
|
const reader = yield Reader.fromAsset(dest);
|
|
326
|
+
expect(reader).not.toBeNull();
|
|
320
327
|
const manifest = reader.json();
|
|
321
328
|
// Check that our specific JSON assertion doesn't have escaped characters
|
|
322
329
|
const activeManifest = manifest.manifests[manifest.active_manifest];
|
|
@@ -385,9 +392,247 @@ describe("Builder", () => {
|
|
|
385
392
|
buffer: dest.buffer,
|
|
386
393
|
mimeType: "jpeg",
|
|
387
394
|
});
|
|
395
|
+
expect(reader).not.toBeNull();
|
|
388
396
|
const manifestStore = reader.json();
|
|
389
397
|
expect(JSON.stringify(manifestStore)).toContain("Test Ingredient");
|
|
390
398
|
expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
|
|
391
399
|
}));
|
|
400
|
+
it("should perform redaction workflow like test_redaction_async", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
401
|
+
// This test mirrors the Rust test_redaction_async test
|
|
402
|
+
// Create a reader to get the parent manifest label from the existing source
|
|
403
|
+
const reader = yield Reader.fromAsset(source);
|
|
404
|
+
expect(reader).not.toBeNull();
|
|
405
|
+
const parentManifestLabel = reader.activeLabel();
|
|
406
|
+
expect(parentManifestLabel).toBeDefined();
|
|
407
|
+
// Create a redacted URI for the assertion we are going to redact
|
|
408
|
+
// Using a common assertion label that might exist
|
|
409
|
+
const assertionLabel = "stds.schema-org.CreativeWork";
|
|
410
|
+
const redactedUri = `contentauth:urn:uuid:${parentManifestLabel}/c2pa.assertions/${assertionLabel}`;
|
|
411
|
+
// Create a builder with edit intent and redactions
|
|
412
|
+
const redactionManifestDefinition = {
|
|
413
|
+
claim_generator: "test-generator",
|
|
414
|
+
claim_generator_info: [
|
|
415
|
+
{
|
|
416
|
+
name: "c2pa_test",
|
|
417
|
+
version: "1.0.0",
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
title: "Test_Redaction_Manifest",
|
|
421
|
+
format: "image/jpeg",
|
|
422
|
+
instance_id: "1234",
|
|
423
|
+
intent: "edit",
|
|
424
|
+
redactions: [redactedUri],
|
|
425
|
+
assertions: [
|
|
426
|
+
{
|
|
427
|
+
label: "org.test.assertion",
|
|
428
|
+
data: {},
|
|
429
|
+
},
|
|
430
|
+
],
|
|
431
|
+
resources: { resources: {} },
|
|
432
|
+
};
|
|
433
|
+
const builder = Builder.withJson(redactionManifestDefinition);
|
|
434
|
+
// Add a redacted action
|
|
435
|
+
const redactedAction = {
|
|
436
|
+
actions: [
|
|
437
|
+
{
|
|
438
|
+
action: "c2pa.redacted",
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
};
|
|
442
|
+
builder.addAssertion("c2pa.actions", redactedAction, "Cbor");
|
|
443
|
+
// Use the callback signer like the other test
|
|
444
|
+
const signerConfig = {
|
|
445
|
+
alg: "es256",
|
|
446
|
+
certs: [publicKey],
|
|
447
|
+
reserveSize: 10000,
|
|
448
|
+
tsaUrl: undefined,
|
|
449
|
+
directCoseHandling: false,
|
|
450
|
+
};
|
|
451
|
+
const testSigner = new TestSigner(privateKey);
|
|
452
|
+
const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
453
|
+
// Sign the manifest with the original image as input
|
|
454
|
+
const dest = { buffer: null };
|
|
455
|
+
const outputBuffer = yield builder.signAsync(signer, source, dest);
|
|
456
|
+
expect(outputBuffer.length).toBeGreaterThan(0);
|
|
457
|
+
// Verify the result by reading the signed manifest
|
|
458
|
+
const signedReader = yield Reader.fromAsset({
|
|
459
|
+
buffer: dest.buffer,
|
|
460
|
+
mimeType: "image/jpeg",
|
|
461
|
+
});
|
|
462
|
+
expect(signedReader).not.toBeNull();
|
|
463
|
+
expect(signedReader).toBeDefined();
|
|
464
|
+
// Check that the manifest was created successfully
|
|
465
|
+
const activeManifest = signedReader.getActive();
|
|
466
|
+
expect(activeManifest).toBeDefined();
|
|
467
|
+
// Verify the redacted action was added
|
|
468
|
+
const assertions = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions;
|
|
469
|
+
const actionsAssertion = assertions === null || assertions === void 0 ? void 0 : assertions.find((a) => a.label === "c2pa.actions.v2");
|
|
470
|
+
expect(actionsAssertion).toBeDefined();
|
|
471
|
+
if (actionsAssertion && isActionsAssertion(actionsAssertion)) {
|
|
472
|
+
const actions = actionsAssertion.data.actions;
|
|
473
|
+
const redactedAction = actions.find((a) => a.action === "c2pa.redacted");
|
|
474
|
+
expect(redactedAction).toBeDefined();
|
|
475
|
+
expect(redactedAction === null || redactedAction === void 0 ? void 0 : redactedAction.action).toBe("c2pa.redacted");
|
|
476
|
+
}
|
|
477
|
+
}));
|
|
478
|
+
it("should test builder remote url", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
479
|
+
// This test mirrors the Rust test_builder_remote_url test
|
|
480
|
+
// Create a simple manifest definition similar to simple_manifest_json()
|
|
481
|
+
const simpleManifestDefinition = {
|
|
482
|
+
claim_generator_info: [
|
|
483
|
+
{
|
|
484
|
+
name: "c2pa_test",
|
|
485
|
+
version: "1.0.0",
|
|
486
|
+
},
|
|
487
|
+
],
|
|
488
|
+
title: "Test_Manifest",
|
|
489
|
+
assertions: [
|
|
490
|
+
{
|
|
491
|
+
label: "c2pa.actions",
|
|
492
|
+
data: {
|
|
493
|
+
actions: [
|
|
494
|
+
{
|
|
495
|
+
action: "c2pa.created",
|
|
496
|
+
digitalSourceType: "http://c2pa.org/digitalsourcetype/empty",
|
|
497
|
+
},
|
|
498
|
+
],
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
],
|
|
502
|
+
};
|
|
503
|
+
const builder = Builder.withJson(simpleManifestDefinition);
|
|
504
|
+
// Set remote URL and no embed flag like the Rust test
|
|
505
|
+
builder.setRemoteUrl("http://my_remote_url");
|
|
506
|
+
builder.setNoEmbed(true);
|
|
507
|
+
// Use the callback signer
|
|
508
|
+
const signerConfig = {
|
|
509
|
+
alg: "es256",
|
|
510
|
+
certs: [publicKey],
|
|
511
|
+
reserveSize: 10000,
|
|
512
|
+
tsaUrl: undefined,
|
|
513
|
+
directCoseHandling: false,
|
|
514
|
+
};
|
|
515
|
+
const testSigner = new TestSigner(privateKey);
|
|
516
|
+
const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
517
|
+
// Sign the Builder and write it to the output stream
|
|
518
|
+
const dest = { buffer: null };
|
|
519
|
+
const manifestData = yield builder.signAsync(signer, source, dest);
|
|
520
|
+
// Check to make sure we have a remote url and no manifest data embedded
|
|
521
|
+
// Reading the image directly should fail since no_embed = true
|
|
522
|
+
// Note: This might fail due to remote URL fetch, which is expected behavior
|
|
523
|
+
try {
|
|
524
|
+
yield Reader.fromAsset({
|
|
525
|
+
buffer: dest.buffer,
|
|
526
|
+
mimeType: "image/jpeg",
|
|
527
|
+
});
|
|
528
|
+
// If we get here, the test should fail because we expect no embedded manifest
|
|
529
|
+
expect.fail("Expected Reader.fromAsset to fail when no_embed = true");
|
|
530
|
+
}
|
|
531
|
+
catch (error) {
|
|
532
|
+
// This is expected - there should be no embedded manifest or remote fetch should fail
|
|
533
|
+
expect(error).toBeDefined();
|
|
534
|
+
}
|
|
535
|
+
// Now validate the manifest against the written asset using the separate manifest data
|
|
536
|
+
const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
|
|
537
|
+
buffer: dest.buffer,
|
|
538
|
+
mimeType: "image/jpeg",
|
|
539
|
+
});
|
|
540
|
+
// Check if the manifest has the expected structure
|
|
541
|
+
const activeManifest = reader.getActive();
|
|
542
|
+
expect(activeManifest).toBeDefined();
|
|
543
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
544
|
+
}));
|
|
545
|
+
it("should add action using addAction method", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
546
|
+
var _a;
|
|
547
|
+
const simpleManifestDefinition = {
|
|
548
|
+
claim_generator_info: [
|
|
549
|
+
{
|
|
550
|
+
name: "c2pa_test",
|
|
551
|
+
version: "1.0.0",
|
|
552
|
+
},
|
|
553
|
+
],
|
|
554
|
+
title: "Test_AddAction",
|
|
555
|
+
format: "image/jpeg",
|
|
556
|
+
assertions: [],
|
|
557
|
+
resources: { resources: {} },
|
|
558
|
+
};
|
|
559
|
+
const builder = Builder.withJson(simpleManifestDefinition);
|
|
560
|
+
// Add an action using addAction method
|
|
561
|
+
// The action needs to be a structured object matching the c2pa Action type
|
|
562
|
+
const actionJson = JSON.stringify({
|
|
563
|
+
action: "c2pa.edited",
|
|
564
|
+
});
|
|
565
|
+
builder.addAction(actionJson);
|
|
566
|
+
// Sign the manifest
|
|
567
|
+
const dest = { path: path.join(tempDir, "add_action_test.jpg") };
|
|
568
|
+
const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
|
|
569
|
+
builder.sign(signer, source, dest);
|
|
570
|
+
// Verify the action was added
|
|
571
|
+
const reader = yield Reader.fromAsset(dest);
|
|
572
|
+
expect(reader).not.toBeNull();
|
|
573
|
+
const activeManifest = reader.getActive();
|
|
574
|
+
const actionsAssertion = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((a) => a.label === "c2pa.actions.v2");
|
|
575
|
+
expect(actionsAssertion).toBeDefined();
|
|
576
|
+
if (isActionsAssertion(actionsAssertion)) {
|
|
577
|
+
const actions = actionsAssertion.data.actions;
|
|
578
|
+
const editedAction = actions.find((a) => a.action === "c2pa.edited");
|
|
579
|
+
expect(editedAction).toBeDefined();
|
|
580
|
+
expect(editedAction === null || editedAction === void 0 ? void 0 : editedAction.action).toBe("c2pa.edited");
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
throw new Error("Actions assertion does not have the expected structure");
|
|
584
|
+
}
|
|
585
|
+
}));
|
|
586
|
+
it("should add ingredient using addIngredient method", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
587
|
+
var _a, _b;
|
|
588
|
+
const simpleManifestDefinition = {
|
|
589
|
+
claim_generator_info: [
|
|
590
|
+
{
|
|
591
|
+
name: "c2pa_test",
|
|
592
|
+
version: "1.0.0",
|
|
593
|
+
},
|
|
594
|
+
],
|
|
595
|
+
title: "Test_AddIngredient",
|
|
596
|
+
format: "image/jpeg",
|
|
597
|
+
ingredients: [],
|
|
598
|
+
assertions: [
|
|
599
|
+
{
|
|
600
|
+
label: "c2pa.actions",
|
|
601
|
+
data: {
|
|
602
|
+
actions: [
|
|
603
|
+
{
|
|
604
|
+
action: "c2pa.created",
|
|
605
|
+
digitalSourceType: "http://c2pa.org/digitalsourcetype/empty",
|
|
606
|
+
},
|
|
607
|
+
],
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
resources: { resources: {} },
|
|
612
|
+
};
|
|
613
|
+
const builder = Builder.withJson(simpleManifestDefinition);
|
|
614
|
+
// Add an ingredient using addIngredient method
|
|
615
|
+
const ingredientJson = JSON.stringify({
|
|
616
|
+
title: "Test Ingredient via addIngredient",
|
|
617
|
+
format: "image/jpeg",
|
|
618
|
+
instance_id: "ingredient-12345",
|
|
619
|
+
relationship: "componentOf",
|
|
620
|
+
});
|
|
621
|
+
builder.addIngredient(ingredientJson);
|
|
622
|
+
// Sign the manifest
|
|
623
|
+
const dest = { path: path.join(tempDir, "add_ingredient_test.jpg") };
|
|
624
|
+
const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
|
|
625
|
+
builder.sign(signer, source, dest);
|
|
626
|
+
// Verify the ingredient was added
|
|
627
|
+
const reader = yield Reader.fromAsset(dest);
|
|
628
|
+
expect(reader).not.toBeNull();
|
|
629
|
+
const activeManifest = reader.getActive();
|
|
630
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients).toBeDefined();
|
|
631
|
+
expect((_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients) === null || _a === void 0 ? void 0 : _a.length).toBeGreaterThan(0);
|
|
632
|
+
const addedIngredient = (_b = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients) === null || _b === void 0 ? void 0 : _b.find((ing) => ing.title === "Test Ingredient via addIngredient");
|
|
633
|
+
expect(addedIngredient).toBeDefined();
|
|
634
|
+
expect(addedIngredient === null || addedIngredient === void 0 ? void 0 : addedIngredient.instance_id).toBe("ingredient-12345");
|
|
635
|
+
expect(addedIngredient === null || addedIngredient === void 0 ? void 0 : addedIngredient.relationship).toBe("componentOf");
|
|
636
|
+
}));
|
|
392
637
|
});
|
|
393
638
|
});
|
|
@@ -143,10 +143,9 @@ describe("IdentityAssertionBuilder", () => {
|
|
|
143
143
|
// Sign the manifest (standard async flow)
|
|
144
144
|
yield builder.signAsync(iaSigner, source, dest);
|
|
145
145
|
// Verify the manifest
|
|
146
|
-
|
|
146
|
+
yield Reader.fromAsset({
|
|
147
147
|
buffer: dest.buffer,
|
|
148
148
|
mimeType: "image/jpeg",
|
|
149
149
|
});
|
|
150
|
-
yield reader.postValidateCawg();
|
|
151
150
|
}));
|
|
152
151
|
});
|
package/dist/Reader.js
CHANGED
|
@@ -34,7 +34,7 @@ export class Reader {
|
|
|
34
34
|
static fromAsset(asset) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
const reader = yield getNeonBinary().readerFromAsset(asset);
|
|
37
|
-
return new Reader(reader);
|
|
37
|
+
return reader ? new Reader(reader) : null;
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
static fromManifestDataAndAsset(manifestData, asset) {
|
|
@@ -57,9 +57,4 @@ export class Reader {
|
|
|
57
57
|
}
|
|
58
58
|
return manifestStore.manifests[activeManifest];
|
|
59
59
|
}
|
|
60
|
-
postValidateCawg() {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
return getNeonBinary().readerPostValidateCawg.call(this.reader);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
60
|
}
|
package/dist/Reader.spec.js
CHANGED
|
@@ -18,23 +18,26 @@ import { Reader } from "./Reader.js";
|
|
|
18
18
|
const tempDir = path.join(__dirname, "tmp");
|
|
19
19
|
describe("Reader", () => {
|
|
20
20
|
const manifestStore = JSON.parse(`{
|
|
21
|
-
"active_manifest": "contentauth:urn:uuid:
|
|
21
|
+
"active_manifest": "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf",
|
|
22
22
|
"manifests": {
|
|
23
|
-
"contentauth:urn:uuid:
|
|
24
|
-
"claim_generator": "make_test_images/0.
|
|
23
|
+
"contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf": {
|
|
24
|
+
"claim_generator": "make_test_images/0.33.1 c2pa-rs/0.33.1",
|
|
25
25
|
"claim_generator_info": [
|
|
26
26
|
{
|
|
27
27
|
"name": "make_test_images",
|
|
28
|
-
"version": "0.
|
|
29
|
-
|
|
28
|
+
"version": "0.33.1"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "c2pa-rs",
|
|
32
|
+
"version": "0.33.1"
|
|
30
33
|
}
|
|
31
34
|
],
|
|
32
|
-
"title": "
|
|
35
|
+
"title": "CA.jpg",
|
|
33
36
|
"format": "image/jpeg",
|
|
34
|
-
"instance_id": "xmp:iid:
|
|
37
|
+
"instance_id": "xmp:iid:ba572347-db0e-4619-b6eb-d38e487da238",
|
|
35
38
|
"thumbnail": {
|
|
36
39
|
"format": "image/jpeg",
|
|
37
|
-
"identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:
|
|
40
|
+
"identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf/c2pa.assertions/c2pa.thumbnail.claim.jpeg"
|
|
38
41
|
},
|
|
39
42
|
"ingredients": [
|
|
40
43
|
{
|
|
@@ -48,18 +51,6 @@ describe("Reader", () => {
|
|
|
48
51
|
},
|
|
49
52
|
"relationship": "parentOf",
|
|
50
53
|
"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
54
|
}
|
|
64
55
|
],
|
|
65
56
|
"assertions": [
|
|
@@ -84,15 +75,10 @@ describe("Reader", () => {
|
|
|
84
75
|
{
|
|
85
76
|
"action": "c2pa.opened",
|
|
86
77
|
"parameters": {
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
"url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
|
|
93
|
-
"hash": "tTBD4/E0R0AjLUdJFpsVz3lE/KJUq22Vz0UGqzhEpVs="
|
|
94
|
-
}
|
|
95
|
-
]
|
|
78
|
+
"ingredient": {
|
|
79
|
+
"url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
|
|
80
|
+
"hash": "5dNlxTKe4afGAicpJa1hF1R3mBZKE+Bl0xmh0McXuO4="
|
|
81
|
+
}
|
|
96
82
|
}
|
|
97
83
|
},
|
|
98
84
|
{
|
|
@@ -100,23 +86,6 @@ describe("Reader", () => {
|
|
|
100
86
|
"parameters": {
|
|
101
87
|
"name": "brightnesscontrast"
|
|
102
88
|
}
|
|
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
89
|
}
|
|
121
90
|
]
|
|
122
91
|
}
|
|
@@ -127,9 +96,9 @@ describe("Reader", () => {
|
|
|
127
96
|
"issuer": "C2PA Test Signing Cert",
|
|
128
97
|
"common_name": "C2PA Signer",
|
|
129
98
|
"cert_serial_number": "720724073027128164015125666832722375746636448153",
|
|
130
|
-
"time": "
|
|
99
|
+
"time": "2024-08-06T21:53:37+00:00"
|
|
131
100
|
},
|
|
132
|
-
"label": "contentauth:urn:uuid:
|
|
101
|
+
"label": "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf"
|
|
133
102
|
}
|
|
134
103
|
}
|
|
135
104
|
}`);
|
|
@@ -140,26 +109,34 @@ describe("Reader", () => {
|
|
|
140
109
|
yield fs.remove(tempDir);
|
|
141
110
|
}));
|
|
142
111
|
it("should read from an ArrayBuffer", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
-
const buffer = yield fs.readFile("./tests/fixtures/
|
|
112
|
+
const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
|
|
144
113
|
const reader = yield Reader.fromAsset({
|
|
145
114
|
buffer,
|
|
146
115
|
mimeType: "jpeg",
|
|
147
116
|
});
|
|
117
|
+
expect(reader).not.toBeNull();
|
|
148
118
|
const json = reader.json();
|
|
149
119
|
expect(json.manifests).toEqual(manifestStore.manifests);
|
|
150
120
|
expect(json.active_manifest).toEqual(manifestStore.active_manifest);
|
|
151
121
|
}));
|
|
152
122
|
it("should read from a file", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
123
|
const reader = yield Reader.fromAsset({
|
|
154
|
-
path: "./tests/fixtures/
|
|
124
|
+
path: "./tests/fixtures/CA.jpg",
|
|
155
125
|
});
|
|
126
|
+
expect(reader).not.toBeNull();
|
|
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
|
}));
|
|
131
|
+
it("should return null for a file without C2PA data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
const reader = yield Reader.fromAsset({
|
|
133
|
+
path: "./tests/fixtures/A.jpg",
|
|
134
|
+
});
|
|
135
|
+
expect(reader).toBeNull();
|
|
136
|
+
}));
|
|
160
137
|
it("should read from manifest data and buffer", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
-
const manifestData = yield fs.readFile("./tests/fixtures/
|
|
162
|
-
const buffer = yield fs.readFile("./tests/fixtures/
|
|
138
|
+
const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
|
|
139
|
+
const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
|
|
163
140
|
const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
|
|
164
141
|
buffer,
|
|
165
142
|
mimeType: "jpeg",
|
|
@@ -169,9 +146,9 @@ describe("Reader", () => {
|
|
|
169
146
|
expect(json.active_manifest).toEqual(manifestStore.active_manifest);
|
|
170
147
|
}));
|
|
171
148
|
it("should read from manifest data and file", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
172
|
-
const manifestData = yield fs.readFile("./tests/fixtures/
|
|
149
|
+
const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
|
|
173
150
|
const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
|
|
174
|
-
path: "./tests/fixtures/
|
|
151
|
+
path: "./tests/fixtures/CA.jpg",
|
|
175
152
|
});
|
|
176
153
|
const json = reader.json();
|
|
177
154
|
expect(json.manifests).toEqual(manifestStore.manifests);
|
|
@@ -181,8 +158,9 @@ describe("Reader", () => {
|
|
|
181
158
|
let bytesWritten = 0;
|
|
182
159
|
const outputPath = path.join(tempDir, "thumbnail.jpg");
|
|
183
160
|
const reader = yield Reader.fromAsset({
|
|
184
|
-
path: "./tests/fixtures/
|
|
161
|
+
path: "./tests/fixtures/CA.jpg",
|
|
185
162
|
});
|
|
163
|
+
expect(reader).not.toBeNull();
|
|
186
164
|
const activeManifest = reader.getActive();
|
|
187
165
|
const uri = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.thumbnail) === null || _a === void 0 ? void 0 : _a.identifier;
|
|
188
166
|
if (uri !== undefined) {
|
|
@@ -190,13 +168,14 @@ describe("Reader", () => {
|
|
|
190
168
|
path: outputPath,
|
|
191
169
|
});
|
|
192
170
|
}
|
|
193
|
-
expect(bytesWritten).toBe(
|
|
171
|
+
expect(bytesWritten).toBe(49690);
|
|
194
172
|
expect(fs.existsSync(outputPath));
|
|
195
173
|
}));
|
|
196
174
|
it("should report manifest is embedded", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
175
|
const reader = yield Reader.fromAsset({
|
|
198
|
-
path: "./tests/fixtures/
|
|
176
|
+
path: "./tests/fixtures/CA.jpg",
|
|
199
177
|
});
|
|
178
|
+
expect(reader).not.toBeNull();
|
|
200
179
|
expect(reader.remoteUrl()).toEqual("");
|
|
201
180
|
expect(reader.isEmbedded()).toBeTruthy();
|
|
202
181
|
}));
|
|
@@ -204,7 +183,55 @@ describe("Reader", () => {
|
|
|
204
183
|
const reader = yield Reader.fromAsset({
|
|
205
184
|
path: "./tests/fixtures/cloud.jpg",
|
|
206
185
|
});
|
|
186
|
+
expect(reader).not.toBeNull();
|
|
207
187
|
expect(reader.remoteUrl()).toEqual("https://cai-manifests.adobe.com/manifests/adobe-urn-uuid-5f37e182-3687-462e-a7fb-573462780391");
|
|
208
188
|
expect(reader.isEmbedded()).toBeFalsy();
|
|
209
189
|
}));
|
|
190
|
+
it("should decode CAWG identity assertion with signature_info", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
+
var _a;
|
|
192
|
+
// This test verifies that postValidateCawg() properly decodes CAWG assertions
|
|
193
|
+
// and extracts signature_info from the signature data, matching c2pa-js behavior
|
|
194
|
+
const reader = yield Reader.fromAsset({
|
|
195
|
+
path: "./tests/fixtures/C_with_CAWG_data.jpg",
|
|
196
|
+
});
|
|
197
|
+
expect(reader).not.toBeNull();
|
|
198
|
+
const activeManifest = reader.getActive();
|
|
199
|
+
// Find the cawg.identity assertion
|
|
200
|
+
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");
|
|
201
|
+
expect(cawgIdentityAssertion).toBeDefined();
|
|
202
|
+
expect(cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data).toBeDefined();
|
|
203
|
+
expect(cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signature_info).toBeDefined();
|
|
204
|
+
// Verify signature_info structure matches c2pa-js behavior
|
|
205
|
+
const signatureInfo = cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signature_info;
|
|
206
|
+
const signerPayload = cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signer_payload;
|
|
207
|
+
// Verify signature_info values
|
|
208
|
+
expect(signatureInfo.alg).toBe("Ed25519");
|
|
209
|
+
expect(signatureInfo.issuer).toBe("C2PA Test Signing Cert");
|
|
210
|
+
expect(signatureInfo.cert_serial_number).toBe("638838410810235485828984295321338730070538954823");
|
|
211
|
+
expect(signatureInfo.revocation_status).toBe(true);
|
|
212
|
+
// Verify signer_payload values
|
|
213
|
+
expect(signerPayload.sig_type).toBe("cawg.x509.cose");
|
|
214
|
+
expect(signerPayload.referenced_assertions).toHaveLength(2);
|
|
215
|
+
expect(signerPayload.referenced_assertions[0]).toEqual({
|
|
216
|
+
url: "self#jumbf=c2pa.assertions/cawg.training-mining",
|
|
217
|
+
hash: "rBBgURB+/0Bc2Uk3+blNpYTGQTxOwzXQ2xhjA3gsqI4=",
|
|
218
|
+
});
|
|
219
|
+
expect(signerPayload.referenced_assertions[1]).toEqual({
|
|
220
|
+
url: "self#jumbf=c2pa.assertions/c2pa.hash.data",
|
|
221
|
+
hash: "sASozh9KFSkW+cyMI0Pw5KYoD2qn7MkUEq9jUUhe/sM=",
|
|
222
|
+
});
|
|
223
|
+
}));
|
|
224
|
+
it("should return null when reading an asset without C2PA metadata", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
225
|
+
// Create a simple JPEG without C2PA data
|
|
226
|
+
const simpleJpeg = Buffer.from([
|
|
227
|
+
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
|
|
228
|
+
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xd9,
|
|
229
|
+
]);
|
|
230
|
+
const asset = {
|
|
231
|
+
buffer: simpleJpeg,
|
|
232
|
+
mimeType: "image/jpeg",
|
|
233
|
+
};
|
|
234
|
+
const reader = yield Reader.fromAsset(asset);
|
|
235
|
+
expect(reader).toBeNull();
|
|
236
|
+
}));
|
|
210
237
|
});
|