@contentauth/c2pa-node 0.4.1 → 0.5.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.
@@ -3,307 +3,279 @@
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 { getCawgTrustConfig, getSettingsJson, getTrustConfig, getVerifyConfig, loadC2paSettings, loadCawgTrustConfig, loadTrustConfig, loadVerifyConfig, patchVerifyConfig, resetSettings, } from "./Settings.js";
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ import { createTrustSettings, createCawgTrustSettings, createVerifySettings, mergeSettings, settingsToJson, loadSettingsFromFile, loadSettingsFromUrl, } from "./Settings.js";
16
+ import * as fs from "fs-extra";
17
+ import * as path from "path";
18
+ import * as os from "os";
19
+ import { vi } from "vitest";
20
+ // Mock node-fetch
21
+ vi.mock("node-fetch", () => ({
22
+ default: vi.fn(),
23
+ }));
7
24
  describe("Settings", () => {
8
- afterAll(() => {
9
- resetSettings();
25
+ it("creates trust settings", () => {
26
+ var _a, _b, _c;
27
+ const trustConfig = {
28
+ verifyTrustList: true,
29
+ userAnchors: "test",
30
+ allowedList: "allowed",
31
+ };
32
+ const settings = createTrustSettings(trustConfig);
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");
10
37
  });
11
- it("loads a trustlist-shaped JSON and returns JSON via getSettingsJson", () => {
38
+ it("creates CAWG trust settings", () => {
12
39
  var _a, _b;
13
- // Matches c2pa-rs settings structure: trust + verify
14
- // trust.allowed_list accepts base64 lines or PEMs; provide a simple base64 line
15
- const settings = {
16
- trust: {
17
- allowed_list: "Zm9v\n", // base64("foo") with newline
18
- },
19
- verify: {
20
- verify_trust: true,
21
- },
40
+ const trustConfig = {
41
+ verifyTrustList: false,
42
+ trustAnchors: "anchors",
22
43
  };
23
- loadC2paSettings(JSON.stringify(settings));
24
- const obj = JSON.parse(getSettingsJson());
25
- expect(obj).toBeTruthy();
26
- expect((_a = obj.trust) === null || _a === void 0 ? void 0 : _a.allowed_list).toBe("Zm9v\n");
27
- expect((_b = obj.verify) === null || _b === void 0 ? void 0 : _b.verify_trust).toBe(true);
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");
28
48
  });
29
- describe("loadTrustConfig", () => {
30
- it("preserves other settings when loading trust config", () => {
31
- // First, load basic settings that work with c2pa-rs
32
- const initialSettings = {
33
- trust: {
34
- allowed_list: "Zm9v\n", // base64("foo") with newline - valid base64
35
- },
36
- verify: {
37
- verify_trust: true,
38
- },
39
- };
40
- loadC2paSettings(JSON.stringify(initialSettings));
41
- // Verify initial settings are loaded
42
- const currentSettings = JSON.parse(getSettingsJson());
43
- expect(currentSettings.verify.verify_trust).toBe(true);
44
- expect(currentSettings.trust.allowed_list).toBe("Zm9v\n");
45
- // Now load only trust config
46
- const trustConfig = {
47
- verifyTrustList: true,
48
- userAnchors: "dGVzdA==\n", // base64("test") with newline - valid base64
49
- trustAnchors: "YW5jaG9y\n", // base64("anchor") with newline - valid base64
50
- allowedList: "Zm9v\n", // base64("foo") with newline
51
- };
52
- loadTrustConfig(trustConfig);
53
- // Verify trust config was updated
54
- const updatedSettings = JSON.parse(getSettingsJson());
55
- expect(updatedSettings.trust.allowed_list).toBe("Zm9v\n");
56
- expect(updatedSettings.trust.user_anchors).toBe("dGVzdA==\n");
57
- expect(updatedSettings.trust.trust_anchors).toBe("YW5jaG9y\n");
58
- // Verify other settings are preserved
59
- expect(updatedSettings.verify.verify_trust).toBe(true);
60
- });
61
- it("works with getTrustConfig to retrieve current trust settings", () => {
62
- // Load initial trust config
63
- const initialTrustConfig = {
64
- verifyTrustList: false,
65
- userAnchors: "dGVzdA==\n", // base64("test") with newline - valid base64
66
- trustAnchors: "YW5jaG9y\n", // base64("anchor") with newline - valid base64
67
- };
68
- loadTrustConfig(initialTrustConfig);
69
- // Verify we can retrieve it
70
- const retrievedConfig = getTrustConfig();
71
- expect(retrievedConfig.verifyTrustList).toBe(false);
72
- expect(retrievedConfig.userAnchors).toBe("dGVzdA==\n");
73
- expect(retrievedConfig.trustAnchors).toBe("YW5jaG9y\n");
74
- // Update trust config
75
- const updatedTrustConfig = {
76
- verifyTrustList: true,
77
- allowedList: "YmFy\n", // base64("bar") with newline
78
- trustConfig: "dHJ1c3Q=\n", // base64("trust") with newline - valid base64
79
- };
80
- loadTrustConfig(updatedTrustConfig);
81
- // Verify updated config
82
- const updatedRetrievedConfig = getTrustConfig();
83
- expect(updatedRetrievedConfig.verifyTrustList).toBe(true);
84
- expect(updatedRetrievedConfig.allowedList).toBe("YmFy\n");
85
- expect(updatedRetrievedConfig.trustConfig).toBe("dHJ1c3Q=\n");
86
- // Previous values should be cleared when not specified
87
- expect(updatedRetrievedConfig.userAnchors).toBeNull();
88
- expect(updatedRetrievedConfig.trustAnchors).toBeNull();
49
+ it("creates verify settings", () => {
50
+ var _a, _b, _c, _d;
51
+ const verifyConfig = {
52
+ verifyAfterReading: true,
53
+ verifyAfterSign: false,
54
+ verifyTrust: true,
55
+ verifyTimestampTrust: false,
56
+ ocspFetch: true,
57
+ remoteManifestFetch: false,
58
+ skipIngredientConflictResolution: true,
59
+ strictV1Validation: false,
60
+ };
61
+ const settings = createVerifySettings(verifyConfig);
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);
67
+ });
68
+ it("merges multiple settings", () => {
69
+ var _a, _b;
70
+ const trustSettings = createTrustSettings({
71
+ verifyTrustList: true,
72
+ userAnchors: "test",
89
73
  });
90
- it("handles empty trust config without errors", () => {
91
- // Load some initial settings
92
- const initialSettings = {
93
- core: { hash_alg: "sha256" },
94
- verify: { verify_trust: true },
95
- };
96
- loadC2paSettings(JSON.stringify(initialSettings));
97
- // Load empty trust config
98
- const emptyTrustConfig = {
99
- verifyTrustList: true,
100
- };
101
- expect(() => loadTrustConfig(emptyTrustConfig)).not.toThrow();
102
- // Verify settings are still intact
103
- const currentSettings = JSON.parse(getSettingsJson());
104
- expect(currentSettings.core.decode_identity_assertions).toBe(true);
105
- expect(currentSettings.verify.verify_trust).toBe(true);
106
- expect(currentSettings.trust.verify_trust_list).toBe(true);
74
+ const verifySettings = createVerifySettings({
75
+ verifyAfterReading: false,
76
+ verifyAfterSign: true,
77
+ verifyTrust: true,
78
+ verifyTimestampTrust: true,
79
+ ocspFetch: false,
80
+ remoteManifestFetch: true,
81
+ skipIngredientConflictResolution: false,
82
+ strictV1Validation: false,
107
83
  });
84
+ const merged = mergeSettings(trustSettings, verifySettings);
85
+ expect(merged.trust).toBeDefined();
86
+ 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);
108
89
  });
109
- describe("loadCawgTrustConfig", () => {
110
- it("preserves other settings when loading CAWG trust config", () => {
111
- // First, load basic settings that work with c2pa-rs
112
- const initialSettings = {
113
- verify: {
114
- verify_trust: false,
115
- },
116
- trust: {
117
- allowed_list: "YmFy\n", // base64("bar") with newline - valid base64
118
- },
119
- };
120
- loadC2paSettings(JSON.stringify(initialSettings));
121
- // Load CAWG trust config
122
- const cawgTrustConfig = {
123
- verifyTrustList: true,
124
- userAnchors: "Y2F3Zw==\n", // base64("cawg") with newline - valid base64
125
- allowedList: "Y2F3Zw==\n", // base64("cawg") with newline
126
- };
127
- loadCawgTrustConfig(cawgTrustConfig);
128
- // Verify CAWG trust config was updated
129
- const updatedSettings = JSON.parse(getSettingsJson());
130
- expect(updatedSettings.cawg_trust.allowed_list).toBe("Y2F3Zw==\n");
131
- expect(updatedSettings.cawg_trust.user_anchors).toBe("Y2F3Zw==\n");
132
- // Verify other settings are preserved
133
- expect(updatedSettings.verify.verify_trust).toBe(false);
134
- expect(updatedSettings.trust.allowed_list).toBe("YmFy\n");
90
+ it("converts settings to JSON", () => {
91
+ const settings = createVerifySettings({
92
+ verifyAfterReading: true,
93
+ verifyAfterSign: true,
94
+ verifyTrust: false,
95
+ verifyTimestampTrust: true,
96
+ ocspFetch: false,
97
+ remoteManifestFetch: true,
98
+ skipIngredientConflictResolution: false,
99
+ strictV1Validation: false,
135
100
  });
136
- it("works with getCawgTrustConfig to retrieve current CAWG trust settings", () => {
137
- // Load CAWG trust config
138
- const cawgTrustConfig = {
139
- verifyTrustList: true,
140
- userAnchors: "Y2F3Zw==\n", // base64("cawg") with newline - valid base64
141
- trustConfig: "c3RvcmU=\n", // base64("store") with newline - valid base64
142
- };
143
- loadCawgTrustConfig(cawgTrustConfig);
144
- // Verify we can retrieve it
145
- const retrievedConfig = getCawgTrustConfig();
146
- expect(retrievedConfig.verifyTrustList).toBe(true);
147
- expect(retrievedConfig.userAnchors).toBe("Y2F3Zw==\n");
148
- expect(retrievedConfig.trustConfig).toBe("c3RvcmU=\n");
101
+ const json = settingsToJson(settings);
102
+ expect(json).toContain("verify");
103
+ expect(json).toContain("verify_after_reading");
104
+ // Should be parseable
105
+ const parsed = JSON.parse(json);
106
+ expect(parsed.verify.verify_after_reading).toBe(true);
107
+ });
108
+ it("does not include undefined values in trust settings JSON", () => {
109
+ const trustConfig = {
110
+ verifyTrustList: true,
111
+ // userAnchors is undefined
112
+ // trustAnchors is undefined
113
+ // trustConfig is undefined
114
+ // allowedList is undefined
115
+ };
116
+ const settings = createTrustSettings(trustConfig);
117
+ const json = settingsToJson(settings);
118
+ const parsed = JSON.parse(json);
119
+ // JSON.stringify automatically excludes undefined values
120
+ expect(parsed.trust.verify_trust_list).toBe(true);
121
+ expect("user_anchors" in parsed.trust).toBe(false);
122
+ expect("trust_anchors" in parsed.trust).toBe(false);
123
+ expect("trust_config" in parsed.trust).toBe(false);
124
+ expect("allowed_list" in parsed.trust).toBe(false);
125
+ });
126
+ it("does not include undefined values in CAWG trust settings JSON", () => {
127
+ const trustConfig = {
128
+ verifyTrustList: false,
129
+ // Only verifyTrustList is defined
130
+ };
131
+ const settings = createCawgTrustSettings(trustConfig);
132
+ const json = settingsToJson(settings);
133
+ const parsed = JSON.parse(json);
134
+ // JSON.stringify automatically excludes undefined values
135
+ expect(parsed.cawg_trust.verify_trust_list).toBe(false);
136
+ expect("user_anchors" in parsed.cawg_trust).toBe(false);
137
+ expect("trust_anchors" in parsed.cawg_trust).toBe(false);
138
+ });
139
+ it("does not include undefined values in verify settings JSON", () => {
140
+ const verifyConfig = {
141
+ verifyAfterReading: true,
142
+ 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
+ };
151
+ const settings = createVerifySettings(verifyConfig);
152
+ const json = settingsToJson(settings);
153
+ const parsed = JSON.parse(json);
154
+ // JSON.stringify automatically excludes undefined values
155
+ expect(parsed.verify.verify_after_reading).toBe(true);
156
+ expect(parsed.verify.verify_after_sign).toBe(false);
157
+ expect("verify_trust" in parsed.verify).toBe(false);
158
+ expect("verify_timestamp_trust" in parsed.verify).toBe(false);
159
+ expect("ocsp_fetch" in parsed.verify).toBe(false);
160
+ expect("remote_manifest_fetch" in parsed.verify).toBe(false);
161
+ });
162
+ it("does not include undefined values when merging settings", () => {
163
+ const settings1 = {
164
+ trust: {
165
+ verify_trust_list: true,
166
+ user_anchors: "test",
167
+ },
168
+ };
169
+ const settings2 = {
170
+ trust: {
171
+ allowed_list: undefined, // Explicitly undefined
172
+ },
173
+ verify: {
174
+ verify_after_reading: false,
175
+ },
176
+ };
177
+ const merged = mergeSettings(settings1, settings2);
178
+ const json = settingsToJson(merged);
179
+ const parsed = JSON.parse(json);
180
+ // JSON.stringify automatically excludes undefined values
181
+ expect(parsed.trust.verify_trust_list).toBe(true);
182
+ expect(parsed.trust.user_anchors).toBe("test");
183
+ expect("allowed_list" in parsed.trust).toBe(false);
184
+ expect(parsed.verify.verify_after_reading).toBe(false);
185
+ });
186
+ it("merges settings with later values overriding earlier ones", () => {
187
+ var _a, _b, _c;
188
+ const settings1 = createVerifySettings({
189
+ verifyAfterReading: true,
190
+ verifyAfterSign: true,
191
+ verifyTrust: false,
192
+ verifyTimestampTrust: true,
193
+ ocspFetch: false,
194
+ remoteManifestFetch: true,
195
+ skipIngredientConflictResolution: false,
196
+ strictV1Validation: false,
149
197
  });
198
+ const settings2 = {
199
+ verify: {
200
+ verify_trust: true, // Override this value
201
+ ocsp_fetch: true, // Override this value
202
+ },
203
+ };
204
+ 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
150
208
  });
151
- describe("settings merge behavior", () => {
152
- it("maintains separate trust and CAWG trust configurations", () => {
153
- // Load initial settings with basic trust config and verify settings
154
- const initialSettings = {
155
- trust: {
156
- allowed_list: "bWFpbg==\n", // base64("main") with newline - valid base64
157
- },
209
+ describe("loadSettingsFromFile", () => {
210
+ let tempDir;
211
+ beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
212
+ tempDir = yield fs.mkdtemp(path.join(os.tmpdir(), "c2pa-settings-test-"));
213
+ }));
214
+ afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
215
+ yield fs.remove(tempDir);
216
+ }));
217
+ it("loads settings from a JSON file", () => __awaiter(void 0, void 0, void 0, function* () {
218
+ const settingsContent = JSON.stringify({
158
219
  verify: {
159
- verify_trust: true,
160
- remote_manifest_fetch: false,
220
+ verify_after_reading: false,
221
+ verify_after_sign: false,
161
222
  },
162
- };
163
- loadC2paSettings(JSON.stringify(initialSettings));
164
- // Update main trust config
165
- const mainTrustConfig = {
166
- verifyTrustList: true,
167
- allowedList: "bWFpbg==\n", // base64("main") with newline
168
- };
169
- loadTrustConfig(mainTrustConfig);
170
- // Update CAWG trust config
171
- const cawgTrustConfig = {
172
- verifyTrustList: false,
173
- allowedList: "Y2F3Zw==\n", // base64("cawg") with newline
174
- };
175
- loadCawgTrustConfig(cawgTrustConfig);
176
- // Update verify config to ensure it doesn't conflict with trust settings
177
- const verifyConfig = {
178
- verifyAfterReading: false,
179
- verifyAfterSign: true,
180
- verifyTrust: false, // This should not affect trust.allowed_list
181
- verifyTimestampTrust: true,
182
- ocspFetch: false,
183
- remoteManifestFetch: true, // This should not affect trust settings
184
- skipIngredientConflictResolution: true,
185
- strictV1Validation: false,
186
- };
187
- loadVerifyConfig(verifyConfig);
188
- // Verify all configs are maintained separately
189
- const finalSettings = JSON.parse(getSettingsJson());
190
- // Main trust config should be preserved
191
- expect(finalSettings.trust.allowed_list).toBe("bWFpbg==\n");
192
- expect(finalSettings.trust.verify_trust_list).toBe(true);
193
- // CAWG trust config should be preserved
194
- expect(finalSettings.cawg_trust.allowed_list).toBe("Y2F3Zw==\n");
195
- expect(finalSettings.cawg_trust.verify_trust_list).toBe(false);
196
- // Verify config should be updated independently
197
- expect(finalSettings.verify.verify_after_reading).toBe(false);
198
- expect(finalSettings.verify.verify_after_sign).toBe(true);
199
- expect(finalSettings.verify.verify_trust).toBe(false);
200
- expect(finalSettings.verify.verify_timestamp_trust).toBe(true);
201
- expect(finalSettings.verify.ocsp_fetch).toBe(false);
202
- expect(finalSettings.verify.remote_manifest_fetch).toBe(true);
203
- expect(finalSettings.verify.skip_ingredient_conflict_resolution).toBe(true);
204
- expect(finalSettings.verify.strict_v1_validation).toBe(false);
205
- // Verify that trust settings are not affected by verify settings
206
- expect(finalSettings.trust.allowed_list).toBe("bWFpbg==\n");
207
- expect(finalSettings.cawg_trust.allowed_list).toBe("Y2F3Zw==\n");
208
- // Settings structure is maintained
209
- expect(finalSettings).toBeTruthy();
210
- });
223
+ });
224
+ const filePath = path.join(tempDir, "settings.json");
225
+ yield fs.writeFile(filePath, settingsContent);
226
+ const loaded = yield loadSettingsFromFile(filePath);
227
+ expect(loaded).toBe(settingsContent);
228
+ // Verify it can be parsed
229
+ const parsed = JSON.parse(loaded);
230
+ expect(parsed.verify.verify_after_reading).toBe(false);
231
+ }));
232
+ it("loads settings from a TOML file", () => __awaiter(void 0, void 0, void 0, function* () {
233
+ const tomlContent = `[verify]
234
+ verify_after_reading = false
235
+ verify_after_sign = false`;
236
+ const filePath = path.join(tempDir, "settings.toml");
237
+ yield fs.writeFile(filePath, tomlContent);
238
+ const loaded = yield loadSettingsFromFile(filePath);
239
+ expect(loaded).toBe(tomlContent);
240
+ expect(loaded).toContain("verify_after_reading");
241
+ }));
242
+ it("throws error for non-existent file", () => __awaiter(void 0, void 0, void 0, function* () {
243
+ const filePath = path.join(tempDir, "nonexistent.json");
244
+ yield expect(loadSettingsFromFile(filePath)).rejects.toThrow();
245
+ }));
211
246
  });
212
- describe("Verify Settings", () => {
213
- it("loads and retrieves verify configuration", () => {
214
- const verifyConfig = {
215
- verifyAfterReading: true,
216
- verifyAfterSign: false,
217
- verifyTrust: true,
218
- verifyTimestampTrust: false,
219
- ocspFetch: true,
220
- remoteManifestFetch: false,
221
- skipIngredientConflictResolution: false,
222
- strictV1Validation: true,
223
- };
224
- loadVerifyConfig(verifyConfig);
225
- const retrievedConfig = getVerifyConfig();
226
- expect(retrievedConfig).toEqual(verifyConfig);
247
+ describe("loadSettingsFromUrl", () => {
248
+ beforeEach(() => {
249
+ vi.clearAllMocks();
227
250
  });
228
- it("preserves other settings when loading verify config", () => {
229
- // First, load basic settings
230
- const initialSettings = {
231
- trust: {
232
- allowed_list: "Zm9v\n", // base64("foo") with newline - valid base64
233
- },
251
+ it("loads settings from a URL", () => __awaiter(void 0, void 0, void 0, function* () {
252
+ const mockSettings = JSON.stringify({
234
253
  verify: {
235
- verify_trust: true,
254
+ verify_after_reading: true,
236
255
  },
237
- };
238
- loadC2paSettings(JSON.stringify(initialSettings));
239
- // Load verify config
240
- const verifyConfig = {
241
- verifyAfterReading: false,
242
- verifyAfterSign: true,
243
- verifyTrust: false,
244
- verifyTimestampTrust: true,
245
- ocspFetch: false,
246
- remoteManifestFetch: true,
247
- skipIngredientConflictResolution: true,
248
- strictV1Validation: false,
249
- };
250
- loadVerifyConfig(verifyConfig);
251
- // Verify the settings are maintained
252
- const finalSettings = JSON.parse(getSettingsJson());
253
- expect(finalSettings.trust.allowed_list).toBe("Zm9v\n");
254
- expect(finalSettings.verify.verify_after_reading).toBe(false);
255
- expect(finalSettings.verify.verify_after_sign).toBe(true);
256
- expect(finalSettings.verify.verify_trust).toBe(false);
257
- expect(finalSettings.verify.verify_timestamp_trust).toBe(true);
258
- expect(finalSettings.verify.ocsp_fetch).toBe(false);
259
- expect(finalSettings.verify.remote_manifest_fetch).toBe(true);
260
- expect(finalSettings.verify.skip_ingredient_conflict_resolution).toBe(true);
261
- expect(finalSettings.verify.strict_v1_validation).toBe(false);
262
- });
263
- it("patches verify configuration with partial updates", () => {
264
- // First, load initial verify configuration
265
- const initialVerifyConfig = {
266
- verifyAfterReading: true,
267
- verifyAfterSign: true,
268
- verifyTrust: false,
269
- verifyTimestampTrust: true,
270
- ocspFetch: false,
271
- remoteManifestFetch: true,
272
- skipIngredientConflictResolution: false,
273
- strictV1Validation: false,
274
- };
275
- loadVerifyConfig(initialVerifyConfig);
276
- // Verify initial configuration is loaded
277
- const initialRetrievedConfig = getVerifyConfig();
278
- expect(initialRetrievedConfig).toEqual(initialVerifyConfig);
279
- // Patch only specific fields
280
- const patch = {
281
- verifyTrust: true,
282
- ocspFetch: true,
283
- strictV1Validation: true,
284
- };
285
- patchVerifyConfig(patch);
286
- // Verify the patched configuration
287
- const patchedRetrievedConfig = getVerifyConfig();
288
- expect(patchedRetrievedConfig.verifyAfterReading).toBe(true); // unchanged
289
- expect(patchedRetrievedConfig.verifyAfterSign).toBe(true); // unchanged
290
- expect(patchedRetrievedConfig.verifyTrust).toBe(true); // patched
291
- expect(patchedRetrievedConfig.verifyTimestampTrust).toBe(true); // unchanged
292
- expect(patchedRetrievedConfig.ocspFetch).toBe(true); // patched
293
- expect(patchedRetrievedConfig.remoteManifestFetch).toBe(true); // unchanged
294
- expect(patchedRetrievedConfig.skipIngredientConflictResolution).toBe(false); // unchanged
295
- expect(patchedRetrievedConfig.strictV1Validation).toBe(true); // patched
296
- // Verify the changes are reflected in getSettingsJson()
297
- const settingsJson = getSettingsJson();
298
- const settings = JSON.parse(settingsJson);
299
- expect(settings.verify.verify_trust).toBe(true);
300
- expect(settings.verify.ocsp_fetch).toBe(true);
301
- expect(settings.verify.strict_v1_validation).toBe(true);
302
- expect(settings.verify.verify_after_reading).toBe(true);
303
- expect(settings.verify.verify_after_sign).toBe(true);
304
- expect(settings.verify.verify_timestamp_trust).toBe(true);
305
- expect(settings.verify.remote_manifest_fetch).toBe(true);
306
- expect(settings.verify.skip_ingredient_conflict_resolution).toBe(false);
307
- });
256
+ });
257
+ const fetch = (yield import("node-fetch")).default;
258
+ vi.mocked(fetch).mockResolvedValue({
259
+ ok: true,
260
+ text: () => __awaiter(void 0, void 0, void 0, function* () { return mockSettings; }),
261
+ });
262
+ const loaded = yield loadSettingsFromUrl("https://example.com/settings.json");
263
+ expect(loaded).toBe(mockSettings);
264
+ expect(fetch).toHaveBeenCalledWith("https://example.com/settings.json");
265
+ }));
266
+ it("throws error for failed fetch", () => __awaiter(void 0, void 0, void 0, function* () {
267
+ const fetch = (yield import("node-fetch")).default;
268
+ vi.mocked(fetch).mockResolvedValue({
269
+ ok: false,
270
+ status: 404,
271
+ statusText: "Not Found",
272
+ });
273
+ yield expect(loadSettingsFromUrl("https://example.com/missing.json")).rejects.toThrow("Failed to fetch settings from URL: 404 Not Found");
274
+ }));
275
+ it("throws error for network failure", () => __awaiter(void 0, void 0, void 0, function* () {
276
+ const fetch = (yield import("node-fetch")).default;
277
+ vi.mocked(fetch).mockRejectedValue(new Error("Network error"));
278
+ yield expect(loadSettingsFromUrl("https://example.com/settings.json")).rejects.toThrow("Network error");
279
+ }));
308
280
  });
309
281
  });
package/dist/index.node CHANGED
Binary file
@@ -1,10 +1,10 @@
1
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";
2
+ import type { BuilderInterface, C2paSettings, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, ReaderInterface, SourceAsset, NeonBuilderHandle } from "./types.d.ts";
3
3
  export declare class Builder implements BuilderInterface {
4
4
  private builder;
5
- private constructor();
6
- static new(): Builder;
7
- static withJson(json: Manifest): Builder;
5
+ constructor(builder: NeonBuilderHandle);
6
+ static new(settings?: C2paSettings): Builder;
7
+ static withJson(json: Manifest, settings?: C2paSettings): Builder;
8
8
  setIntent(intent: BuilderIntent): void;
9
9
  setNoEmbed(noEmbed?: boolean): void;
10
10
  setRemoteUrl(remoteUrl: string): void;
@@ -14,11 +14,12 @@ export declare class Builder implements BuilderInterface {
14
14
  addIngredient(ingredientJson: string, ingredient?: SourceAsset): Promise<void>;
15
15
  addIngredientFromReader(reader: ReaderInterface): Ingredient;
16
16
  toArchive(asset: DestinationAsset): Promise<void>;
17
- static fromArchive(asset: SourceAsset): Promise<Builder>;
17
+ static fromArchive(asset: SourceAsset, settings?: C2paSettings): Promise<Builder>;
18
18
  sign(signer: LocalSignerInterface, input: SourceAsset, output: DestinationAsset): Buffer;
19
19
  signFile(signer: LocalSignerInterface, filePath: string, output: DestinationAsset): Buffer;
20
20
  signConfigAsync(callback: (data: Buffer) => Promise<Buffer>, signerConfig: JsCallbackSignerConfig, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
21
21
  signAsync(signer: CallbackSignerInterface | IdentityAssertionSignerInterface, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
22
22
  getManifestDefinition(): Manifest;
23
23
  updateManifestProperty(property: string, value: ClaimVersion): void;
24
+ getHandle(): NeonBuilderHandle;
24
25
  }
@@ -1,14 +1,14 @@
1
1
  import type { Manifest, ManifestStore } from "@contentauth/c2pa-types";
2
- import type { DestinationAsset, ReaderInterface, SourceAsset, NeonReaderHandle } from "./types.d.ts";
2
+ import type { C2paSettings, DestinationAsset, ReaderInterface, ResourceAsset, SourceAsset, NeonReaderHandle } from "./types.d.ts";
3
3
  export declare class Reader implements ReaderInterface {
4
4
  private reader;
5
5
  constructor(reader: NeonReaderHandle);
6
6
  json(): ManifestStore;
7
7
  remoteUrl(): string;
8
8
  isEmbedded(): boolean;
9
- resourceToAsset(uri: string, asset: DestinationAsset): Promise<number>;
10
- static fromAsset(asset: SourceAsset): Promise<Reader | null>;
11
- static fromManifestDataAndAsset(manifestData: Buffer, asset: SourceAsset): Promise<Reader>;
9
+ resourceToAsset(uri: string, asset: DestinationAsset): Promise<ResourceAsset>;
10
+ static fromAsset(asset: SourceAsset, settings?: C2paSettings): Promise<Reader | null>;
11
+ static fromManifestDataAndAsset(manifestData: Buffer, asset: SourceAsset, settings?: C2paSettings): Promise<Reader>;
12
12
  activeLabel(): string | undefined;
13
13
  getActive(): Manifest | undefined;
14
14
  getHandle(): NeonReaderHandle;