@contentauth/c2pa-node 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@
15
15
  import { Buffer } from "buffer";
16
16
  import type {
17
17
  BuilderIntent,
18
+ Ingredient,
18
19
  Manifest,
19
20
  ManifestStore,
20
21
  } from "@contentauth/c2pa-types";
@@ -110,7 +111,7 @@ export interface LocalSignerInterface {
110
111
  certs(): Array<Buffer>;
111
112
  reserveSize(): number;
112
113
  timeAuthorityUrl(): string | undefined;
113
- signer(): NeonLocalSignerHandle;
114
+ getHandle(): NeonLocalSignerHandle;
114
115
  }
115
116
 
116
117
  /**
@@ -123,14 +124,14 @@ export interface CallbackSignerInterface {
123
124
  reserveSize(): number;
124
125
  timeAuthorityUrl(): string | undefined;
125
126
  directCoseHandling(): boolean;
126
- signer(): NeonCallbackSignerHandle;
127
+ getHandle(): NeonCallbackSignerHandle;
127
128
  }
128
129
 
129
130
  export interface CallbackCredentialHolderInterface {
130
131
  sigType(): string;
131
132
  reserveSize(): number;
132
133
  sign(payload: SignerPayload): Promise<Buffer>;
133
- signer(): NeonCallbackCredentialHolderHandle;
134
+ getHandle(): NeonCallbackCredentialHolderHandle;
134
135
  }
135
136
 
136
137
  /**
@@ -176,17 +177,37 @@ export interface HashedUri {
176
177
  }
177
178
 
178
179
  export interface BuilderInterface {
180
+ /** An intent lets the API know what kind of manifest to create.
181
+ * Intents are `Create`, `Edit`, or `Update`.
182
+ * This allows the API to check that you are doing the right thing.
183
+ * It can also do things for you, like add parent ingredients from the source asset
184
+ * and automatically add required c2pa.created or c2pa.opened actions.
185
+ * Create requires a `DigitalSourceType`. It is used for assets without a parent ingredient.
186
+ * Edit requires a parent ingredient and is used for most assets that are being edited.
187
+ * Update is a special case with many restrictions but is more compact than Edit.
188
+ * @param intent The intent of the manifest
189
+ */
179
190
  setIntent(intent: BuilderIntent): void;
191
+
180
192
  /**
181
193
  * Set the no embed flag of the manifest
182
194
  * @param noEmbed The no embed flag of the manifest
183
195
  */
184
196
  setNoEmbed(noEmbed: boolean): void;
197
+
185
198
  /**
186
199
  * Set the remote URL of the manifest
187
200
  * @param url The remote URL of the manifest
188
201
  */
189
202
  setRemoteUrl(url: string): void;
203
+
204
+ /**
205
+ * Add a single action to the manifest.
206
+ * This is a convenience method for adding an action to the `Actions` assertion.
207
+ * @param actionJson The JSON representation of the action
208
+ */
209
+ addAction(actionJson: string): void;
210
+
190
211
  /**
191
212
  * Add CBOR assertion to the builder
192
213
  * @param label The label of the assertion
@@ -206,11 +227,20 @@ export interface BuilderInterface {
206
227
  addResource(uri: string, resource: SourceAsset): Promise<void>;
207
228
 
208
229
  /**
209
- * Add an ingredient from a buffer or file
230
+ * Add an ingredient to the manifest
210
231
  * @param ingredientJson The JSON representation of the ingredient
211
- * @param ingredient The source and format of the ingredient
232
+ * @param ingredient Optional source asset (buffer or file) for the ingredient
233
+ */
234
+ addIngredient(
235
+ ingredientJson: string,
236
+ ingredient?: SourceAsset,
237
+ ): Promise<void>;
238
+
239
+ /**
240
+ * Add an ingredient to the manifest from a Reader
241
+ * @param reader The Reader object of the ingredient
212
242
  */
213
- addIngredient(ingredientJson: string, ingredient: SourceAsset): Promise<void>;
243
+ addIngredientFromReader(reader: ReaderInterface): Ingredient;
214
244
 
215
245
  /**
216
246
  * Convert the Builder into a archive formatted buffer or file
@@ -311,9 +341,9 @@ export interface ReaderInterface {
311
341
  resourceToAsset(uri: string, output: DestinationAsset): Promise<number>;
312
342
 
313
343
  /**
314
- * Run CAWG validation
344
+ * Get the internal handle for use with Neon bindings
315
345
  */
316
- postValidateCawg(): Promise<void>;
346
+ getHandle(): NeonReaderHandle;
317
347
  }
318
348
 
319
349
  export interface IdentityAssertionSignerInterface {
@@ -327,7 +357,7 @@ export interface IdentityAssertionSignerInterface {
327
357
  identityAssertionBuilder: IdentityAssertionBuilderInterface,
328
358
  ): void;
329
359
 
330
- signer(): NeonIdentityAssertionSignerHandle;
360
+ getHandle(): NeonIdentityAssertionSignerHandle;
331
361
  }
332
362
 
333
363
  export interface IdentityAssertionBuilderInterface {
@@ -408,8 +438,6 @@ export interface VerifyConfig {
408
438
  ocspFetch: boolean;
409
439
  /** Whether to fetch remote manifests */
410
440
  remoteManifestFetch: boolean;
411
- /** Whether to check ingredient trust */
412
- checkIngredientTrust: boolean;
413
441
  /** Whether to skip ingredient conflict resolution */
414
442
  skipIngredientConflictResolution: boolean;
415
443
  /** 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.1",
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,14 @@ 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
+ )?;
58
+ cx.export_function(
59
+ "builderAddIngredientFromReader",
60
+ neon_builder::NeonBuilder::add_ingredient_from_reader,
61
+ )?;
53
62
  cx.export_function("builderToArchive", neon_builder::NeonBuilder::to_archive)?;
54
63
  cx.export_function(
55
64
  "builderFromArchive",
@@ -92,10 +101,6 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
92
101
  "readerResourceToAsset",
93
102
  neon_reader::NeonReader::resource_to_asset,
94
103
  )?;
95
- cx.export_function(
96
- "readerPostValidateCawg",
97
- neon_reader::NeonReader::post_validate_cawg,
98
- )?;
99
104
 
100
105
  // Signers
101
106
  cx.export_function("localSignerNew", neon_signer::NeonLocalSigner::new)?;
@@ -186,5 +191,8 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
186
191
  cx.export_function("loadVerifyConfig", settings::load_verify_config)?;
187
192
  cx.export_function("getVerifyConfig", settings::get_verify_config)?;
188
193
 
194
+ // Reset Settings
195
+ cx.export_function("resetSettings", settings::reset_settings)?;
196
+
189
197
  Ok(())
190
198
  }
@@ -14,9 +14,10 @@
14
14
  use crate::asset::parse_asset;
15
15
  use crate::error::{as_js_error, Error};
16
16
  use crate::neon_identity_assertion_signer::NeonIdentityAssertionSigner;
17
+ use crate::neon_reader::NeonReader;
17
18
  use crate::neon_signer::{CallbackSignerConfig, NeonCallbackSigner, NeonLocalSigner};
18
19
  use crate::runtime::runtime;
19
- use c2pa::{Builder, BuilderIntent};
20
+ use c2pa::{Builder, BuilderIntent, Ingredient};
20
21
  use neon::prelude::*;
21
22
  use neon_serde4;
22
23
  use serde::{Deserialize, Serialize};
@@ -88,6 +89,19 @@ impl NeonBuilder {
88
89
  Ok(cx.undefined())
89
90
  }
90
91
 
92
+ pub fn add_action(mut cx: FunctionContext) -> JsResult<JsUndefined> {
93
+ let rt = runtime();
94
+ let this = cx.this::<JsBox<Self>>()?;
95
+ let action_json = cx.argument::<JsString>(0)?.value(&mut cx);
96
+ let action: c2pa::assertions::Action =
97
+ serde_json::from_str(&action_json).or_else(|err| cx.throw_error(err.to_string()))?;
98
+ let mut builder = rt.block_on(async { this.builder.lock().await });
99
+ builder
100
+ .add_action(action)
101
+ .or_else(|err| cx.throw_error(err.to_string()))?;
102
+ Ok(cx.undefined())
103
+ }
104
+
91
105
  pub fn add_assertion(mut cx: FunctionContext) -> JsResult<JsUndefined> {
92
106
  let rt = runtime();
93
107
  let this = cx.this::<JsBox<Self>>()?;
@@ -123,7 +137,6 @@ impl NeonBuilder {
123
137
  }
124
138
 
125
139
  pub fn add_resource(mut cx: FunctionContext) -> JsResult<JsPromise> {
126
- let rt = runtime();
127
140
  let this = cx.this::<JsBox<Self>>()?;
128
141
  let uri = cx.argument::<JsString>(0)?.value(&mut cx);
129
142
  let resource = cx
@@ -131,27 +144,37 @@ impl NeonBuilder {
131
144
  .and_then(|obj| parse_asset(&mut cx, obj))?;
132
145
  let builder = Arc::clone(&this.builder);
133
146
 
134
- let channel = cx.channel();
135
- let (deferred, promise) = cx.promise();
136
-
137
- rt.spawn(async move {
138
- let mut builder = builder.lock().await;
139
-
140
- let result = resource.into_read_stream().and_then(|mut resource_stream| {
141
- builder.add_resource(&uri, &mut resource_stream)?;
142
- Ok(())
143
- });
147
+ let promise = cx
148
+ .task(move || {
149
+ // Block on acquiring the async mutex lock
150
+ let rt = runtime();
151
+ let mut builder = rt.block_on(async { builder.lock().await });
144
152
 
145
- deferred.settle_with(&channel, |mut cx| match result {
153
+ resource.into_read_stream().and_then(|mut resource_stream| {
154
+ builder.add_resource(&uri, &mut resource_stream)?;
155
+ Ok(())
156
+ })
157
+ })
158
+ .promise(move |mut cx, result: Result<(), Error>| match result {
146
159
  Ok(_) => Ok(cx.undefined()),
147
160
  Err(err) => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
148
161
  });
149
- });
150
162
 
151
163
  Ok(promise)
152
164
  }
165
+ pub fn add_ingredient(mut cx: FunctionContext) -> JsResult<JsUndefined> {
166
+ let rt = runtime();
167
+ let this = cx.this::<JsBox<Self>>()?;
168
+ let ingredient_json = cx.argument::<JsString>(0)?.value(&mut cx);
169
+ let ingredient = Ingredient::from_json(&ingredient_json)
170
+ .or_else(|err| cx.throw_error(err.to_string()))?;
171
+
172
+ let mut builder = rt.block_on(async { this.builder.lock().await });
173
+ builder.add_ingredient(ingredient);
174
+ Ok(cx.undefined())
175
+ }
153
176
 
154
- pub fn add_ingredient(mut cx: FunctionContext) -> JsResult<JsPromise> {
177
+ pub fn add_ingredient_from_asset(mut cx: FunctionContext) -> JsResult<JsPromise> {
155
178
  let rt = runtime();
156
179
  let this = cx.this::<JsBox<Self>>()?;
157
180
  let ingredient_json = cx.argument::<JsString>(0)?.value(&mut cx);
@@ -167,18 +190,24 @@ impl NeonBuilder {
167
190
  rt.spawn(async move {
168
191
  let mut builder = builder.lock().await;
169
192
 
170
- let result = ingredient
171
- .mime_type()
172
- .ok_or_else(|| Error::Signing("Ingredient asset must have a mime type".to_string()))
173
- .and_then(|format| {
174
- let mut ingredient_stream = ingredient.into_read_stream()?;
175
- builder.add_ingredient_from_stream(
193
+ let result = async {
194
+ let format = ingredient
195
+ .mime_type()
196
+ .ok_or_else(|| {
197
+ Error::Signing("Ingredient asset must have a mime type".to_string())
198
+ })?
199
+ .to_owned();
200
+ let mut ingredient_stream = ingredient.into_read_stream()?;
201
+ builder
202
+ .add_ingredient_from_stream_async(
176
203
  &ingredient_json,
177
204
  &format,
178
205
  &mut ingredient_stream,
179
- )?;
180
- Ok(())
181
- });
206
+ )
207
+ .await?;
208
+ Ok(())
209
+ }
210
+ .await;
182
211
 
183
212
  deferred.settle_with(&channel, move |mut cx| match result {
184
213
  Ok(_) => Ok(cx.undefined()),
@@ -189,54 +218,63 @@ impl NeonBuilder {
189
218
  Ok(promise)
190
219
  }
191
220
 
192
- pub fn to_archive(mut cx: FunctionContext) -> JsResult<JsPromise> {
221
+ pub fn add_ingredient_from_reader(mut cx: FunctionContext) -> JsResult<JsString> {
193
222
  let rt = runtime();
223
+ let this = cx.this::<JsBox<Self>>()?;
224
+ let reader = cx.argument::<JsBox<NeonReader>>(0)?.reader();
225
+
226
+ let mut builder = rt.block_on(async { this.builder.lock().await });
227
+ let reader = rt.block_on(async { reader.lock().await });
228
+ let ingredient = builder
229
+ .add_ingredient_from_reader(&reader)
230
+ .or_else(|err| cx.throw_error(err.to_string()))?;
231
+ let json =
232
+ serde_json::to_string(&ingredient).or_else(|err| cx.throw_error(err.to_string()))?;
233
+ Ok(cx.string(json))
234
+ }
235
+
236
+ pub fn to_archive(mut cx: FunctionContext) -> JsResult<JsPromise> {
194
237
  let this = cx.this::<JsBox<Self>>()?;
195
238
  let dest = cx
196
239
  .argument::<JsObject>(0)
197
240
  .and_then(|obj| parse_asset(&mut cx, obj))?;
198
241
  let builder = Arc::clone(&this.builder);
199
242
 
200
- let channel = cx.channel();
201
- let (deferred, promise) = cx.promise();
202
-
203
- rt.spawn(async move {
204
- let mut builder = builder.lock().await;
205
- let result = dest.write_stream().and_then(|dest_stream| {
206
- builder.to_archive(dest_stream)?;
207
- Ok(())
208
- });
243
+ let promise = cx
244
+ .task(move || {
245
+ // Block on acquiring the async mutex lock
246
+ let rt = runtime();
247
+ let mut builder = rt.block_on(async { builder.lock().await });
209
248
 
210
- deferred.settle_with(&channel, move |mut cx| match result {
249
+ dest.write_stream().and_then(|dest_stream| {
250
+ builder.to_archive(dest_stream)?;
251
+ Ok(())
252
+ })
253
+ })
254
+ .promise(move |mut cx, result: Result<(), Error>| match result {
211
255
  Ok(_) => Ok(cx.undefined()),
212
256
  Err(err) => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
213
257
  });
214
- });
215
258
  Ok(promise)
216
259
  }
217
260
 
218
261
  pub fn from_archive(mut cx: FunctionContext) -> JsResult<JsPromise> {
219
- let rt = runtime();
220
262
  let source = cx
221
263
  .argument::<JsObject>(0)
222
264
  .and_then(|obj| parse_asset(&mut cx, obj))?;
223
265
 
224
- let channel = cx.channel();
225
- let (deferred, promise) = cx.promise();
226
-
227
- rt.spawn(async move {
228
- let result = source.into_read_stream().and_then(|source_stream| {
266
+ let promise = cx
267
+ .task(move || {
268
+ let source_stream = source.into_read_stream()?;
229
269
  let builder = Builder::from_archive(source_stream)?;
230
270
  Ok(builder)
231
- });
232
-
233
- deferred.settle_with(&channel, move |mut cx| match result {
271
+ })
272
+ .promise(move |mut cx, result: Result<Builder, Error>| match result {
234
273
  Ok(builder) => Ok(cx.boxed(Self {
235
274
  builder: Arc::new(Mutex::new(builder)),
236
275
  })),
237
276
  Err(err) => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
238
277
  });
239
- });
240
278
  Ok(promise)
241
279
  }
242
280
 
@@ -12,9 +12,9 @@
12
12
  // each license.
13
13
 
14
14
  use crate::asset::parse_asset;
15
- use crate::error::{as_js_error, Error};
15
+ use crate::error::{as_js_error, Error, Result};
16
16
  use crate::runtime::runtime;
17
- use c2pa::{identity::validator::CawgValidator, Reader};
17
+ use c2pa::Reader;
18
18
  use neon::prelude::*;
19
19
  use neon::types::buffer::TypedArray;
20
20
  use std::sync::Arc;
@@ -34,56 +34,84 @@ impl NeonReader {
34
34
  }))
35
35
  }
36
36
 
37
+ #[allow(clippy::borrowed_box)]
38
+ pub(crate) fn reader(&self) -> Arc<Mutex<Reader>> {
39
+ Arc::clone(&self.reader)
40
+ }
41
+
37
42
  pub fn from_stream(mut cx: FunctionContext) -> JsResult<JsPromise> {
43
+ let rt = runtime();
44
+ let channel = cx.channel();
38
45
  let source = cx
39
46
  .argument::<JsObject>(0)
40
47
  .and_then(|obj| parse_asset(&mut cx, obj))?;
41
48
 
42
- let promise = cx
43
- .task(move || {
49
+ let (deferred, promise) = cx.promise();
50
+ rt.spawn(async move {
51
+ let result: Result<Reader> = async {
44
52
  let format = source
45
53
  .mime_type()
46
54
  .ok_or_else(|| {
47
55
  Error::Signing("Ingredient asset must have a mime type".to_string())
48
56
  })?
49
57
  .to_owned();
58
+
50
59
  let stream = source.into_read_stream()?;
51
- let reader = Reader::from_stream(&format, stream)?;
60
+ let reader = Reader::from_stream_async(&format, stream).await?;
52
61
  Ok(reader)
53
- })
54
- .promise(move |mut cx, result: Result<Reader, Error>| match result {
62
+ }
63
+ .await;
64
+
65
+ deferred.settle_with(&channel, move |mut cx| match result {
55
66
  Ok(reader) => {
56
67
  let boxed_reader = cx.boxed(Self {
57
68
  reader: Arc::new(Mutex::new(reader)),
58
69
  });
59
70
  Ok(boxed_reader.upcast::<JsValue>())
60
71
  }
61
- Err(err) => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
72
+ Err(err) => {
73
+ // Check if the error is due to missing C2PA data
74
+ // Return null instead of throwing for these specific cases
75
+ match &err {
76
+ Error::C2pa(c2pa_err) => match c2pa_err {
77
+ c2pa::Error::JumbfNotFound => Ok(cx.null().upcast::<JsValue>()),
78
+ _ => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
79
+ },
80
+ _ => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
81
+ }
82
+ }
62
83
  });
84
+ });
63
85
  Ok(promise)
64
86
  }
65
87
 
66
88
  pub fn from_manifest_data_and_asset(mut cx: FunctionContext) -> JsResult<JsPromise> {
89
+ let rt = runtime();
90
+ let channel = cx.channel();
67
91
  let manifest_data = cx.argument::<JsBuffer>(0)?;
68
92
  let asset = cx
69
93
  .argument::<JsObject>(1)
70
94
  .and_then(|obj| parse_asset(&mut cx, obj))?;
71
95
 
72
96
  let c2pa_data = manifest_data.as_slice(&cx).to_vec();
73
- let promise = cx
74
- .task(move || {
97
+ let (deferred, promise) = cx.promise();
98
+ rt.spawn(async move {
99
+ let result = async {
75
100
  let format = asset
76
101
  .mime_type()
77
102
  .ok_or_else(|| {
78
103
  Error::Signing("Ingredient asset must have a mime type".to_string())
79
104
  })?
80
105
  .to_owned();
81
- let mut stream = asset.into_read_stream()?;
106
+ let stream = asset.into_read_stream()?;
82
107
  let reader =
83
- Reader::from_manifest_data_and_stream(&c2pa_data, &format, &mut stream)?;
108
+ Reader::from_manifest_data_and_stream_async(&c2pa_data, &format, stream)
109
+ .await?;
84
110
  Ok(reader)
85
- })
86
- .promise(move |mut cx, result: Result<Reader, Error>| match result {
111
+ }
112
+ .await;
113
+
114
+ deferred.settle_with(&channel, move |mut cx| match result {
87
115
  Ok(reader) => {
88
116
  let boxed_reader = cx.boxed(Self {
89
117
  reader: Arc::new(Mutex::new(reader)),
@@ -92,7 +120,7 @@ impl NeonReader {
92
120
  }
93
121
  Err(err) => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
94
122
  });
95
-
123
+ });
96
124
  Ok(promise)
97
125
  }
98
126
 
@@ -170,28 +198,4 @@ impl NeonReader {
170
198
  });
171
199
  Ok(promise)
172
200
  }
173
-
174
- pub fn post_validate_cawg(mut cx: FunctionContext) -> JsResult<JsPromise> {
175
- let rt = runtime();
176
- let this = cx.this::<JsBox<Self>>()?;
177
- let reader = Arc::clone(&this.reader);
178
-
179
- let channel = cx.channel();
180
- let (deferred, promise) = cx.promise();
181
-
182
- rt.spawn(async move {
183
- let result = reader
184
- .lock()
185
- .await
186
- .post_validate_async(&CawgValidator {})
187
- .await
188
- .map_err(Error::from);
189
-
190
- deferred.settle_with(&channel, move |mut cx| match result {
191
- Ok(_) => Ok(cx.undefined()),
192
- Err(err) => as_js_error(&mut cx, err).and_then(|err| cx.throw(err)),
193
- });
194
- });
195
- Ok(promise)
196
- }
197
201
  }
package/src/settings.rs CHANGED
@@ -356,7 +356,6 @@ pub fn load_verify_config(mut cx: FunctionContext) -> JsResult<JsUndefined> {
356
356
  "verify_timestamp_trust": true,
357
357
  "ocsp_fetch": false,
358
358
  "remote_manifest_fetch": true,
359
- "check_ingredient_trust": true,
360
359
  "skip_ingredient_conflict_resolution": false,
361
360
  "strict_v1_validation": false
362
361
  },
@@ -399,11 +398,11 @@ pub fn load_verify_config(mut cx: FunctionContext) -> JsResult<JsUndefined> {
399
398
  if let Some(val) = verify_config.get("remote_manifest_fetch") {
400
399
  obj.insert("remote_manifest_fetch".to_string(), val.clone());
401
400
  }
402
- if let Some(val) = verify_config.get("check_ingredient_trust") {
403
- obj.insert("check_ingredient_trust".to_string(), val.clone());
404
- }
405
401
  if let Some(val) = verify_config.get("skip_ingredient_conflict_resolution") {
406
- obj.insert("skip_ingredient_conflict_resolution".to_string(), val.clone());
402
+ obj.insert(
403
+ "skip_ingredient_conflict_resolution".to_string(),
404
+ val.clone(),
405
+ );
407
406
  }
408
407
  if let Some(val) = verify_config.get("strict_v1_validation") {
409
408
  obj.insert("strict_v1_validation".to_string(), val.clone());
@@ -454,7 +453,6 @@ pub fn get_verify_config(mut cx: FunctionContext) -> JsResult<JsValue> {
454
453
  "verify_timestamp_trust": true,
455
454
  "ocsp_fetch": false,
456
455
  "remote_manifest_fetch": true,
457
- "check_ingredient_trust": true,
458
456
  "skip_ingredient_conflict_resolution": false,
459
457
  "strict_v1_validation": false
460
458
  });
@@ -477,7 +475,6 @@ pub fn get_verify_config(mut cx: FunctionContext) -> JsResult<JsValue> {
477
475
  "verify_timestamp_trust": true,
478
476
  "ocsp_fetch": false,
479
477
  "remote_manifest_fetch": true,
480
- "check_ingredient_trust": true,
481
478
  "skip_ingredient_conflict_resolution": false,
482
479
  "strict_v1_validation": false
483
480
  });
@@ -485,3 +482,23 @@ pub fn get_verify_config(mut cx: FunctionContext) -> JsResult<JsValue> {
485
482
  }
486
483
  }
487
484
  }
485
+
486
+ /// Reset settings to their default values.
487
+ /// This replicates the private reset() function from c2pa-rs Settings.
488
+ pub fn reset_settings(mut cx: FunctionContext) -> JsResult<JsUndefined> {
489
+ // Create default settings and get their TOML representation
490
+ let default_settings = Settings::default();
491
+ let default_toml = toml::to_string(&default_settings)
492
+ .or_else(|e| cx.throw_error(format!("Failed to serialize default settings: {}", e)))?;
493
+
494
+ // Apply the default settings
495
+ match Settings::from_toml(&default_toml) {
496
+ Ok(_) => {
497
+ // Store the default TOML for worker threads
498
+ set_global_settings_toml(Some(default_toml));
499
+ reload_runtime();
500
+ Ok(cx.undefined())
501
+ }
502
+ Err(e) => cx.throw_error(format!("Failed to apply default settings: {}", e)),
503
+ }
504
+ }