@contentauth/c2pa-node 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.lock CHANGED
@@ -495,9 +495,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
495
495
 
496
496
  [[package]]
497
497
  name = "c2pa"
498
- version = "0.77.0"
498
+ version = "0.78.4"
499
499
  source = "registry+https://github.com/rust-lang/crates.io-index"
500
- checksum = "fe6c3fcc525dcac6cde7d020cc4d3065b2d2042e48efc096baba97876b276f41"
500
+ checksum = "7cae87cdb2ae6070bf628f889d745797071b194ecb31c711b452617308075c5e"
501
501
  dependencies = [
502
502
  "asn1-rs",
503
503
  "async-generic",
package/Cargo.toml CHANGED
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
11
11
  [dependencies]
12
12
  async-trait = "0.1.77"
13
13
  ciborium = "0.2.2"
14
- c2pa = { version = "0.77.0", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto", "default_http"] }
14
+ c2pa = { version = "0.78.4", 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 = [
@@ -454,6 +454,29 @@ describe("Builder", () => {
454
454
  expect(JSON.stringify(manifestStore)).toContain("Test Ingredient");
455
455
  expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
456
456
  }));
457
+ it("should add ingredient with custom metadata", () => __awaiter(void 0, void 0, void 0, function* () {
458
+ const builder = Builder.new();
459
+ const ingredient = {
460
+ title: "Test Ingredient",
461
+ format: "image/jpeg",
462
+ instance_id: "ingredient-12345",
463
+ relationship: "componentOf",
464
+ metadata: {
465
+ customString: "my custom value",
466
+ customNumber: 42,
467
+ customBool: true,
468
+ customObject: {
469
+ nested: "value",
470
+ count: 123
471
+ },
472
+ customArray: ["item1", "item2", "item3"]
473
+ }
474
+ };
475
+ yield builder.addIngredient(JSON.stringify(ingredient));
476
+ const definition = builder.getManifestDefinition();
477
+ expect(definition.ingredients).toHaveLength(1);
478
+ expect(definition.ingredients[0]).toMatchObject(ingredient);
479
+ }));
457
480
  it("should perform redaction workflow like test_redaction_async", () => __awaiter(void 0, void 0, void 0, function* () {
458
481
  // This test mirrors the Rust test_redaction_async test
459
482
  // Create a reader to get the parent manifest label from the existing source
package/dist/Settings.js CHANGED
@@ -20,21 +20,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  // each license.
21
21
  import * as fs from "fs-extra";
22
22
  import fetch from "node-fetch";
23
+ function snakeCaseify(object) {
24
+ return Object.entries(object).reduce((result, [key, val]) => {
25
+ result[snakeCase(key)] =
26
+ typeof val === "object" && val !== null ? snakeCaseify(val) : val;
27
+ return result;
28
+ }, {});
29
+ }
30
+ function snakeCase(str) {
31
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
32
+ }
23
33
  /**
24
34
  * Create a Settings object with trust configuration.
25
35
  * @param trustConfig The trust configuration
26
36
  * @returns Settings object that can be passed to Reader/Builder
27
37
  */
28
38
  export function createTrustSettings(trustConfig) {
29
- return {
30
- trust: {
31
- verify_trust_list: trustConfig.verifyTrustList,
32
- user_anchors: trustConfig.userAnchors,
33
- trust_anchors: trustConfig.trustAnchors,
34
- trust_config: trustConfig.trustConfig,
35
- allowed_list: trustConfig.allowedList,
36
- },
37
- };
39
+ return { trust: Object.assign({}, trustConfig) };
38
40
  }
39
41
  /**
40
42
  * Create a settings object with CAWG trust configuration.
@@ -42,15 +44,7 @@ export function createTrustSettings(trustConfig) {
42
44
  * @returns Settings object that can be passed to Reader/Builder
43
45
  */
44
46
  export function createCawgTrustSettings(trustConfig) {
45
- return {
46
- cawg_trust: {
47
- verify_trust_list: trustConfig.verifyTrustList,
48
- user_anchors: trustConfig.userAnchors,
49
- trust_anchors: trustConfig.trustAnchors,
50
- trust_config: trustConfig.trustConfig,
51
- allowed_list: trustConfig.allowedList,
52
- },
53
- };
47
+ return { cawgTrust: Object.assign({}, trustConfig) };
54
48
  }
55
49
  /**
56
50
  * Create a settings object with verify configuration.
@@ -58,18 +52,7 @@ export function createCawgTrustSettings(trustConfig) {
58
52
  * @returns Settings object that can be passed to Reader/Builder
59
53
  */
60
54
  export function createVerifySettings(verifyConfig) {
61
- return {
62
- verify: {
63
- verify_after_reading: verifyConfig.verifyAfterReading,
64
- verify_after_sign: verifyConfig.verifyAfterSign,
65
- verify_trust: verifyConfig.verifyTrust,
66
- verify_timestamp_trust: verifyConfig.verifyTimestampTrust,
67
- ocsp_fetch: verifyConfig.ocspFetch,
68
- remote_manifest_fetch: verifyConfig.remoteManifestFetch,
69
- skip_ingredient_conflict_resolution: verifyConfig.skipIngredientConflictResolution,
70
- strict_v1_validation: verifyConfig.strictV1Validation,
71
- },
72
- };
55
+ return { verify: Object.assign({}, verifyConfig) };
73
56
  }
74
57
  /**
75
58
  * Merge multiple settings objects into one.
@@ -83,8 +66,8 @@ export function mergeSettings(...settings) {
83
66
  if (setting.trust) {
84
67
  merged.trust = Object.assign(Object.assign({}, merged.trust), setting.trust);
85
68
  }
86
- if (setting.cawg_trust) {
87
- merged.cawg_trust = Object.assign(Object.assign({}, merged.cawg_trust), setting.cawg_trust);
69
+ if (setting.cawgTrust) {
70
+ merged.cawgTrust = Object.assign(Object.assign({}, merged.cawgTrust), setting.cawgTrust);
88
71
  }
89
72
  if (setting.verify) {
90
73
  merged.verify = Object.assign(Object.assign({}, merged.verify), setting.verify);
@@ -97,11 +80,12 @@ export function mergeSettings(...settings) {
97
80
  }
98
81
  /**
99
82
  * Convert a settings object to a JSON string.
83
+ * Converts camelCase keys to snake_case to match the c2pa-rs settings format.
100
84
  * @param settings The settings object
101
- * @returns JSON string representation
85
+ * @returns JSON string representation with snake_case keys
102
86
  */
103
87
  export function settingsToJson(settings) {
104
- return JSON.stringify(settings);
88
+ return JSON.stringify(snakeCaseify(settings));
105
89
  }
106
90
  /**
107
91
  * Load settings from a TOML or JSON file.
@@ -31,9 +31,9 @@ describe("Settings", () => {
31
31
  };
32
32
  const settings = createTrustSettings(trustConfig);
33
33
  expect(settings.trust).toBeDefined();
34
- expect((_a = settings.trust) === null || _a === void 0 ? void 0 : _a.verify_trust_list).toBe(true);
35
- expect((_b = settings.trust) === null || _b === void 0 ? void 0 : _b.user_anchors).toBe("test");
36
- expect((_c = settings.trust) === null || _c === void 0 ? void 0 : _c.allowed_list).toBe("allowed");
34
+ expect((_a = settings.trust) === null || _a === void 0 ? void 0 : _a.verifyTrustList).toBe(true);
35
+ expect((_b = settings.trust) === null || _b === void 0 ? void 0 : _b.userAnchors).toBe("test");
36
+ expect((_c = settings.trust) === null || _c === void 0 ? void 0 : _c.allowedList).toBe("allowed");
37
37
  });
38
38
  it("creates CAWG trust settings", () => {
39
39
  var _a, _b;
@@ -42,9 +42,9 @@ describe("Settings", () => {
42
42
  trustAnchors: "anchors",
43
43
  };
44
44
  const settings = createCawgTrustSettings(trustConfig);
45
- expect(settings.cawg_trust).toBeDefined();
46
- expect((_a = settings.cawg_trust) === null || _a === void 0 ? void 0 : _a.verify_trust_list).toBe(false);
47
- expect((_b = settings.cawg_trust) === null || _b === void 0 ? void 0 : _b.trust_anchors).toBe("anchors");
45
+ expect(settings.cawgTrust).toBeDefined();
46
+ expect((_a = settings.cawgTrust) === null || _a === void 0 ? void 0 : _a.verifyTrustList).toBe(false);
47
+ expect((_b = settings.cawgTrust) === null || _b === void 0 ? void 0 : _b.trustAnchors).toBe("anchors");
48
48
  });
49
49
  it("creates verify settings", () => {
50
50
  var _a, _b, _c, _d;
@@ -60,10 +60,20 @@ describe("Settings", () => {
60
60
  };
61
61
  const settings = createVerifySettings(verifyConfig);
62
62
  expect(settings.verify).toBeDefined();
63
- expect((_a = settings.verify) === null || _a === void 0 ? void 0 : _a.verify_after_reading).toBe(true);
64
- expect((_b = settings.verify) === null || _b === void 0 ? void 0 : _b.verify_after_sign).toBe(false);
65
- expect((_c = settings.verify) === null || _c === void 0 ? void 0 : _c.verify_trust).toBe(true);
66
- expect((_d = settings.verify) === null || _d === void 0 ? void 0 : _d.ocsp_fetch).toBe(true);
63
+ expect((_a = settings.verify) === null || _a === void 0 ? void 0 : _a.verifyAfterReading).toBe(true);
64
+ expect((_b = settings.verify) === null || _b === void 0 ? void 0 : _b.verifyAfterSign).toBe(false);
65
+ expect((_c = settings.verify) === null || _c === void 0 ? void 0 : _c.verifyTrust).toBe(true);
66
+ expect((_d = settings.verify) === null || _d === void 0 ? void 0 : _d.ocspFetch).toBe(true);
67
+ });
68
+ it("creates verify settings with partial config", () => {
69
+ var _a, _b, _c;
70
+ const settings = createVerifySettings({
71
+ verifyAfterReading: false,
72
+ });
73
+ expect(settings.verify).toBeDefined();
74
+ expect((_a = settings.verify) === null || _a === void 0 ? void 0 : _a.verifyAfterReading).toBe(false);
75
+ expect((_b = settings.verify) === null || _b === void 0 ? void 0 : _b.verifyAfterSign).toBeUndefined();
76
+ expect((_c = settings.verify) === null || _c === void 0 ? void 0 : _c.verifyTrust).toBeUndefined();
67
77
  });
68
78
  it("merges multiple settings", () => {
69
79
  var _a, _b;
@@ -84,10 +94,10 @@ describe("Settings", () => {
84
94
  const merged = mergeSettings(trustSettings, verifySettings);
85
95
  expect(merged.trust).toBeDefined();
86
96
  expect(merged.verify).toBeDefined();
87
- expect((_a = merged.trust) === null || _a === void 0 ? void 0 : _a.verify_trust_list).toBe(true);
88
- expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.verify_after_reading).toBe(false);
97
+ expect((_a = merged.trust) === null || _a === void 0 ? void 0 : _a.verifyTrustList).toBe(true);
98
+ expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.verifyAfterReading).toBe(false);
89
99
  });
90
- it("converts settings to JSON", () => {
100
+ it("converts settings to JSON with snake_case keys", () => {
91
101
  const settings = createVerifySettings({
92
102
  verifyAfterReading: true,
93
103
  verifyAfterSign: true,
@@ -101,22 +111,17 @@ describe("Settings", () => {
101
111
  const json = settingsToJson(settings);
102
112
  expect(json).toContain("verify");
103
113
  expect(json).toContain("verify_after_reading");
104
- // Should be parseable
114
+ // Should be parseable with snake_case keys
105
115
  const parsed = JSON.parse(json);
106
116
  expect(parsed.verify.verify_after_reading).toBe(true);
107
117
  });
108
118
  it("does not include undefined values in trust settings JSON", () => {
109
119
  const trustConfig = {
110
120
  verifyTrustList: true,
111
- // userAnchors is undefined
112
- // trustAnchors is undefined
113
- // trustConfig is undefined
114
- // allowedList is undefined
115
121
  };
116
122
  const settings = createTrustSettings(trustConfig);
117
123
  const json = settingsToJson(settings);
118
124
  const parsed = JSON.parse(json);
119
- // JSON.stringify automatically excludes undefined values
120
125
  expect(parsed.trust.verify_trust_list).toBe(true);
121
126
  expect("user_anchors" in parsed.trust).toBe(false);
122
127
  expect("trust_anchors" in parsed.trust).toBe(false);
@@ -126,12 +131,10 @@ describe("Settings", () => {
126
131
  it("does not include undefined values in CAWG trust settings JSON", () => {
127
132
  const trustConfig = {
128
133
  verifyTrustList: false,
129
- // Only verifyTrustList is defined
130
134
  };
131
135
  const settings = createCawgTrustSettings(trustConfig);
132
136
  const json = settingsToJson(settings);
133
137
  const parsed = JSON.parse(json);
134
- // JSON.stringify automatically excludes undefined values
135
138
  expect(parsed.cawg_trust.verify_trust_list).toBe(false);
136
139
  expect("user_anchors" in parsed.cawg_trust).toBe(false);
137
140
  expect("trust_anchors" in parsed.cawg_trust).toBe(false);
@@ -140,18 +143,10 @@ describe("Settings", () => {
140
143
  const verifyConfig = {
141
144
  verifyAfterReading: true,
142
145
  verifyAfterSign: false,
143
- // Only first two are defined, rest are undefined
144
- verifyTrust: undefined,
145
- verifyTimestampTrust: undefined,
146
- ocspFetch: undefined,
147
- remoteManifestFetch: undefined,
148
- skipIngredientConflictResolution: undefined,
149
- strictV1Validation: undefined,
150
146
  };
151
147
  const settings = createVerifySettings(verifyConfig);
152
148
  const json = settingsToJson(settings);
153
149
  const parsed = JSON.parse(json);
154
- // JSON.stringify automatically excludes undefined values
155
150
  expect(parsed.verify.verify_after_reading).toBe(true);
156
151
  expect(parsed.verify.verify_after_sign).toBe(false);
157
152
  expect("verify_trust" in parsed.verify).toBe(false);
@@ -162,22 +157,22 @@ describe("Settings", () => {
162
157
  it("does not include undefined values when merging settings", () => {
163
158
  const settings1 = {
164
159
  trust: {
165
- verify_trust_list: true,
166
- user_anchors: "test",
160
+ verifyTrustList: true,
161
+ userAnchors: "test",
167
162
  },
168
163
  };
169
164
  const settings2 = {
170
165
  trust: {
171
- allowed_list: undefined, // Explicitly undefined
166
+ verifyTrustList: true,
167
+ allowedList: undefined,
172
168
  },
173
169
  verify: {
174
- verify_after_reading: false,
170
+ verifyAfterReading: false,
175
171
  },
176
172
  };
177
173
  const merged = mergeSettings(settings1, settings2);
178
174
  const json = settingsToJson(merged);
179
175
  const parsed = JSON.parse(json);
180
- // JSON.stringify automatically excludes undefined values
181
176
  expect(parsed.trust.verify_trust_list).toBe(true);
182
177
  expect(parsed.trust.user_anchors).toBe("test");
183
178
  expect("allowed_list" in parsed.trust).toBe(false);
@@ -197,14 +192,14 @@ describe("Settings", () => {
197
192
  });
198
193
  const settings2 = {
199
194
  verify: {
200
- verify_trust: true, // Override this value
201
- ocsp_fetch: true, // Override this value
195
+ verifyTrust: true,
196
+ ocspFetch: true,
202
197
  },
203
198
  };
204
199
  const merged = mergeSettings(settings1, settings2);
205
- expect((_a = merged.verify) === null || _a === void 0 ? void 0 : _a.verify_after_reading).toBe(true); // from settings1
206
- expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.verify_trust).toBe(true); // overridden by settings2
207
- expect((_c = merged.verify) === null || _c === void 0 ? void 0 : _c.ocsp_fetch).toBe(true); // overridden by settings2
200
+ expect((_a = merged.verify) === null || _a === void 0 ? void 0 : _a.verifyAfterReading).toBe(true); // from settings1
201
+ expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.verifyTrust).toBe(true); // overridden by settings2
202
+ expect((_c = merged.verify) === null || _c === void 0 ? void 0 : _c.ocspFetch).toBe(true); // overridden by settings2
208
203
  });
209
204
  describe("loadSettingsFromFile", () => {
210
205
  let tempDir;
package/dist/index.node CHANGED
Binary file
@@ -26,8 +26,9 @@ export declare function createVerifySettings(verifyConfig: VerifyConfig): Settin
26
26
  export declare function mergeSettings(...settings: SettingsContext[]): SettingsContext;
27
27
  /**
28
28
  * Convert a settings object to a JSON string.
29
+ * Converts camelCase keys to snake_case to match the c2pa-rs settings format.
29
30
  * @param settings The settings object
30
- * @returns JSON string representation
31
+ * @returns JSON string representation with snake_case keys
31
32
  */
32
33
  export declare function settingsToJson(settings: SettingsContext): string;
33
34
  /**
@@ -19,6 +19,9 @@ import type {
19
19
  Manifest,
20
20
  ManifestStore,
21
21
  } from "@contentauth/c2pa-types";
22
+
23
+ export type { Ingredient } from "@contentauth/c2pa-types";
24
+
22
25
  /**
23
26
  * Describes the digital signature algorithms allowed by the C2PA spec
24
27
  *
@@ -59,7 +62,7 @@ export type TrustmarkVariant =
59
62
  // Quality Trustmark model
60
63
  | "Q";
61
64
 
62
- type ManifestAssertionKind = "Cbor" | "Json" | "Binary" | "Uri";
65
+ export type ManifestAssertionKind = "Cbor" | "Json" | "Binary" | "Uri";
63
66
 
64
67
  /**
65
68
  * A buffer for the source asset
@@ -450,21 +453,21 @@ export interface TrustConfig {
450
453
  */
451
454
  export interface VerifyConfig {
452
455
  /** Whether to verify after reading a manifest */
453
- verifyAfterReading: boolean;
456
+ verifyAfterReading?: boolean;
454
457
  /** Whether to verify after signing a manifest */
455
- verifyAfterSign: boolean;
458
+ verifyAfterSign?: boolean;
456
459
  /** Whether to verify trust during validation */
457
- verifyTrust: boolean;
460
+ verifyTrust?: boolean;
458
461
  /** Whether to verify timestamp trust */
459
- verifyTimestampTrust: boolean;
462
+ verifyTimestampTrust?: boolean;
460
463
  /** Whether to fetch OCSP responses */
461
- ocspFetch: boolean;
464
+ ocspFetch?: boolean;
462
465
  /** Whether to fetch remote manifests */
463
- remoteManifestFetch: boolean;
466
+ remoteManifestFetch?: boolean;
464
467
  /** Whether to skip ingredient conflict resolution */
465
- skipIngredientConflictResolution: boolean;
468
+ skipIngredientConflictResolution?: boolean;
466
469
  /** Whether to use strict v1 validation */
467
- strictV1Validation: boolean;
470
+ strictV1Validation?: boolean;
468
471
  }
469
472
 
470
473
  /**
@@ -474,32 +477,11 @@ export interface VerifyConfig {
474
477
  */
475
478
  export interface SettingsContext {
476
479
  /** C2PA trust configuration */
477
- trust?: {
478
- verify_trust_list?: boolean;
479
- user_anchors?: string;
480
- trust_anchors?: string;
481
- trust_config?: string;
482
- allowed_list?: string;
483
- };
480
+ trust?: TrustConfig;
484
481
  /** CAWG trust configuration */
485
- cawg_trust?: {
486
- verify_trust_list?: boolean;
487
- user_anchors?: string;
488
- trust_anchors?: string;
489
- trust_config?: string;
490
- allowed_list?: string;
491
- };
482
+ cawgTrust?: TrustConfig;
492
483
  /** Verification configuration */
493
- verify?: {
494
- verify_after_reading?: boolean;
495
- verify_after_sign?: boolean;
496
- verify_trust?: boolean;
497
- verify_timestamp_trust?: boolean;
498
- ocsp_fetch?: boolean;
499
- remote_manifest_fetch?: boolean;
500
- skip_ingredient_conflict_resolution?: boolean;
501
- strict_v1_validation?: boolean;
502
- };
484
+ verify?: VerifyConfig;
503
485
  /** Builder configuration */
504
486
  builder?: {
505
487
  thumbnail?: {
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.5.2",
7
+ "version": "0.5.4",
8
8
  "description": "Node.js bindings for C2PA",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",