@contentauth/c2pa-node 0.4.2 → 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.
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.72.0", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto", "default_http"] }
14
+ c2pa = { version = "0.74.0", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto", "default_http"] }
15
15
  futures = "0.3"
16
16
  image = "0.25.6"
17
17
  neon = { version = "1.0.0", default-features = false, features = [
package/README.md CHANGED
@@ -49,7 +49,7 @@ This command will download precompiled binaries for the following systems:
49
49
 
50
50
  ### Reader
51
51
 
52
- The `Reader` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests.
52
+ The `Reader` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
53
53
 
54
54
  ```javascript
55
55
  import { Reader } from '@contentauth/c2pa-node';
@@ -57,6 +57,15 @@ import { Reader } from '@contentauth/c2pa-node';
57
57
  // Read from an asset file
58
58
  const reader = await Reader.fromAsset(inputAsset);
59
59
 
60
+ // Read with custom settings
61
+ const settings = {
62
+ verify: {
63
+ verify_after_reading: false,
64
+ verify_trust: true
65
+ }
66
+ };
67
+ const reader = await Reader.fromAsset(inputAsset, settings);
68
+
60
69
  // Read from manifest data and asset
61
70
  const reader = await Reader.fromManifestDataAndAsset(manifestData, asset);
62
71
 
@@ -75,7 +84,7 @@ const remoteUrl = reader.remoteUrl();
75
84
 
76
85
  ### Builder
77
86
 
78
- The `Builder` class is the main component for creating and signing C2PA manifests. It provides methods to add assertions, resources, and ingredients to manifests, and handles the signing process. Use the `Signer` class to sign the manifests.
87
+ The `Builder` class is the main component for creating and signing C2PA manifests. It provides methods to add assertions, resources, and ingredients to manifests, and handles the signing process. Use the `Signer` class to sign the manifests. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
79
88
 
80
89
  ```javascript
81
90
  import { Builder } from '@contentauth/c2pa-node';
@@ -83,9 +92,20 @@ import { Builder } from '@contentauth/c2pa-node';
83
92
  // Create a new builder
84
93
  const builder = Builder.new();
85
94
 
95
+ // Create with custom settings
96
+ const settings = {
97
+ builder: {
98
+ generate_c2pa_archive: true
99
+ }
100
+ };
101
+ const builder = Builder.new(settings);
102
+
86
103
  // Or create from an existing manifest definition
87
104
  const builder = Builder.withJson(manifestDefinition);
88
105
 
106
+ // Or create with both manifest and settings
107
+ const builder = Builder.withJson(manifestDefinition, settings);
108
+
89
109
  // Add assertions to the manifest
90
110
  builder.addAssertion('c2pa.actions', actionsAssertion);
91
111
 
@@ -214,40 +234,116 @@ const decodedData = await trustmark.decode(imageBuffer);
214
234
 
215
235
  ### Settings and Configuration
216
236
 
217
- The library provides comprehensive settings management for trust configuration, verification settings, and global C2PA settings:
237
+ The library provides comprehensive settings management that can be configured per Reader/Builder instance or using helper functions. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
238
+
239
+ #### Per-Instance Settings
240
+
241
+ Settings can be passed directly to `Reader` and `Builder` constructors:
242
+
243
+ ```javascript
244
+ import { Reader, Builder } from '@contentauth/c2pa-node';
245
+
246
+ // Create settings object
247
+ const settings = {
248
+ verify: {
249
+ verify_after_reading: false,
250
+ verify_after_sign: false,
251
+ verify_trust: true,
252
+ ocsp_fetch: true
253
+ },
254
+ trust: {
255
+ verify_trust_list: true,
256
+ trust_anchors: "path/to/anchors.pem"
257
+ }
258
+ };
259
+
260
+ // Pass settings to Reader
261
+ const reader = await Reader.fromAsset(inputAsset, settings);
262
+
263
+ // Pass settings to Builder
264
+ const builder = Builder.new(settings);
265
+
266
+ // Settings can also be JSON strings
267
+ const settingsJson = JSON.stringify(settings);
268
+ const builder2 = Builder.new(settingsJson);
269
+ ```
270
+
271
+ #### Settings Helper Functions
272
+
273
+ The library provides helper functions to create and manage settings objects:
218
274
 
219
275
  ```javascript
220
276
  import {
221
- loadC2paSettings,
222
- loadTrustConfig,
223
- loadVerifyConfig,
277
+ createTrustSettings,
278
+ createCawgTrustSettings,
279
+ createVerifySettings,
280
+ mergeSettings,
281
+ settingsToJson,
224
282
  loadSettingsFromFile,
225
283
  loadSettingsFromUrl
226
284
  } from '@contentauth/c2pa-node';
227
285
 
228
- // Load settings from JSON string
229
- loadC2paSettings('{"trust": {"verify_trust_list": true}}');
230
-
231
- // Load settings from file
232
- await loadSettingsFromFile('./c2pa-settings.json');
233
-
234
- // Load settings from URL
235
- await loadSettingsFromUrl('https://example.com/c2pa-settings.json');
286
+ // Create trust settings
287
+ const trustSettings = createTrustSettings({
288
+ verifyTrustList: true,
289
+ userAnchors: "path/to/user-anchors.pem",
290
+ trustAnchors: "path/to/trust-anchors.pem",
291
+ allowedList: "path/to/allowed-list.pem"
292
+ });
236
293
 
237
- // Configure trust settings
238
- loadTrustConfig({
294
+ // Create CAWG trust settings
295
+ const cawgTrustSettings = createCawgTrustSettings({
239
296
  verifyTrustList: true,
240
- userAnchors: ['anchor1', 'anchor2'],
241
- trustAnchors: ['trust-anchor1'],
242
- allowedList: ['allowed-cert1']
297
+ trustAnchors: "path/to/cawg-anchors.pem"
243
298
  });
244
299
 
245
- // Configure verification settings
246
- loadVerifyConfig({
247
- verifyAfterReading: true,
248
- verifyAfterSign: true,
300
+ // Create verify settings
301
+ const verifySettings = createVerifySettings({
302
+ verifyAfterReading: false,
303
+ verifyAfterSign: false,
249
304
  verifyTrust: true,
305
+ verifyTimestampTrust: true,
250
306
  ocspFetch: true,
251
- remoteManifestFetch: true
307
+ remoteManifestFetch: true,
308
+ skipIngredientConflictResolution: false,
309
+ strictV1Validation: false
252
310
  });
311
+
312
+ // Merge multiple settings
313
+ const combinedSettings = mergeSettings(trustSettings, verifySettings);
314
+
315
+ // Convert settings to JSON string
316
+ const jsonString = settingsToJson(combinedSettings);
317
+
318
+ // Load settings from file (JSON or TOML)
319
+ const fileSettings = await loadSettingsFromFile('./c2pa-settings.toml');
320
+ const reader = await Reader.fromAsset(inputAsset, fileSettings);
321
+
322
+ // Load settings from URL
323
+ const urlSettings = await loadSettingsFromUrl('https://example.com/c2pa-settings.json');
324
+ const builder = Builder.new(urlSettings);
253
325
  ```
326
+
327
+ #### Available Settings
328
+
329
+ **Trust Settings:**
330
+ - `verifyTrustList` - Whether to verify against the trust list
331
+ - `userAnchors` - User-provided trust anchors (PEM format or path)
332
+ - `trustAnchors` - Trust anchors for validation (PEM format or path)
333
+ - `trustConfig` - Path to trust configuration file
334
+ - `allowedList` - Allowed list of certificates (PEM format or path)
335
+
336
+ **Verify Settings:**
337
+ - `verifyAfterReading` - Whether to verify after reading a manifest
338
+ - `verifyAfterSign` - Whether to verify after signing a manifest
339
+ - `verifyTrust` - Whether to verify trust during validation
340
+ - `verifyTimestampTrust` - Whether to verify timestamp trust
341
+ - `ocspFetch` - Whether to fetch OCSP responses
342
+ - `remoteManifestFetch` - Whether to fetch remote manifests
343
+ - `skipIngredientConflictResolution` - Whether to skip ingredient conflict resolution
344
+ - `strictV1Validation` - Whether to use strict v1 validation
345
+
346
+ **Builder Settings:**
347
+ - `generate_c2pa_archive` - Whether to generate C2PA archive format
348
+
349
+ **Note:** Settings are passed as per-instance configuration. There are no global settings that affect all Readers and Builders.
package/dist/Builder.js CHANGED
@@ -18,11 +18,16 @@ export class Builder {
18
18
  constructor(builder) {
19
19
  this.builder = builder;
20
20
  }
21
- static new() {
22
- const builder = getNeonBinary().builderNew();
21
+ static new(settings) {
22
+ const settingsStr = settings
23
+ ? typeof settings === "string"
24
+ ? settings
25
+ : JSON.stringify(settings)
26
+ : undefined;
27
+ const builder = getNeonBinary().builderNew(settingsStr);
23
28
  return new Builder(builder);
24
29
  }
25
- static withJson(json) {
30
+ static withJson(json, settings) {
26
31
  let jsonString;
27
32
  try {
28
33
  jsonString = JSON.stringify(json);
@@ -34,7 +39,12 @@ export class Builder {
34
39
  }
35
40
  throw new Error("Failed to stringify JSON Manifest Definition: Unknown error");
36
41
  }
37
- const builder = getNeonBinary().builderWithJson(jsonString);
42
+ const settingsStr = settings
43
+ ? typeof settings === "string"
44
+ ? settings
45
+ : JSON.stringify(settings)
46
+ : undefined;
47
+ const builder = getNeonBinary().builderWithJson(jsonString, settingsStr);
38
48
  return new Builder(builder);
39
49
  }
40
50
  setIntent(intent) {
@@ -78,9 +88,14 @@ export class Builder {
78
88
  return getNeonBinary().builderToArchive.call(this.builder, asset);
79
89
  });
80
90
  }
81
- static fromArchive(asset) {
91
+ static fromArchive(asset, settings) {
82
92
  return __awaiter(this, void 0, void 0, function* () {
83
- return new Builder(yield getNeonBinary().builderFromArchive(asset));
93
+ const settingsStr = settings
94
+ ? typeof settings === "string"
95
+ ? settings
96
+ : JSON.stringify(settings)
97
+ : undefined;
98
+ return new Builder(yield getNeonBinary().builderFromArchive(asset, settingsStr));
84
99
  });
85
100
  }
86
101
  sign(signer, input, output) {
@@ -19,7 +19,6 @@ import { isActionsAssertion } from "./assertions.js";
19
19
  import { CallbackSigner, LocalSigner } from "./Signer.js";
20
20
  import { Reader } from "./Reader.js";
21
21
  import { Builder } from "./Builder.js";
22
- import { loadC2paSettings, resetSettings } from "./Settings.js";
23
22
  const tempDir = path.join(__dirname, "tmp");
24
23
  class TestSigner {
25
24
  constructor(privateKey) {
@@ -253,51 +252,44 @@ describe("Builder", () => {
253
252
  expect(stats.size).toBeGreaterThan(0);
254
253
  }));
255
254
  it("should construct reader directly from builder archive buffer", () => __awaiter(void 0, void 0, void 0, function* () {
256
- // Enable c2pa archive format
257
- loadC2paSettings(JSON.stringify({
255
+ const settings = JSON.stringify({
258
256
  builder: {
259
257
  generate_c2pa_archive: true,
260
258
  },
261
259
  verify: {
262
260
  verify_after_reading: false,
263
261
  },
264
- }));
265
- try {
266
- // Create a builder
267
- const simpleManifestDefinition = {
268
- claim_generator_info: [
269
- {
270
- name: "c2pa_test",
271
- version: "1.0.0",
272
- },
273
- ],
274
- title: "Test_Manifest",
275
- format: "image/jpeg",
276
- assertions: [],
277
- resources: { resources: {} },
278
- };
279
- const testBuilder = Builder.withJson(simpleManifestDefinition);
280
- // Add an ingredient
281
- yield testBuilder.addIngredient(parent_json, source);
282
- // Create an archive from the builder written to a buffer
283
- const archive = {
284
- buffer: null,
285
- };
286
- yield testBuilder.toArchive(archive);
287
- // Verify buffer was populated
288
- expect(archive.buffer).not.toBeNull();
289
- expect(archive.buffer.length).toBeGreaterThan(0);
290
- // Construct a reader from the builder archive with mime-type "application/c2pa"
291
- const reader = yield Reader.fromAsset({
292
- buffer: archive.buffer,
293
- mimeType: "application/c2pa",
294
- });
295
- expect(reader).not.toBeNull();
296
- }
297
- finally {
298
- // Reset settings to defaults
299
- resetSettings();
300
- }
262
+ });
263
+ // Create a builder
264
+ const simpleManifestDefinition = {
265
+ claim_generator_info: [
266
+ {
267
+ name: "c2pa_test",
268
+ version: "1.0.0",
269
+ },
270
+ ],
271
+ title: "Test_Manifest",
272
+ format: "image/jpeg",
273
+ assertions: [],
274
+ resources: { resources: {} },
275
+ };
276
+ const testBuilder = Builder.withJson(simpleManifestDefinition, settings);
277
+ // Add an ingredient
278
+ yield testBuilder.addIngredient(parent_json, source);
279
+ // Create an archive from the builder written to a buffer
280
+ const archive = {
281
+ buffer: null,
282
+ };
283
+ yield testBuilder.toArchive(archive);
284
+ // Verify buffer was populated
285
+ expect(archive.buffer).not.toBeNull();
286
+ expect(archive.buffer.length).toBeGreaterThan(0);
287
+ // Construct a reader from the builder archive with mime-type "application/c2pa"
288
+ const reader = yield Reader.fromAsset({
289
+ buffer: archive.buffer,
290
+ mimeType: "application/c2pa",
291
+ }, settings);
292
+ expect(reader).not.toBeNull();
301
293
  }));
302
294
  it("should sign data with callback to file", () => __awaiter(void 0, void 0, void 0, function* () {
303
295
  const dest = {
package/dist/Reader.js CHANGED
@@ -31,15 +31,17 @@ export class Reader {
31
31
  return getNeonBinary().readerResourceToAsset.call(this.reader, uri, asset);
32
32
  });
33
33
  }
34
- static fromAsset(asset) {
34
+ static fromAsset(asset, settings) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- const reader = yield getNeonBinary().readerFromAsset(asset);
36
+ const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
37
+ const reader = yield getNeonBinary().readerFromAsset(asset, settingsStr);
37
38
  return reader ? new Reader(reader) : null;
38
39
  });
39
40
  }
40
- static fromManifestDataAndAsset(manifestData, asset) {
41
+ static fromManifestDataAndAsset(manifestData, asset, settings) {
41
42
  return __awaiter(this, void 0, void 0, function* () {
42
- const reader = yield getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset);
43
+ const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
44
+ const reader = yield getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset, settingsStr);
43
45
  return new Reader(reader);
44
46
  });
45
47
  }
package/dist/Settings.js CHANGED
@@ -19,190 +19,112 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
21
  import * as fs from "fs-extra";
22
- import path from "path";
23
22
  import fetch from "node-fetch";
24
- import { getNeonBinary } from "./binary.js";
25
23
  /**
26
- * Load settings from a JSON string and apply them globally.
27
- * @param json The JSON string containing the settings configuration
24
+ * Create a Settings object with trust configuration.
25
+ * @param trustConfig The trust configuration
26
+ * @returns Settings object that can be passed to Reader/Builder
28
27
  */
29
- export function loadC2paSettings(json) {
30
- getNeonBinary().loadSettings(json);
31
- }
32
- /**
33
- * Load settings from a TOML string and apply them globally.
34
- * @param toml The TOML string containing the settings configuration
35
- */
36
- export function loadC2paSettingsToml(toml) {
37
- getNeonBinary().loadSettingsToml(toml);
38
- }
39
- /**
40
- * Load settings from a TOML or JSON file path and apply them globally.
41
- * The file format is determined by the file extension (.toml for TOML, otherwise JSON).
42
- * @param filePath The path to the settings file
43
- */
44
- export function loadSettingsFromFile(filePath) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const ext = path.extname(filePath).toLowerCase();
47
- const content = yield fs.readFile(filePath, "utf8");
48
- if (ext === ".toml") {
49
- loadC2paSettingsToml(content);
50
- return;
51
- }
52
- // Assume JSON (or JSON5 that is valid JSON) otherwise
53
- // If needed, callers can ensure the content is valid JSON.
54
- loadC2paSettings(content);
55
- });
56
- }
57
- /**
58
- * Load settings from a URL and apply them globally.
59
- * The format is determined by the content-type header or file extension (.toml for TOML, otherwise JSON).
60
- * @param url The URL to fetch the settings from
61
- */
62
- export function loadSettingsFromUrl(url) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const res = yield fetch(url);
65
- if (!res.ok) {
66
- throw new Error(`Failed to fetch settings from URL: ${res.status} ${res.statusText}`);
67
- }
68
- const contentType = res.headers.get("content-type") || "";
69
- const text = yield res.text();
70
- const isToml = contentType.includes("toml") || url.toLowerCase().endsWith(".toml");
71
- if (isToml) {
72
- loadC2paSettingsToml(text);
73
- return;
74
- }
75
- // Treat as JSON by default
76
- loadC2paSettings(text);
77
- });
78
- }
79
- /**
80
- * Get the current settings as a JSON string.
81
- * @returns The JSON representation of the current settings
82
- */
83
- export function getSettingsJson() {
84
- return getNeonBinary().getSettingsJson();
85
- }
86
- /**
87
- * Load trust configuration into the main trust settings.
88
- * @param trustConfig The trust configuration object
89
- */
90
- export function loadTrustConfig(trustConfig) {
91
- var _a, _b, _c, _d;
92
- // Convert settings to snake_case for the neon Rust code.
93
- // Explicitly set undefined fields to null to ensure they are cleared
94
- const config = {
95
- verify_trust_list: trustConfig.verifyTrustList,
96
- user_anchors: (_a = trustConfig.userAnchors) !== null && _a !== void 0 ? _a : null,
97
- trust_anchors: (_b = trustConfig.trustAnchors) !== null && _b !== void 0 ? _b : null,
98
- trust_config: (_c = trustConfig.trustConfig) !== null && _c !== void 0 ? _c : null,
99
- allowed_list: (_d = trustConfig.allowedList) !== null && _d !== void 0 ? _d : null,
100
- };
101
- getNeonBinary().loadTrustConfig(JSON.stringify(config));
102
- }
103
- /**
104
- * Load trust configuration into the CAWG trust settings.
105
- * @param trustConfig The trust configuration object
106
- */
107
- export function loadCawgTrustConfig(trustConfig) {
108
- var _a, _b, _c, _d;
109
- // Convert settings to snake_case for the neon Rust code
110
- // Explicitly set undefined fields to null to ensure they are cleared
111
- const config = {
112
- verify_trust_list: trustConfig.verifyTrustList,
113
- user_anchors: (_a = trustConfig.userAnchors) !== null && _a !== void 0 ? _a : null,
114
- trust_anchors: (_b = trustConfig.trustAnchors) !== null && _b !== void 0 ? _b : null,
115
- trust_config: (_c = trustConfig.trustConfig) !== null && _c !== void 0 ? _c : null,
116
- allowed_list: (_d = trustConfig.allowedList) !== null && _d !== void 0 ? _d : null,
28
+ 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
+ },
117
37
  };
118
- getNeonBinary().loadCawgTrustConfig(JSON.stringify(config));
119
38
  }
120
39
  /**
121
- * Get the current trust configuration.
122
- * @returns The current trust configuration object
40
+ * Create a settings object with CAWG trust configuration.
41
+ * @param trustConfig The CAWG trust configuration
42
+ * @returns Settings object that can be passed to Reader/Builder
123
43
  */
124
- export function getTrustConfig() {
125
- var _a, _b, _c, _d;
126
- const json = getNeonBinary().getTrustConfig();
127
- const parsed = JSON.parse(json);
128
- // Convert snake_case to camelCase to match TrustConfig interface
129
- // Handle undefined values by converting them to null
44
+ export function createCawgTrustSettings(trustConfig) {
130
45
  return {
131
- verifyTrustList: parsed.verify_trust_list,
132
- userAnchors: (_a = parsed.user_anchors) !== null && _a !== void 0 ? _a : null,
133
- trustAnchors: (_b = parsed.trust_anchors) !== null && _b !== void 0 ? _b : null,
134
- trustConfig: (_c = parsed.trust_config) !== null && _c !== void 0 ? _c : null,
135
- allowedList: (_d = parsed.allowed_list) !== null && _d !== void 0 ? _d : null,
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
+ },
136
53
  };
137
54
  }
138
55
  /**
139
- * Get the current CAWG trust configuration.
140
- * @returns The current CAWG trust configuration object
56
+ * Create a settings object with verify configuration.
57
+ * @param verifyConfig The verify configuration
58
+ * @returns Settings object that can be passed to Reader/Builder
141
59
  */
142
- export function getCawgTrustConfig() {
143
- var _a, _b, _c, _d;
144
- const json = getNeonBinary().getCawgTrustConfig();
145
- const parsed = JSON.parse(json);
146
- // Convert snake_case to camelCase to match TrustConfig interface
147
- // Handle undefined values by converting them to null
60
+ export function createVerifySettings(verifyConfig) {
148
61
  return {
149
- verifyTrustList: parsed.verify_trust_list,
150
- userAnchors: (_a = parsed.user_anchors) !== null && _a !== void 0 ? _a : null,
151
- trustAnchors: (_b = parsed.trust_anchors) !== null && _b !== void 0 ? _b : null,
152
- trustConfig: (_c = parsed.trust_config) !== null && _c !== void 0 ? _c : null,
153
- allowedList: (_d = parsed.allowed_list) !== null && _d !== void 0 ? _d : null,
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
+ },
154
72
  };
155
73
  }
156
74
  /**
157
- * Load verify configuration into the verify settings.
158
- * @param verifyConfig The verify configuration object
75
+ * Merge multiple settings objects into one.
76
+ * Later settings override earlier ones.
77
+ * @param settings Settings objects to merge
78
+ * @returns Merged settings object
159
79
  */
160
- export function loadVerifyConfig(verifyConfig) {
161
- // Convert camelCase to snake_case for the neon Rust code
162
- const config = {
163
- verify_after_reading: verifyConfig.verifyAfterReading,
164
- verify_after_sign: verifyConfig.verifyAfterSign,
165
- verify_trust: verifyConfig.verifyTrust,
166
- verify_timestamp_trust: verifyConfig.verifyTimestampTrust,
167
- ocsp_fetch: verifyConfig.ocspFetch,
168
- remote_manifest_fetch: verifyConfig.remoteManifestFetch,
169
- skip_ingredient_conflict_resolution: verifyConfig.skipIngredientConflictResolution,
170
- strict_v1_validation: verifyConfig.strictV1Validation,
171
- };
172
- getNeonBinary().loadVerifyConfig(JSON.stringify(config));
80
+ export function mergeSettings(...settings) {
81
+ const merged = {};
82
+ for (const setting of settings) {
83
+ if (setting.trust) {
84
+ merged.trust = Object.assign(Object.assign({}, merged.trust), setting.trust);
85
+ }
86
+ if (setting.cawg_trust) {
87
+ merged.cawg_trust = Object.assign(Object.assign({}, merged.cawg_trust), setting.cawg_trust);
88
+ }
89
+ if (setting.verify) {
90
+ merged.verify = Object.assign(Object.assign({}, merged.verify), setting.verify);
91
+ }
92
+ if (setting.builder) {
93
+ merged.builder = Object.assign(Object.assign({}, merged.builder), setting.builder);
94
+ }
95
+ }
96
+ return merged;
173
97
  }
174
98
  /**
175
- * Patch the verify configuration with any subset of fields.
176
- * @param patch Partial verify config fields to update
99
+ * Convert a settings object to a JSON string.
100
+ * @param settings The settings object
101
+ * @returns JSON string representation
177
102
  */
178
- export function patchVerifyConfig(patch) {
179
- const current = getVerifyConfig();
180
- const updated = Object.assign(Object.assign({}, current), patch);
181
- loadVerifyConfig(updated);
103
+ export function settingsToJson(settings) {
104
+ return JSON.stringify(settings);
182
105
  }
183
106
  /**
184
- * Get the current verify configuration.
185
- * @returns The current verify configuration object
107
+ * Load settings from a TOML or JSON file.
108
+ * @param filePath The path to the settings file
109
+ * @returns Settings as a string (TOML or JSON depending on file extension)
186
110
  */
187
- export function getVerifyConfig() {
188
- const json = getNeonBinary().getVerifyConfig();
189
- const parsed = JSON.parse(json);
190
- // Convert snake_case to camelCase to match VerifyConfig interface
191
- return {
192
- verifyAfterReading: parsed.verify_after_reading,
193
- verifyAfterSign: parsed.verify_after_sign,
194
- verifyTrust: parsed.verify_trust,
195
- verifyTimestampTrust: parsed.verify_timestamp_trust,
196
- ocspFetch: parsed.ocsp_fetch,
197
- remoteManifestFetch: parsed.remote_manifest_fetch,
198
- skipIngredientConflictResolution: parsed.skip_ingredient_conflict_resolution,
199
- strictV1Validation: parsed.strict_v1_validation,
200
- };
111
+ export function loadSettingsFromFile(filePath) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const content = yield fs.readFile(filePath, "utf8");
114
+ return content;
115
+ });
201
116
  }
202
117
  /**
203
- * Reset settings to their default values.
204
- * This clears any custom settings and restores the default configuration.
118
+ * Load settings from a URL.
119
+ * @param url The URL to fetch the settings from
120
+ * @returns Settings as a string
205
121
  */
206
- export function resetSettings() {
207
- getNeonBinary().resetSettings();
122
+ export function loadSettingsFromUrl(url) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ const res = yield fetch(url);
125
+ if (!res.ok) {
126
+ throw new Error(`Failed to fetch settings from URL: ${res.status} ${res.statusText}`);
127
+ }
128
+ return yield res.text();
129
+ });
208
130
  }