@contentauth/c2pa-node 0.3.0 → 0.4.1

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.
@@ -177,6 +177,7 @@ 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
183
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
@@ -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,6 +227,7 @@ 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
233
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
@@ -246,6 +249,7 @@ 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
255
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
@@ -270,6 +274,7 @@ 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
280
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
@@ -295,6 +300,7 @@ 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
306
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
@@ -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,6 +392,7 @@ 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");
@@ -393,6 +401,7 @@ describe("Builder", () => {
393
401
  // This test mirrors the Rust test_redaction_async test
394
402
  // Create a reader to get the parent manifest label from the existing source
395
403
  const reader = yield Reader.fromAsset(source);
404
+ expect(reader).not.toBeNull();
396
405
  const parentManifestLabel = reader.activeLabel();
397
406
  expect(parentManifestLabel).toBeDefined();
398
407
  // Create a redacted URI for the assertion we are going to redact
@@ -450,6 +459,7 @@ describe("Builder", () => {
450
459
  buffer: dest.buffer,
451
460
  mimeType: "image/jpeg",
452
461
  });
462
+ expect(signedReader).not.toBeNull();
453
463
  expect(signedReader).toBeDefined();
454
464
  // Check that the manifest was created successfully
455
465
  const activeManifest = signedReader.getActive();
@@ -532,5 +542,135 @@ describe("Builder", () => {
532
542
  expect(activeManifest).toBeDefined();
533
543
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
534
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
+ }));
637
+ it("should add ingredient from reader", () => __awaiter(void 0, void 0, void 0, function* () {
638
+ var _a;
639
+ const builder1 = Builder.new();
640
+ builder1.setIntent("edit");
641
+ const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
642
+ const dest1 = {
643
+ buffer: null,
644
+ };
645
+ builder1.sign(signer, source, dest1);
646
+ // Read the signed file back with Reader
647
+ const reader = yield Reader.fromAsset({
648
+ buffer: dest1.buffer,
649
+ mimeType: "image/jpeg",
650
+ });
651
+ expect(reader).not.toBeNull();
652
+ // Create a new builder and add ingredient from the reader
653
+ const builder2 = Builder.new();
654
+ const ingredient = builder2.addIngredientFromReader(reader);
655
+ expect(ingredient).toBeDefined();
656
+ // Verify the ingredient was added to the builder
657
+ const definition = builder2.getManifestDefinition();
658
+ expect(definition.ingredients).toBeDefined();
659
+ expect(definition.ingredients.length).toBeGreaterThan(0);
660
+ // Sign again with the new builder
661
+ const dest2 = {
662
+ buffer: null,
663
+ };
664
+ builder2.sign(signer, source, dest2);
665
+ // Verify the ingredient is in the signed manifest
666
+ const reader2 = yield Reader.fromAsset({
667
+ buffer: dest2.buffer,
668
+ mimeType: "image/jpeg",
669
+ });
670
+ expect(reader2).not.toBeNull();
671
+ const activeManifest = reader2.getActive();
672
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients).toBeDefined();
673
+ expect((_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
674
+ }));
535
675
  });
536
676
  });
@@ -25,7 +25,7 @@ export class IdentityAssertionBuilder {
25
25
  }
26
26
  static identityBuilderForCredentialHolder(credentialHolder) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- const builder = getNeonBinary().identityBuilderForCredentialHolder(credentialHolder.signer());
28
+ const builder = getNeonBinary().identityBuilderForCredentialHolder(credentialHolder.getHandle());
29
29
  return new IdentityAssertionBuilder(builder);
30
30
  });
31
31
  }
@@ -50,7 +50,7 @@ export class IdentityAssertionSigner {
50
50
  addIdentityAssertion(identityAssertionBuilder) {
51
51
  getNeonBinary().identitySignerAddIdentityAssertion.call(this._signer, identityAssertionBuilder.builder());
52
52
  }
53
- signer() {
53
+ getHandle() {
54
54
  return this._signer;
55
55
  }
56
56
  }
@@ -58,7 +58,7 @@ export class CallbackCredentialHolder {
58
58
  constructor(callbackCredentialHolder) {
59
59
  this.callbackCredentialHolder = callbackCredentialHolder;
60
60
  }
61
- signer() {
61
+ getHandle() {
62
62
  return this.callbackCredentialHolder;
63
63
  }
64
64
  static newCallbackCredentialHolder(reserveSize, sigType, callback) {
@@ -136,17 +136,16 @@ describe("IdentityAssertionBuilder", () => {
136
136
  buffer: yield fs.readFile("./tests/fixtures/thumbnail.jpg"),
137
137
  });
138
138
  // Create and configure the identity assertion
139
- const iaSigner = IdentityAssertionSigner.new(c2paSigner.signer());
139
+ const iaSigner = IdentityAssertionSigner.new(c2paSigner.getHandle());
140
140
  const iab = yield IdentityAssertionBuilder.identityBuilderForCredentialHolder(cawgSigner);
141
141
  iab.addReferencedAssertions(["cawg.training-mining"]);
142
142
  iaSigner.addIdentityAssertion(iab);
143
143
  // Sign the manifest (standard async flow)
144
144
  yield builder.signAsync(iaSigner, source, dest);
145
145
  // Verify the manifest
146
- const reader = yield Reader.fromAsset({
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,7 @@ 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
- });
60
+ getHandle() {
61
+ return this.reader;
64
62
  }
65
63
  }
@@ -15,7 +15,6 @@ 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";
19
18
  const tempDir = path.join(__dirname, "tmp");
20
19
  describe("Reader", () => {
21
20
  const manifestStore = JSON.parse(`{
@@ -104,7 +103,6 @@ describe("Reader", () => {
104
103
  }
105
104
  }`);
106
105
  beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
107
- patchVerifyConfig({ verifyTrust: false });
108
106
  yield fs.ensureDir(tempDir);
109
107
  }));
110
108
  afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -116,6 +114,7 @@ describe("Reader", () => {
116
114
  buffer,
117
115
  mimeType: "jpeg",
118
116
  });
117
+ expect(reader).not.toBeNull();
119
118
  const json = reader.json();
120
119
  expect(json.manifests).toEqual(manifestStore.manifests);
121
120
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
@@ -124,10 +123,17 @@ describe("Reader", () => {
124
123
  const reader = yield Reader.fromAsset({
125
124
  path: "./tests/fixtures/CA.jpg",
126
125
  });
126
+ expect(reader).not.toBeNull();
127
127
  const json = reader.json();
128
128
  expect(json.manifests).toEqual(manifestStore.manifests);
129
129
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
130
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
+ }));
131
137
  it("should read from manifest data and buffer", () => __awaiter(void 0, void 0, void 0, function* () {
132
138
  const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
133
139
  const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
@@ -154,6 +160,7 @@ describe("Reader", () => {
154
160
  const reader = yield Reader.fromAsset({
155
161
  path: "./tests/fixtures/CA.jpg",
156
162
  });
163
+ expect(reader).not.toBeNull();
157
164
  const activeManifest = reader.getActive();
158
165
  const uri = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.thumbnail) === null || _a === void 0 ? void 0 : _a.identifier;
159
166
  if (uri !== undefined) {
@@ -168,6 +175,7 @@ describe("Reader", () => {
168
175
  const reader = yield Reader.fromAsset({
169
176
  path: "./tests/fixtures/CA.jpg",
170
177
  });
178
+ expect(reader).not.toBeNull();
171
179
  expect(reader.remoteUrl()).toEqual("");
172
180
  expect(reader.isEmbedded()).toBeTruthy();
173
181
  }));
@@ -175,6 +183,7 @@ describe("Reader", () => {
175
183
  const reader = yield Reader.fromAsset({
176
184
  path: "./tests/fixtures/cloud.jpg",
177
185
  });
186
+ expect(reader).not.toBeNull();
178
187
  expect(reader.remoteUrl()).toEqual("https://cai-manifests.adobe.com/manifests/adobe-urn-uuid-5f37e182-3687-462e-a7fb-573462780391");
179
188
  expect(reader.isEmbedded()).toBeFalsy();
180
189
  }));
@@ -185,8 +194,7 @@ describe("Reader", () => {
185
194
  const reader = yield Reader.fromAsset({
186
195
  path: "./tests/fixtures/C_with_CAWG_data.jpg",
187
196
  });
188
- // Call postValidateCawg to decode CAWG assertions
189
- yield reader.postValidateCawg();
197
+ expect(reader).not.toBeNull();
190
198
  const activeManifest = reader.getActive();
191
199
  // Find the cawg.identity assertion
192
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");
@@ -213,4 +221,17 @@ describe("Reader", () => {
213
221
  hash: "sASozh9KFSkW+cyMI0Pw5KYoD2qn7MkUEq9jUUhe/sM=",
214
222
  });
215
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
+ }));
216
237
  });
package/dist/Settings.js CHANGED
@@ -166,7 +166,6 @@ export function loadVerifyConfig(verifyConfig) {
166
166
  verify_timestamp_trust: verifyConfig.verifyTimestampTrust,
167
167
  ocsp_fetch: verifyConfig.ocspFetch,
168
168
  remote_manifest_fetch: verifyConfig.remoteManifestFetch,
169
- check_ingredient_trust: verifyConfig.checkIngredientTrust,
170
169
  skip_ingredient_conflict_resolution: verifyConfig.skipIngredientConflictResolution,
171
170
  strict_v1_validation: verifyConfig.strictV1Validation,
172
171
  };
@@ -196,8 +195,14 @@ export function getVerifyConfig() {
196
195
  verifyTimestampTrust: parsed.verify_timestamp_trust,
197
196
  ocspFetch: parsed.ocsp_fetch,
198
197
  remoteManifestFetch: parsed.remote_manifest_fetch,
199
- checkIngredientTrust: parsed.check_ingredient_trust,
200
198
  skipIngredientConflictResolution: parsed.skip_ingredient_conflict_resolution,
201
199
  strictV1Validation: parsed.strict_v1_validation,
202
200
  };
203
201
  }
202
+ /**
203
+ * Reset settings to their default values.
204
+ * This clears any custom settings and restores the default configuration.
205
+ */
206
+ export function resetSettings() {
207
+ getNeonBinary().resetSettings();
208
+ }
@@ -3,8 +3,11 @@
3
3
  // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
4
  // or the MIT license (http://opensource.org/licenses/MIT),
5
5
  // at your option.
6
- import { loadC2paSettings, loadTrustConfig, loadCawgTrustConfig, getSettingsJson, getTrustConfig, getCawgTrustConfig, loadVerifyConfig, getVerifyConfig, patchVerifyConfig, } from "./Settings.js";
6
+ import { getCawgTrustConfig, getSettingsJson, getTrustConfig, getVerifyConfig, loadC2paSettings, loadCawgTrustConfig, loadTrustConfig, loadVerifyConfig, patchVerifyConfig, resetSettings, } from "./Settings.js";
7
7
  describe("Settings", () => {
8
+ afterAll(() => {
9
+ resetSettings();
10
+ });
8
11
  it("loads a trustlist-shaped JSON and returns JSON via getSettingsJson", () => {
9
12
  var _a, _b;
10
13
  // Matches c2pa-rs settings structure: trust + verify
@@ -98,7 +101,7 @@ describe("Settings", () => {
98
101
  expect(() => loadTrustConfig(emptyTrustConfig)).not.toThrow();
99
102
  // Verify settings are still intact
100
103
  const currentSettings = JSON.parse(getSettingsJson());
101
- expect(currentSettings.core.merkle_tree_max_proofs).toBe(5);
104
+ expect(currentSettings.core.decode_identity_assertions).toBe(true);
102
105
  expect(currentSettings.verify.verify_trust).toBe(true);
103
106
  expect(currentSettings.trust.verify_trust_list).toBe(true);
104
107
  });
@@ -178,7 +181,6 @@ describe("Settings", () => {
178
181
  verifyTimestampTrust: true,
179
182
  ocspFetch: false,
180
183
  remoteManifestFetch: true, // This should not affect trust settings
181
- checkIngredientTrust: false,
182
184
  skipIngredientConflictResolution: true,
183
185
  strictV1Validation: false,
184
186
  };
@@ -198,7 +200,6 @@ describe("Settings", () => {
198
200
  expect(finalSettings.verify.verify_timestamp_trust).toBe(true);
199
201
  expect(finalSettings.verify.ocsp_fetch).toBe(false);
200
202
  expect(finalSettings.verify.remote_manifest_fetch).toBe(true);
201
- expect(finalSettings.verify.check_ingredient_trust).toBe(false);
202
203
  expect(finalSettings.verify.skip_ingredient_conflict_resolution).toBe(true);
203
204
  expect(finalSettings.verify.strict_v1_validation).toBe(false);
204
205
  // Verify that trust settings are not affected by verify settings
@@ -217,7 +218,6 @@ describe("Settings", () => {
217
218
  verifyTimestampTrust: false,
218
219
  ocspFetch: true,
219
220
  remoteManifestFetch: false,
220
- checkIngredientTrust: true,
221
221
  skipIngredientConflictResolution: false,
222
222
  strictV1Validation: true,
223
223
  };
@@ -244,7 +244,6 @@ describe("Settings", () => {
244
244
  verifyTimestampTrust: true,
245
245
  ocspFetch: false,
246
246
  remoteManifestFetch: true,
247
- checkIngredientTrust: false,
248
247
  skipIngredientConflictResolution: true,
249
248
  strictV1Validation: false,
250
249
  };
@@ -258,7 +257,6 @@ describe("Settings", () => {
258
257
  expect(finalSettings.verify.verify_timestamp_trust).toBe(true);
259
258
  expect(finalSettings.verify.ocsp_fetch).toBe(false);
260
259
  expect(finalSettings.verify.remote_manifest_fetch).toBe(true);
261
- expect(finalSettings.verify.check_ingredient_trust).toBe(false);
262
260
  expect(finalSettings.verify.skip_ingredient_conflict_resolution).toBe(true);
263
261
  expect(finalSettings.verify.strict_v1_validation).toBe(false);
264
262
  });
@@ -271,7 +269,6 @@ describe("Settings", () => {
271
269
  verifyTimestampTrust: true,
272
270
  ocspFetch: false,
273
271
  remoteManifestFetch: true,
274
- checkIngredientTrust: true,
275
272
  skipIngredientConflictResolution: false,
276
273
  strictV1Validation: false,
277
274
  };
@@ -294,7 +291,6 @@ describe("Settings", () => {
294
291
  expect(patchedRetrievedConfig.verifyTimestampTrust).toBe(true); // unchanged
295
292
  expect(patchedRetrievedConfig.ocspFetch).toBe(true); // patched
296
293
  expect(patchedRetrievedConfig.remoteManifestFetch).toBe(true); // unchanged
297
- expect(patchedRetrievedConfig.checkIngredientTrust).toBe(true); // unchanged
298
294
  expect(patchedRetrievedConfig.skipIngredientConflictResolution).toBe(false); // unchanged
299
295
  expect(patchedRetrievedConfig.strictV1Validation).toBe(true); // patched
300
296
  // Verify the changes are reflected in getSettingsJson()
@@ -307,7 +303,6 @@ describe("Settings", () => {
307
303
  expect(settings.verify.verify_after_sign).toBe(true);
308
304
  expect(settings.verify.verify_timestamp_trust).toBe(true);
309
305
  expect(settings.verify.remote_manifest_fetch).toBe(true);
310
- expect(settings.verify.check_ingredient_trust).toBe(true);
311
306
  expect(settings.verify.skip_ingredient_conflict_resolution).toBe(false);
312
307
  });
313
308
  });
package/dist/Signer.js CHANGED
@@ -42,7 +42,7 @@ export class LocalSigner {
42
42
  timeAuthorityUrl() {
43
43
  return getNeonBinary().localSignerTimeAuthorityUrl.call(this.localSigner);
44
44
  }
45
- signer() {
45
+ getHandle() {
46
46
  return this.localSigner;
47
47
  }
48
48
  }
@@ -50,7 +50,7 @@ export class CallbackSigner {
50
50
  constructor(callbackSigner) {
51
51
  this.callbackSigner = callbackSigner;
52
52
  }
53
- signer() {
53
+ getHandle() {
54
54
  return this.callbackSigner;
55
55
  }
56
56
  static newSigner(config, callback) {
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
21
22
  import * as fs from "fs-extra";
22
23
  import * as crypto from "crypto";
23
24
  import { CallbackSigner } from "./Signer.js";
@@ -147,14 +148,13 @@ describe("CallbackSigner", () => {
147
148
  yield builder.signAsync(signer, source, dest);
148
149
  // Read the signed manifest back and verify signature is valid
149
150
  const reader = yield Reader.fromAsset({
150
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
151
151
  buffer: dest.buffer,
152
152
  mimeType: "image/jpeg",
153
153
  });
154
+ expect(reader).not.toBeNull();
154
155
  const manifestStore = reader.json();
155
156
  const activeManifest = reader.getActive();
156
157
  // If validation_status is undefined, the signature is valid
157
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
158
158
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
159
159
  expect(manifestStore.active_manifest).not.toBeUndefined();
160
160
  expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest_Buffer");
package/dist/index.node CHANGED
Binary file
@@ -1,5 +1,5 @@
1
- import type { BuilderIntent, Manifest } from "@contentauth/c2pa-types";
2
- import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, SourceAsset } from "./types.d.ts";
1
+ import type { BuilderIntent, Ingredient, Manifest } from "@contentauth/c2pa-types";
2
+ import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, ReaderInterface, SourceAsset } from "./types.d.ts";
3
3
  export declare class Builder implements BuilderInterface {
4
4
  private builder;
5
5
  private constructor();
@@ -8,9 +8,11 @@ export declare class Builder implements BuilderInterface {
8
8
  setIntent(intent: BuilderIntent): void;
9
9
  setNoEmbed(noEmbed?: boolean): void;
10
10
  setRemoteUrl(remoteUrl: string): void;
11
+ addAction(actionJson: string): void;
11
12
  addAssertion(label: string, assertion: unknown, assertionKind?: ManifestAssertionKind): void;
12
13
  addResource(uri: string, resource: SourceAsset): Promise<void>;
13
- addIngredient(ingredientJson: string, ingredient: SourceAsset): Promise<void>;
14
+ addIngredient(ingredientJson: string, ingredient?: SourceAsset): Promise<void>;
15
+ addIngredientFromReader(reader: ReaderInterface): Ingredient;
14
16
  toArchive(asset: DestinationAsset): Promise<void>;
15
17
  static fromArchive(asset: SourceAsset): Promise<Builder>;
16
18
  sign(signer: LocalSignerInterface, input: SourceAsset, output: DestinationAsset): Buffer;
@@ -12,12 +12,12 @@ export declare class IdentityAssertionSigner implements IdentityAssertionSignerI
12
12
  constructor(_signer: NeonIdentityAssertionSignerHandle);
13
13
  static new(signer: NeonCallbackSignerHandle): IdentityAssertionSigner;
14
14
  addIdentityAssertion(identityAssertionBuilder: IdentityAssertionBuilder): void;
15
- signer(): NeonIdentityAssertionSignerHandle;
15
+ getHandle(): NeonIdentityAssertionSignerHandle;
16
16
  }
17
17
  export declare class CallbackCredentialHolder implements CallbackCredentialHolderInterface {
18
18
  private callbackCredentialHolder;
19
19
  constructor(callbackCredentialHolder: NeonCallbackCredentialHolderHandle);
20
- signer(): NeonCallbackCredentialHolderHandle;
20
+ getHandle(): NeonCallbackCredentialHolderHandle;
21
21
  static newCallbackCredentialHolder(reserveSize: number, sigType: string, callback: (signerPayload: SignerPayload) => Promise<Buffer>): CallbackCredentialHolder;
22
22
  sign(payload: SignerPayload): Promise<Buffer>;
23
23
  reserveSize(): number;
@@ -7,9 +7,9 @@ export declare class Reader implements ReaderInterface {
7
7
  remoteUrl(): string;
8
8
  isEmbedded(): boolean;
9
9
  resourceToAsset(uri: string, asset: DestinationAsset): Promise<number>;
10
- static fromAsset(asset: SourceAsset): Promise<Reader>;
10
+ static fromAsset(asset: SourceAsset): Promise<Reader | null>;
11
11
  static fromManifestDataAndAsset(manifestData: Buffer, asset: SourceAsset): Promise<Reader>;
12
12
  activeLabel(): string | undefined;
13
13
  getActive(): Manifest | undefined;
14
- postValidateCawg(): Promise<void>;
14
+ getHandle(): NeonReaderHandle;
15
15
  }
@@ -61,3 +61,8 @@ export declare function patchVerifyConfig(patch: Partial<VerifyConfig>): void;
61
61
  * @returns The current verify configuration object
62
62
  */
63
63
  export declare function getVerifyConfig(): VerifyConfig;
64
+ /**
65
+ * Reset settings to their default values.
66
+ * This clears any custom settings and restores the default configuration.
67
+ */
68
+ export declare function resetSettings(): void;
@@ -8,12 +8,12 @@ export declare class LocalSigner implements LocalSignerInterface {
8
8
  certs(): Array<Buffer>;
9
9
  reserveSize(): number;
10
10
  timeAuthorityUrl(): string | undefined;
11
- signer(): NeonLocalSignerHandle;
11
+ getHandle(): NeonLocalSignerHandle;
12
12
  }
13
13
  export declare class CallbackSigner implements CallbackSignerInterface {
14
14
  private callbackSigner;
15
15
  constructor(callbackSigner: NeonCallbackSignerHandle);
16
- signer(): NeonCallbackSignerHandle;
16
+ getHandle(): NeonCallbackSignerHandle;
17
17
  static newSigner(config: JsCallbackSignerConfig, callback: (data: Buffer) => Promise<Buffer>): CallbackSigner;
18
18
  sign(data: Buffer): Promise<Buffer>;
19
19
  alg(): SigningAlg;