@contentauth/c2pa-node 0.3.0 → 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.
@@ -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,97 @@ 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
+ }));
535
637
  });
536
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
- 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,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
  }
@@ -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
  });
@@ -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
@@ -8,9 +8,10 @@ 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>;
14
15
  toArchive(asset: DestinationAsset): Promise<void>;
15
16
  static fromArchive(asset: SourceAsset): Promise<Builder>;
16
17
  sign(signer: LocalSignerInterface, input: SourceAsset, output: DestinationAsset): Buffer;
@@ -7,9 +7,8 @@ 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>;
15
14
  }
@@ -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;
@@ -176,17 +176,37 @@ export interface HashedUri {
176
176
  }
177
177
 
178
178
  export interface BuilderInterface {
179
+ /** An intent lets the API know what kind of manifest to create.
180
+ * Intents are `Create`, `Edit`, or `Update`.
181
+ * This allows the API to check that you are doing the right thing.
182
+ * It can also do things for you, like add parent ingredients from the source asset
183
+ * and automatically add required c2pa.created or c2pa.opened actions.
184
+ * Create requires a `DigitalSourceType`. It is used for assets without a parent ingredient.
185
+ * Edit requires a parent ingredient and is used for most assets that are being edited.
186
+ * Update is a special case with many restrictions but is more compact than Edit.
187
+ * @param intent The intent of the manifest
188
+ */
179
189
  setIntent(intent: BuilderIntent): void;
190
+
180
191
  /**
181
192
  * Set the no embed flag of the manifest
182
193
  * @param noEmbed The no embed flag of the manifest
183
194
  */
184
195
  setNoEmbed(noEmbed: boolean): void;
196
+
185
197
  /**
186
198
  * Set the remote URL of the manifest
187
199
  * @param url The remote URL of the manifest
188
200
  */
189
201
  setRemoteUrl(url: string): void;
202
+
203
+ /**
204
+ * Add a single action to the manifest.
205
+ * This is a convenience method for adding an action to the `Actions` assertion.
206
+ * @param actionJson The JSON representation of the action
207
+ */
208
+ addAction(actionJson: string): void;
209
+
190
210
  /**
191
211
  * Add CBOR assertion to the builder
192
212
  * @param label The label of the assertion
@@ -206,11 +226,14 @@ export interface BuilderInterface {
206
226
  addResource(uri: string, resource: SourceAsset): Promise<void>;
207
227
 
208
228
  /**
209
- * Add an ingredient from a buffer or file
229
+ * Add an ingredient to the manifest
210
230
  * @param ingredientJson The JSON representation of the ingredient
211
- * @param ingredient The source and format of the ingredient
231
+ * @param ingredient Optional source asset (buffer or file) for the ingredient
212
232
  */
213
- addIngredient(ingredientJson: string, ingredient: SourceAsset): Promise<void>;
233
+ addIngredient(
234
+ ingredientJson: string,
235
+ ingredient?: SourceAsset,
236
+ ): Promise<void>;
214
237
 
215
238
  /**
216
239
  * Convert the Builder into a archive formatted buffer or file
@@ -309,11 +332,6 @@ export interface ReaderInterface {
309
332
  * @param filePath The path to the file
310
333
  */
311
334
  resourceToAsset(uri: string, output: DestinationAsset): Promise<number>;
312
-
313
- /**
314
- * Run CAWG validation
315
- */
316
- postValidateCawg(): Promise<void>;
317
335
  }
318
336
 
319
337
  export interface IdentityAssertionSignerInterface {
@@ -408,8 +426,6 @@ export interface VerifyConfig {
408
426
  ocspFetch: boolean;
409
427
  /** Whether to fetch remote manifests */
410
428
  remoteManifestFetch: boolean;
411
- /** Whether to check ingredient trust */
412
- checkIngredientTrust: boolean;
413
429
  /** Whether to skip ingredient conflict resolution */
414
430
  skipIngredientConflictResolution: boolean;
415
431
  /** Whether to use strict v1 validation */
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.3.0",
7
+ "version": "0.4.0",
8
8
  "description": "Node.js bindings for C2PA",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",
@@ -68,7 +68,7 @@
68
68
  "scripts": {
69
69
  "build": "run-s build:rust build:ts",
70
70
  "build:debug": "run-s build:rust-debug build:ts",
71
- "build:docs": "rimraf docs && typedoc --plugin typedoc-plugin-markdown --readme none --out docs js-src/index.ts",
71
+ "build:docs": "rimraf docs-typedoc && typedoc --plugin typedoc-plugin-markdown --readme README.md --out docs-typedoc js-src/index.ts && cpy \"docs-typedoc/**\" docs --parents --overwrite --ignore=\"docs-typedoc/classes/index.md\" --ignore=\"docs-typedoc/README.md\" && rimraf docs-typedoc",
72
72
  "build:rust": "pnpm run build:rust-debug --release",
73
73
  "build:rust-debug": "cargo build --message-format=json-render-diagnostics > cargo.log",
74
74
  "build:ts": "tsc -b && cpy index.node dist && cpy index.node js-src && cpy --flat js-src/types.d.ts dist/types",
package/src/lib.rs CHANGED
@@ -38,6 +38,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
38
38
  "builderSetRemoteUrl",
39
39
  neon_builder::NeonBuilder::set_remote_url,
40
40
  )?;
41
+ cx.export_function("builderAddAction", neon_builder::NeonBuilder::add_action)?;
41
42
  cx.export_function(
42
43
  "builderAddAssertion",
43
44
  neon_builder::NeonBuilder::add_assertion,
@@ -50,6 +51,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
50
51
  "builderAddIngredient",
51
52
  neon_builder::NeonBuilder::add_ingredient,
52
53
  )?;
54
+ cx.export_function(
55
+ "builderAddIngredientFromAsset",
56
+ neon_builder::NeonBuilder::add_ingredient_from_asset,
57
+ )?;
53
58
  cx.export_function("builderToArchive", neon_builder::NeonBuilder::to_archive)?;
54
59
  cx.export_function(
55
60
  "builderFromArchive",
@@ -92,10 +97,6 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
92
97
  "readerResourceToAsset",
93
98
  neon_reader::NeonReader::resource_to_asset,
94
99
  )?;
95
- cx.export_function(
96
- "readerPostValidateCawg",
97
- neon_reader::NeonReader::post_validate_cawg,
98
- )?;
99
100
 
100
101
  // Signers
101
102
  cx.export_function("localSignerNew", neon_signer::NeonLocalSigner::new)?;
@@ -186,5 +187,8 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
186
187
  cx.export_function("loadVerifyConfig", settings::load_verify_config)?;
187
188
  cx.export_function("getVerifyConfig", settings::get_verify_config)?;
188
189
 
190
+ // Reset Settings
191
+ cx.export_function("resetSettings", settings::reset_settings)?;
192
+
189
193
  Ok(())
190
194
  }